4cc0682f69e5e2d50317bd43731eae7facdad2a4
[src/low-level-can-generator.git] / src / openxc / command.cpp
1 #include "command.hpp"\r
2 \r
3 namespace openxc\r
4 {\r
5         std::string command::name() const\r
6         {\r
7                 return name_;\r
8         }\r
9         \r
10         bool command::enabled() const\r
11         {\r
12                 return enabled_;\r
13         }\r
14         \r
15         std::string command::handler() const\r
16         {\r
17                 return handler_;\r
18         }\r
19         \r
20         void command::from_json(const nlohmann::json& j)\r
21         {\r
22                 name_ = j.count("name") ? j["name"].get<std::string>() : "";\r
23                 enabled_ = j.count("enabled") ? j["enabled"].get<bool>() : true;\r
24                 handler_ = j.count("handler") ? j["handler"].get<std::string>() : "";\r
25         }\r
26 \r
27         nlohmann::json command::to_json() const\r
28         {\r
29                 nlohmann::json j;\r
30                 j["name"] = name_;\r
31                 j["enabled"] = enabled_;\r
32                 j["handler"] = handler_;\r
33                 return j;\r
34         }\r
35 \r
36         void to_json(nlohmann::json& j, const command& p)\r
37         {\r
38                 j = p.to_json();\r
39         }\r
40 \r
41         void from_json(const nlohmann::json& j, command& p)\r
42         {\r
43                 p.from_json(j);\r
44         }\r
45 }\r