1 #ifndef NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 17 #include "yaml-cpp/binary.h" 18 #include "yaml-cpp/node/impl.h" 19 #include "yaml-cpp/node/iterator.h" 20 #include "yaml-cpp/node/node.h" 21 #include "yaml-cpp/node/type.h" 22 #include "yaml-cpp/null.h" 32 namespace conversion {
33 inline bool IsInfinity(
const std::string& input) {
34 return input ==
".inf" || input ==
".Inf" || input ==
".INF" ||
35 input ==
"+.inf" || input ==
"+.Inf" || input ==
"+.INF";
38 inline bool IsNegativeInfinity(
const std::string& input) {
39 return input ==
"-.inf" || input ==
"-.Inf" || input ==
"-.INF";
42 inline bool IsNaN(
const std::string& input) {
43 return input ==
".nan" || input ==
".NaN" || input ==
".NAN";
50 static Node encode(
const Node& rhs) {
return rhs; }
52 static bool decode(
const Node& node,
Node& rhs) {
61 static Node encode(
const std::string& rhs) {
return Node(rhs); }
63 static bool decode(
const Node& node, std::string& rhs) {
74 static Node encode(
const char*& rhs) {
return Node(rhs); }
77 template <std::
size_t N>
79 static Node encode(
const char(&rhs)[N]) {
return Node(rhs); }
86 static bool decode(
const Node& node,
_Null& ) {
91 #define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \ 93 struct convert<type> { \ 94 static Node encode(const type& rhs) { \ 95 std::stringstream stream; \ 96 stream.precision(std::numeric_limits<type>::digits10 + 1); \ 98 return Node(stream.str()); \ 101 static bool decode(const Node& node, type& rhs) { \ 102 if (node.Type() != NodeType::Scalar) \ 104 const std::string& input = node.Scalar(); \ 105 std::stringstream stream(input); \ 106 stream.unsetf(std::ios::dec); \ 107 if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) \ 109 if (std::numeric_limits<type>::has_infinity) { \ 110 if (conversion::IsInfinity(input)) { \ 111 rhs = std::numeric_limits<type>::infinity(); \ 113 } else if (conversion::IsNegativeInfinity(input)) { \ 114 rhs = negative_op std::numeric_limits<type>::infinity(); \ 119 if (std::numeric_limits<type>::has_quiet_NaN && \ 120 conversion::IsNaN(input)) { \ 121 rhs = std::numeric_limits<type>::quiet_NaN(); \ 129 #define YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(type) \ 130 YAML_DEFINE_CONVERT_STREAMABLE(type, -) 132 #define YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(type) \ 133 YAML_DEFINE_CONVERT_STREAMABLE(type, +) 135 YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(
int);
136 YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(
short);
137 YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(
long);
138 YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(
long long);
139 YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(
unsigned);
140 YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(
unsigned short);
141 YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(
unsigned long);
142 YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(
unsigned long long);
144 YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(
char);
145 YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(
signed char);
146 YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(
unsigned char);
148 YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(
float);
149 YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(
double);
150 YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(
long double);
152 #undef YAML_DEFINE_CONVERT_STREAMABLE_SIGNED 153 #undef YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED 154 #undef YAML_DEFINE_CONVERT_STREAMABLE 159 static Node encode(
bool rhs) {
return rhs ?
Node(
"true") : Node(
"false"); }
161 YAML_CPP_API
static bool decode(
const Node& node,
bool& rhs);
165 template <
typename K,
typename V>
167 static Node encode(
const std::map<K, V>& rhs) {
168 Node node(NodeType::Map);
169 for (
typename std::map<K, V>::const_iterator it = rhs.begin();
170 it != rhs.end(); ++it)
171 node.force_insert(it->first, it->second);
175 static bool decode(
const Node& node, std::map<K, V>& rhs) {
181 #
if defined(__GNUC__) && __GNUC__ < 4
183 rhs[it->first.template as<K>()] = it->second.template as<V>();
185 rhs[it->first.as<K>()] = it->second.as<V>();
192 template <
typename T>
194 static Node encode(
const std::vector<T>& rhs) {
195 Node node(NodeType::Sequence);
196 for (
typename std::vector<T>::const_iterator it = rhs.begin();
197 it != rhs.end(); ++it)
202 static bool decode(
const Node& node, std::vector<T>& rhs) {
203 if (!node.IsSequence())
208 #
if defined(__GNUC__) && __GNUC__ < 4
210 rhs.push_back(it->template as<T>());
212 rhs.push_back(it->as<T>());
219 template <
typename T>
221 static Node encode(
const std::list<T>& rhs) {
222 Node node(NodeType::Sequence);
223 for (
typename std::list<T>::const_iterator it = rhs.begin();
224 it != rhs.end(); ++it)
229 static bool decode(
const Node& node, std::list<T>& rhs) {
230 if (!node.IsSequence())
235 #
if defined(__GNUC__) && __GNUC__ < 4
237 rhs.push_back(it->template as<T>());
239 rhs.push_back(it->as<T>());
246 template <
typename T, std::
size_t N>
248 static Node encode(
const std::array<T, N>& rhs) {
249 Node node(NodeType::Sequence);
250 for (
const auto& element : rhs) {
251 node.push_back(element);
256 static bool decode(
const Node& node, std::array<T, N>& rhs) {
257 if (!isNodeValid(node)) {
261 for (
auto i = 0u; i < node.size(); ++i) {
262 #if defined(__GNUC__) && __GNUC__ < 4 264 rhs[i] = node[i].template as<T>();
266 rhs[i] = node[i].as<T>();
273 static bool isNodeValid(
const Node& node) {
274 return node.IsSequence() && node.size() == N;
279 template <
typename T,
typename U>
281 static Node encode(
const std::pair<T, U>& rhs) {
282 Node node(NodeType::Sequence);
283 node.push_back(rhs.first);
284 node.push_back(rhs.second);
288 static bool decode(
const Node& node, std::pair<T, U>& rhs) {
289 if (!node.IsSequence())
291 if (node.size() != 2)
294 #if defined(__GNUC__) && __GNUC__ < 4 296 rhs.first = node[0].template as<T>();
298 rhs.first = node[0].as<T>();
300 #if defined(__GNUC__) && __GNUC__ < 4 302 rhs.second = node[1].template as<U>();
304 rhs.second = node[1].as<U>();
314 return Node(EncodeBase64(rhs.data(), rhs.size()));
317 static bool decode(
const Node& node,
Binary& rhs) {
318 if (!node.IsScalar())
321 std::vector<unsigned char> data = DecodeBase64(node.Scalar());
322 if (data.empty() && !node.Scalar().empty())
331 #endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
Definition: iterator.h:21
Definition: _tbb_windef.h:37
Definition: DrawableObjectLoader.h:10