-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvariable.h
More file actions
87 lines (82 loc) · 1.89 KB
/
Copy pathvariable.h
File metadata and controls
87 lines (82 loc) · 1.89 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include <variant>
#include <map>
#include <yaml-cpp/yaml.h>
#include "logs.h"
namespace shelllet {
enum Columns {
Name,
Type,
Value,
Ref, // ref count
Desc,
Count
};
struct Var {
std::string name;
std::string type;
std::string value; // js data types[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures]
std::int32_t ref;
std::string desc;
static inline std::map<Columns, std::string> keys = { {Name, "name"}, {Type, "type"}, {Value, "value"}, {Ref, "ref"}, {Desc, "desc"} };
};
}
namespace YAML {
using namespace shelllet;
template<>
struct convert<Var> {
static Node encode(const Var& rhs) {
Node node;
node[Var::keys[Name]] = rhs.name;
node[Var::keys[Type]] = rhs.type;
node[Var::keys[Columns::Value]] = rhs.value;
node[Var::keys[Ref]] = rhs.ref;
node[Var::keys[Desc]] = rhs.desc;
return node;
}
static bool decode(const Node& node, Var& rhs) {
try
{
rhs.name = node[Var::keys[Name]].as<std::string>();
}
catch (const std::exception& err)
{
LOG_FATAL("rpa") << "# parse variables error: " << err.what();
}
try
{
rhs.type = node[Var::keys[Type]].as<std::string>();
}
catch (const std::exception& err)
{
LOG_FATAL("rpa") << "# parse variables error: " << err.what();
}
try
{
rhs.value = node[Var::keys[Columns::Value]].as<std::string>();
}
catch (const std::exception& err)
{
LOG_FATAL("rpa") << "# parse variables error: " << err.what();
}
try
{
rhs.ref = node[Var::keys[Ref]].as<std::int32_t>();
}
catch (const std::exception& err)
{
rhs.ref = 0;
LOG_FATAL("rpa") << "# parse variables error: " << err.what();
}
try
{
rhs.desc = node[Var::keys[Desc]].as<std::string>();
}
catch (const std::exception& err)
{
LOG_FATAL("rpa") << "# parse variables error: " << err.what();
}
return true;
}
};
}