xmlrpc_value_traits.hpp
Go to the documentation of this file.
1 #pragma once
2 
11 #include <array>
12 #include <ctime>
13 #include <list>
14 #include <map>
15 #include <set>
16 #include <string>
17 #include <unordered_map>
18 #include <unordered_set>
19 #include <vector>
20 
21 #include <XmlRpcValue.h>
22 
24 
25 namespace cras
26 {
27 
33 constexpr const char* to_cstring(const ::XmlRpc::XmlRpcValue::Type &value)
34 {
35  switch (value)
36  {
37  case ::XmlRpc::XmlRpcValue::TypeBoolean:
38  return "bool";
39  case ::XmlRpc::XmlRpcValue::TypeInt:
40  return "int";
41  case ::XmlRpc::XmlRpcValue::TypeDouble:
42  return "double";
43  case ::XmlRpc::XmlRpcValue::TypeString:
44  return "string";
45  case ::XmlRpc::XmlRpcValue::TypeDateTime:
46  return "datetime";
47  case ::XmlRpc::XmlRpcValue::TypeBase64:
48  return "binary";
49  case ::XmlRpc::XmlRpcValue::TypeArray:
50  return "array";
51  case ::XmlRpc::XmlRpcValue::TypeStruct:
52  return "struct";
53  default:
54  return "invalid";
55  }
56 }
57 
58 // cras::to_string overload
59 template<>
60 inline ::std::string to_string(const ::XmlRpc::XmlRpcValue::Type &value)
61 {
63 }
64 
69 template<typename T, class = void>
71 {
73  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInvalid };
74 
76  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
77 
81  constexpr static const bool isCanonical { false };
82 };
83 
84 template<> struct XmlRpcValueTraits<bool>
85 {
86  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeBoolean };
87  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
88  constexpr static const bool isCanonical { true };
89 };
90 
91 template<> struct XmlRpcValueTraits<char>
92 {
93  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
94  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
95  constexpr static const bool isCanonical { false };
96 };
97 
98 template<> struct XmlRpcValueTraits<signed char>
99 {
100  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
101  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
102  constexpr static const bool isCanonical { false };
103 };
104 
105 template<> struct XmlRpcValueTraits<short> // NOLINT
106 {
107  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
108  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
109  constexpr static const bool isCanonical { false };
110 };
111 
112 template<> struct XmlRpcValueTraits<int>
113 {
114  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
115  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
116  constexpr static const bool isCanonical { true };
117 };
118 
119 template<> struct XmlRpcValueTraits<long> // NOLINT
120 {
121  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
122  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
123  constexpr static const bool isCanonical { false };
124 };
125 
126 template<> struct XmlRpcValueTraits<long long> // NOLINT
127 {
128  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
129  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
130  constexpr static const bool isCanonical { false };
131 };
132 
133 template<> struct XmlRpcValueTraits<unsigned char>
134 {
135  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
136  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
137  constexpr static const bool isCanonical { false };
138 };
139 
140 template<> struct XmlRpcValueTraits<unsigned short> // NOLINT
141 {
142  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
143  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
144  constexpr static const bool isCanonical { false };
145 };
146 
147 template<> struct XmlRpcValueTraits<unsigned int>
148 {
149  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
150  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
151  constexpr static const bool isCanonical { false };
152 };
153 
154 template<> struct XmlRpcValueTraits<unsigned long> // NOLINT
155 {
156  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
157  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
158  constexpr static const bool isCanonical { false };
159 };
160 
161 template<> struct XmlRpcValueTraits<unsigned long long> // NOLINT
162 {
163  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeInt };
164  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
165  constexpr static const bool isCanonical { false };
166 };
167 
168 template<> struct XmlRpcValueTraits<float>
169 {
170  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeDouble };
171  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
172  constexpr static const bool isCanonical { false };
173 };
174 
175 template<> struct XmlRpcValueTraits<double>
176 {
177  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeDouble };
178  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
179  constexpr static const bool isCanonical { true };
180 };
181 
182 template<> struct XmlRpcValueTraits<long double>
183 {
184  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeDouble };
185  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
186  constexpr static const bool isCanonical { false };
187 };
188 
189 template<> struct XmlRpcValueTraits<::std::string>
190 {
191  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeString };
192  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
193  constexpr static const bool isCanonical { true };
194 };
195 
196 template<> struct XmlRpcValueTraits<char*>
197 {
198  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeString };
199  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
200  constexpr static const bool isCanonical { false };
201 };
202 
203 template<> struct XmlRpcValueTraits<const char*>
204 {
205  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeString };
206  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
207  constexpr static const bool isCanonical { false };
208 };
209 
210 template<> struct XmlRpcValueTraits<::tm>
211 {
212  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeDateTime };
213  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
214  constexpr static const bool isCanonical { true };
215 };
216 
218 {
219  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeBase64 };
220  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
221  constexpr static const bool isCanonical { true };
222 };
223 
224 template<typename T> struct XmlRpcValueTraits<::std::vector<T>,
225  typename ::std::enable_if<::cras::XmlRpcValueTraits<T>::xmlRpcType != ::XmlRpc::XmlRpcValue::TypeInvalid>::type>
226 {
227  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeArray };
228  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
230 };
231 
232 template<typename T> struct XmlRpcValueTraits<::std::list<T>,
233  typename ::std::enable_if<::cras::XmlRpcValueTraits<T>::xmlRpcType != ::XmlRpc::XmlRpcValue::TypeInvalid>::type>
234 {
235  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeArray };
236  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
237  constexpr static const bool isCanonical { false };
238 };
239 
240 template<typename T> struct XmlRpcValueTraits<::std::set<T>,
241  typename ::std::enable_if<::cras::XmlRpcValueTraits<T>::xmlRpcType != ::XmlRpc::XmlRpcValue::TypeInvalid>::type>
242 {
243  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeArray };
244  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
245  constexpr static const bool isCanonical { false };
246 };
247 
248 template<typename T> struct XmlRpcValueTraits<::std::unordered_set<T>,
249  typename ::std::enable_if<::cras::XmlRpcValueTraits<T>::xmlRpcType != ::XmlRpc::XmlRpcValue::TypeInvalid>::type>
250 {
251  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeArray };
252  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
253  constexpr static const bool isCanonical { false };
254 };
255 
256 template<typename T, size_t N> struct XmlRpcValueTraits<::std::array<T, N>,
257  typename ::std::enable_if<::cras::XmlRpcValueTraits<T>::xmlRpcType != ::XmlRpc::XmlRpcValue::TypeInvalid>::type>
258 {
259  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeArray };
260  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
261  constexpr static const bool isCanonical { false };
262 };
263 
264 template<typename T> struct XmlRpcValueTraits<::std::map<::std::string, T>,
265  typename ::std::enable_if<::cras::XmlRpcValueTraits<T>::xmlRpcType != ::XmlRpc::XmlRpcValue::TypeInvalid>::type>
266 {
267  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeStruct };
268  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
270 };
271 
272 template<typename T> struct XmlRpcValueTraits<::std::unordered_map<::std::string, T>,
273  typename ::std::enable_if<::cras::XmlRpcValueTraits<T>::xmlRpcType != ::XmlRpc::XmlRpcValue::TypeInvalid>::type>
274 {
275  constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType { ::XmlRpc::XmlRpcValue::TypeStruct };
276  constexpr static const char* stringType { ::cras::to_cstring(xmlRpcType) };
277  constexpr static const bool isCanonical { false };
278 };
279 
280 }
cras::XmlRpcValueTraits::xmlRpcType
constexpr static const ::XmlRpc::XmlRpcValue::Type xmlRpcType
Corresponding XmlRpcValue type that can represent values of T. TypeInvalid for non-representable type...
Definition: xmlrpc_value_traits.hpp:73
cras::to_cstring
constexpr const char * to_cstring(const ::XmlRpc::XmlRpcValue::Type &value)
Return a string representation of the XmlRpcValue type.
Definition: xmlrpc_value_traits.hpp:33
cras
Definition: any.hpp:15
XmlRpc::XmlRpcValue::BinaryData
std::vector< char > BinaryData
XmlRpc::XmlRpcValue::TypeBase64
TypeBase64
XmlRpc::XmlRpcValue::TypeInt
TypeInt
XmlRpc::XmlRpcValue::TypeInvalid
TypeInvalid
cras::XmlRpcValueTraits
Type traits for XmlRpcValue.
Definition: xmlrpc_value_traits.hpp:70
string_utils.hpp
Utils for working with strings.
XmlRpc::XmlRpcValue::TypeStruct
TypeStruct
XmlRpc::XmlRpcValue::TypeDouble
TypeDouble
XmlRpc::XmlRpcValue::TypeString
TypeString
XmlRpcValue.h
XmlRpc::XmlRpcValue::TypeArray
TypeArray
cras::XmlRpcValueTraits::stringType
constexpr static const char * stringType
String representation of xmlRpcType.
Definition: xmlrpc_value_traits.hpp:76
cras::int
int
Definition: xmlrpc_value_utils.hpp:125
cras::XmlRpcValueTraits::isCanonical
constexpr static const bool isCanonical
Whether T is a "canonical" type for XmlRpcValue, i.e. whether there is a conversion function defined ...
Definition: xmlrpc_value_traits.hpp:81
XmlRpc::XmlRpcValue::TypeBoolean
TypeBoolean
cras::to_string
inline ::std::string to_string(const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &value)
Definition: string_utils/eigen.hpp:21
XmlRpc::XmlRpcValue::TypeDateTime
TypeDateTime


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Tue Nov 26 2024 03:49:04