mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Run clang-format
This commit is contained in:
@@ -1,39 +1,45 @@
|
|||||||
#ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/mark.h"
|
#include "yaml-cpp/mark.h"
|
||||||
#include "yaml-cpp/traits.h"
|
#include "yaml-cpp/traits.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
// error messages
|
// error messages
|
||||||
namespace ErrorMsg
|
namespace ErrorMsg {
|
||||||
{
|
const char* const YAML_DIRECTIVE_ARGS =
|
||||||
const char * const YAML_DIRECTIVE_ARGS = "YAML directives must have exactly one argument";
|
"YAML directives must have exactly one argument";
|
||||||
const char* const YAML_VERSION = "bad YAML version: ";
|
const char* const YAML_VERSION = "bad YAML version: ";
|
||||||
const char* const YAML_MAJOR_VERSION = "YAML major version too large";
|
const char* const YAML_MAJOR_VERSION = "YAML major version too large";
|
||||||
const char* const REPEATED_YAML_DIRECTIVE = "repeated YAML directive";
|
const char* const REPEATED_YAML_DIRECTIVE = "repeated YAML directive";
|
||||||
const char * const TAG_DIRECTIVE_ARGS = "TAG directives must have exactly two arguments";
|
const char* const TAG_DIRECTIVE_ARGS =
|
||||||
|
"TAG directives must have exactly two arguments";
|
||||||
const char* const REPEATED_TAG_DIRECTIVE = "repeated TAG directive";
|
const char* const REPEATED_TAG_DIRECTIVE = "repeated TAG directive";
|
||||||
const char * const CHAR_IN_TAG_HANDLE = "illegal character found while scanning tag handle";
|
const char* const CHAR_IN_TAG_HANDLE =
|
||||||
|
"illegal character found while scanning tag handle";
|
||||||
const char* const TAG_WITH_NO_SUFFIX = "tag handle with no suffix";
|
const char* const TAG_WITH_NO_SUFFIX = "tag handle with no suffix";
|
||||||
const char* const END_OF_VERBATIM_TAG = "end of verbatim tag not found";
|
const char* const END_OF_VERBATIM_TAG = "end of verbatim tag not found";
|
||||||
const char* const END_OF_MAP = "end of map not found";
|
const char* const END_OF_MAP = "end of map not found";
|
||||||
const char* const END_OF_MAP_FLOW = "end of map flow not found";
|
const char* const END_OF_MAP_FLOW = "end of map flow not found";
|
||||||
const char* const END_OF_SEQ = "end of sequence not found";
|
const char* const END_OF_SEQ = "end of sequence not found";
|
||||||
const char* const END_OF_SEQ_FLOW = "end of sequence flow not found";
|
const char* const END_OF_SEQ_FLOW = "end of sequence flow not found";
|
||||||
const char * const MULTIPLE_TAGS = "cannot assign multiple tags to the same node";
|
const char* const MULTIPLE_TAGS =
|
||||||
const char * const MULTIPLE_ANCHORS = "cannot assign multiple anchors to the same node";
|
"cannot assign multiple tags to the same node";
|
||||||
const char * const MULTIPLE_ALIASES = "cannot assign multiple aliases to the same node";
|
const char* const MULTIPLE_ANCHORS =
|
||||||
const char * const ALIAS_CONTENT = "aliases can't have any content, *including* tags";
|
"cannot assign multiple anchors to the same node";
|
||||||
|
const char* const MULTIPLE_ALIASES =
|
||||||
|
"cannot assign multiple aliases to the same node";
|
||||||
|
const char* const ALIAS_CONTENT =
|
||||||
|
"aliases can't have any content, *including* tags";
|
||||||
const char* const INVALID_HEX = "bad character found while scanning hex number";
|
const char* const INVALID_HEX = "bad character found while scanning hex number";
|
||||||
const char* const INVALID_UNICODE = "invalid unicode: ";
|
const char* const INVALID_UNICODE = "invalid unicode: ";
|
||||||
const char* const INVALID_ESCAPE = "unknown escape character: ";
|
const char* const INVALID_ESCAPE = "unknown escape character: ";
|
||||||
@@ -41,21 +47,28 @@ namespace YAML
|
|||||||
const char* const DOC_IN_SCALAR = "illegal document indicator in scalar";
|
const char* const DOC_IN_SCALAR = "illegal document indicator in scalar";
|
||||||
const char* const EOF_IN_SCALAR = "illegal EOF in scalar";
|
const char* const EOF_IN_SCALAR = "illegal EOF in scalar";
|
||||||
const char* const CHAR_IN_SCALAR = "illegal character in scalar";
|
const char* const CHAR_IN_SCALAR = "illegal character in scalar";
|
||||||
const char * const TAB_IN_INDENTATION = "illegal tab when looking for indentation";
|
const char* const TAB_IN_INDENTATION =
|
||||||
|
"illegal tab when looking for indentation";
|
||||||
const char* const FLOW_END = "illegal flow end";
|
const char* const FLOW_END = "illegal flow end";
|
||||||
const char* const BLOCK_ENTRY = "illegal block entry";
|
const char* const BLOCK_ENTRY = "illegal block entry";
|
||||||
const char* const MAP_KEY = "illegal map key";
|
const char* const MAP_KEY = "illegal map key";
|
||||||
const char* const MAP_VALUE = "illegal map value";
|
const char* const MAP_VALUE = "illegal map value";
|
||||||
const char* const ALIAS_NOT_FOUND = "alias not found after *";
|
const char* const ALIAS_NOT_FOUND = "alias not found after *";
|
||||||
const char* const ANCHOR_NOT_FOUND = "anchor not found after &";
|
const char* const ANCHOR_NOT_FOUND = "anchor not found after &";
|
||||||
const char * const CHAR_IN_ALIAS = "illegal character found while scanning alias";
|
const char* const CHAR_IN_ALIAS =
|
||||||
const char * const CHAR_IN_ANCHOR = "illegal character found while scanning anchor";
|
"illegal character found while scanning alias";
|
||||||
const char * const ZERO_INDENT_IN_BLOCK = "cannot set zero indentation for a block scalar";
|
const char* const CHAR_IN_ANCHOR =
|
||||||
|
"illegal character found while scanning anchor";
|
||||||
|
const char* const ZERO_INDENT_IN_BLOCK =
|
||||||
|
"cannot set zero indentation for a block scalar";
|
||||||
const char* const CHAR_IN_BLOCK = "unexpected character in block scalar";
|
const char* const CHAR_IN_BLOCK = "unexpected character in block scalar";
|
||||||
const char * const AMBIGUOUS_ANCHOR = "cannot assign the same alias to multiple nodes";
|
const char* const AMBIGUOUS_ANCHOR =
|
||||||
|
"cannot assign the same alias to multiple nodes";
|
||||||
const char* const UNKNOWN_ANCHOR = "the referenced anchor is not defined";
|
const char* const UNKNOWN_ANCHOR = "the referenced anchor is not defined";
|
||||||
|
|
||||||
const char * const INVALID_NODE = "invalid node; this may result from using a map iterator as a sequence iterator, or vice-versa";
|
const char* const INVALID_NODE =
|
||||||
|
"invalid node; this may result from using a map iterator as a sequence "
|
||||||
|
"iterator, or vice-versa";
|
||||||
const char* const INVALID_SCALAR = "invalid scalar";
|
const char* const INVALID_SCALAR = "invalid scalar";
|
||||||
const char* const KEY_NOT_FOUND = "key not found";
|
const char* const KEY_NOT_FOUND = "key not found";
|
||||||
const char* const BAD_CONVERSION = "bad conversion";
|
const char* const BAD_CONVERSION = "bad conversion";
|
||||||
@@ -67,14 +80,16 @@ namespace YAML
|
|||||||
const char* const UNMATCHED_GROUP_TAG = "unmatched group tag";
|
const char* const UNMATCHED_GROUP_TAG = "unmatched group tag";
|
||||||
const char* const UNEXPECTED_END_SEQ = "unexpected end sequence token";
|
const char* const UNEXPECTED_END_SEQ = "unexpected end sequence token";
|
||||||
const char* const UNEXPECTED_END_MAP = "unexpected end map token";
|
const char* const UNEXPECTED_END_MAP = "unexpected end map token";
|
||||||
const char * const SINGLE_QUOTED_CHAR = "invalid character in single-quoted string";
|
const char* const SINGLE_QUOTED_CHAR =
|
||||||
|
"invalid character in single-quoted string";
|
||||||
const char* const INVALID_ANCHOR = "invalid anchor";
|
const char* const INVALID_ANCHOR = "invalid anchor";
|
||||||
const char* const INVALID_ALIAS = "invalid alias";
|
const char* const INVALID_ALIAS = "invalid alias";
|
||||||
const char* const INVALID_TAG = "invalid tag";
|
const char* const INVALID_TAG = "invalid tag";
|
||||||
const char* const BAD_FILE = "bad file";
|
const char* const BAD_FILE = "bad file";
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline const std::string KEY_NOT_FOUND_WITH_KEY(const T&, typename disable_if<is_numeric<T> >::type * = 0) {
|
inline const std::string KEY_NOT_FOUND_WITH_KEY(
|
||||||
|
const T&, typename disable_if<is_numeric<T> >::type* = 0) {
|
||||||
return KEY_NOT_FOUND;
|
return KEY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +100,8 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline const std::string KEY_NOT_FOUND_WITH_KEY(const T& key, typename enable_if<is_numeric<T> >::type * = 0) {
|
inline const std::string KEY_NOT_FOUND_WITH_KEY(
|
||||||
|
const T& key, typename enable_if<is_numeric<T> >::type* = 0) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << KEY_NOT_FOUND << ": " << key;
|
stream << KEY_NOT_FOUND << ": " << key;
|
||||||
return stream.str();
|
return stream.str();
|
||||||
@@ -102,9 +118,11 @@ namespace YAML
|
|||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const std::string build_what(const Mark& mark, const std::string& msg) {
|
static const std::string build_what(const Mark& mark,
|
||||||
|
const std::string& msg) {
|
||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
output << "yaml-cpp: error at line " << mark.line+1 << ", column " << mark.column+1 << ": " << msg;
|
output << "yaml-cpp: error at line " << mark.line + 1 << ", column "
|
||||||
|
<< mark.column + 1 << ": " << msg;
|
||||||
return output.str();
|
return output.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -132,7 +150,8 @@ namespace YAML
|
|||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
KeyNotFound(const Mark& mark_, const T& key_)
|
KeyNotFound(const Mark& mark_, const T& key_)
|
||||||
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {}
|
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -146,7 +165,8 @@ namespace YAML
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline TypedKeyNotFound <T> MakeTypedKeyNotFound(const Mark& mark, const T& key) {
|
inline TypedKeyNotFound<T> MakeTypedKeyNotFound(const Mark& mark,
|
||||||
|
const T& key) {
|
||||||
return TypedKeyNotFound<T>(mark, key);
|
return TypedKeyNotFound<T>(mark, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,8 +185,7 @@ namespace YAML
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class TypedBadConversion : public BadConversion {
|
class TypedBadConversion : public BadConversion {
|
||||||
public:
|
public:
|
||||||
TypedBadConversion()
|
TypedBadConversion() : BadConversion() {}
|
||||||
: BadConversion() {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class BadDereference : public RepresentationException {
|
class BadDereference : public RepresentationException {
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
#ifndef NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/binary.h"
|
#include "yaml-cpp/binary.h"
|
||||||
#include "yaml-cpp/node/node.h"
|
#include "yaml-cpp/node/node.h"
|
||||||
#include "yaml-cpp/node/iterator.h"
|
#include "yaml-cpp/node/iterator.h"
|
||||||
@@ -16,11 +17,11 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
namespace conversion {
|
namespace conversion {
|
||||||
inline bool IsInfinity(const std::string& input) {
|
inline bool IsInfinity(const std::string& input) {
|
||||||
return input == ".inf" || input == ".Inf" || input == ".INF" || input == "+.inf" || input == "+.Inf" || input == "+.INF";
|
return input == ".inf" || input == ".Inf" || input == ".INF" ||
|
||||||
|
input == "+.inf" || input == "+.Inf" || input == "+.INF";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsNegativeInfinity(const std::string& input) {
|
inline bool IsNegativeInfinity(const std::string& input) {
|
||||||
@@ -35,9 +36,7 @@ namespace YAML
|
|||||||
// std::string
|
// std::string
|
||||||
template <>
|
template <>
|
||||||
struct convert<std::string> {
|
struct convert<std::string> {
|
||||||
static Node encode(const std::string& rhs) {
|
static Node encode(const std::string& rhs) { return Node(rhs); }
|
||||||
return Node(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool decode(const Node& node, std::string& rhs) {
|
static bool decode(const Node& node, std::string& rhs) {
|
||||||
if (!node.IsScalar())
|
if (!node.IsScalar())
|
||||||
@@ -50,23 +49,17 @@ namespace YAML
|
|||||||
// C-strings can only be encoded
|
// C-strings can only be encoded
|
||||||
template <>
|
template <>
|
||||||
struct convert<const char*> {
|
struct convert<const char*> {
|
||||||
static Node encode(const char *&rhs) {
|
static Node encode(const char*& rhs) { return Node(rhs); }
|
||||||
return Node(rhs);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
struct convert<const char[N]> {
|
struct convert<const char[N]> {
|
||||||
static Node encode(const char (&rhs)[N]) {
|
static Node encode(const char (&rhs)[N]) { return Node(rhs); }
|
||||||
return Node(rhs);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct convert<_Null> {
|
struct convert<_Null> {
|
||||||
static Node encode(const _Null& /* rhs */) {
|
static Node encode(const _Null& /* rhs */) { return Node(); }
|
||||||
return Node();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool decode(const Node& node, _Null& /* rhs */) {
|
static bool decode(const Node& node, _Null& /* rhs */) {
|
||||||
return node.IsNull();
|
return node.IsNull();
|
||||||
@@ -101,7 +94,8 @@ namespace YAML
|
|||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
if(std::numeric_limits<type>::has_quiet_NaN && conversion::IsNaN(input)) {\
|
if (std::numeric_limits<type>::has_quiet_NaN && \
|
||||||
|
conversion::IsNaN(input)) { \
|
||||||
rhs = std::numeric_limits<type>::quiet_NaN(); \
|
rhs = std::numeric_limits<type>::quiet_NaN(); \
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
@@ -139,9 +133,7 @@ namespace YAML
|
|||||||
// bool
|
// bool
|
||||||
template <>
|
template <>
|
||||||
struct convert<bool> {
|
struct convert<bool> {
|
||||||
static Node encode(bool rhs) {
|
static Node encode(bool rhs) { return rhs ? Node("true") : Node("false"); }
|
||||||
return rhs ? Node("true") : Node("false");
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool decode(const Node& node, bool& rhs);
|
static bool decode(const Node& node, bool& rhs);
|
||||||
};
|
};
|
||||||
@@ -151,7 +143,8 @@ namespace YAML
|
|||||||
struct convert<std::map<K, V> > {
|
struct convert<std::map<K, V> > {
|
||||||
static Node encode(const std::map<K, V>& rhs) {
|
static Node encode(const std::map<K, V>& rhs) {
|
||||||
Node node(NodeType::Map);
|
Node node(NodeType::Map);
|
||||||
for(typename std::map<K, V>::const_iterator it=rhs.begin();it!=rhs.end();++it)
|
for (typename std::map<K, V>::const_iterator it = rhs.begin();
|
||||||
|
it != rhs.end(); ++it)
|
||||||
node.force_insert(it->first, it->second);
|
node.force_insert(it->first, it->second);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -177,7 +170,8 @@ namespace YAML
|
|||||||
struct convert<std::vector<T> > {
|
struct convert<std::vector<T> > {
|
||||||
static Node encode(const std::vector<T>& rhs) {
|
static Node encode(const std::vector<T>& rhs) {
|
||||||
Node node(NodeType::Sequence);
|
Node node(NodeType::Sequence);
|
||||||
for(typename std::vector<T>::const_iterator it=rhs.begin();it!=rhs.end();++it)
|
for (typename std::vector<T>::const_iterator it = rhs.begin();
|
||||||
|
it != rhs.end(); ++it)
|
||||||
node.push_back(*it);
|
node.push_back(*it);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -203,7 +197,8 @@ namespace YAML
|
|||||||
struct convert<std::list<T> > {
|
struct convert<std::list<T> > {
|
||||||
static Node encode(const std::list<T>& rhs) {
|
static Node encode(const std::list<T>& rhs) {
|
||||||
Node node(NodeType::Sequence);
|
Node node(NodeType::Sequence);
|
||||||
for(typename std::list<T>::const_iterator it=rhs.begin();it!=rhs.end();++it)
|
for (typename std::list<T>::const_iterator it = rhs.begin();
|
||||||
|
it != rhs.end(); ++it)
|
||||||
node.push_back(*it);
|
node.push_back(*it);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
#ifndef NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
struct unspecified_bool {
|
struct unspecified_bool {
|
||||||
struct NOT_ALLOWED;
|
struct NOT_ALLOWED;
|
||||||
static void true_value(NOT_ALLOWED*) {}
|
static void true_value(NOT_ALLOWED*) {}
|
||||||
@@ -18,9 +18,9 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define YAML_CPP_OPERATOR_BOOL() \
|
#define YAML_CPP_OPERATOR_BOOL() \
|
||||||
operator YAML::detail::unspecified_bool_type() const\
|
operator YAML::detail::unspecified_bool_type() const { \
|
||||||
{\
|
return this->operator!() ? 0 \
|
||||||
return this->operator!() ? 0 : &YAML::detail::unspecified_bool::true_value;\
|
: &YAML::detail::unspecified_bool::true_value; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
@@ -1,33 +1,37 @@
|
|||||||
#ifndef NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/node/detail/node.h"
|
#include "yaml-cpp/node/detail/node.h"
|
||||||
#include "yaml-cpp/node/detail/node_data.h"
|
#include "yaml-cpp/node/detail/node_data.h"
|
||||||
#include <boost/type_traits.hpp>
|
#include <boost/type_traits.hpp>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template <typename Key, typename Enable = void>
|
template <typename Key, typename Enable = void>
|
||||||
struct get_idx {
|
struct get_idx {
|
||||||
static node *get(const std::vector<node *>& /* sequence */, const Key& /* key */, shared_memory_holder /* pMemory */) {
|
static node* get(const std::vector<node*>& /* sequence */,
|
||||||
|
const Key& /* key */, shared_memory_holder /* pMemory */) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
struct get_idx<Key, typename boost::enable_if_c<boost::is_unsigned<Key>::value && !boost::is_same<Key, bool>::value>::type> {
|
struct get_idx<
|
||||||
static node *get(const std::vector<node *>& sequence, const Key& key, shared_memory_holder /* pMemory */) {
|
Key, typename boost::enable_if_c<boost::is_unsigned<Key>::value &&
|
||||||
|
!boost::is_same<Key, bool>::value>::type> {
|
||||||
|
static node* get(const std::vector<node*>& sequence, const Key& key,
|
||||||
|
shared_memory_holder /* pMemory */) {
|
||||||
return key < sequence.size() ? sequence[key] : 0;
|
return key < sequence.size() ? sequence[key] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static node *get(std::vector<node *>& sequence, const Key& key, shared_memory_holder pMemory) {
|
static node* get(std::vector<node*>& sequence, const Key& key,
|
||||||
|
shared_memory_holder pMemory) {
|
||||||
if (key > sequence.size())
|
if (key > sequence.size())
|
||||||
return 0;
|
return 0;
|
||||||
if (key == sequence.size())
|
if (key == sequence.size())
|
||||||
@@ -38,18 +42,24 @@ namespace YAML
|
|||||||
|
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
struct get_idx<Key, typename boost::enable_if<boost::is_signed<Key> >::type> {
|
struct get_idx<Key, typename boost::enable_if<boost::is_signed<Key> >::type> {
|
||||||
static node *get(const std::vector<node *>& sequence, const Key& key, shared_memory_holder pMemory) {
|
static node* get(const std::vector<node*>& sequence, const Key& key,
|
||||||
return key >= 0 ? get_idx<std::size_t>::get(sequence, static_cast<std::size_t>(key), pMemory) : 0;
|
shared_memory_holder pMemory) {
|
||||||
|
return key >= 0 ? get_idx<std::size_t>::get(
|
||||||
|
sequence, static_cast<std::size_t>(key), pMemory)
|
||||||
|
: 0;
|
||||||
}
|
}
|
||||||
static node *get(std::vector<node *>& sequence, const Key& key, shared_memory_holder pMemory) {
|
static node* get(std::vector<node*>& sequence, const Key& key,
|
||||||
return key >= 0 ? get_idx<std::size_t>::get(sequence, static_cast<std::size_t>(key), pMemory) : 0;
|
shared_memory_holder pMemory) {
|
||||||
|
return key >= 0 ? get_idx<std::size_t>::get(
|
||||||
|
sequence, static_cast<std::size_t>(key), pMemory)
|
||||||
|
: 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// indexing
|
// indexing
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
inline node& node_data::get(const Key& key, shared_memory_holder pMemory) const
|
inline node& node_data::get(const Key& key,
|
||||||
{
|
shared_memory_holder pMemory) const {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Map:
|
case NodeType::Map:
|
||||||
break;
|
break;
|
||||||
@@ -73,8 +83,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
inline node& node_data::get(const Key& key, shared_memory_holder pMemory)
|
inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
|
||||||
{
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Map:
|
case NodeType::Map:
|
||||||
break;
|
break;
|
||||||
@@ -104,8 +113,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
inline bool node_data::remove(const Key& key, shared_memory_holder pMemory)
|
inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) {
|
||||||
{
|
|
||||||
if (m_type != NodeType::Map)
|
if (m_type != NodeType::Map)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -121,8 +129,8 @@ namespace YAML
|
|||||||
|
|
||||||
// map
|
// map
|
||||||
template <typename Key, typename Value>
|
template <typename Key, typename Value>
|
||||||
inline void node_data::force_insert(const Key& key, const Value& value, shared_memory_holder pMemory)
|
inline void node_data::force_insert(const Key& key, const Value& value,
|
||||||
{
|
shared_memory_holder pMemory) {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Map:
|
case NodeType::Map:
|
||||||
break;
|
break;
|
||||||
@@ -141,22 +149,22 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool node_data::equals(node& node, const T& rhs, shared_memory_holder pMemory)
|
inline bool node_data::equals(node& node, const T& rhs,
|
||||||
{
|
shared_memory_holder pMemory) {
|
||||||
T lhs;
|
T lhs;
|
||||||
if (convert<T>::decode(Node(node, pMemory), lhs))
|
if (convert<T>::decode(Node(node, pMemory), lhs))
|
||||||
return lhs == rhs;
|
return lhs == rhs;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool node_data::equals(node& node, const char *rhs, shared_memory_holder pMemory)
|
inline bool node_data::equals(node& node, const char* rhs,
|
||||||
{
|
shared_memory_holder pMemory) {
|
||||||
return equals<std::string>(node, rhs, pMemory);
|
return equals<std::string>(node, rhs, pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline node& node_data::convert_to_node(const T& rhs, shared_memory_holder pMemory)
|
inline node& node_data::convert_to_node(const T& rhs,
|
||||||
{
|
shared_memory_holder pMemory) {
|
||||||
Node value = convert<T>::encode(rhs);
|
Node value = convert<T>::encode(rhs);
|
||||||
value.EnsureNodeExists();
|
value.EnsureNodeExists();
|
||||||
pMemory->merge(*value.m_pMemory);
|
pMemory->merge(*value.m_pMemory);
|
||||||
|
@@ -1,33 +1,29 @@
|
|||||||
#ifndef VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/node/ptr.h"
|
#include "yaml-cpp/node/ptr.h"
|
||||||
#include "yaml-cpp/node/detail/node_iterator.h"
|
#include "yaml-cpp/node/detail/node_iterator.h"
|
||||||
#include <boost/iterator/iterator_adaptor.hpp>
|
#include <boost/iterator/iterator_adaptor.hpp>
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
struct iterator_value;
|
struct iterator_value;
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
class iterator_base: public boost::iterator_adaptor<
|
class iterator_base
|
||||||
iterator_base<V>,
|
: public boost::iterator_adaptor<iterator_base<V>, node_iterator, V,
|
||||||
node_iterator,
|
std::forward_iterator_tag, V> {
|
||||||
V,
|
|
||||||
std::forward_iterator_tag,
|
|
||||||
V>
|
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
template<typename> friend class iterator_base;
|
template <typename>
|
||||||
|
friend class iterator_base;
|
||||||
struct enabler {};
|
struct enabler {};
|
||||||
typedef typename iterator_base::base_type base_type;
|
typedef typename iterator_base::base_type base_type;
|
||||||
|
|
||||||
@@ -36,10 +32,16 @@ namespace YAML
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
iterator_base() {}
|
iterator_base() {}
|
||||||
explicit iterator_base(base_type rhs, shared_memory_holder pMemory): iterator_base::iterator_adaptor_(rhs), m_pMemory(pMemory) {}
|
explicit iterator_base(base_type rhs, shared_memory_holder pMemory)
|
||||||
|
: iterator_base::iterator_adaptor_(rhs), m_pMemory(pMemory) {}
|
||||||
|
|
||||||
template <class W>
|
template <class W>
|
||||||
iterator_base(const iterator_base<W>& rhs, typename boost::enable_if<boost::is_convertible<W*, V*>, enabler>::type = enabler()): iterator_base::iterator_adaptor_(rhs.base()), m_pMemory(rhs.m_pMemory) {}
|
iterator_base(
|
||||||
|
const iterator_base<W>& rhs,
|
||||||
|
typename boost::enable_if<boost::is_convertible<W*, V*>, enabler>::type =
|
||||||
|
enabler())
|
||||||
|
: iterator_base::iterator_adaptor_(rhs.base()),
|
||||||
|
m_pMemory(rhs.m_pMemory) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class boost::iterator_core_access;
|
friend class boost::iterator_core_access;
|
||||||
|
@@ -1,23 +1,24 @@
|
|||||||
#ifndef VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
class node;
|
class node;
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
struct iterator_value;
|
struct iterator_value;
|
||||||
template<typename V> class iterator_base;
|
template <typename V>
|
||||||
|
class iterator_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef detail::iterator_base<detail::iterator_value> iterator;
|
typedef detail::iterator_base<detail::iterator_value> iterator;
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
#ifndef VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -9,10 +11,8 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class memory {
|
class memory {
|
||||||
public:
|
public:
|
||||||
node& create_node();
|
node& create_node();
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
#ifndef NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/node/type.h"
|
#include "yaml-cpp/node/type.h"
|
||||||
#include "yaml-cpp/node/ptr.h"
|
#include "yaml-cpp/node/ptr.h"
|
||||||
@@ -13,12 +14,9 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
class node : private boost::noncopyable {
|
||||||
{
|
|
||||||
class node: private boost::noncopyable
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
node() : m_pRef(new node_ref) {}
|
node() : m_pRef(new node_ref) {}
|
||||||
|
|
||||||
@@ -36,7 +34,8 @@ namespace YAML
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_pRef->mark_defined();
|
m_pRef->mark_defined();
|
||||||
for(nodes::iterator it=m_dependencies.begin();it!=m_dependencies.end();++it)
|
for (nodes::iterator it = m_dependencies.begin();
|
||||||
|
it != m_dependencies.end(); ++it)
|
||||||
(*it)->mark_defined();
|
(*it)->mark_defined();
|
||||||
m_dependencies.clear();
|
m_dependencies.clear();
|
||||||
}
|
}
|
||||||
@@ -80,10 +79,14 @@ namespace YAML
|
|||||||
// size/iterator
|
// size/iterator
|
||||||
std::size_t size() const { return m_pRef->size(); }
|
std::size_t size() const { return m_pRef->size(); }
|
||||||
|
|
||||||
const_node_iterator begin() const { return static_cast<const node_ref&>(*m_pRef).begin(); }
|
const_node_iterator begin() const {
|
||||||
|
return static_cast<const node_ref&>(*m_pRef).begin();
|
||||||
|
}
|
||||||
node_iterator begin() { return m_pRef->begin(); }
|
node_iterator begin() { return m_pRef->begin(); }
|
||||||
|
|
||||||
const_node_iterator end() const { return static_cast<const node_ref&>(*m_pRef).end(); }
|
const_node_iterator end() const {
|
||||||
|
return static_cast<const node_ref&>(*m_pRef).end();
|
||||||
|
}
|
||||||
node_iterator end() { return m_pRef->end(); }
|
node_iterator end() { return m_pRef->end(); }
|
||||||
|
|
||||||
// sequence
|
// sequence
|
||||||
@@ -98,26 +101,40 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
// indexing
|
// indexing
|
||||||
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) const { return static_cast<const node_ref&>(*m_pRef).get(key, pMemory); }
|
template <typename Key>
|
||||||
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) {
|
node& get(const Key& key, shared_memory_holder pMemory) const {
|
||||||
|
return static_cast<const node_ref&>(*m_pRef).get(key, pMemory);
|
||||||
|
}
|
||||||
|
template <typename Key>
|
||||||
|
node& get(const Key& key, shared_memory_holder pMemory) {
|
||||||
node& value = m_pRef->get(key, pMemory);
|
node& value = m_pRef->get(key, pMemory);
|
||||||
value.add_dependency(*this);
|
value.add_dependency(*this);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
template<typename Key> bool remove(const Key& key, shared_memory_holder pMemory) { return m_pRef->remove(key, pMemory); }
|
template <typename Key>
|
||||||
|
bool remove(const Key& key, shared_memory_holder pMemory) {
|
||||||
|
return m_pRef->remove(key, pMemory);
|
||||||
|
}
|
||||||
|
|
||||||
node& get(node& key, shared_memory_holder pMemory) const { return static_cast<const node_ref&>(*m_pRef).get(key, pMemory); }
|
node& get(node& key, shared_memory_holder pMemory) const {
|
||||||
|
return static_cast<const node_ref&>(*m_pRef).get(key, pMemory);
|
||||||
|
}
|
||||||
node& get(node& key, shared_memory_holder pMemory) {
|
node& get(node& key, shared_memory_holder pMemory) {
|
||||||
node& value = m_pRef->get(key, pMemory);
|
node& value = m_pRef->get(key, pMemory);
|
||||||
key.add_dependency(*this);
|
key.add_dependency(*this);
|
||||||
value.add_dependency(*this);
|
value.add_dependency(*this);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
bool remove(node& key, shared_memory_holder pMemory) { return m_pRef->remove(key, pMemory); }
|
bool remove(node& key, shared_memory_holder pMemory) {
|
||||||
|
return m_pRef->remove(key, pMemory);
|
||||||
|
}
|
||||||
|
|
||||||
// map
|
// map
|
||||||
template <typename Key, typename Value>
|
template <typename Key, typename Value>
|
||||||
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory){ m_pRef->force_insert(key, value, pMemory); }
|
void force_insert(const Key& key, const Value& value,
|
||||||
|
shared_memory_holder pMemory) {
|
||||||
|
m_pRef->force_insert(key, value, pMemory);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
shared_node_ref m_pRef;
|
shared_node_ref m_pRef;
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
#ifndef VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/node/iterator.h"
|
#include "yaml-cpp/node/iterator.h"
|
||||||
#include "yaml-cpp/node/ptr.h"
|
#include "yaml-cpp/node/ptr.h"
|
||||||
@@ -15,12 +16,9 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
class node_data : private boost::noncopyable {
|
||||||
{
|
|
||||||
class node_data: private boost::noncopyable
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
node_data();
|
node_data();
|
||||||
|
|
||||||
@@ -31,7 +29,9 @@ namespace YAML
|
|||||||
void set_scalar(const std::string& scalar);
|
void set_scalar(const std::string& scalar);
|
||||||
|
|
||||||
bool is_defined() const { return m_isDefined; }
|
bool is_defined() const { return m_isDefined; }
|
||||||
NodeType::value type() const { return m_isDefined ? m_type : NodeType::Undefined; }
|
NodeType::value type() const {
|
||||||
|
return m_isDefined ? m_type : NodeType::Undefined;
|
||||||
|
}
|
||||||
const std::string& scalar() const { return m_scalar; }
|
const std::string& scalar() const { return m_scalar; }
|
||||||
const std::string& tag() const { return m_tag; }
|
const std::string& tag() const { return m_tag; }
|
||||||
|
|
||||||
@@ -49,9 +49,12 @@ namespace YAML
|
|||||||
void insert(node& key, node& value, shared_memory_holder pMemory);
|
void insert(node& key, node& value, shared_memory_holder pMemory);
|
||||||
|
|
||||||
// indexing
|
// indexing
|
||||||
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) const;
|
template <typename Key>
|
||||||
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory);
|
node& get(const Key& key, shared_memory_holder pMemory) const;
|
||||||
template<typename Key> bool remove(const Key& key, shared_memory_holder pMemory);
|
template <typename Key>
|
||||||
|
node& get(const Key& key, shared_memory_holder pMemory);
|
||||||
|
template <typename Key>
|
||||||
|
bool remove(const Key& key, shared_memory_holder pMemory);
|
||||||
|
|
||||||
node& get(node& key, shared_memory_holder pMemory) const;
|
node& get(node& key, shared_memory_holder pMemory) const;
|
||||||
node& get(node& key, shared_memory_holder pMemory);
|
node& get(node& key, shared_memory_holder pMemory);
|
||||||
@@ -59,7 +62,8 @@ namespace YAML
|
|||||||
|
|
||||||
// map
|
// map
|
||||||
template <typename Key, typename Value>
|
template <typename Key, typename Value>
|
||||||
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory);
|
void force_insert(const Key& key, const Value& value,
|
||||||
|
shared_memory_holder pMemory);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::string empty_scalar;
|
static std::string empty_scalar;
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
#ifndef VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/node/ptr.h"
|
#include "yaml-cpp/node/ptr.h"
|
||||||
#include <boost/iterator/iterator_facade.hpp>
|
#include <boost/iterator/iterator_facade.hpp>
|
||||||
@@ -14,11 +15,15 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
struct iterator_type {
|
||||||
{
|
enum value {
|
||||||
struct iterator_type { enum value { None, Sequence, Map }; };
|
None,
|
||||||
|
Sequence,
|
||||||
|
Map
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
struct node_iterator_value : public std::pair<V*, V*> {
|
struct node_iterator_value : public std::pair<V*, V*> {
|
||||||
@@ -49,14 +54,11 @@ namespace YAML
|
|||||||
typedef node_map::const_iterator map;
|
typedef node_map::const_iterator map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
class node_iterator_base: public boost::iterator_facade<
|
class node_iterator_base
|
||||||
node_iterator_base<V>,
|
: public boost::iterator_facade<
|
||||||
node_iterator_value<V>,
|
node_iterator_base<V>, node_iterator_value<V>,
|
||||||
std::forward_iterator_tag,
|
std::forward_iterator_tag, node_iterator_value<V> > {
|
||||||
node_iterator_value<V> >
|
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
struct enabler {};
|
struct enabler {};
|
||||||
|
|
||||||
@@ -66,18 +68,27 @@ namespace YAML
|
|||||||
typedef node_iterator_value<V> value_type;
|
typedef node_iterator_value<V> value_type;
|
||||||
|
|
||||||
node_iterator_base() : m_type(iterator_type::None) {}
|
node_iterator_base() : m_type(iterator_type::None) {}
|
||||||
explicit node_iterator_base(SeqIter seqIt): m_type(iterator_type::Sequence), m_seqIt(seqIt) {}
|
explicit node_iterator_base(SeqIter seqIt)
|
||||||
explicit node_iterator_base(MapIter mapIt, MapIter mapEnd): m_type(iterator_type::Map), m_mapIt(mapIt), m_mapEnd(mapEnd) {
|
: m_type(iterator_type::Sequence), m_seqIt(seqIt) {}
|
||||||
|
explicit node_iterator_base(MapIter mapIt, MapIter mapEnd)
|
||||||
|
: m_type(iterator_type::Map), m_mapIt(mapIt), m_mapEnd(mapEnd) {
|
||||||
m_mapIt = increment_until_defined(m_mapIt);
|
m_mapIt = increment_until_defined(m_mapIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename W>
|
template <typename W>
|
||||||
node_iterator_base(const node_iterator_base<W>& rhs, typename boost::enable_if<boost::is_convertible<W*, V*>, enabler>::type = enabler())
|
node_iterator_base(
|
||||||
: m_type(rhs.m_type), m_seqIt(rhs.m_seqIt), m_mapIt(rhs.m_mapIt), m_mapEnd(rhs.m_mapEnd) {}
|
const node_iterator_base<W>& rhs,
|
||||||
|
typename boost::enable_if<boost::is_convertible<W*, V*>, enabler>::type =
|
||||||
|
enabler())
|
||||||
|
: m_type(rhs.m_type),
|
||||||
|
m_seqIt(rhs.m_seqIt),
|
||||||
|
m_mapIt(rhs.m_mapIt),
|
||||||
|
m_mapEnd(rhs.m_mapEnd) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class boost::iterator_core_access;
|
friend class boost::iterator_core_access;
|
||||||
template<typename> friend class node_iterator_base;
|
template <typename>
|
||||||
|
friend class node_iterator_base;
|
||||||
|
|
||||||
template <typename W>
|
template <typename W>
|
||||||
bool equal(const node_iterator_base<W>& rhs) const {
|
bool equal(const node_iterator_base<W>& rhs) const {
|
||||||
@@ -85,16 +96,20 @@ namespace YAML
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case iterator_type::None: return true;
|
case iterator_type::None:
|
||||||
case iterator_type::Sequence: return m_seqIt == rhs.m_seqIt;
|
return true;
|
||||||
case iterator_type::Map: return m_mapIt == rhs.m_mapIt;
|
case iterator_type::Sequence:
|
||||||
|
return m_seqIt == rhs.m_seqIt;
|
||||||
|
case iterator_type::Map:
|
||||||
|
return m_mapIt == rhs.m_mapIt;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void increment() {
|
void increment() {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case iterator_type::None: break;
|
case iterator_type::None:
|
||||||
|
break;
|
||||||
case iterator_type::Sequence:
|
case iterator_type::Sequence:
|
||||||
++m_seqIt;
|
++m_seqIt;
|
||||||
break;
|
break;
|
||||||
@@ -107,9 +122,12 @@ namespace YAML
|
|||||||
|
|
||||||
value_type dereference() const {
|
value_type dereference() const {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case iterator_type::None: return value_type();
|
case iterator_type::None:
|
||||||
case iterator_type::Sequence: return value_type(**m_seqIt);
|
return value_type();
|
||||||
case iterator_type::Map: return value_type(*m_mapIt->first, *m_mapIt->second);
|
case iterator_type::Sequence:
|
||||||
|
return value_type(**m_seqIt);
|
||||||
|
case iterator_type::Map:
|
||||||
|
return value_type(*m_mapIt->first, *m_mapIt->second);
|
||||||
}
|
}
|
||||||
return value_type();
|
return value_type();
|
||||||
}
|
}
|
||||||
|
@@ -1,23 +1,21 @@
|
|||||||
#ifndef VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/node/type.h"
|
#include "yaml-cpp/node/type.h"
|
||||||
#include "yaml-cpp/node/ptr.h"
|
#include "yaml-cpp/node/ptr.h"
|
||||||
#include "yaml-cpp/node/detail/node_data.h"
|
#include "yaml-cpp/node/detail/node_data.h"
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
class node_ref : private boost::noncopyable {
|
||||||
{
|
|
||||||
class node_ref: private boost::noncopyable
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
node_ref() : m_pData(new node_data) {}
|
node_ref() : m_pData(new node_data) {}
|
||||||
|
|
||||||
@@ -37,28 +35,54 @@ namespace YAML
|
|||||||
// size/iterator
|
// size/iterator
|
||||||
std::size_t size() const { return m_pData->size(); }
|
std::size_t size() const { return m_pData->size(); }
|
||||||
|
|
||||||
const_node_iterator begin() const { return static_cast<const node_data&>(*m_pData).begin(); }
|
const_node_iterator begin() const {
|
||||||
|
return static_cast<const node_data&>(*m_pData).begin();
|
||||||
|
}
|
||||||
node_iterator begin() { return m_pData->begin(); }
|
node_iterator begin() { return m_pData->begin(); }
|
||||||
|
|
||||||
const_node_iterator end() const { return static_cast<const node_data&>(*m_pData).end(); }
|
const_node_iterator end() const {
|
||||||
|
return static_cast<const node_data&>(*m_pData).end();
|
||||||
|
}
|
||||||
node_iterator end() { return m_pData->end(); }
|
node_iterator end() { return m_pData->end(); }
|
||||||
|
|
||||||
// sequence
|
// sequence
|
||||||
void push_back(node& node, shared_memory_holder pMemory) { m_pData->push_back(node, pMemory); }
|
void push_back(node& node, shared_memory_holder pMemory) {
|
||||||
void insert(node& key, node& value, shared_memory_holder pMemory) { m_pData->insert(key, value, pMemory); }
|
m_pData->push_back(node, pMemory);
|
||||||
|
}
|
||||||
|
void insert(node& key, node& value, shared_memory_holder pMemory) {
|
||||||
|
m_pData->insert(key, value, pMemory);
|
||||||
|
}
|
||||||
|
|
||||||
// indexing
|
// indexing
|
||||||
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) const { return static_cast<const node_data&>(*m_pData).get(key, pMemory); }
|
template <typename Key>
|
||||||
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) { return m_pData->get(key, pMemory); }
|
node& get(const Key& key, shared_memory_holder pMemory) const {
|
||||||
template<typename Key> bool remove(const Key& key, shared_memory_holder pMemory) { return m_pData->remove(key, pMemory); }
|
return static_cast<const node_data&>(*m_pData).get(key, pMemory);
|
||||||
|
}
|
||||||
|
template <typename Key>
|
||||||
|
node& get(const Key& key, shared_memory_holder pMemory) {
|
||||||
|
return m_pData->get(key, pMemory);
|
||||||
|
}
|
||||||
|
template <typename Key>
|
||||||
|
bool remove(const Key& key, shared_memory_holder pMemory) {
|
||||||
|
return m_pData->remove(key, pMemory);
|
||||||
|
}
|
||||||
|
|
||||||
node& get(node& key, shared_memory_holder pMemory) const { return static_cast<const node_data&>(*m_pData).get(key, pMemory); }
|
node& get(node& key, shared_memory_holder pMemory) const {
|
||||||
node& get(node& key, shared_memory_holder pMemory) { return m_pData->get(key, pMemory); }
|
return static_cast<const node_data&>(*m_pData).get(key, pMemory);
|
||||||
bool remove(node& key, shared_memory_holder pMemory) { return m_pData->remove(key, pMemory); }
|
}
|
||||||
|
node& get(node& key, shared_memory_holder pMemory) {
|
||||||
|
return m_pData->get(key, pMemory);
|
||||||
|
}
|
||||||
|
bool remove(node& key, shared_memory_holder pMemory) {
|
||||||
|
return m_pData->remove(key, pMemory);
|
||||||
|
}
|
||||||
|
|
||||||
// map
|
// map
|
||||||
template <typename Key, typename Value>
|
template <typename Key, typename Value>
|
||||||
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory) { m_pData->force_insert(key, value, pMemory); }
|
void force_insert(const Key& key, const Value& value,
|
||||||
|
shared_memory_holder pMemory) {
|
||||||
|
m_pData->force_insert(key, value, pMemory);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
shared_node_data m_pData;
|
shared_node_data m_pData;
|
||||||
|
@@ -1,15 +1,16 @@
|
|||||||
#ifndef NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
class Emitter;
|
class Emitter;
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
@@ -20,4 +21,3 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
#ifndef NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/node/node.h"
|
#include "yaml-cpp/node/node.h"
|
||||||
#include "yaml-cpp/node/iterator.h"
|
#include "yaml-cpp/node/iterator.h"
|
||||||
#include "yaml-cpp/node/detail/memory.h"
|
#include "yaml-cpp/node/detail/memory.h"
|
||||||
@@ -13,45 +14,42 @@
|
|||||||
#include "yaml-cpp/exceptions.h"
|
#include "yaml-cpp/exceptions.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
inline Node::Node() : m_isValid(true), m_pNode(NULL) {}
|
||||||
inline Node::Node(): m_isValid(true), m_pNode(NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Node::Node(NodeType::value type): m_isValid(true), m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node())
|
inline Node::Node(NodeType::value type)
|
||||||
{
|
: m_isValid(true),
|
||||||
|
m_pMemory(new detail::memory_holder),
|
||||||
|
m_pNode(&m_pMemory->create_node()) {
|
||||||
m_pNode->set_type(type);
|
m_pNode->set_type(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline Node::Node(const T& rhs): m_isValid(true), m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node())
|
inline Node::Node(const T& rhs)
|
||||||
{
|
: m_isValid(true),
|
||||||
|
m_pMemory(new detail::memory_holder),
|
||||||
|
m_pNode(&m_pMemory->create_node()) {
|
||||||
Assign(rhs);
|
Assign(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Node::Node(const detail::iterator_value& rhs): m_isValid(rhs.m_isValid), m_pMemory(rhs.m_pMemory), m_pNode(rhs.m_pNode)
|
inline Node::Node(const detail::iterator_value& rhs)
|
||||||
{
|
: m_isValid(rhs.m_isValid),
|
||||||
}
|
m_pMemory(rhs.m_pMemory),
|
||||||
|
m_pNode(rhs.m_pNode) {}
|
||||||
|
|
||||||
inline Node::Node(const Node& rhs): m_isValid(rhs.m_isValid), m_pMemory(rhs.m_pMemory), m_pNode(rhs.m_pNode)
|
inline Node::Node(const Node& rhs)
|
||||||
{
|
: m_isValid(rhs.m_isValid),
|
||||||
}
|
m_pMemory(rhs.m_pMemory),
|
||||||
|
m_pNode(rhs.m_pNode) {}
|
||||||
|
|
||||||
inline Node::Node(Zombie): m_isValid(false), m_pNode(NULL)
|
inline Node::Node(Zombie) : m_isValid(false), m_pNode(NULL) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory): m_isValid(true), m_pMemory(pMemory), m_pNode(&node)
|
inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory)
|
||||||
{
|
: m_isValid(true), m_pMemory(pMemory), m_pNode(&node) {}
|
||||||
}
|
|
||||||
|
|
||||||
inline Node::~Node()
|
inline Node::~Node() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Node::EnsureNodeExists() const
|
inline void Node::EnsureNodeExists() const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
if (!m_pNode) {
|
if (!m_pNode) {
|
||||||
@@ -61,15 +59,13 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Node::IsDefined() const
|
inline bool Node::IsDefined() const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return m_pNode ? m_pNode->is_defined() : true;
|
return m_pNode ? m_pNode->is_defined() : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NodeType::value Node::Type() const
|
inline NodeType::value Node::Type() const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return m_pNode ? m_pNode->type() : NodeType::Null;
|
return m_pNode ? m_pNode->type() : NodeType::Null;
|
||||||
@@ -136,37 +132,32 @@ namespace YAML
|
|||||||
|
|
||||||
// access functions
|
// access functions
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline const T Node::as() const
|
inline const T Node::as() const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return as_if<T, void>(*this)();
|
return as_if<T, void>(*this)();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename S>
|
template <typename T, typename S>
|
||||||
inline const T Node::as(const S& fallback) const
|
inline const T Node::as(const S& fallback) const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return as_if<T, S>(*this)(fallback);
|
return as_if<T, S>(*this)(fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string& Node::Scalar() const
|
inline const std::string& Node::Scalar() const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar;
|
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string& Node::Tag() const
|
inline const std::string& Node::Tag() const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar;
|
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Node::SetTag(const std::string& tag)
|
inline void Node::SetTag(const std::string& tag) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
@@ -174,8 +165,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
// assignment
|
// assignment
|
||||||
inline bool Node::is(const Node& rhs) const
|
inline bool Node::is(const Node& rhs) const {
|
||||||
{
|
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
if (!m_pNode || !rhs.m_pNode)
|
if (!m_pNode || !rhs.m_pNode)
|
||||||
@@ -184,16 +174,14 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline Node& Node::operator=(const T& rhs)
|
inline Node& Node::operator=(const T& rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
Assign(rhs);
|
Assign(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Node::reset(const YAML::Node& rhs)
|
inline void Node::reset(const YAML::Node& rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
m_pMemory = rhs.m_pMemory;
|
m_pMemory = rhs.m_pMemory;
|
||||||
@@ -201,40 +189,35 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Node::Assign(const T& rhs)
|
inline void Node::Assign(const T& rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
AssignData(convert<T>::encode(rhs));
|
AssignData(convert<T>::encode(rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void Node::Assign(const std::string& rhs)
|
inline void Node::Assign(const std::string& rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
m_pNode->set_scalar(rhs);
|
m_pNode->set_scalar(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Node::Assign(const char *rhs)
|
inline void Node::Assign(const char* rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
m_pNode->set_scalar(rhs);
|
m_pNode->set_scalar(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Node::Assign(char *rhs)
|
inline void Node::Assign(char* rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
m_pNode->set_scalar(rhs);
|
m_pNode->set_scalar(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Node& Node::operator=(const Node& rhs)
|
inline Node& Node::operator=(const Node& rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
if (is(rhs))
|
if (is(rhs))
|
||||||
@@ -243,8 +226,7 @@ namespace YAML
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Node::AssignData(const Node& rhs)
|
inline void Node::AssignData(const Node& rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
@@ -254,8 +236,7 @@ namespace YAML
|
|||||||
m_pMemory->merge(*rhs.m_pMemory);
|
m_pMemory->merge(*rhs.m_pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Node::AssignNode(const Node& rhs)
|
inline void Node::AssignNode(const Node& rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
rhs.EnsureNodeExists();
|
rhs.EnsureNodeExists();
|
||||||
@@ -272,36 +253,32 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
// size/iterator
|
// size/iterator
|
||||||
inline std::size_t Node::size() const
|
inline std::size_t Node::size() const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return m_pNode ? m_pNode->size() : 0;
|
return m_pNode ? m_pNode->size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const_iterator Node::begin() const
|
inline const_iterator Node::begin() const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return m_pNode ? const_iterator(m_pNode->begin(), m_pMemory) : const_iterator();
|
return m_pNode ? const_iterator(m_pNode->begin(), m_pMemory)
|
||||||
|
: const_iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline iterator Node::begin()
|
inline iterator Node::begin() {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return m_pNode ? iterator(m_pNode->begin(), m_pMemory) : iterator();
|
return m_pNode ? iterator(m_pNode->begin(), m_pMemory) : iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const_iterator Node::end() const
|
inline const_iterator Node::end() const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return m_pNode ? const_iterator(m_pNode->end(), m_pMemory) : const_iterator();
|
return m_pNode ? const_iterator(m_pNode->end(), m_pMemory) : const_iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline iterator Node::end()
|
inline iterator Node::end() {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
return m_pNode ? iterator(m_pNode->end(), m_pMemory) : iterator();
|
return m_pNode ? iterator(m_pNode->end(), m_pMemory) : iterator();
|
||||||
@@ -309,15 +286,13 @@ namespace YAML
|
|||||||
|
|
||||||
// sequence
|
// sequence
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Node::push_back(const T& rhs)
|
inline void Node::push_back(const T& rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
push_back(Node(rhs));
|
push_back(Node(rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Node::push_back(const Node& rhs)
|
inline void Node::push_back(const Node& rhs) {
|
||||||
{
|
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
@@ -374,18 +349,17 @@ namespace YAML
|
|||||||
|
|
||||||
// indexing
|
// indexing
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
inline const Node Node::operator[](const Key& key) const
|
inline const Node Node::operator[](const Key& key) const {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
detail::node& value = static_cast<const detail::node&>(*m_pNode).get(detail::to_value(key), m_pMemory);
|
detail::node& value = static_cast<const detail::node&>(*m_pNode)
|
||||||
|
.get(detail::to_value(key), m_pMemory);
|
||||||
return Node(value, m_pMemory);
|
return Node(value, m_pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
inline Node Node::operator[](const Key& key)
|
inline Node Node::operator[](const Key& key) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
@@ -394,26 +368,24 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
inline bool Node::remove(const Key& key)
|
inline bool Node::remove(const Key& key) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
return m_pNode->remove(detail::to_value(key), m_pMemory);
|
return m_pNode->remove(detail::to_value(key), m_pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Node Node::operator[](const Node& key) const
|
inline const Node Node::operator[](const Node& key) const {
|
||||||
{
|
|
||||||
if (!m_isValid || !key.m_isValid)
|
if (!m_isValid || !key.m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
key.EnsureNodeExists();
|
key.EnsureNodeExists();
|
||||||
detail::node& value = static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory);
|
detail::node& value =
|
||||||
|
static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory);
|
||||||
return Node(value, m_pMemory);
|
return Node(value, m_pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Node Node::operator[](const Node& key)
|
inline Node Node::operator[](const Node& key) {
|
||||||
{
|
|
||||||
if (!m_isValid || !key.m_isValid)
|
if (!m_isValid || !key.m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
@@ -422,8 +394,7 @@ namespace YAML
|
|||||||
return Node(value, m_pMemory);
|
return Node(value, m_pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Node::remove(const Node& key)
|
inline bool Node::remove(const Node& key) {
|
||||||
{
|
|
||||||
if (!m_isValid || !key.m_isValid)
|
if (!m_isValid || !key.m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
@@ -433,19 +404,16 @@ namespace YAML
|
|||||||
|
|
||||||
// map
|
// map
|
||||||
template <typename Key, typename Value>
|
template <typename Key, typename Value>
|
||||||
inline void Node::force_insert(const Key& key, const Value& value)
|
inline void Node::force_insert(const Key& key, const Value& value) {
|
||||||
{
|
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
m_pNode->force_insert(detail::to_value(key), detail::to_value(value), m_pMemory);
|
m_pNode->force_insert(detail::to_value(key), detail::to_value(value),
|
||||||
|
m_pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// free functions
|
// free functions
|
||||||
inline bool operator==(const Node& lhs, const Node& rhs)
|
inline bool operator==(const Node& lhs, const Node& rhs) { return lhs.is(rhs); }
|
||||||
{
|
|
||||||
return lhs.is(rhs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
#ifndef VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/node/node.h"
|
#include "yaml-cpp/node/node.h"
|
||||||
#include "yaml-cpp/node/detail/iterator_fwd.h"
|
#include "yaml-cpp/node/detail/iterator_fwd.h"
|
||||||
@@ -14,13 +15,15 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
struct iterator_value : public Node, std::pair<Node, Node> {
|
struct iterator_value : public Node, std::pair<Node, Node> {
|
||||||
iterator_value() {}
|
iterator_value() {}
|
||||||
explicit iterator_value(const Node& rhs): Node(rhs), std::pair<Node, Node>(Node(Node::ZombieNode), Node(Node::ZombieNode)) {}
|
explicit iterator_value(const Node& rhs)
|
||||||
explicit iterator_value(const Node& key, const Node& value): Node(Node::ZombieNode), std::pair<Node, Node>(key, value) {}
|
: Node(rhs),
|
||||||
|
std::pair<Node, Node>(Node(Node::ZombieNode), Node(Node::ZombieNode)) {}
|
||||||
|
explicit iterator_value(const Node& key, const Node& value)
|
||||||
|
: Node(Node::ZombieNode), std::pair<Node, Node>(key, value) {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
#ifndef NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/node/ptr.h"
|
#include "yaml-cpp/node/ptr.h"
|
||||||
#include "yaml-cpp/node/type.h"
|
#include "yaml-cpp/node/type.h"
|
||||||
@@ -13,24 +14,25 @@
|
|||||||
#include "yaml-cpp/node/detail/bool_type.h"
|
#include "yaml-cpp/node/detail/bool_type.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
class Node {
|
||||||
class Node
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
friend class NodeBuilder;
|
friend class NodeBuilder;
|
||||||
friend class NodeEvents;
|
friend class NodeEvents;
|
||||||
friend struct detail::iterator_value;
|
friend struct detail::iterator_value;
|
||||||
friend class detail::node_data;
|
friend class detail::node_data;
|
||||||
template<typename> friend class detail::iterator_base;
|
template <typename>
|
||||||
template<typename T, typename S> friend struct as_if;
|
friend class detail::iterator_base;
|
||||||
|
template <typename T, typename S>
|
||||||
|
friend struct as_if;
|
||||||
|
|
||||||
typedef YAML::iterator iterator;
|
typedef YAML::iterator iterator;
|
||||||
typedef YAML::const_iterator const_iterator;
|
typedef YAML::const_iterator const_iterator;
|
||||||
|
|
||||||
Node();
|
Node();
|
||||||
explicit Node(NodeType::value type);
|
explicit Node(NodeType::value type);
|
||||||
template<typename T> explicit Node(const T& rhs);
|
template <typename T>
|
||||||
|
explicit Node(const T& rhs);
|
||||||
explicit Node(const detail::iterator_value& rhs);
|
explicit Node(const detail::iterator_value& rhs);
|
||||||
Node(const Node& rhs);
|
Node(const Node& rhs);
|
||||||
~Node();
|
~Node();
|
||||||
@@ -47,15 +49,18 @@ namespace YAML
|
|||||||
bool operator!() const { return !IsDefined(); }
|
bool operator!() const { return !IsDefined(); }
|
||||||
|
|
||||||
// access
|
// access
|
||||||
template<typename T> const T as() const;
|
template <typename T>
|
||||||
template<typename T, typename S> const T as(const S& fallback) const;
|
const T as() const;
|
||||||
|
template <typename T, typename S>
|
||||||
|
const T as(const S& fallback) const;
|
||||||
const std::string& Scalar() const;
|
const std::string& Scalar() const;
|
||||||
const std::string& Tag() const;
|
const std::string& Tag() const;
|
||||||
void SetTag(const std::string& tag);
|
void SetTag(const std::string& tag);
|
||||||
|
|
||||||
// assignment
|
// assignment
|
||||||
bool is(const Node& rhs) const;
|
bool is(const Node& rhs) const;
|
||||||
template<typename T> Node& operator=(const T& rhs);
|
template <typename T>
|
||||||
|
Node& operator=(const T& rhs);
|
||||||
Node& operator=(const Node& rhs);
|
Node& operator=(const Node& rhs);
|
||||||
void reset(const Node& rhs = Node());
|
void reset(const Node& rhs = Node());
|
||||||
|
|
||||||
@@ -69,13 +74,17 @@ namespace YAML
|
|||||||
iterator end();
|
iterator end();
|
||||||
|
|
||||||
// sequence
|
// sequence
|
||||||
template<typename T> void push_back(const T& rhs);
|
template <typename T>
|
||||||
|
void push_back(const T& rhs);
|
||||||
void push_back(const Node& rhs);
|
void push_back(const Node& rhs);
|
||||||
|
|
||||||
// indexing
|
// indexing
|
||||||
template<typename Key> const Node operator[](const Key& key) const;
|
template <typename Key>
|
||||||
template<typename Key> Node operator[](const Key& key);
|
const Node operator[](const Key& key) const;
|
||||||
template<typename Key> bool remove(const Key& key);
|
template <typename Key>
|
||||||
|
Node operator[](const Key& key);
|
||||||
|
template <typename Key>
|
||||||
|
bool remove(const Key& key);
|
||||||
|
|
||||||
const Node operator[](const Node& key) const;
|
const Node operator[](const Node& key) const;
|
||||||
Node operator[](const Node& key);
|
Node operator[](const Node& key);
|
||||||
@@ -86,13 +95,16 @@ namespace YAML
|
|||||||
void force_insert(const Key& key, const Value& value);
|
void force_insert(const Key& key, const Value& value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Zombie { ZombieNode };
|
enum Zombie {
|
||||||
|
ZombieNode
|
||||||
|
};
|
||||||
explicit Node(Zombie);
|
explicit Node(Zombie);
|
||||||
explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
|
explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
|
||||||
|
|
||||||
void EnsureNodeExists() const;
|
void EnsureNodeExists() const;
|
||||||
|
|
||||||
template<typename T> void Assign(const T& rhs);
|
template <typename T>
|
||||||
|
void Assign(const T& rhs);
|
||||||
void Assign(const char* rhs);
|
void Assign(const char* rhs);
|
||||||
void Assign(char* rhs);
|
void Assign(char* rhs);
|
||||||
|
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
#ifndef VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -9,8 +11,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
Node Load(const std::string& input);
|
Node Load(const std::string& input);
|
||||||
@@ -25,4 +26,3 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
|
@@ -1,16 +1,16 @@
|
|||||||
#ifndef VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
class node;
|
class node;
|
||||||
class node_ref;
|
class node_ref;
|
||||||
|
@@ -1,14 +1,22 @@
|
|||||||
#ifndef VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace YAML {
|
||||||
namespace YAML
|
struct NodeType {
|
||||||
{
|
enum value {
|
||||||
struct NodeType { enum value { Undefined, Null, Scalar, Sequence, Map }; };
|
Undefined,
|
||||||
|
Null,
|
||||||
|
Scalar,
|
||||||
|
Sequence,
|
||||||
|
Map
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
@@ -1,25 +1,24 @@
|
|||||||
#ifndef PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/noncopyable.h"
|
#include "yaml-cpp/noncopyable.h"
|
||||||
#include <ios>
|
#include <ios>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
struct Directives;
|
struct Directives;
|
||||||
struct Token;
|
struct Token;
|
||||||
class EventHandler;
|
class EventHandler;
|
||||||
class Scanner;
|
class Scanner;
|
||||||
|
|
||||||
class YAML_CPP_API Parser: private noncopyable
|
class YAML_CPP_API Parser : private noncopyable {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Parser();
|
Parser();
|
||||||
Parser(std::istream& in);
|
Parser(std::istream& in);
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
#ifndef YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -2,23 +2,20 @@
|
|||||||
#include "yaml-cpp/node/impl.h"
|
#include "yaml-cpp/node/impl.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
// we're not gonna mess with the mess that is all the isupper/etc. functions
|
// we're not gonna mess with the mess that is all the isupper/etc. functions
|
||||||
bool IsLower(char ch) { return 'a' <= ch && ch <= 'z'; }
|
bool IsLower(char ch) { return 'a' <= ch && ch <= 'z'; }
|
||||||
bool IsUpper(char ch) { return 'A' <= ch && ch <= 'Z'; }
|
bool IsUpper(char ch) { return 'A' <= ch && ch <= 'Z'; }
|
||||||
char ToLower(char ch) { return IsUpper(ch) ? ch + 'a' - 'A' : ch; }
|
char ToLower(char ch) { return IsUpper(ch) ? ch + 'a' - 'A' : ch; }
|
||||||
|
|
||||||
std::string tolower(const std::string& str)
|
std::string tolower(const std::string& str) {
|
||||||
{
|
|
||||||
std::string s(str);
|
std::string s(str);
|
||||||
std::transform(s.begin(), s.end(), s.begin(), ToLower);
|
std::transform(s.begin(), s.end(), s.begin(), ToLower);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool IsEntirely(const std::string& str, T func)
|
bool IsEntirely(const std::string& str, T func) {
|
||||||
{
|
|
||||||
for (std::size_t i = 0; i < str.size(); i++)
|
for (std::size_t i = 0; i < str.size(); i++)
|
||||||
if (!func(str[i]))
|
if (!func(str[i]))
|
||||||
return false;
|
return false;
|
||||||
@@ -31,8 +28,7 @@ namespace
|
|||||||
// . UPPERCASE
|
// . UPPERCASE
|
||||||
// . lowercase
|
// . lowercase
|
||||||
// . Capitalized
|
// . Capitalized
|
||||||
bool IsFlexibleCase(const std::string& str)
|
bool IsFlexibleCase(const std::string& str) {
|
||||||
{
|
|
||||||
if (str.empty())
|
if (str.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -45,8 +41,7 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
bool convert<bool>::decode(const Node& node, bool& rhs) {
|
bool convert<bool>::decode(const Node& node, bool& rhs) {
|
||||||
if (!node.IsScalar())
|
if (!node.IsScalar())
|
||||||
return false;
|
return false;
|
||||||
@@ -56,12 +51,7 @@ namespace YAML
|
|||||||
// http://yaml.org/type/bool.html)
|
// http://yaml.org/type/bool.html)
|
||||||
static const struct {
|
static const struct {
|
||||||
std::string truename, falsename;
|
std::string truename, falsename;
|
||||||
} names[] = {
|
} names[] = {{"y", "n"}, {"yes", "no"}, {"true", "false"}, {"on", "off"}, };
|
||||||
{ "y", "n" },
|
|
||||||
{ "yes", "no" },
|
|
||||||
{ "true", "false" },
|
|
||||||
{ "on", "off" },
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!IsFlexibleCase(node.Scalar()))
|
if (!IsFlexibleCase(node.Scalar()))
|
||||||
return false;
|
return false;
|
||||||
|
12
src/emit.cpp
12
src/emit.cpp
@@ -3,25 +3,21 @@
|
|||||||
#include "yaml-cpp/emitter.h"
|
#include "yaml-cpp/emitter.h"
|
||||||
#include "nodeevents.h"
|
#include "nodeevents.h"
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
Emitter& operator<<(Emitter& out, const Node& node) {
|
||||||
Emitter& operator << (Emitter& out, const Node& node)
|
|
||||||
{
|
|
||||||
EmitFromEvents emitFromEvents(out);
|
EmitFromEvents emitFromEvents(out);
|
||||||
NodeEvents events(node);
|
NodeEvents events(node);
|
||||||
events.Emit(emitFromEvents);
|
events.Emit(emitFromEvents);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator << (std::ostream& out, const Node& node)
|
std::ostream& operator<<(std::ostream& out, const Node& node) {
|
||||||
{
|
|
||||||
Emitter emitter(out);
|
Emitter emitter(out);
|
||||||
emitter << node;
|
emitter << node;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Dump(const Node& node)
|
std::string Dump(const Node& node) {
|
||||||
{
|
|
||||||
Emitter emitter;
|
Emitter emitter;
|
||||||
emitter << node;
|
emitter << node;
|
||||||
return emitter.c_str();
|
return emitter.c_str();
|
||||||
|
@@ -1,12 +1,9 @@
|
|||||||
#include "yaml-cpp/node/detail/memory.h"
|
#include "yaml-cpp/node/detail/memory.h"
|
||||||
#include "yaml-cpp/node/detail/node.h"
|
#include "yaml-cpp/node/detail/node.h"
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
void memory_holder::merge(memory_holder& rhs) {
|
||||||
{
|
|
||||||
void memory_holder::merge(memory_holder& rhs)
|
|
||||||
{
|
|
||||||
if (m_pMemory == rhs.m_pMemory)
|
if (m_pMemory == rhs.m_pMemory)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -14,15 +11,13 @@ namespace YAML
|
|||||||
rhs.m_pMemory = m_pMemory;
|
rhs.m_pMemory = m_pMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
node& memory::create_node()
|
node& memory::create_node() {
|
||||||
{
|
|
||||||
shared_node pNode(new node);
|
shared_node pNode(new node);
|
||||||
m_nodes.insert(pNode);
|
m_nodes.insert(pNode);
|
||||||
return *pNode;
|
return *pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory::merge(const memory& rhs)
|
void memory::merge(const memory& rhs) {
|
||||||
{
|
|
||||||
m_nodes.insert(rhs.m_nodes.begin(), rhs.m_nodes.end());
|
m_nodes.insert(rhs.m_nodes.begin(), rhs.m_nodes.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,10 +2,8 @@
|
|||||||
#include "nodebuilder.h"
|
#include "nodebuilder.h"
|
||||||
#include "nodeevents.h"
|
#include "nodeevents.h"
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
Node Clone(const Node& node) {
|
||||||
Node Clone(const Node& node)
|
|
||||||
{
|
|
||||||
NodeEvents events(node);
|
NodeEvents events(node);
|
||||||
NodeBuilder builder;
|
NodeBuilder builder;
|
||||||
events.Emit(builder);
|
events.Emit(builder);
|
||||||
|
@@ -4,32 +4,26 @@
|
|||||||
#include "yaml-cpp/exceptions.h"
|
#include "yaml-cpp/exceptions.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
std::string node_data::empty_scalar;
|
std::string node_data::empty_scalar;
|
||||||
|
|
||||||
node_data::node_data(): m_isDefined(false), m_type(NodeType::Null), m_seqSize(0)
|
node_data::node_data()
|
||||||
{
|
: m_isDefined(false), m_type(NodeType::Null), m_seqSize(0) {}
|
||||||
}
|
|
||||||
|
|
||||||
void node_data::mark_defined()
|
void node_data::mark_defined() {
|
||||||
{
|
|
||||||
if (m_type == NodeType::Undefined)
|
if (m_type == NodeType::Undefined)
|
||||||
m_type = NodeType::Null;
|
m_type = NodeType::Null;
|
||||||
m_isDefined = true;
|
m_isDefined = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::set_type(NodeType::value type)
|
void node_data::set_type(NodeType::value type) {
|
||||||
{
|
|
||||||
if (type == NodeType::Undefined) {
|
if (type == NodeType::Undefined) {
|
||||||
m_type = type;
|
m_type = type;
|
||||||
m_isDefined = false;
|
m_isDefined = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_isDefined = true;
|
m_isDefined = true;
|
||||||
if (type == m_type)
|
if (type == m_type)
|
||||||
return;
|
return;
|
||||||
@@ -54,47 +48,43 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::set_tag(const std::string& tag)
|
void node_data::set_tag(const std::string& tag) { m_tag = tag; }
|
||||||
{
|
|
||||||
m_tag = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
void node_data::set_null()
|
void node_data::set_null() {
|
||||||
{
|
|
||||||
m_isDefined = true;
|
m_isDefined = true;
|
||||||
m_type = NodeType::Null;
|
m_type = NodeType::Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::set_scalar(const std::string& scalar)
|
void node_data::set_scalar(const std::string& scalar) {
|
||||||
{
|
|
||||||
m_isDefined = true;
|
m_isDefined = true;
|
||||||
m_type = NodeType::Scalar;
|
m_type = NodeType::Scalar;
|
||||||
m_scalar = scalar;
|
m_scalar = scalar;
|
||||||
}
|
}
|
||||||
|
|
||||||
// size/iterator
|
// size/iterator
|
||||||
std::size_t node_data::size() const
|
std::size_t node_data::size() const {
|
||||||
{
|
|
||||||
if (!m_isDefined)
|
if (!m_isDefined)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Sequence: compute_seq_size(); return m_seqSize;
|
case NodeType::Sequence:
|
||||||
case NodeType::Map: compute_map_size(); return m_map.size() - m_undefinedPairs.size();
|
compute_seq_size();
|
||||||
|
return m_seqSize;
|
||||||
|
case NodeType::Map:
|
||||||
|
compute_map_size();
|
||||||
|
return m_map.size() - m_undefinedPairs.size();
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::compute_seq_size() const
|
void node_data::compute_seq_size() const {
|
||||||
{
|
|
||||||
while (m_seqSize < m_sequence.size() && m_sequence[m_seqSize]->is_defined())
|
while (m_seqSize < m_sequence.size() && m_sequence[m_seqSize]->is_defined())
|
||||||
m_seqSize++;
|
m_seqSize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::compute_map_size() const
|
void node_data::compute_map_size() const {
|
||||||
{
|
|
||||||
kv_pairs::iterator it = m_undefinedPairs.begin();
|
kv_pairs::iterator it = m_undefinedPairs.begin();
|
||||||
while (it != m_undefinedPairs.end()) {
|
while (it != m_undefinedPairs.end()) {
|
||||||
kv_pairs::iterator jt = boost::next(it);
|
kv_pairs::iterator jt = boost::next(it);
|
||||||
@@ -104,57 +94,64 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const_node_iterator node_data::begin() const
|
const_node_iterator node_data::begin() const {
|
||||||
{
|
|
||||||
if (!m_isDefined)
|
if (!m_isDefined)
|
||||||
return const_node_iterator();
|
return const_node_iterator();
|
||||||
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Sequence: return const_node_iterator(m_sequence.begin());
|
case NodeType::Sequence:
|
||||||
case NodeType::Map: return const_node_iterator(m_map.begin(), m_map.end());
|
return const_node_iterator(m_sequence.begin());
|
||||||
default: return const_node_iterator();
|
case NodeType::Map:
|
||||||
|
return const_node_iterator(m_map.begin(), m_map.end());
|
||||||
|
default:
|
||||||
|
return const_node_iterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node_iterator node_data::begin()
|
node_iterator node_data::begin() {
|
||||||
{
|
|
||||||
if (!m_isDefined)
|
if (!m_isDefined)
|
||||||
return node_iterator();
|
return node_iterator();
|
||||||
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Sequence: return node_iterator(m_sequence.begin());
|
case NodeType::Sequence:
|
||||||
case NodeType::Map: return node_iterator(m_map.begin(), m_map.end());
|
return node_iterator(m_sequence.begin());
|
||||||
default: return node_iterator();
|
case NodeType::Map:
|
||||||
|
return node_iterator(m_map.begin(), m_map.end());
|
||||||
|
default:
|
||||||
|
return node_iterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const_node_iterator node_data::end() const
|
const_node_iterator node_data::end() const {
|
||||||
{
|
|
||||||
if (!m_isDefined)
|
if (!m_isDefined)
|
||||||
return const_node_iterator();
|
return const_node_iterator();
|
||||||
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Sequence: return const_node_iterator(m_sequence.end());
|
case NodeType::Sequence:
|
||||||
case NodeType::Map: return const_node_iterator(m_map.end(), m_map.end());
|
return const_node_iterator(m_sequence.end());
|
||||||
default: return const_node_iterator();
|
case NodeType::Map:
|
||||||
|
return const_node_iterator(m_map.end(), m_map.end());
|
||||||
|
default:
|
||||||
|
return const_node_iterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node_iterator node_data::end()
|
node_iterator node_data::end() {
|
||||||
{
|
|
||||||
if (!m_isDefined)
|
if (!m_isDefined)
|
||||||
return node_iterator();
|
return node_iterator();
|
||||||
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Sequence: return node_iterator(m_sequence.end());
|
case NodeType::Sequence:
|
||||||
case NodeType::Map: return node_iterator(m_map.end(), m_map.end());
|
return node_iterator(m_sequence.end());
|
||||||
default: return node_iterator();
|
case NodeType::Map:
|
||||||
|
return node_iterator(m_map.end(), m_map.end());
|
||||||
|
default:
|
||||||
|
return node_iterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sequence
|
// sequence
|
||||||
void node_data::push_back(node& node, shared_memory_holder /* pMemory */)
|
void node_data::push_back(node& node, shared_memory_holder /* pMemory */) {
|
||||||
{
|
|
||||||
if (m_type == NodeType::Undefined || m_type == NodeType::Null) {
|
if (m_type == NodeType::Undefined || m_type == NodeType::Null) {
|
||||||
m_type = NodeType::Sequence;
|
m_type = NodeType::Sequence;
|
||||||
reset_sequence();
|
reset_sequence();
|
||||||
@@ -166,8 +163,7 @@ namespace YAML
|
|||||||
m_sequence.push_back(&node);
|
m_sequence.push_back(&node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::insert(node& key, node& value, shared_memory_holder pMemory)
|
void node_data::insert(node& key, node& value, shared_memory_holder pMemory) {
|
||||||
{
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Map:
|
case NodeType::Map:
|
||||||
break;
|
break;
|
||||||
@@ -184,8 +180,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
// indexing
|
// indexing
|
||||||
node& node_data::get(node& key, shared_memory_holder pMemory) const
|
node& node_data::get(node& key, shared_memory_holder pMemory) const {
|
||||||
{
|
|
||||||
if (m_type != NodeType::Map)
|
if (m_type != NodeType::Map)
|
||||||
return pMemory->create_node();
|
return pMemory->create_node();
|
||||||
|
|
||||||
@@ -197,8 +192,7 @@ namespace YAML
|
|||||||
return pMemory->create_node();
|
return pMemory->create_node();
|
||||||
}
|
}
|
||||||
|
|
||||||
node& node_data::get(node& key, shared_memory_holder pMemory)
|
node& node_data::get(node& key, shared_memory_holder pMemory) {
|
||||||
{
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Map:
|
case NodeType::Map:
|
||||||
break;
|
break;
|
||||||
@@ -221,8 +215,7 @@ namespace YAML
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool node_data::remove(node& key, shared_memory_holder /* pMemory */)
|
bool node_data::remove(node& key, shared_memory_holder /* pMemory */) {
|
||||||
{
|
|
||||||
if (m_type != NodeType::Map)
|
if (m_type != NodeType::Map)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -236,27 +229,23 @@ namespace YAML
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::reset_sequence()
|
void node_data::reset_sequence() {
|
||||||
{
|
|
||||||
m_sequence.clear();
|
m_sequence.clear();
|
||||||
m_seqSize = 0;
|
m_seqSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::reset_map()
|
void node_data::reset_map() {
|
||||||
{
|
|
||||||
m_map.clear();
|
m_map.clear();
|
||||||
m_undefinedPairs.clear();
|
m_undefinedPairs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::insert_map_pair(node& key, node& value)
|
void node_data::insert_map_pair(node& key, node& value) {
|
||||||
{
|
|
||||||
m_map[&key] = &value;
|
m_map[&key] = &value;
|
||||||
if (!key.is_defined() || !value.is_defined())
|
if (!key.is_defined() || !value.is_defined())
|
||||||
m_undefinedPairs.push_back(kv_pair(&key, &value));
|
m_undefinedPairs.push_back(kv_pair(&key, &value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::convert_to_map(shared_memory_holder pMemory)
|
void node_data::convert_to_map(shared_memory_holder pMemory) {
|
||||||
{
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case NodeType::Undefined:
|
case NodeType::Undefined:
|
||||||
case NodeType::Null:
|
case NodeType::Null:
|
||||||
@@ -274,8 +263,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::convert_sequence_to_map(shared_memory_holder pMemory)
|
void node_data::convert_sequence_to_map(shared_memory_holder pMemory) {
|
||||||
{
|
|
||||||
assert(m_type == NodeType::Sequence);
|
assert(m_type == NodeType::Sequence);
|
||||||
|
|
||||||
reset_map();
|
reset_map();
|
||||||
|
@@ -4,101 +4,86 @@
|
|||||||
#include "yaml-cpp/node/impl.h"
|
#include "yaml-cpp/node/impl.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
NodeBuilder::NodeBuilder()
|
||||||
NodeBuilder::NodeBuilder(): m_pMemory(new detail::memory_holder), m_pRoot(0), m_mapDepth(0)
|
: m_pMemory(new detail::memory_holder), m_pRoot(0), m_mapDepth(0) {
|
||||||
{
|
|
||||||
m_anchors.push_back(0); // since the anchors start at 1
|
m_anchors.push_back(0); // since the anchors start at 1
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeBuilder::~NodeBuilder()
|
NodeBuilder::~NodeBuilder() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Node NodeBuilder::Root()
|
Node NodeBuilder::Root() {
|
||||||
{
|
|
||||||
if (!m_pRoot)
|
if (!m_pRoot)
|
||||||
return Node();
|
return Node();
|
||||||
|
|
||||||
return Node(*m_pRoot, m_pMemory);
|
return Node(*m_pRoot, m_pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::OnDocumentStart(const Mark&)
|
void NodeBuilder::OnDocumentStart(const Mark&) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void NodeBuilder::OnDocumentEnd()
|
void NodeBuilder::OnDocumentEnd() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void NodeBuilder::OnNull(const Mark& /* mark */, anchor_t anchor)
|
void NodeBuilder::OnNull(const Mark& /* mark */, anchor_t anchor) {
|
||||||
{
|
|
||||||
detail::node& node = Push(anchor);
|
detail::node& node = Push(anchor);
|
||||||
node.set_null();
|
node.set_null();
|
||||||
Pop();
|
Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::OnAlias(const Mark& /* mark */, anchor_t anchor)
|
void NodeBuilder::OnAlias(const Mark& /* mark */, anchor_t anchor) {
|
||||||
{
|
|
||||||
detail::node& node = *m_anchors[anchor];
|
detail::node& node = *m_anchors[anchor];
|
||||||
Push(node);
|
Push(node);
|
||||||
Pop();
|
Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::OnScalar(const Mark& /* mark */, const std::string& tag, anchor_t anchor, const std::string& value)
|
void NodeBuilder::OnScalar(const Mark& /* mark */, const std::string& tag,
|
||||||
{
|
anchor_t anchor, const std::string& value) {
|
||||||
detail::node& node = Push(anchor);
|
detail::node& node = Push(anchor);
|
||||||
node.set_scalar(value);
|
node.set_scalar(value);
|
||||||
node.set_tag(tag);
|
node.set_tag(tag);
|
||||||
Pop();
|
Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::OnSequenceStart(const Mark& /* mark */, const std::string& tag, anchor_t anchor)
|
void NodeBuilder::OnSequenceStart(const Mark& /* mark */,
|
||||||
{
|
const std::string& tag, anchor_t anchor) {
|
||||||
detail::node& node = Push(anchor);
|
detail::node& node = Push(anchor);
|
||||||
node.set_tag(tag);
|
node.set_tag(tag);
|
||||||
node.set_type(NodeType::Sequence);
|
node.set_type(NodeType::Sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::OnSequenceEnd()
|
void NodeBuilder::OnSequenceEnd() { Pop(); }
|
||||||
{
|
|
||||||
Pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NodeBuilder::OnMapStart(const Mark& /* mark */, const std::string& tag, anchor_t anchor)
|
void NodeBuilder::OnMapStart(const Mark& /* mark */, const std::string& tag,
|
||||||
{
|
anchor_t anchor) {
|
||||||
detail::node& node = Push(anchor);
|
detail::node& node = Push(anchor);
|
||||||
node.set_type(NodeType::Map);
|
node.set_type(NodeType::Map);
|
||||||
node.set_tag(tag);
|
node.set_tag(tag);
|
||||||
m_mapDepth++;
|
m_mapDepth++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::OnMapEnd()
|
void NodeBuilder::OnMapEnd() {
|
||||||
{
|
|
||||||
assert(m_mapDepth > 0);
|
assert(m_mapDepth > 0);
|
||||||
m_mapDepth--;
|
m_mapDepth--;
|
||||||
Pop();
|
Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
detail::node& NodeBuilder::Push(anchor_t anchor)
|
detail::node& NodeBuilder::Push(anchor_t anchor) {
|
||||||
{
|
|
||||||
detail::node& node = m_pMemory->create_node();
|
detail::node& node = m_pMemory->create_node();
|
||||||
RegisterAnchor(anchor, node);
|
RegisterAnchor(anchor, node);
|
||||||
Push(node);
|
Push(node);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::Push(detail::node& node)
|
void NodeBuilder::Push(detail::node& node) {
|
||||||
{
|
const bool needsKey =
|
||||||
const bool needsKey = (!m_stack.empty() && m_stack.back()->type() == NodeType::Map && m_keys.size() < m_mapDepth);
|
(!m_stack.empty() && m_stack.back()->type() == NodeType::Map &&
|
||||||
|
m_keys.size() < m_mapDepth);
|
||||||
|
|
||||||
m_stack.push_back(&node);
|
m_stack.push_back(&node);
|
||||||
if (needsKey)
|
if (needsKey)
|
||||||
m_keys.push_back(PushedKey(&node, false));
|
m_keys.push_back(PushedKey(&node, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::Pop()
|
void NodeBuilder::Pop() {
|
||||||
{
|
|
||||||
assert(!m_stack.empty());
|
assert(!m_stack.empty());
|
||||||
if (m_stack.size() == 1) {
|
if (m_stack.size() == 1) {
|
||||||
m_pRoot = m_stack[0];
|
m_pRoot = m_stack[0];
|
||||||
@@ -128,8 +113,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node)
|
void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node) {
|
||||||
{
|
|
||||||
if (anchor) {
|
if (anchor) {
|
||||||
assert(anchor == m_anchors.size());
|
assert(anchor == m_anchors.size());
|
||||||
m_anchors.push_back(&node);
|
m_anchors.push_back(&node);
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
#ifndef NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -9,12 +11,10 @@
|
|||||||
#include "yaml-cpp/node/ptr.h"
|
#include "yaml-cpp/node/ptr.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
class NodeBuilder: public EventHandler
|
class NodeBuilder : public EventHandler {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
NodeBuilder();
|
NodeBuilder();
|
||||||
virtual ~NodeBuilder();
|
virtual ~NodeBuilder();
|
||||||
@@ -26,12 +26,15 @@ namespace YAML
|
|||||||
|
|
||||||
virtual void OnNull(const Mark& mark, anchor_t anchor);
|
virtual void OnNull(const Mark& mark, anchor_t anchor);
|
||||||
virtual void OnAlias(const Mark& mark, anchor_t anchor);
|
virtual void OnAlias(const Mark& mark, anchor_t anchor);
|
||||||
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value);
|
virtual void OnScalar(const Mark& mark, const std::string& tag,
|
||||||
|
anchor_t anchor, const std::string& value);
|
||||||
|
|
||||||
virtual void OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor);
|
virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
|
||||||
|
anchor_t anchor);
|
||||||
virtual void OnSequenceEnd();
|
virtual void OnSequenceEnd();
|
||||||
|
|
||||||
virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor);
|
virtual void OnMapStart(const Mark& mark, const std::string& tag,
|
||||||
|
anchor_t anchor);
|
||||||
virtual void OnMapEnd();
|
virtual void OnMapEnd();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -55,4 +58,3 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
|
@@ -4,29 +4,26 @@
|
|||||||
#include "yaml-cpp/eventhandler.h"
|
#include "yaml-cpp/eventhandler.h"
|
||||||
#include "yaml-cpp/mark.h"
|
#include "yaml-cpp/mark.h"
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
void NodeEvents::AliasManager::RegisterReference(const detail::node& node) {
|
||||||
void NodeEvents::AliasManager::RegisterReference(const detail::node& node)
|
|
||||||
{
|
|
||||||
m_anchorByIdentity.insert(std::make_pair(node.ref(), _CreateNewAnchor()));
|
m_anchorByIdentity.insert(std::make_pair(node.ref(), _CreateNewAnchor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
anchor_t NodeEvents::AliasManager::LookupAnchor(const detail::node& node) const
|
anchor_t NodeEvents::AliasManager::LookupAnchor(const detail::node& node)
|
||||||
{
|
const {
|
||||||
AnchorByIdentity::const_iterator it = m_anchorByIdentity.find(node.ref());
|
AnchorByIdentity::const_iterator it = m_anchorByIdentity.find(node.ref());
|
||||||
if (it == m_anchorByIdentity.end())
|
if (it == m_anchorByIdentity.end())
|
||||||
return 0;
|
return 0;
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeEvents::NodeEvents(const Node& node): m_pMemory(node.m_pMemory), m_root(node.m_pNode)
|
NodeEvents::NodeEvents(const Node& node)
|
||||||
{
|
: m_pMemory(node.m_pMemory), m_root(node.m_pNode) {
|
||||||
if (m_root)
|
if (m_root)
|
||||||
Setup(*m_root);
|
Setup(*m_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeEvents::Setup(const detail::node& node)
|
void NodeEvents::Setup(const detail::node& node) {
|
||||||
{
|
|
||||||
int& refCount = m_refCount[node.ref()];
|
int& refCount = m_refCount[node.ref()];
|
||||||
refCount++;
|
refCount++;
|
||||||
if (refCount > 1)
|
if (refCount > 1)
|
||||||
@@ -36,15 +33,15 @@ namespace YAML
|
|||||||
for (detail::const_node_iterator it = node.begin(); it != node.end(); ++it)
|
for (detail::const_node_iterator it = node.begin(); it != node.end(); ++it)
|
||||||
Setup(**it);
|
Setup(**it);
|
||||||
} else if (node.type() == NodeType::Map) {
|
} else if (node.type() == NodeType::Map) {
|
||||||
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) {
|
for (detail::const_node_iterator it = node.begin(); it != node.end();
|
||||||
|
++it) {
|
||||||
Setup(*it->first);
|
Setup(*it->first);
|
||||||
Setup(*it->second);
|
Setup(*it->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeEvents::Emit(EventHandler& handler)
|
void NodeEvents::Emit(EventHandler& handler) {
|
||||||
{
|
|
||||||
AliasManager am;
|
AliasManager am;
|
||||||
|
|
||||||
handler.OnDocumentStart(Mark());
|
handler.OnDocumentStart(Mark());
|
||||||
@@ -53,8 +50,8 @@ namespace YAML
|
|||||||
handler.OnDocumentEnd();
|
handler.OnDocumentEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeEvents::Emit(const detail::node& node, EventHandler& handler, AliasManager& am) const
|
void NodeEvents::Emit(const detail::node& node, EventHandler& handler,
|
||||||
{
|
AliasManager& am) const {
|
||||||
anchor_t anchor = NullAnchor;
|
anchor_t anchor = NullAnchor;
|
||||||
if (IsAliased(node)) {
|
if (IsAliased(node)) {
|
||||||
anchor = am.LookupAnchor(node);
|
anchor = am.LookupAnchor(node);
|
||||||
@@ -78,13 +75,15 @@ namespace YAML
|
|||||||
break;
|
break;
|
||||||
case NodeType::Sequence:
|
case NodeType::Sequence:
|
||||||
handler.OnSequenceStart(Mark(), node.tag(), anchor);
|
handler.OnSequenceStart(Mark(), node.tag(), anchor);
|
||||||
for(detail::const_node_iterator it=node.begin();it!=node.end();++it)
|
for (detail::const_node_iterator it = node.begin(); it != node.end();
|
||||||
|
++it)
|
||||||
Emit(**it, handler, am);
|
Emit(**it, handler, am);
|
||||||
handler.OnSequenceEnd();
|
handler.OnSequenceEnd();
|
||||||
break;
|
break;
|
||||||
case NodeType::Map:
|
case NodeType::Map:
|
||||||
handler.OnMapStart(Mark(), node.tag(), anchor);
|
handler.OnMapStart(Mark(), node.tag(), anchor);
|
||||||
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) {
|
for (detail::const_node_iterator it = node.begin(); it != node.end();
|
||||||
|
++it) {
|
||||||
Emit(*it->first, handler, am);
|
Emit(*it->first, handler, am);
|
||||||
Emit(*it->second, handler, am);
|
Emit(*it->second, handler, am);
|
||||||
}
|
}
|
||||||
@@ -93,8 +92,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeEvents::IsAliased(const detail::node& node) const
|
bool NodeEvents::IsAliased(const detail::node& node) const {
|
||||||
{
|
|
||||||
RefCount::const_iterator it = m_refCount.find(node.ref());
|
RefCount::const_iterator it = m_refCount.find(node.ref());
|
||||||
return it != m_refCount.end() && it->second > 1;
|
return it != m_refCount.end() && it->second > 1;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
#ifndef NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -10,13 +12,11 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
class EventHandler;
|
class EventHandler;
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
class NodeEvents
|
class NodeEvents {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
explicit NodeEvents(const Node& node);
|
explicit NodeEvents(const Node& node);
|
||||||
|
|
||||||
@@ -41,7 +41,8 @@ namespace YAML
|
|||||||
};
|
};
|
||||||
|
|
||||||
void Setup(const detail::node& node);
|
void Setup(const detail::node& node);
|
||||||
void Emit(const detail::node& node, EventHandler& handler, AliasManager& am) const;
|
void Emit(const detail::node& node, EventHandler& handler,
|
||||||
|
AliasManager& am) const;
|
||||||
bool IsAliased(const detail::node& node) const;
|
bool IsAliased(const detail::node& node) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -54,4 +55,3 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
|
@@ -2,22 +2,21 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
ostream_wrapper::ostream_wrapper()
|
||||||
ostream_wrapper::ostream_wrapper(): m_buffer(1), m_pStream(0), m_pos(0), m_row(0), m_col(0), m_comment(false)
|
: m_buffer(1),
|
||||||
{
|
m_pStream(0),
|
||||||
}
|
m_pos(0),
|
||||||
|
m_row(0),
|
||||||
|
m_col(0),
|
||||||
|
m_comment(false) {}
|
||||||
|
|
||||||
ostream_wrapper::ostream_wrapper(std::ostream& stream): m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false)
|
ostream_wrapper::ostream_wrapper(std::ostream& stream)
|
||||||
{
|
: m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false) {}
|
||||||
}
|
|
||||||
|
|
||||||
ostream_wrapper::~ostream_wrapper()
|
ostream_wrapper::~ostream_wrapper() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ostream_wrapper::write(const std::string& str)
|
void ostream_wrapper::write(const std::string& str) {
|
||||||
{
|
|
||||||
if (m_pStream) {
|
if (m_pStream) {
|
||||||
m_pStream->write(str.c_str(), str.size());
|
m_pStream->write(str.c_str(), str.size());
|
||||||
} else {
|
} else {
|
||||||
@@ -29,8 +28,7 @@ namespace YAML
|
|||||||
update_pos(str[i]);
|
update_pos(str[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ostream_wrapper::write(const char *str, std::size_t size)
|
void ostream_wrapper::write(const char* str, std::size_t size) {
|
||||||
{
|
|
||||||
if (m_pStream) {
|
if (m_pStream) {
|
||||||
m_pStream->write(str, size);
|
m_pStream->write(str, size);
|
||||||
} else {
|
} else {
|
||||||
@@ -42,8 +40,7 @@ namespace YAML
|
|||||||
update_pos(str[i]);
|
update_pos(str[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ostream_wrapper::update_pos(char ch)
|
void ostream_wrapper::update_pos(char ch) {
|
||||||
{
|
|
||||||
m_pos++;
|
m_pos++;
|
||||||
m_col++;
|
m_col++;
|
||||||
|
|
||||||
|
@@ -7,8 +7,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML {
|
||||||
{
|
|
||||||
Node Load(const std::string& input) {
|
Node Load(const std::string& input) {
|
||||||
std::stringstream stream(input);
|
std::stringstream stream(input);
|
||||||
return Load(stream);
|
return Load(stream);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -31,38 +31,38 @@ namespace {
|
|||||||
try { \
|
try { \
|
||||||
(cond); \
|
(cond); \
|
||||||
return " Expression did not throw: " #cond; \
|
return " Expression did not throw: " #cond; \
|
||||||
} catch(const exc&) {\
|
} \
|
||||||
} catch(const std::runtime_error& e) {\
|
catch (const exc&) { \
|
||||||
|
} \
|
||||||
|
catch (const std::runtime_error& e) { \
|
||||||
std::stringstream stream; \
|
std::stringstream stream; \
|
||||||
stream << " Expression threw runtime error ther than " #exc ":\n " #cond "\n " << e.what();\
|
stream << " Expression threw runtime error ther than " #exc \
|
||||||
|
":\n " #cond "\n " << e.what(); \
|
||||||
return stream.str(); \
|
return stream.str(); \
|
||||||
} catch(...) {\
|
} \
|
||||||
return " Expression threw unknown exception, other than " #exc ":\n " #cond;\
|
catch (...) { \
|
||||||
|
return " Expression threw unknown exception, other than " #exc \
|
||||||
|
":\n " #cond; \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
namespace Test
|
namespace Test {
|
||||||
{
|
namespace Node {
|
||||||
namespace Node
|
TEST SimpleScalar() {
|
||||||
{
|
|
||||||
TEST SimpleScalar()
|
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Node("Hello, World!");
|
YAML::Node node = YAML::Node("Hello, World!");
|
||||||
YAML_ASSERT(node.IsScalar());
|
YAML_ASSERT(node.IsScalar());
|
||||||
YAML_ASSERT(node.as<std::string>() == "Hello, World!");
|
YAML_ASSERT(node.as<std::string>() == "Hello, World!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST IntScalar()
|
TEST IntScalar() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Node(15);
|
YAML::Node node = YAML::Node(15);
|
||||||
YAML_ASSERT(node.IsScalar());
|
YAML_ASSERT(node.IsScalar());
|
||||||
YAML_ASSERT(node.as<int>() == 15);
|
YAML_ASSERT(node.as<int>() == 15);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST SimpleAppendSequence()
|
TEST SimpleAppendSequence() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node.push_back(10);
|
node.push_back(10);
|
||||||
node.push_back("foo");
|
node.push_back("foo");
|
||||||
@@ -76,8 +76,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST SimpleAssignSequence()
|
TEST SimpleAssignSequence() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node[0] = 10;
|
node[0] = 10;
|
||||||
node[1] = "foo";
|
node[1] = "foo";
|
||||||
@@ -91,8 +90,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST SimpleMap()
|
TEST SimpleMap() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node["key"] = "value";
|
node["key"] = "value";
|
||||||
YAML_ASSERT(node.IsMap());
|
YAML_ASSERT(node.IsMap());
|
||||||
@@ -101,8 +99,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST MapWithUndefinedValues()
|
TEST MapWithUndefinedValues() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node["key"] = "value";
|
node["key"] = "value";
|
||||||
node["undefined"];
|
node["undefined"];
|
||||||
@@ -117,8 +114,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST MapIteratorWithUndefinedValues()
|
TEST MapIteratorWithUndefinedValues() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node["key"] = "value";
|
node["key"] = "value";
|
||||||
node["undefined"];
|
node["undefined"];
|
||||||
@@ -130,8 +126,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST SimpleSubkeys()
|
TEST SimpleSubkeys() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node["device"]["udid"] = "12345";
|
node["device"]["udid"] = "12345";
|
||||||
node["device"]["name"] = "iPhone";
|
node["device"]["name"] = "iPhone";
|
||||||
@@ -144,8 +139,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST StdVector()
|
TEST StdVector() {
|
||||||
{
|
|
||||||
std::vector<int> primes;
|
std::vector<int> primes;
|
||||||
primes.push_back(2);
|
primes.push_back(2);
|
||||||
primes.push_back(3);
|
primes.push_back(3);
|
||||||
@@ -160,8 +154,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST StdList()
|
TEST StdList() {
|
||||||
{
|
|
||||||
std::list<int> primes;
|
std::list<int> primes;
|
||||||
primes.push_back(2);
|
primes.push_back(2);
|
||||||
primes.push_back(3);
|
primes.push_back(3);
|
||||||
@@ -176,8 +169,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST StdMap()
|
TEST StdMap() {
|
||||||
{
|
|
||||||
std::map<int, int> squares;
|
std::map<int, int> squares;
|
||||||
squares[0] = 0;
|
squares[0] = 0;
|
||||||
squares[1] = 1;
|
squares[1] = 1;
|
||||||
@@ -191,8 +183,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST StdPair()
|
TEST StdPair() {
|
||||||
{
|
|
||||||
std::pair<int, std::string> p;
|
std::pair<int, std::string> p;
|
||||||
p.first = 5;
|
p.first = 5;
|
||||||
p.second = "five";
|
p.second = "five";
|
||||||
@@ -203,8 +194,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST SimpleAlias()
|
TEST SimpleAlias() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node["foo"] = "value";
|
node["foo"] = "value";
|
||||||
node["bar"] = node["foo"];
|
node["bar"] = node["foo"];
|
||||||
@@ -215,8 +205,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST AliasAsKey()
|
TEST AliasAsKey() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node["foo"] = "value";
|
node["foo"] = "value";
|
||||||
YAML::Node value = node["foo"];
|
YAML::Node value = node["foo"];
|
||||||
@@ -228,8 +217,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST SelfReferenceSequence()
|
TEST SelfReferenceSequence() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node[0] = node;
|
node[0] = node;
|
||||||
YAML_ASSERT(node.IsSequence());
|
YAML_ASSERT(node.IsSequence());
|
||||||
@@ -240,8 +228,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST ValueSelfReferenceMap()
|
TEST ValueSelfReferenceMap() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node["key"] = node;
|
node["key"] = node;
|
||||||
YAML_ASSERT(node.IsMap());
|
YAML_ASSERT(node.IsMap());
|
||||||
@@ -252,8 +239,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST KeySelfReferenceMap()
|
TEST KeySelfReferenceMap() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node[node] = "value";
|
node[node] = "value";
|
||||||
YAML_ASSERT(node.IsMap());
|
YAML_ASSERT(node.IsMap());
|
||||||
@@ -262,8 +248,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST SelfReferenceMap()
|
TEST SelfReferenceMap() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node[node] = node;
|
node[node] = node;
|
||||||
YAML_ASSERT(node.IsMap());
|
YAML_ASSERT(node.IsMap());
|
||||||
@@ -274,8 +259,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST TempMapVariable()
|
TEST TempMapVariable() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
YAML::Node tmp = node["key"];
|
YAML::Node tmp = node["key"];
|
||||||
tmp = "value";
|
tmp = "value";
|
||||||
@@ -285,8 +269,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST TempMapVariableAlias()
|
TEST TempMapVariableAlias() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
YAML::Node tmp = node["key"];
|
YAML::Node tmp = node["key"];
|
||||||
tmp = node["other"];
|
tmp = node["other"];
|
||||||
@@ -299,8 +282,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST Bool()
|
TEST Bool() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node[true] = false;
|
node[true] = false;
|
||||||
YAML_ASSERT(node.IsMap());
|
YAML_ASSERT(node.IsMap());
|
||||||
@@ -308,8 +290,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST AutoBoolConversion()
|
TEST AutoBoolConversion() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node["foo"] = "bar";
|
node["foo"] = "bar";
|
||||||
YAML_ASSERT(static_cast<bool>(node["foo"]));
|
YAML_ASSERT(static_cast<bool>(node["foo"]));
|
||||||
@@ -318,15 +299,13 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST Reassign()
|
TEST Reassign() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("foo");
|
YAML::Node node = YAML::Load("foo");
|
||||||
node = YAML::Node();
|
node = YAML::Node();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST FallbackValues()
|
TEST FallbackValues() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("foo: bar\nx: 2");
|
YAML::Node node = YAML::Load("foo: bar\nx: 2");
|
||||||
YAML_ASSERT(node["foo"].as<std::string>() == "bar");
|
YAML_ASSERT(node["foo"].as<std::string>() == "bar");
|
||||||
YAML_ASSERT(node["foo"].as<std::string>("hello") == "bar");
|
YAML_ASSERT(node["foo"].as<std::string>("hello") == "bar");
|
||||||
@@ -337,8 +316,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST NumericConversion()
|
TEST NumericConversion() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("[1.5, 1, .nan, .inf, -.inf, 0x15, 015]");
|
YAML::Node node = YAML::Load("[1.5, 1, .nan, .inf, -.inf, 0x15, 015]");
|
||||||
YAML_ASSERT(node[0].as<float>() == 1.5f);
|
YAML_ASSERT(node[0].as<float>() == 1.5f);
|
||||||
YAML_ASSERT(node[0].as<double>() == 1.5);
|
YAML_ASSERT(node[0].as<double>() == 1.5);
|
||||||
@@ -353,16 +331,31 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST Binary()
|
TEST Binary() {
|
||||||
{
|
YAML::Node node = YAML::Load(
|
||||||
YAML::Node node = YAML::Load("[!!binary \"SGVsbG8sIFdvcmxkIQ==\", !!binary \"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4K\"]");
|
"[!!binary \"SGVsbG8sIFdvcmxkIQ==\", !!binary "
|
||||||
YAML_ASSERT(node[0].as<YAML::Binary>() == YAML::Binary(reinterpret_cast<const unsigned char*>("Hello, World!"), 13));
|
"\"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieS"
|
||||||
YAML_ASSERT(node[1].as<YAML::Binary>() == YAML::Binary(reinterpret_cast<const unsigned char*>("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.\n"), 270));
|
"B0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIG"
|
||||||
|
"x1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbi"
|
||||||
|
"B0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZG"
|
||||||
|
"dlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS"
|
||||||
|
"4K\"]");
|
||||||
|
YAML_ASSERT(node[0].as<YAML::Binary>() ==
|
||||||
|
YAML::Binary(
|
||||||
|
reinterpret_cast<const unsigned char*>("Hello, World!"), 13));
|
||||||
|
YAML_ASSERT(node[1].as<YAML::Binary>() ==
|
||||||
|
YAML::Binary(reinterpret_cast<const unsigned char*>(
|
||||||
|
"Man is distinguished, not only by his reason, "
|
||||||
|
"but by this singular passion from other "
|
||||||
|
"animals, which is a lust of the mind, that by "
|
||||||
|
"a perseverance of delight in the continued and "
|
||||||
|
"indefatigable generation of knowledge, exceeds "
|
||||||
|
"the short vehemence of any carnal pleasure.\n"),
|
||||||
|
270));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST IterateSequence()
|
TEST IterateSequence() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
|
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
|
||||||
int seq[] = {1, 3, 5, 7};
|
int seq[] = {1, 3, 5, 7};
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -375,8 +368,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST IterateMap()
|
TEST IterateMap() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("{a: A, b: B, c: C}");
|
YAML::Node node = YAML::Load("{a: A, b: B, c: C}");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
|
for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
|
||||||
@@ -389,8 +381,7 @@ namespace Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BOOST_FOREACH
|
#ifdef BOOST_FOREACH
|
||||||
TEST ForEach()
|
TEST ForEach() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
|
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
|
||||||
int seq[] = {1, 3, 5, 7};
|
int seq[] = {1, 3, 5, 7};
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -401,8 +392,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST ForEachMap()
|
TEST ForEachMap() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("{a: A, b: B, c: C}");
|
YAML::Node node = YAML::Load("{a: A, b: B, c: C}");
|
||||||
BOOST_FOREACH(const YAML::const_iterator::value_type & p, node) {
|
BOOST_FOREACH(const YAML::const_iterator::value_type & p, node) {
|
||||||
YAML_ASSERT(p.first.as<char>() + 'A' - 'a' == p.second.as<char>());
|
YAML_ASSERT(p.first.as<char>() + 'A' - 'a' == p.second.as<char>());
|
||||||
@@ -411,8 +401,7 @@ namespace Test
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST CloneScalar()
|
TEST CloneScalar() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("!foo monkey");
|
YAML::Node node = YAML::Load("!foo monkey");
|
||||||
YAML::Node clone = Clone(node);
|
YAML::Node clone = Clone(node);
|
||||||
YAML_ASSERT(!(node == clone));
|
YAML_ASSERT(!(node == clone));
|
||||||
@@ -421,8 +410,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST CloneSeq()
|
TEST CloneSeq() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
|
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
|
||||||
YAML::Node clone = Clone(node);
|
YAML::Node clone = Clone(node);
|
||||||
YAML_ASSERT(!(node == clone));
|
YAML_ASSERT(!(node == clone));
|
||||||
@@ -433,8 +421,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST CloneMap()
|
TEST CloneMap() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("{foo: bar}");
|
YAML::Node node = YAML::Load("{foo: bar}");
|
||||||
YAML::Node clone = Clone(node);
|
YAML::Node clone = Clone(node);
|
||||||
YAML_ASSERT(!(node == clone));
|
YAML_ASSERT(!(node == clone));
|
||||||
@@ -444,8 +431,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST CloneAlias()
|
TEST CloneAlias() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("&foo [*foo]");
|
YAML::Node node = YAML::Load("&foo [*foo]");
|
||||||
YAML::Node clone = Clone(node);
|
YAML::Node clone = Clone(node);
|
||||||
YAML_ASSERT(!(node == clone));
|
YAML_ASSERT(!(node == clone));
|
||||||
@@ -455,8 +441,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST ForceInsertIntoMap()
|
TEST ForceInsertIntoMap() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
node["a"] = "b";
|
node["a"] = "b";
|
||||||
node.force_insert("x", "y");
|
node.force_insert("x", "y");
|
||||||
@@ -472,7 +457,8 @@ namespace Test
|
|||||||
ab = true;
|
ab = true;
|
||||||
else if (it->second.as<std::string>() == "5")
|
else if (it->second.as<std::string>() == "5")
|
||||||
a5 = true;
|
a5 = true;
|
||||||
} else if(it->first.as<std::string>() == "x" && it->second.as<std::string>() == "y")
|
} else if (it->first.as<std::string>() == "x" &&
|
||||||
|
it->second.as<std::string>() == "y")
|
||||||
xy = true;
|
xy = true;
|
||||||
}
|
}
|
||||||
YAML_ASSERT(ab);
|
YAML_ASSERT(ab);
|
||||||
@@ -481,8 +467,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST ResetNode()
|
TEST ResetNode() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("[1, 2, 3]");
|
YAML::Node node = YAML::Load("[1, 2, 3]");
|
||||||
YAML_ASSERT(!node.IsNull());
|
YAML_ASSERT(!node.IsNull());
|
||||||
YAML::Node other = node;
|
YAML::Node other = node;
|
||||||
@@ -495,8 +480,7 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST DereferenceIteratorError()
|
TEST DereferenceIteratorError() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Load("[{a: b}, 1, 2]");
|
YAML::Node node = YAML::Load("[{a: b}, 1, 2]");
|
||||||
YAML_ASSERT_THROWS(node.begin()->first.as<int>(), YAML::InvalidNode);
|
YAML_ASSERT_THROWS(node.begin()->first.as<int>(), YAML::InvalidNode);
|
||||||
YAML_ASSERT((*node.begin()).IsMap() == true);
|
YAML_ASSERT((*node.begin()).IsMap() == true);
|
||||||
@@ -506,16 +490,14 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST FloatingPrecision()
|
TEST FloatingPrecision() {
|
||||||
{
|
|
||||||
const double x = 0.123456789;
|
const double x = 0.123456789;
|
||||||
YAML::Node node = YAML::Node(x);
|
YAML::Node node = YAML::Node(x);
|
||||||
YAML_ASSERT(node.as<double>() == x);
|
YAML_ASSERT(node.as<double>() == x);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST EmitEmptyNode()
|
TEST EmitEmptyNode() {
|
||||||
{
|
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
YAML::Emitter emitter;
|
YAML::Emitter emitter;
|
||||||
emitter << node;
|
emitter << node;
|
||||||
@@ -523,19 +505,20 @@ namespace Test
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST SpaceChar()
|
TEST SpaceChar() {
|
||||||
{
|
|
||||||
YAML::Node node = YAML::Node(' ');
|
YAML::Node node = YAML::Node(' ');
|
||||||
YAML_ASSERT(node.as<char>() == ' ');
|
YAML_ASSERT(node.as<char>() == ' ');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed,
|
||||||
|
int& total) {
|
||||||
TEST ret;
|
TEST ret;
|
||||||
try {
|
try {
|
||||||
ret = test();
|
ret = test();
|
||||||
} catch(const std::exception& e) {
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
ret.ok = false;
|
ret.ok = false;
|
||||||
ret.error = e.what();
|
ret.error = e.what();
|
||||||
}
|
}
|
||||||
@@ -549,18 +532,21 @@ namespace Test
|
|||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RunNodeTests()
|
bool RunNodeTests() {
|
||||||
{
|
|
||||||
int passed = 0;
|
int passed = 0;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
RunNodeTest(&Node::SimpleScalar, "simple scalar", passed, total);
|
RunNodeTest(&Node::SimpleScalar, "simple scalar", passed, total);
|
||||||
RunNodeTest(&Node::IntScalar, "int scalar", passed, total);
|
RunNodeTest(&Node::IntScalar, "int scalar", passed, total);
|
||||||
RunNodeTest(&Node::SimpleAppendSequence, "simple append sequence", passed, total);
|
RunNodeTest(&Node::SimpleAppendSequence, "simple append sequence", passed,
|
||||||
RunNodeTest(&Node::SimpleAssignSequence, "simple assign sequence", passed, total);
|
total);
|
||||||
|
RunNodeTest(&Node::SimpleAssignSequence, "simple assign sequence", passed,
|
||||||
|
total);
|
||||||
RunNodeTest(&Node::SimpleMap, "simple map", passed, total);
|
RunNodeTest(&Node::SimpleMap, "simple map", passed, total);
|
||||||
RunNodeTest(&Node::MapWithUndefinedValues, "map with undefined values", passed, total);
|
RunNodeTest(&Node::MapWithUndefinedValues, "map with undefined values",
|
||||||
RunNodeTest(&Node::MapIteratorWithUndefinedValues, "map iterator with undefined values", passed, total);
|
passed, total);
|
||||||
|
RunNodeTest(&Node::MapIteratorWithUndefinedValues,
|
||||||
|
"map iterator with undefined values", passed, total);
|
||||||
RunNodeTest(&Node::SimpleSubkeys, "simple subkey", passed, total);
|
RunNodeTest(&Node::SimpleSubkeys, "simple subkey", passed, total);
|
||||||
RunNodeTest(&Node::StdVector, "std::vector", passed, total);
|
RunNodeTest(&Node::StdVector, "std::vector", passed, total);
|
||||||
RunNodeTest(&Node::StdList, "std::list", passed, total);
|
RunNodeTest(&Node::StdList, "std::list", passed, total);
|
||||||
@@ -568,12 +554,16 @@ namespace Test
|
|||||||
RunNodeTest(&Node::StdPair, "std::pair", passed, total);
|
RunNodeTest(&Node::StdPair, "std::pair", passed, total);
|
||||||
RunNodeTest(&Node::SimpleAlias, "simple alias", passed, total);
|
RunNodeTest(&Node::SimpleAlias, "simple alias", passed, total);
|
||||||
RunNodeTest(&Node::AliasAsKey, "alias as key", passed, total);
|
RunNodeTest(&Node::AliasAsKey, "alias as key", passed, total);
|
||||||
RunNodeTest(&Node::SelfReferenceSequence, "self reference sequence", passed, total);
|
RunNodeTest(&Node::SelfReferenceSequence, "self reference sequence", passed,
|
||||||
RunNodeTest(&Node::ValueSelfReferenceMap, "value self reference map", passed, total);
|
total);
|
||||||
RunNodeTest(&Node::KeySelfReferenceMap, "key self reference map", passed, total);
|
RunNodeTest(&Node::ValueSelfReferenceMap, "value self reference map", passed,
|
||||||
|
total);
|
||||||
|
RunNodeTest(&Node::KeySelfReferenceMap, "key self reference map", passed,
|
||||||
|
total);
|
||||||
RunNodeTest(&Node::SelfReferenceMap, "self reference map", passed, total);
|
RunNodeTest(&Node::SelfReferenceMap, "self reference map", passed, total);
|
||||||
RunNodeTest(&Node::TempMapVariable, "temp map variable", passed, total);
|
RunNodeTest(&Node::TempMapVariable, "temp map variable", passed, total);
|
||||||
RunNodeTest(&Node::TempMapVariableAlias, "temp map variable alias", passed, total);
|
RunNodeTest(&Node::TempMapVariableAlias, "temp map variable alias", passed,
|
||||||
|
total);
|
||||||
RunNodeTest(&Node::Bool, "bool", passed, total);
|
RunNodeTest(&Node::Bool, "bool", passed, total);
|
||||||
RunNodeTest(&Node::AutoBoolConversion, "auto bool conversion", passed, total);
|
RunNodeTest(&Node::AutoBoolConversion, "auto bool conversion", passed, total);
|
||||||
RunNodeTest(&Node::Reassign, "reassign", passed, total);
|
RunNodeTest(&Node::Reassign, "reassign", passed, total);
|
||||||
@@ -590,9 +580,11 @@ namespace Test
|
|||||||
RunNodeTest(&Node::CloneSeq, "clone seq", passed, total);
|
RunNodeTest(&Node::CloneSeq, "clone seq", passed, total);
|
||||||
RunNodeTest(&Node::CloneMap, "clone map", passed, total);
|
RunNodeTest(&Node::CloneMap, "clone map", passed, total);
|
||||||
RunNodeTest(&Node::CloneAlias, "clone alias", passed, total);
|
RunNodeTest(&Node::CloneAlias, "clone alias", passed, total);
|
||||||
RunNodeTest(&Node::ForceInsertIntoMap, "force insert into map", passed, total);
|
RunNodeTest(&Node::ForceInsertIntoMap, "force insert into map", passed,
|
||||||
|
total);
|
||||||
RunNodeTest(&Node::ResetNode, "reset node", passed, total);
|
RunNodeTest(&Node::ResetNode, "reset node", passed, total);
|
||||||
RunNodeTest(&Node::DereferenceIteratorError, "dereference iterator error", passed, total);
|
RunNodeTest(&Node::DereferenceIteratorError, "dereference iterator error",
|
||||||
|
passed, total);
|
||||||
RunNodeTest(&Node::FloatingPrecision, "floating precision", passed, total);
|
RunNodeTest(&Node::FloatingPrecision, "floating precision", passed, total);
|
||||||
RunNodeTest(&Node::EmitEmptyNode, "emit empty node", passed, total);
|
RunNodeTest(&Node::EmitEmptyNode, "emit empty node", passed, total);
|
||||||
RunNodeTest(&Node::SpaceChar, "space char", passed, total);
|
RunNodeTest(&Node::SpaceChar, "space char", passed, total);
|
||||||
|
@@ -1,8 +1,5 @@
|
|||||||
#include "parsertests.h"
|
#include "parsertests.h"
|
||||||
|
|
||||||
namespace Test {
|
namespace Test {
|
||||||
bool RunParserTests()
|
bool RunParserTests() { return true; }
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -3,12 +3,14 @@
|
|||||||
#include "yaml-cpp/yaml.h"
|
#include "yaml-cpp/yaml.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
|
#define YAML_ASSERT(cond) \
|
||||||
|
do { \
|
||||||
|
if (!(cond)) \
|
||||||
|
return " Assert failed: " #cond; \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
namespace Test
|
namespace Test {
|
||||||
{
|
namespace Spec {
|
||||||
namespace Spec
|
|
||||||
{
|
|
||||||
// 2.1
|
// 2.1
|
||||||
TEST SeqScalars() {
|
TEST SeqScalars() {
|
||||||
YAML::Node doc = YAML::Load(ex2_1);
|
YAML::Node doc = YAML::Load(ex2_1);
|
||||||
@@ -177,7 +179,6 @@ namespace Test
|
|||||||
yankees_braves.push_back("New York Yankees");
|
yankees_braves.push_back("New York Yankees");
|
||||||
yankees_braves.push_back("Atlanta Braves");
|
yankees_braves.push_back("Atlanta Braves");
|
||||||
|
|
||||||
|
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc[tigers_cubs].size() == 1);
|
YAML_ASSERT(doc[tigers_cubs].size() == 1);
|
||||||
YAML_ASSERT(doc[tigers_cubs][0].as<std::string>() == "2001-07-23");
|
YAML_ASSERT(doc[tigers_cubs][0].as<std::string>() == "2001-07-23");
|
||||||
@@ -216,7 +217,8 @@ namespace Test
|
|||||||
// 2.14
|
// 2.14
|
||||||
TEST InFoldedScalarsNewlinesBecomeSpaces() {
|
TEST InFoldedScalarsNewlinesBecomeSpaces() {
|
||||||
YAML::Node doc = YAML::Load(ex2_14);
|
YAML::Node doc = YAML::Load(ex2_14);
|
||||||
YAML_ASSERT(doc.as<std::string>() == "Mark McGwire's year was crippled by a knee injury.");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
"Mark McGwire's year was crippled by a knee injury.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,8 +238,10 @@ namespace Test
|
|||||||
YAML::Node doc = YAML::Load(ex2_16);
|
YAML::Node doc = YAML::Load(ex2_16);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["name"].as<std::string>() == "Mark McGwire");
|
YAML_ASSERT(doc["name"].as<std::string>() == "Mark McGwire");
|
||||||
YAML_ASSERT(doc["accomplishment"].as<std::string>() == "Mark set a major league home run record in 1998.\n");
|
YAML_ASSERT(doc["accomplishment"].as<std::string>() ==
|
||||||
YAML_ASSERT(doc["stats"].as<std::string>() == "65 Home Runs\n0.278 Batting Average\n");
|
"Mark set a major league home run record in 1998.\n");
|
||||||
|
YAML_ASSERT(doc["stats"].as<std::string>() ==
|
||||||
|
"65 Home Runs\n0.278 Batting Average\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,8 +262,10 @@ namespace Test
|
|||||||
TEST MultiLineFlowScalars() {
|
TEST MultiLineFlowScalars() {
|
||||||
YAML::Node doc = YAML::Load(ex2_18);
|
YAML::Node doc = YAML::Load(ex2_18);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["plain"].as<std::string>() == "This unquoted scalar spans many lines.");
|
YAML_ASSERT(doc["plain"].as<std::string>() ==
|
||||||
YAML_ASSERT(doc["quoted"].as<std::string>() == "So does this quoted scalar.\n");
|
"This unquoted scalar spans many lines.");
|
||||||
|
YAML_ASSERT(doc["quoted"].as<std::string>() ==
|
||||||
|
"So does this quoted scalar.\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,14 +282,12 @@ namespace Test
|
|||||||
"R0lGODlhDAAMAIQAAP//9/X\n"
|
"R0lGODlhDAAMAIQAAP//9/X\n"
|
||||||
"17unp5WZmZgAAAOfn515eXv\n"
|
"17unp5WZmZgAAAOfn515eXv\n"
|
||||||
"Pz7Y6OjuDg4J+fn5OTk6enp\n"
|
"Pz7Y6OjuDg4J+fn5OTk6enp\n"
|
||||||
"56enmleECcgggoBADs=\n"
|
"56enmleECcgggoBADs=\n");
|
||||||
);
|
|
||||||
YAML_ASSERT(doc["application specific tag"].Tag() == "!something");
|
YAML_ASSERT(doc["application specific tag"].Tag() == "!something");
|
||||||
YAML_ASSERT(doc["application specific tag"].as<std::string>() ==
|
YAML_ASSERT(doc["application specific tag"].as<std::string>() ==
|
||||||
"The semantics of the tag\n"
|
"The semantics of the tag\n"
|
||||||
"above may be different for\n"
|
"above may be different for\n"
|
||||||
"different documents."
|
"different documents.");
|
||||||
);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,32 +356,40 @@ namespace Test
|
|||||||
YAML_ASSERT(doc["bill-to"]["given"].as<std::string>() == "Chris");
|
YAML_ASSERT(doc["bill-to"]["given"].as<std::string>() == "Chris");
|
||||||
YAML_ASSERT(doc["bill-to"]["family"].as<std::string>() == "Dumars");
|
YAML_ASSERT(doc["bill-to"]["family"].as<std::string>() == "Dumars");
|
||||||
YAML_ASSERT(doc["bill-to"]["address"].size() == 4);
|
YAML_ASSERT(doc["bill-to"]["address"].size() == 4);
|
||||||
YAML_ASSERT(doc["bill-to"]["address"]["lines"].as<std::string>() == "458 Walkman Dr.\nSuite #292\n");
|
YAML_ASSERT(doc["bill-to"]["address"]["lines"].as<std::string>() ==
|
||||||
YAML_ASSERT(doc["bill-to"]["address"]["city"].as<std::string>() == "Royal Oak");
|
"458 Walkman Dr.\nSuite #292\n");
|
||||||
|
YAML_ASSERT(doc["bill-to"]["address"]["city"].as<std::string>() ==
|
||||||
|
"Royal Oak");
|
||||||
YAML_ASSERT(doc["bill-to"]["address"]["state"].as<std::string>() == "MI");
|
YAML_ASSERT(doc["bill-to"]["address"]["state"].as<std::string>() == "MI");
|
||||||
YAML_ASSERT(doc["bill-to"]["address"]["postal"].as<std::string>() == "48046");
|
YAML_ASSERT(doc["bill-to"]["address"]["postal"].as<std::string>() == "48046");
|
||||||
YAML_ASSERT(doc["ship-to"].size() == 3);
|
YAML_ASSERT(doc["ship-to"].size() == 3);
|
||||||
YAML_ASSERT(doc["ship-to"]["given"].as<std::string>() == "Chris");
|
YAML_ASSERT(doc["ship-to"]["given"].as<std::string>() == "Chris");
|
||||||
YAML_ASSERT(doc["ship-to"]["family"].as<std::string>() == "Dumars");
|
YAML_ASSERT(doc["ship-to"]["family"].as<std::string>() == "Dumars");
|
||||||
YAML_ASSERT(doc["ship-to"]["address"].size() == 4);
|
YAML_ASSERT(doc["ship-to"]["address"].size() == 4);
|
||||||
YAML_ASSERT(doc["ship-to"]["address"]["lines"].as<std::string>() == "458 Walkman Dr.\nSuite #292\n");
|
YAML_ASSERT(doc["ship-to"]["address"]["lines"].as<std::string>() ==
|
||||||
YAML_ASSERT(doc["ship-to"]["address"]["city"].as<std::string>() == "Royal Oak");
|
"458 Walkman Dr.\nSuite #292\n");
|
||||||
|
YAML_ASSERT(doc["ship-to"]["address"]["city"].as<std::string>() ==
|
||||||
|
"Royal Oak");
|
||||||
YAML_ASSERT(doc["ship-to"]["address"]["state"].as<std::string>() == "MI");
|
YAML_ASSERT(doc["ship-to"]["address"]["state"].as<std::string>() == "MI");
|
||||||
YAML_ASSERT(doc["ship-to"]["address"]["postal"].as<std::string>() == "48046");
|
YAML_ASSERT(doc["ship-to"]["address"]["postal"].as<std::string>() == "48046");
|
||||||
YAML_ASSERT(doc["product"].size() == 2);
|
YAML_ASSERT(doc["product"].size() == 2);
|
||||||
YAML_ASSERT(doc["product"][0].size() == 4);
|
YAML_ASSERT(doc["product"][0].size() == 4);
|
||||||
YAML_ASSERT(doc["product"][0]["sku"].as<std::string>() == "BL394D");
|
YAML_ASSERT(doc["product"][0]["sku"].as<std::string>() == "BL394D");
|
||||||
YAML_ASSERT(doc["product"][0]["quantity"].as<int>() == 4);
|
YAML_ASSERT(doc["product"][0]["quantity"].as<int>() == 4);
|
||||||
YAML_ASSERT(doc["product"][0]["description"].as<std::string>() == "Basketball");
|
YAML_ASSERT(doc["product"][0]["description"].as<std::string>() ==
|
||||||
|
"Basketball");
|
||||||
YAML_ASSERT(doc["product"][0]["price"].as<std::string>() == "450.00");
|
YAML_ASSERT(doc["product"][0]["price"].as<std::string>() == "450.00");
|
||||||
YAML_ASSERT(doc["product"][1].size() == 4);
|
YAML_ASSERT(doc["product"][1].size() == 4);
|
||||||
YAML_ASSERT(doc["product"][1]["sku"].as<std::string>() == "BL4438H");
|
YAML_ASSERT(doc["product"][1]["sku"].as<std::string>() == "BL4438H");
|
||||||
YAML_ASSERT(doc["product"][1]["quantity"].as<int>() == 1);
|
YAML_ASSERT(doc["product"][1]["quantity"].as<int>() == 1);
|
||||||
YAML_ASSERT(doc["product"][1]["description"].as<std::string>() == "Super Hoop");
|
YAML_ASSERT(doc["product"][1]["description"].as<std::string>() ==
|
||||||
|
"Super Hoop");
|
||||||
YAML_ASSERT(doc["product"][1]["price"].as<std::string>() == "2392.00");
|
YAML_ASSERT(doc["product"][1]["price"].as<std::string>() == "2392.00");
|
||||||
YAML_ASSERT(doc["tax"].as<std::string>() == "251.42");
|
YAML_ASSERT(doc["tax"].as<std::string>() == "251.42");
|
||||||
YAML_ASSERT(doc["total"].as<std::string>() == "4443.52");
|
YAML_ASSERT(doc["total"].as<std::string>() == "4443.52");
|
||||||
YAML_ASSERT(doc["comments"].as<std::string>() == "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.");
|
YAML_ASSERT(
|
||||||
|
doc["comments"].as<std::string>() ==
|
||||||
|
"Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,7 +403,8 @@ namespace Test
|
|||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["Time"].as<std::string>() == "2001-11-23 15:01:42 -5");
|
YAML_ASSERT(doc["Time"].as<std::string>() == "2001-11-23 15:01:42 -5");
|
||||||
YAML_ASSERT(doc["User"].as<std::string>() == "ed");
|
YAML_ASSERT(doc["User"].as<std::string>() == "ed");
|
||||||
YAML_ASSERT(doc["Warning"].as<std::string>() == "This is an error message for the log file");
|
YAML_ASSERT(doc["Warning"].as<std::string>() ==
|
||||||
|
"This is an error message for the log file");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -399,7 +412,8 @@ namespace Test
|
|||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["Time"].as<std::string>() == "2001-11-23 15:02:31 -5");
|
YAML_ASSERT(doc["Time"].as<std::string>() == "2001-11-23 15:02:31 -5");
|
||||||
YAML_ASSERT(doc["User"].as<std::string>() == "ed");
|
YAML_ASSERT(doc["User"].as<std::string>() == "ed");
|
||||||
YAML_ASSERT(doc["Warning"].as<std::string>() == "A slightly different error message.");
|
YAML_ASSERT(doc["Warning"].as<std::string>() ==
|
||||||
|
"A slightly different error message.");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -412,7 +426,8 @@ namespace Test
|
|||||||
YAML_ASSERT(doc["Stack"][0].size() == 3);
|
YAML_ASSERT(doc["Stack"][0].size() == 3);
|
||||||
YAML_ASSERT(doc["Stack"][0]["file"].as<std::string>() == "TopClass.py");
|
YAML_ASSERT(doc["Stack"][0]["file"].as<std::string>() == "TopClass.py");
|
||||||
YAML_ASSERT(doc["Stack"][0]["line"].as<std::string>() == "23");
|
YAML_ASSERT(doc["Stack"][0]["line"].as<std::string>() == "23");
|
||||||
YAML_ASSERT(doc["Stack"][0]["code"].as<std::string>() == "x = MoreObject(\"345\\n\")\n");
|
YAML_ASSERT(doc["Stack"][0]["code"].as<std::string>() ==
|
||||||
|
"x = MoreObject(\"345\\n\")\n");
|
||||||
YAML_ASSERT(doc["Stack"][1].size() == 3);
|
YAML_ASSERT(doc["Stack"][1].size() == 3);
|
||||||
YAML_ASSERT(doc["Stack"][1]["file"].as<std::string>() == "MoreClass.py");
|
YAML_ASSERT(doc["Stack"][1]["file"].as<std::string>() == "MoreClass.py");
|
||||||
YAML_ASSERT(doc["Stack"][1]["line"].as<std::string>() == "58");
|
YAML_ASSERT(doc["Stack"][1]["line"].as<std::string>() == "58");
|
||||||
@@ -460,7 +475,8 @@ namespace Test
|
|||||||
TEST NodePropertyIndicators() {
|
TEST NodePropertyIndicators() {
|
||||||
YAML::Node doc = YAML::Load(ex5_6);
|
YAML::Node doc = YAML::Load(ex5_6);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["anchored"].as<std::string>() == "value"); // TODO: assert tag
|
YAML_ASSERT(doc["anchored"].as<std::string>() ==
|
||||||
|
"value"); // TODO: assert tag
|
||||||
YAML_ASSERT(doc["alias"].as<std::string>() == "value");
|
YAML_ASSERT(doc["alias"].as<std::string>() == "value");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -489,7 +505,8 @@ namespace Test
|
|||||||
// 5.11
|
// 5.11
|
||||||
TEST LineBreakCharacters() {
|
TEST LineBreakCharacters() {
|
||||||
YAML::Node doc = YAML::Load(ex5_11);
|
YAML::Node doc = YAML::Load(ex5_11);
|
||||||
YAML_ASSERT(doc.as<std::string>() == "Line break (no glyph)\nLine break (glyphed)\n");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
"Line break (no glyph)\nLine break (glyphed)\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,7 +525,10 @@ namespace Test
|
|||||||
// 5.13
|
// 5.13
|
||||||
TEST EscapedCharacters() {
|
TEST EscapedCharacters() {
|
||||||
YAML::Node doc = YAML::Load(ex5_13);
|
YAML::Node doc = YAML::Load(ex5_13);
|
||||||
YAML_ASSERT(doc.as<std::string>() == "Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " + std::string("\x00", 1) + " \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
"Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " +
|
||||||
|
std::string("\x00", 1) +
|
||||||
|
" \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,7 +536,8 @@ namespace Test
|
|||||||
TEST InvalidEscapedCharacters() {
|
TEST InvalidEscapedCharacters() {
|
||||||
try {
|
try {
|
||||||
YAML::Load(ex5_14);
|
YAML::Load(ex5_14);
|
||||||
} catch(const YAML::ParserException& e) {
|
}
|
||||||
|
catch (const YAML::ParserException& e) {
|
||||||
YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::INVALID_ESCAPE) + "c");
|
YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::INVALID_ESCAPE) + "c");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -529,11 +550,15 @@ namespace Test
|
|||||||
YAML::Node doc = YAML::Load(ex6_1);
|
YAML::Node doc = YAML::Load(ex6_1);
|
||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc["Not indented"].size() == 2);
|
YAML_ASSERT(doc["Not indented"].size() == 2);
|
||||||
YAML_ASSERT(doc["Not indented"]["By one space"].as<std::string>() == "By four\n spaces\n");
|
YAML_ASSERT(doc["Not indented"]["By one space"].as<std::string>() ==
|
||||||
|
"By four\n spaces\n");
|
||||||
YAML_ASSERT(doc["Not indented"]["Flow style"].size() == 3);
|
YAML_ASSERT(doc["Not indented"]["Flow style"].size() == 3);
|
||||||
YAML_ASSERT(doc["Not indented"]["Flow style"][0].as<std::string>() == "By two");
|
YAML_ASSERT(doc["Not indented"]["Flow style"][0].as<std::string>() ==
|
||||||
YAML_ASSERT(doc["Not indented"]["Flow style"][1].as<std::string>() == "Also by two");
|
"By two");
|
||||||
YAML_ASSERT(doc["Not indented"]["Flow style"][2].as<std::string>() == "Still by two");
|
YAML_ASSERT(doc["Not indented"]["Flow style"][1].as<std::string>() ==
|
||||||
|
"Also by two");
|
||||||
|
YAML_ASSERT(doc["Not indented"]["Flow style"][2].as<std::string>() ==
|
||||||
|
"Still by two");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,7 +682,8 @@ namespace Test
|
|||||||
TEST InvalidRepeatedYAMLDirective() {
|
TEST InvalidRepeatedYAMLDirective() {
|
||||||
try {
|
try {
|
||||||
YAML::Load(ex6_15);
|
YAML::Load(ex6_15);
|
||||||
} catch(const YAML::ParserException& e) {
|
}
|
||||||
|
catch (const YAML::ParserException& e) {
|
||||||
YAML_ASSERT(e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE);
|
YAML_ASSERT(e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -677,7 +703,8 @@ namespace Test
|
|||||||
TEST InvalidRepeatedTagDirective() {
|
TEST InvalidRepeatedTagDirective() {
|
||||||
try {
|
try {
|
||||||
YAML::Load(ex6_17);
|
YAML::Load(ex6_17);
|
||||||
} catch(const YAML::ParserException& e) {
|
}
|
||||||
|
catch (const YAML::ParserException& e) {
|
||||||
if (e.msg == YAML::ErrorMsg::REPEATED_TAG_DIRECTIVE)
|
if (e.msg == YAML::ErrorMsg::REPEATED_TAG_DIRECTIVE)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -784,7 +811,8 @@ namespace Test
|
|||||||
// 6.25
|
// 6.25
|
||||||
TEST InvalidVerbatimTags() {
|
TEST InvalidVerbatimTags() {
|
||||||
YAML::Node doc = YAML::Load(ex6_25);
|
YAML::Node doc = YAML::Load(ex6_25);
|
||||||
return " not implemented yet"; // TODO: check tags (but we probably will say these are valid, I think)
|
return " not implemented yet"; // TODO: check tags (but we probably will say
|
||||||
|
// these are valid, I think)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6.26
|
// 6.26
|
||||||
@@ -805,7 +833,8 @@ namespace Test
|
|||||||
bool threw = false;
|
bool threw = false;
|
||||||
try {
|
try {
|
||||||
YAML::Load(ex6_27a);
|
YAML::Load(ex6_27a);
|
||||||
} catch(const YAML::ParserException& e) {
|
}
|
||||||
|
catch (const YAML::ParserException& e) {
|
||||||
threw = true;
|
threw = true;
|
||||||
if (e.msg != YAML::ErrorMsg::TAG_WITH_NO_SUFFIX)
|
if (e.msg != YAML::ErrorMsg::TAG_WITH_NO_SUFFIX)
|
||||||
throw;
|
throw;
|
||||||
@@ -814,7 +843,8 @@ namespace Test
|
|||||||
if (!threw)
|
if (!threw)
|
||||||
return " No exception was thrown for a tag with no suffix";
|
return " No exception was thrown for a tag with no suffix";
|
||||||
|
|
||||||
YAML::Load(ex6_27b); // TODO: should we reject this one (since !h! is not declared)?
|
YAML::Load(
|
||||||
|
ex6_27b); // TODO: should we reject this one (since !h! is not declared)?
|
||||||
return " not implemented yet";
|
return " not implemented yet";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -880,21 +910,24 @@ namespace Test
|
|||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"].as<std::string>() == "value");
|
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"]
|
||||||
|
.as<std::string>() == "value");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.5
|
// 7.5
|
||||||
TEST DoubleQuotedLineBreaks() {
|
TEST DoubleQuotedLineBreaks() {
|
||||||
YAML::Node doc = YAML::Load(ex7_5);
|
YAML::Node doc = YAML::Load(ex7_5);
|
||||||
YAML_ASSERT(doc.as<std::string>() == "folded to a space,\nto a line feed, or \t \tnon-content");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
"folded to a space,\nto a line feed, or \t \tnon-content");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.6
|
// 7.6
|
||||||
TEST DoubleQuotedLines() {
|
TEST DoubleQuotedLines() {
|
||||||
YAML::Node doc = YAML::Load(ex7_6);
|
YAML::Node doc = YAML::Load(ex7_6);
|
||||||
YAML_ASSERT(doc.as<std::string>() == " 1st non-empty\n2nd non-empty 3rd non-empty ");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
" 1st non-empty\n2nd non-empty 3rd non-empty ");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -911,14 +944,16 @@ namespace Test
|
|||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"].as<std::string>() == "value");
|
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"]
|
||||||
|
.as<std::string>() == "value");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.9
|
// 7.9
|
||||||
TEST SingleQuotedLines() {
|
TEST SingleQuotedLines() {
|
||||||
YAML::Node doc = YAML::Load(ex7_9);
|
YAML::Node doc = YAML::Load(ex7_9);
|
||||||
YAML_ASSERT(doc.as<std::string>() == " 1st non-empty\n2nd non-empty 3rd non-empty ");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
" 1st non-empty\n2nd non-empty 3rd non-empty ");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -946,14 +981,16 @@ namespace Test
|
|||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"].as<std::string>() == "value");
|
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"]
|
||||||
|
.as<std::string>() == "value");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.12
|
// 7.12
|
||||||
TEST PlainLines() {
|
TEST PlainLines() {
|
||||||
YAML::Node doc = YAML::Load(ex7_12);
|
YAML::Node doc = YAML::Load(ex7_12);
|
||||||
YAML_ASSERT(doc.as<std::string>() == "1st non-empty\n2nd non-empty 3rd non-empty");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
"1st non-empty\n2nd non-empty 3rd non-empty");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1069,7 +1106,8 @@ namespace Test
|
|||||||
TEST InvalidImplicitKeys() {
|
TEST InvalidImplicitKeys() {
|
||||||
try {
|
try {
|
||||||
YAML::Load(ex7_22);
|
YAML::Load(ex7_22);
|
||||||
} catch(const YAML::Exception& e) {
|
}
|
||||||
|
catch (const YAML::Exception& e) {
|
||||||
if (e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW)
|
if (e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -1135,7 +1173,8 @@ namespace Test
|
|||||||
bool threw = false;
|
bool threw = false;
|
||||||
try {
|
try {
|
||||||
YAML::Load(ex8_3a);
|
YAML::Load(ex8_3a);
|
||||||
} catch(const YAML::Exception& e) {
|
}
|
||||||
|
catch (const YAML::Exception& e) {
|
||||||
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
|
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
|
||||||
throw;
|
throw;
|
||||||
|
|
||||||
@@ -1143,14 +1182,16 @@ namespace Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!threw)
|
if (!threw)
|
||||||
return " no exception thrown for less indented auto-detecting indentation for a literal block scalar";
|
return " no exception thrown for less indented auto-detecting "
|
||||||
|
"indentation for a literal block scalar";
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
bool threw = false;
|
bool threw = false;
|
||||||
try {
|
try {
|
||||||
YAML::Load(ex8_3b);
|
YAML::Load(ex8_3b);
|
||||||
} catch(const YAML::Exception& e) {
|
}
|
||||||
|
catch (const YAML::Exception& e) {
|
||||||
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
|
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
|
||||||
throw;
|
throw;
|
||||||
|
|
||||||
@@ -1158,14 +1199,16 @@ namespace Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!threw)
|
if (!threw)
|
||||||
return " no exception thrown for less indented auto-detecting indentation for a folded block scalar";
|
return " no exception thrown for less indented auto-detecting "
|
||||||
|
"indentation for a folded block scalar";
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
bool threw = false;
|
bool threw = false;
|
||||||
try {
|
try {
|
||||||
YAML::Load(ex8_3c);
|
YAML::Load(ex8_3c);
|
||||||
} catch(const YAML::Exception& e) {
|
}
|
||||||
|
catch (const YAML::Exception& e) {
|
||||||
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
|
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
|
||||||
throw;
|
throw;
|
||||||
|
|
||||||
@@ -1173,7 +1216,8 @@ namespace Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!threw)
|
if (!threw)
|
||||||
return " no exception thrown for less indented explicit indentation for a literal block scalar";
|
return " no exception thrown for less indented explicit indentation for "
|
||||||
|
"a literal block scalar";
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1195,7 +1239,11 @@ namespace Test
|
|||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["strip"].as<std::string>() == "# text");
|
YAML_ASSERT(doc["strip"].as<std::string>() == "# text");
|
||||||
YAML_ASSERT(doc["clip"].as<std::string>() == "# text\n");
|
YAML_ASSERT(doc["clip"].as<std::string>() == "# text\n");
|
||||||
YAML_ASSERT(doc["keep"].as<std::string>() == "# text\n"); // Note: I believe this is a bug in the YAML spec - it should be "# text\n\n"
|
YAML_ASSERT(doc["keep"].as<std::string>() == "# text\n"); // Note: I believe
|
||||||
|
// this is a bug in
|
||||||
|
// the YAML spec -
|
||||||
|
// it should be "#
|
||||||
|
// text\n\n"
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1233,28 +1281,36 @@ namespace Test
|
|||||||
// 8.10
|
// 8.10
|
||||||
TEST FoldedLines() {
|
TEST FoldedLines() {
|
||||||
YAML::Node doc = YAML::Load(ex8_10);
|
YAML::Node doc = YAML::Load(ex8_10);
|
||||||
YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
|
||||||
|
"lines\n\nlast line\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.11
|
// 8.11
|
||||||
TEST MoreIndentedLines() {
|
TEST MoreIndentedLines() {
|
||||||
YAML::Node doc = YAML::Load(ex8_11);
|
YAML::Node doc = YAML::Load(ex8_11);
|
||||||
YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
|
||||||
|
"lines\n\nlast line\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.12
|
// 8.12
|
||||||
TEST EmptySeparationLines() {
|
TEST EmptySeparationLines() {
|
||||||
YAML::Node doc = YAML::Load(ex8_12);
|
YAML::Node doc = YAML::Load(ex8_12);
|
||||||
YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
|
||||||
|
"lines\n\nlast line\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.13
|
// 8.13
|
||||||
TEST FinalEmptyLines() {
|
TEST FinalEmptyLines() {
|
||||||
YAML::Node doc = YAML::Load(ex8_13);
|
YAML::Node doc = YAML::Load(ex8_13);
|
||||||
YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
|
YAML_ASSERT(doc.as<std::string>() ==
|
||||||
|
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
|
||||||
|
"lines\n\nlast line\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1343,7 +1399,11 @@ namespace Test
|
|||||||
TEST BlockScalarNodes() {
|
TEST BlockScalarNodes() {
|
||||||
YAML::Node doc = YAML::Load(ex8_21);
|
YAML::Node doc = YAML::Load(ex8_21);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["literal"].as<std::string>() == "value"); // Note: I believe this is a bug in the YAML spec - it should be "value\n"
|
YAML_ASSERT(doc["literal"].as<std::string>() == "value"); // Note: I believe
|
||||||
|
// this is a bug in
|
||||||
|
// the YAML spec -
|
||||||
|
// it should be
|
||||||
|
// "value\n"
|
||||||
YAML_ASSERT(doc["folded"].as<std::string>() == "value");
|
YAML_ASSERT(doc["folded"].as<std::string>() == "value");
|
||||||
YAML_ASSERT(doc["folded"].Tag() == "!foo");
|
YAML_ASSERT(doc["folded"].Tag() == "!foo");
|
||||||
return true;
|
return true;
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
#ifndef NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#ifndef NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
#define NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
#if defined(_MSC_VER) || \
|
||||||
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||||
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -10,4 +12,3 @@ namespace Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A6666
|
#endif // NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A6666
|
||||||
|
|
||||||
|
@@ -9,10 +9,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace Test
|
namespace Test {
|
||||||
{
|
void RunAll() {
|
||||||
void RunAll()
|
|
||||||
{
|
|
||||||
bool passed = true;
|
bool passed = true;
|
||||||
if (!RunParserTests())
|
if (!RunParserTests())
|
||||||
passed = false;
|
passed = false;
|
||||||
@@ -30,4 +28,3 @@ namespace Test
|
|||||||
std::cout << "All tests passed!\n";
|
std::cout << "All tests passed!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,35 +17,36 @@ Params ParseArgs(int argc, char **argv) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NullEventHandler: public YAML::EventHandler
|
class NullEventHandler : public YAML::EventHandler {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
virtual void OnDocumentStart(const YAML::Mark&) {}
|
virtual void OnDocumentStart(const YAML::Mark&) {}
|
||||||
virtual void OnDocumentEnd() {}
|
virtual void OnDocumentEnd() {}
|
||||||
|
|
||||||
virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
|
virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
|
||||||
virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
|
virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
|
||||||
virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {}
|
virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t,
|
||||||
|
const std::string&) {}
|
||||||
|
|
||||||
virtual void OnSequenceStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
|
virtual void OnSequenceStart(const YAML::Mark&, const std::string&,
|
||||||
|
YAML::anchor_t) {}
|
||||||
virtual void OnSequenceEnd() {}
|
virtual void OnSequenceEnd() {}
|
||||||
|
|
||||||
virtual void OnMapStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
|
virtual void OnMapStart(const YAML::Mark&, const std::string&,
|
||||||
|
YAML::anchor_t) {}
|
||||||
virtual void OnMapEnd() {}
|
virtual void OnMapEnd() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
void parse(std::istream& input)
|
void parse(std::istream& input) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
YAML::Node doc = YAML::Load(input);
|
YAML::Node doc = YAML::Load(input);
|
||||||
std::cout << doc << "\n";
|
std::cout << doc << "\n";
|
||||||
} catch(const YAML::Exception& e) {
|
}
|
||||||
|
catch (const YAML::Exception& e) {
|
||||||
std::cerr << e.what() << "\n";
|
std::cerr << e.what() << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char** argv) {
|
||||||
{
|
|
||||||
Params p = ParseArgs(argc, argv);
|
Params p = ParseArgs(argc, argv);
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
|
Reference in New Issue
Block a user