SOIL C++
C++ Unified Device Interface
json_helpers.cpp
Go to the documentation of this file.
1#include "json_helpers.h"
2#include "Types.h"
3
4template <typename T>
5web::json::value SOIL::to_json(const T& value)
6{
7 return web::json::value(value);
8}
9
10template<>
11web::json::value SOIL::to_json<double>(const double& value)
12{
13 return web::json::value::number(value);
14}
15
16template<>
17web::json::value SOIL::to_json<int64_t>(const int64_t& value)
18{
19 return web::json::value::number(value);
20}
21
22template<>
23web::json::value SOIL::to_json<int>(const int& value)
24{
25 return web::json::value::number(value);
26}
27
28template<>
29web::json::value SOIL::to_json<std::string>(const std::string& value)
30{
31 return web::json::value::string(utility::conversions::to_string_t(value));
32}
33
34template<>
35web::json::value SOIL::to_json<SOIL::TIME>(const SOIL::TIME& value)
36{
37 return to_json<std::string>(value.rfc3339());
38}
39
40template<>
41web::json::value SOIL::to_json<SOIL::ENUM>(const SOIL::ENUM& value)
42{
43 return to_json<std::string>(value.selected());
44}
45
46template<>
47web::json::value SOIL::to_json<SOIL::BOOL>(const bool& value)
48{
49 return web::json::value::boolean(value);
50}
51
52
53
54template<>
55double SOIL::to_value<double>(web::json::value value)
56{
57 return value.as_double();
58}
59
60
61template<>
62int SOIL::to_value<int>(web::json::value value)
63{
64 return value.as_integer();
65}
66
67template<>
68int64_t SOIL::to_value<int64_t>(web::json::value value)
69{
70 return static_cast<int64_t>(value.as_integer());
71}
72
73template<>
74std::string SOIL::to_value<std::string>(web::json::value json)
75{
76 return utility::conversions::to_utf8string(json.as_string());
77}
78
79template<>
80SOIL::TIME SOIL::to_value<SOIL::TIME>(web::json::value json)
81{
82 return SOIL::TIME(to_value<std::string>(json));
83}
84
85template<>
86SOIL::ENUM SOIL::to_value<SOIL::ENUM>(web::json::value json)
87{
88 return SOIL::ENUM(to_value<std::string>(json));
89}
90
91template<>
92bool SOIL::to_value<bool>(web::json::value json)
93{
94 return json.as_bool();
95}
nlohmann::json json
SOIL Enum Datatype.
Definition: Enum.h:16
std::string selected(void) const
Get selected value.
Definition: Enum.cpp:21
SOIL Time.
Definition: Time.h:13
DLL std::string rfc3339(void) const
RFC3339 representation.
Definition: Time.cpp:6
Time TIME
SOIL Time.
Definition: Types.h:54
DLL int to_value< int >(web::json::value value)
Enum ENUM
SOIL Enum.
Definition: Types.h:47
DLL web::json::value to_json(const T &value)
Value to JSON.
DLL web::json::value to_json< int >(const int &value)
DLL double to_value< double >(web::json::value value)
DLL web::json::value to_json< double >(const double &value)
DLL int64_t to_value< int64_t >(web::json::value value)
DLL web::json::value to_json< int64_t >(const int64_t &value)
DLL bool to_value< bool >(web::json::value json)