-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathobject_to_container.hpp
More file actions
40 lines (37 loc) · 1.14 KB
/
object_to_container.hpp
File metadata and controls
40 lines (37 loc) · 1.14 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
#pragma once
#include <mapnik/version.hpp>
#include <mapnik/attribute.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/value/types.hpp>
static inline void object_to_container(mapnik::attributes& cont, Napi::Object const& vars)
{
Napi::Array names = vars.GetPropertyNames();
std::size_t length = names.Length();
mapnik::transcoder tr("utf8");
cont.reserve(length);
for (std::size_t i = 0; i < length; ++i)
{
std::string name = names.Get(i).ToString();
Napi::Value value = vars.Get(name);
if (value.IsBoolean())
{
cont[name] = value.As<Napi::Boolean>().Value();
}
else if (value.IsString())
{
cont[name] = tr.transcode(value.As<Napi::String>().Utf8Value().c_str());
}
else if (value.IsNumber())
{
mapnik::value_double num = value.As<Napi::Number>().DoubleValue();
if (num == value.As<Napi::Number>().Int32Value())
{
cont[name] = static_cast<mapnik::value_integer>(num);
}
else
{
cont[name] = num;
}
}
}
}