-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdal-private.cpp
52 lines (41 loc) · 967 Bytes
/
gdal-private.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "infra/gdal-private.h"
#include "infra/exception.h"
namespace inf::gdal {
using namespace inf;
int throw_if_not_supported(int result)
{
if (result == CPLE_NotSupported) {
throw RuntimeError("Operation not supported");
}
return result;
}
void throw_last_error(std::string_view msg)
{
auto* errorMsg = CPLGetLastErrorMsg();
if (errorMsg != nullptr && strlen(errorMsg) > 0) {
throw RuntimeError("{}: {}", msg, errorMsg);
} else {
throw RuntimeError(msg);
}
}
void check_error(CPLErr err, std::string_view msg)
{
if (err != CE_None) {
throw_last_error(msg);
}
}
void check_error(OGRErr err, std::string_view msg)
{
if (err != OGRERR_NONE) {
throw_last_error(msg);
}
}
CPLStringList create_string_list(std::span<const std::string> options)
{
CPLStringList result;
for (auto& opt : options) {
result.AddString(opt.c_str());
}
return result;
}
}