-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathutils.hpp
More file actions
66 lines (52 loc) · 1.47 KB
/
utils.hpp
File metadata and controls
66 lines (52 loc) · 1.47 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include <napi.h>
// stl
#include <string>
#include <memory>
// core types
#include <mapnik/unicode.hpp>
#include <mapnik/value/types.hpp>
#include <mapnik/value.hpp>
#include <mapnik/version.hpp>
#include <mapnik/params.hpp>
namespace node_mapnik {
using value_integer = mapnik::value_integer;
// adapted to work for both mapnik features and mapnik parameters
struct value_converter
{
explicit value_converter(Napi::Env env)
: env_(env) {}
Napi::Value operator()(value_integer val) const
{
return Napi::Number::New(env_, val);
}
Napi::Value operator()(mapnik::value_bool val) const
{
return Napi::Boolean::New(env_, val);
}
Napi::Value operator()(double val) const
{
return Napi::Number::New(env_, val);
}
Napi::Value operator()(std::string const& val) const
{
return Napi::String::New(env_, val.c_str());
}
Napi::Value operator()(mapnik::value_unicode_string const& val) const
{
std::string buffer;
mapnik::to_utf8(val, buffer);
return Napi::String::New(env_, buffer.c_str());
}
Napi::Value operator()(mapnik::value_null const&) const
{
return env_.Null();
}
private:
Napi::Env env_;
};
inline void params_to_object(Napi::Env env, Napi::Object& params, std::string const& key, mapnik::value_holder const& val)
{
params.Set(key, mapnik::util::apply_visitor(value_converter(env), val));
}
} // namespace node_mapnik