Run clang-format

This commit is contained in:
Jesse Beder
2014-03-22 13:05:03 -05:00
parent 3355bbb399
commit d63ec48c8a
40 changed files with 5797 additions and 5687 deletions

View File

@@ -30,7 +30,7 @@
// #pragma message( "Defining YAML_CPP_API for DLL import" ) // #pragma message( "Defining YAML_CPP_API for DLL import" )
#define YAML_CPP_API __declspec(dllimport) #define YAML_CPP_API __declspec(dllimport)
#endif // yaml_cpp_EXPORTS #endif // yaml_cpp_EXPORTS
#else // YAML_CPP_DLL #else // YAML_CPP_DLL
#define YAML_CPP_API #define YAML_CPP_API
#endif // YAML_CPP_DLL #endif // YAML_CPP_DLL

View File

@@ -1,208 +1,227 @@
#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 =
{ "YAML directives must have exactly one argument";
const char * const YAML_DIRECTIVE_ARGS = "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 =
const char * const TAG_DIRECTIVE_ARGS = "TAG directives must have exactly two arguments"; "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 =
const char * const TAG_WITH_NO_SUFFIX = "tag handle with no suffix"; "illegal character found while scanning tag handle";
const char * const END_OF_VERBATIM_TAG = "end of verbatim tag not found"; const char* const TAG_WITH_NO_SUFFIX = "tag handle with no suffix";
const char * const END_OF_MAP = "end of map not found"; const char* const END_OF_VERBATIM_TAG = "end of verbatim tag not found";
const char * const END_OF_MAP_FLOW = "end of map flow not found"; const char* const END_OF_MAP = "end of map not found";
const char * const END_OF_SEQ = "end of sequence not found"; const char* const END_OF_MAP_FLOW = "end of map flow not found";
const char * const END_OF_SEQ_FLOW = "end of sequence flow not found"; const char* const END_OF_SEQ = "end of sequence not found";
const char * const MULTIPLE_TAGS = "cannot assign multiple tags to the same node"; const char* const END_OF_SEQ_FLOW = "end of sequence flow not found";
const char * const MULTIPLE_ANCHORS = "cannot assign multiple anchors to the same node"; const char* const MULTIPLE_TAGS =
const char * const MULTIPLE_ALIASES = "cannot assign multiple aliases to the same node"; "cannot assign multiple tags to the same node";
const char * const ALIAS_CONTENT = "aliases can't have any content, *including* tags"; const char* const MULTIPLE_ANCHORS =
const char * const INVALID_HEX = "bad character found while scanning hex number"; "cannot assign multiple anchors to the same node";
const char * const INVALID_UNICODE = "invalid unicode: "; const char* const MULTIPLE_ALIASES =
const char * const INVALID_ESCAPE = "unknown escape character: "; "cannot assign multiple aliases to the same node";
const char * const UNKNOWN_TOKEN = "unknown token"; const char* const ALIAS_CONTENT =
const char * const DOC_IN_SCALAR = "illegal document indicator in scalar"; "aliases can't have any content, *including* tags";
const char * const EOF_IN_SCALAR = "illegal EOF in scalar"; const char* const INVALID_HEX = "bad character found while scanning hex number";
const char * const CHAR_IN_SCALAR = "illegal character in scalar"; const char* const INVALID_UNICODE = "invalid unicode: ";
const char * const TAB_IN_INDENTATION = "illegal tab when looking for indentation"; const char* const INVALID_ESCAPE = "unknown escape character: ";
const char * const FLOW_END = "illegal flow end"; const char* const UNKNOWN_TOKEN = "unknown token";
const char * const BLOCK_ENTRY = "illegal block entry"; const char* const DOC_IN_SCALAR = "illegal document indicator in scalar";
const char * const MAP_KEY = "illegal map key"; const char* const EOF_IN_SCALAR = "illegal EOF in scalar";
const char * const MAP_VALUE = "illegal map value"; const char* const CHAR_IN_SCALAR = "illegal character in scalar";
const char * const ALIAS_NOT_FOUND = "alias not found after *"; const char* const TAB_IN_INDENTATION =
const char * const ANCHOR_NOT_FOUND = "anchor not found after &"; "illegal tab when looking for indentation";
const char * const CHAR_IN_ALIAS = "illegal character found while scanning alias"; const char* const FLOW_END = "illegal flow end";
const char * const CHAR_IN_ANCHOR = "illegal character found while scanning anchor"; const char* const BLOCK_ENTRY = "illegal block entry";
const char * const ZERO_INDENT_IN_BLOCK = "cannot set zero indentation for a block scalar"; const char* const MAP_KEY = "illegal map key";
const char * const CHAR_IN_BLOCK = "unexpected character in block scalar"; const char* const MAP_VALUE = "illegal map value";
const char * const AMBIGUOUS_ANCHOR = "cannot assign the same alias to multiple nodes"; const char* const ALIAS_NOT_FOUND = "alias not found after *";
const char * const UNKNOWN_ANCHOR = "the referenced anchor is not defined"; 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_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 AMBIGUOUS_ANCHOR =
"cannot assign the same alias to multiple nodes";
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 =
const char * const INVALID_SCALAR = "invalid scalar"; "invalid node; this may result from using a map iterator as a sequence "
const char * const KEY_NOT_FOUND = "key not found"; "iterator, or vice-versa";
const char * const BAD_CONVERSION = "bad conversion"; const char* const INVALID_SCALAR = "invalid scalar";
const char * const BAD_DEREFERENCE = "bad dereference"; const char* const KEY_NOT_FOUND = "key not found";
const char * const BAD_SUBSCRIPT = "operator[] call on a scalar"; const char* const BAD_CONVERSION = "bad conversion";
const char * const BAD_PUSHBACK = "appending to a non-sequence"; const char* const BAD_DEREFERENCE = "bad dereference";
const char * const BAD_INSERT = "inserting in a non-convertible-to-map"; const char* const BAD_SUBSCRIPT = "operator[] call on a scalar";
const char* const BAD_PUSHBACK = "appending to a non-sequence";
const char * const UNMATCHED_GROUP_TAG = "unmatched group tag"; const char* const BAD_INSERT = "inserting in a non-convertible-to-map";
const char * const UNEXPECTED_END_SEQ = "unexpected end sequence 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 INVALID_ANCHOR = "invalid anchor";
const char * const INVALID_ALIAS = "invalid alias";
const char * const INVALID_TAG = "invalid tag";
const char * const BAD_FILE = "bad file";
template <typename T> const char* const UNMATCHED_GROUP_TAG = "unmatched group tag";
inline const std::string KEY_NOT_FOUND_WITH_KEY(const T&, typename disable_if<is_numeric<T> >::type * = 0) { const char* const UNEXPECTED_END_SEQ = "unexpected end sequence token";
return KEY_NOT_FOUND; 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 INVALID_ANCHOR = "invalid anchor";
const char* const INVALID_ALIAS = "invalid alias";
const char* const INVALID_TAG = "invalid tag";
const char* const BAD_FILE = "bad file";
inline const std::string KEY_NOT_FOUND_WITH_KEY(const std::string& key) { template <typename T>
std::stringstream stream; inline const std::string KEY_NOT_FOUND_WITH_KEY(
stream << KEY_NOT_FOUND << ": " << key; const T&, typename disable_if<is_numeric<T> >::type* = 0) {
return stream.str(); return KEY_NOT_FOUND;
}
template <typename T>
inline const std::string KEY_NOT_FOUND_WITH_KEY(const T& key, typename enable_if<is_numeric<T> >::type * = 0) {
std::stringstream stream;
stream << KEY_NOT_FOUND << ": " << key;
return stream.str();
}
}
class Exception: public std::runtime_error {
public:
Exception(const Mark& mark_, const std::string& msg_)
: std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
virtual ~Exception() throw() {}
Mark mark;
std::string msg;
private:
static const std::string build_what(const Mark& mark, const std::string& msg) {
std::stringstream output;
output << "yaml-cpp: error at line " << mark.line+1 << ", column " << mark.column+1 << ": " << msg;
return output.str();
}
};
class ParserException: public Exception {
public:
ParserException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {}
};
class RepresentationException: public Exception {
public:
RepresentationException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {}
};
// representation exceptions
class InvalidScalar: public RepresentationException {
public:
InvalidScalar(const Mark& mark_)
: RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
};
class KeyNotFound: public RepresentationException {
public:
template <typename T>
KeyNotFound(const Mark& mark_, const T& key_)
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {}
};
template <typename T>
class TypedKeyNotFound: public KeyNotFound {
public:
TypedKeyNotFound(const Mark& mark_, const T& key_)
: KeyNotFound(mark_, key_), key(key_) {}
virtual ~TypedKeyNotFound() throw() {}
T key;
};
template <typename T>
inline TypedKeyNotFound <T> MakeTypedKeyNotFound(const Mark& mark, const T& key) {
return TypedKeyNotFound <T> (mark, key);
}
class InvalidNode: public RepresentationException {
public:
InvalidNode()
: RepresentationException(Mark::null_mark(), ErrorMsg::INVALID_NODE) {}
};
class BadConversion: public RepresentationException {
public:
BadConversion()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_CONVERSION) {}
};
template<typename T>
class TypedBadConversion: public BadConversion {
public:
TypedBadConversion()
: BadConversion() {}
};
class BadDereference: public RepresentationException {
public:
BadDereference()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
};
class BadSubscript: public RepresentationException {
public:
BadSubscript()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
};
class BadPushback: public RepresentationException {
public:
BadPushback()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
};
class BadInsert: public RepresentationException {
public:
BadInsert()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
};
class EmitterException: public Exception {
public:
EmitterException(const std::string& msg_)
: Exception(Mark::null_mark(), msg_) {}
};
class BadFile: public Exception {
public:
BadFile(): Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {}
};
} }
#endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 inline const std::string KEY_NOT_FOUND_WITH_KEY(const std::string& key) {
std::stringstream stream;
stream << KEY_NOT_FOUND << ": " << key;
return stream.str();
}
template <typename T>
inline const std::string KEY_NOT_FOUND_WITH_KEY(
const T& key, typename enable_if<is_numeric<T> >::type* = 0) {
std::stringstream stream;
stream << KEY_NOT_FOUND << ": " << key;
return stream.str();
}
}
class Exception : public std::runtime_error {
public:
Exception(const Mark& mark_, const std::string& msg_)
: std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
virtual ~Exception() throw() {}
Mark mark;
std::string msg;
private:
static const std::string build_what(const Mark& mark,
const std::string& msg) {
std::stringstream output;
output << "yaml-cpp: error at line " << mark.line + 1 << ", column "
<< mark.column + 1 << ": " << msg;
return output.str();
}
};
class ParserException : public Exception {
public:
ParserException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {}
};
class RepresentationException : public Exception {
public:
RepresentationException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {}
};
// representation exceptions
class InvalidScalar : public RepresentationException {
public:
InvalidScalar(const Mark& mark_)
: RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
};
class KeyNotFound : public RepresentationException {
public:
template <typename T>
KeyNotFound(const Mark& mark_, const T& key_)
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {
}
};
template <typename T>
class TypedKeyNotFound : public KeyNotFound {
public:
TypedKeyNotFound(const Mark& mark_, const T& key_)
: KeyNotFound(mark_, key_), key(key_) {}
virtual ~TypedKeyNotFound() throw() {}
T key;
};
template <typename T>
inline TypedKeyNotFound<T> MakeTypedKeyNotFound(const Mark& mark,
const T& key) {
return TypedKeyNotFound<T>(mark, key);
}
class InvalidNode : public RepresentationException {
public:
InvalidNode()
: RepresentationException(Mark::null_mark(), ErrorMsg::INVALID_NODE) {}
};
class BadConversion : public RepresentationException {
public:
BadConversion()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_CONVERSION) {}
};
template <typename T>
class TypedBadConversion : public BadConversion {
public:
TypedBadConversion() : BadConversion() {}
};
class BadDereference : public RepresentationException {
public:
BadDereference()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
};
class BadSubscript : public RepresentationException {
public:
BadSubscript()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
};
class BadPushback : public RepresentationException {
public:
BadPushback()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
};
class BadInsert : public RepresentationException {
public:
BadInsert()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
};
class EmitterException : public Exception {
public:
EmitterException(const std::string& msg_)
: Exception(Mark::null_mark(), msg_) {}
};
class BadFile : public Exception {
public:
BadFile() : Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {}
};
}
#endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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,265 +17,259 @@
#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" ||
return input == ".inf" || input == ".Inf" || input == ".INF" || input == "+.inf" || input == "+.Inf" || input == "+.INF"; input == "+.inf" || input == "+.Inf" || input == "+.INF";
} }
inline bool IsNegativeInfinity(const std::string& input) {
return input == "-.inf" || input == "-.Inf" || input == "-.INF";
}
inline bool IsNaN(const std::string& input) {
return input == ".nan" || input == ".NaN" || input == ".NAN";
}
}
// std::string
template<>
struct convert<std::string> {
static Node encode(const std::string& rhs) {
return Node(rhs);
}
static bool decode(const Node& node, std::string& rhs) {
if(!node.IsScalar())
return false;
rhs = node.Scalar();
return true;
}
};
// C-strings can only be encoded
template<>
struct convert<const char *> {
static Node encode(const char *&rhs) {
return Node(rhs);
}
};
template<std::size_t N> inline bool IsNegativeInfinity(const std::string& input) {
struct convert<const char[N]> { return input == "-.inf" || input == "-.Inf" || input == "-.INF";
static Node encode(const char (&rhs)[N]) { }
return Node(rhs);
}
};
template<> inline bool IsNaN(const std::string& input) {
struct convert<_Null> { return input == ".nan" || input == ".NaN" || input == ".NAN";
static Node encode(const _Null& /* rhs */) { }
return Node(); }
}
static bool decode(const Node& node, _Null& /* rhs */) {
return node.IsNull();
}
};
#define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op)\
template<>\
struct convert<type> {\
static Node encode(const type& rhs) {\
std::stringstream stream;\
stream.precision(std::numeric_limits<type>::digits10 + 1);\
stream << rhs;\
return Node(stream.str());\
}\
\
static bool decode(const Node& node, type& rhs) {\
if(node.Type() != NodeType::Scalar)\
return false;\
const std::string& input = node.Scalar();\
std::stringstream stream(input);\
stream.unsetf(std::ios::dec);\
if((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof())\
return true;\
if(std::numeric_limits<type>::has_infinity) {\
if(conversion::IsInfinity(input)) {\
rhs = std::numeric_limits<type>::infinity();\
return true;\
} else if(conversion::IsNegativeInfinity(input)) {\
rhs = negative_op std::numeric_limits<type>::infinity();\
return true;\
}\
}\
\
if(std::numeric_limits<type>::has_quiet_NaN && conversion::IsNaN(input)) {\
rhs = std::numeric_limits<type>::quiet_NaN();\
return true;\
}\
\
return false;\
}\
}
#define YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(type)\
YAML_DEFINE_CONVERT_STREAMABLE(type, -)
#define YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(type)\ // std::string
YAML_DEFINE_CONVERT_STREAMABLE(type, +) template <>
struct convert<std::string> {
static Node encode(const std::string& rhs) { return Node(rhs); }
static bool decode(const Node& node, std::string& rhs) {
if (!node.IsScalar())
return false;
rhs = node.Scalar();
return true;
}
};
// C-strings can only be encoded
template <>
struct convert<const char*> {
static Node encode(const char*& rhs) { return Node(rhs); }
};
template <std::size_t N>
struct convert<const char[N]> {
static Node encode(const char (&rhs)[N]) { return Node(rhs); }
};
template <>
struct convert<_Null> {
static Node encode(const _Null& /* rhs */) { return Node(); }
static bool decode(const Node& node, _Null& /* rhs */) {
return node.IsNull();
}
};
#define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \
template <> \
struct convert<type> { \
static Node encode(const type& rhs) { \
std::stringstream stream; \
stream.precision(std::numeric_limits<type>::digits10 + 1); \
stream << rhs; \
return Node(stream.str()); \
} \
\
static bool decode(const Node& node, type& rhs) { \
if (node.Type() != NodeType::Scalar) \
return false; \
const std::string& input = node.Scalar(); \
std::stringstream stream(input); \
stream.unsetf(std::ios::dec); \
if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) \
return true; \
if (std::numeric_limits<type>::has_infinity) { \
if (conversion::IsInfinity(input)) { \
rhs = std::numeric_limits<type>::infinity(); \
return true; \
} else if (conversion::IsNegativeInfinity(input)) { \
rhs = negative_op std::numeric_limits<type>::infinity(); \
return true; \
} \
} \
\
if (std::numeric_limits<type>::has_quiet_NaN && \
conversion::IsNaN(input)) { \
rhs = std::numeric_limits<type>::quiet_NaN(); \
return true; \
} \
\
return false; \
} \
}
#define YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(type) \
YAML_DEFINE_CONVERT_STREAMABLE(type, -)
#define YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(type) \
YAML_DEFINE_CONVERT_STREAMABLE(type, +)
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(int);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(short);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long long);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned short);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long long);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(char);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(float);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(double);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long double);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(int);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(short);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long long);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned short);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long long);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(char);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(float);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(double);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long double);
#undef YAML_DEFINE_CONVERT_STREAMABLE_SIGNED #undef YAML_DEFINE_CONVERT_STREAMABLE_SIGNED
#undef YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED #undef YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED
#undef YAML_DEFINE_CONVERT_STREAMABLE #undef YAML_DEFINE_CONVERT_STREAMABLE
// bool
template<>
struct convert<bool> {
static Node encode(bool rhs) {
return rhs ? Node("true") : Node("false");
}
static bool decode(const Node& node, bool& rhs);
};
// std::map // bool
template<typename K, typename V> template <>
struct convert<std::map<K, V> > { struct convert<bool> {
static Node encode(const std::map<K, V>& rhs) { static Node encode(bool rhs) { return rhs ? Node("true") : Node("false"); }
Node node(NodeType::Map);
for(typename std::map<K, V>::const_iterator it=rhs.begin();it!=rhs.end();++it)
node.force_insert(it->first, it->second);
return node;
}
static bool decode(const Node& node, std::map<K, V>& rhs) {
if(!node.IsMap())
return false;
rhs.clear(); static bool decode(const Node& node, bool& rhs);
for(const_iterator it=node.begin();it!=node.end();++it) };
// std::map
template <typename K, typename V>
struct convert<std::map<K, V> > {
static Node encode(const std::map<K, V>& rhs) {
Node node(NodeType::Map);
for (typename std::map<K, V>::const_iterator it = rhs.begin();
it != rhs.end(); ++it)
node.force_insert(it->first, it->second);
return node;
}
static bool decode(const Node& node, std::map<K, V>& rhs) {
if (!node.IsMap())
return false;
rhs.clear();
for (const_iterator it = node.begin(); it != node.end(); ++it)
#if defined(__GNUC__) && __GNUC__ < 4 #if defined(__GNUC__) && __GNUC__ < 4
//workaround for GCC 3: // workaround for GCC 3:
rhs[it->first.template as<K>()] = it->second.template as<V>(); rhs[it->first.template as<K>()] = it->second.template as<V>();
#else #else
rhs[it->first.as<K>()] = it->second.as<V>(); rhs[it->first.as<K>()] = it->second.as<V>();
#endif #endif
return true; return true;
} }
}; };
// std::vector // std::vector
template<typename T> template <typename T>
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();
node.push_back(*it); it != rhs.end(); ++it)
return node; node.push_back(*it);
} return node;
}
static bool decode(const Node& node, std::vector<T>& rhs) {
if(!node.IsSequence()) static bool decode(const Node& node, std::vector<T>& rhs) {
return false; if (!node.IsSequence())
return false;
rhs.clear();
for(const_iterator it=node.begin();it!=node.end();++it) rhs.clear();
for (const_iterator it = node.begin(); it != node.end(); ++it)
#if defined(__GNUC__) && __GNUC__ < 4 #if defined(__GNUC__) && __GNUC__ < 4
//workaround for GCC 3: // workaround for GCC 3:
rhs.push_back(it->template as<T>()); rhs.push_back(it->template as<T>());
#else #else
rhs.push_back(it->as<T>()); rhs.push_back(it->as<T>());
#endif #endif
return true; return true;
} }
}; };
// std::list // std::list
template<typename T> template <typename T>
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();
node.push_back(*it); it != rhs.end(); ++it)
return node; node.push_back(*it);
} return node;
}
static bool decode(const Node& node, std::list<T>& rhs) {
if(!node.IsSequence()) static bool decode(const Node& node, std::list<T>& rhs) {
return false; if (!node.IsSequence())
return false;
rhs.clear();
for(const_iterator it=node.begin();it!=node.end();++it) rhs.clear();
for (const_iterator it = node.begin(); it != node.end(); ++it)
#if defined(__GNUC__) && __GNUC__ < 4 #if defined(__GNUC__) && __GNUC__ < 4
//workaround for GCC 3: // workaround for GCC 3:
rhs.push_back(it->template as<T>()); rhs.push_back(it->template as<T>());
#else #else
rhs.push_back(it->as<T>()); rhs.push_back(it->as<T>());
#endif #endif
return true; return true;
} }
}; };
// std::pair // std::pair
template<typename T, typename U> template <typename T, typename U>
struct convert<std::pair<T, U> > { struct convert<std::pair<T, U> > {
static Node encode(const std::pair<T, U>& rhs) { static Node encode(const std::pair<T, U>& rhs) {
Node node(NodeType::Sequence); Node node(NodeType::Sequence);
node.push_back(rhs.first); node.push_back(rhs.first);
node.push_back(rhs.second); node.push_back(rhs.second);
return node; return node;
} }
static bool decode(const Node& node, std::pair<T, U>& rhs) { static bool decode(const Node& node, std::pair<T, U>& rhs) {
if(!node.IsSequence()) if (!node.IsSequence())
return false; return false;
if (node.size() != 2) if (node.size() != 2)
return false; return false;
#if defined(__GNUC__) && __GNUC__ < 4 #if defined(__GNUC__) && __GNUC__ < 4
//workaround for GCC 3: // workaround for GCC 3:
rhs.first = node[0].template as<T>(); rhs.first = node[0].template as<T>();
#else #else
rhs.first = node[0].as<T>(); rhs.first = node[0].as<T>();
#endif #endif
#if defined(__GNUC__) && __GNUC__ < 4 #if defined(__GNUC__) && __GNUC__ < 4
//workaround for GCC 3: // workaround for GCC 3:
rhs.second = node[1].template as<U>(); rhs.second = node[1].template as<U>();
#else #else
rhs.second = node[1].as<U>(); rhs.second = node[1].as<U>();
#endif #endif
return true; return true;
} }
}; };
// binary // binary
template<> template <>
struct convert<Binary> { struct convert<Binary> {
static Node encode(const Binary& rhs) { static Node encode(const Binary& rhs) {
return Node(EncodeBase64(rhs.data(), rhs.size())); return Node(EncodeBase64(rhs.data(), rhs.size()));
} }
static bool decode(const Node& node, Binary& rhs) { static bool decode(const Node& node, Binary& rhs) {
if(!node.IsScalar()) if (!node.IsScalar())
return false; return false;
std::vector<unsigned char> data = DecodeBase64(node.Scalar()); std::vector<unsigned char> data = DecodeBase64(node.Scalar());
if(data.empty() && !node.Scalar().empty()) if (data.empty() && !node.Scalar().empty())
return false; return false;
rhs.swap(data); rhs.swap(data);
return true; return true;
} }
}; };
} }
#endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,26 +1,26 @@
#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 NOT_ALLOWED;
struct unspecified_bool { static void true_value(NOT_ALLOWED*) {}
struct NOT_ALLOWED; };
static void true_value(NOT_ALLOWED*) {} typedef void (*unspecified_bool_type)(unspecified_bool::NOT_ALLOWED*);
}; }
typedef void (*unspecified_bool_type)(unspecified_bool::NOT_ALLOWED*);
}
} }
#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

View File

@@ -1,168 +1,176 @@
#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>
{ struct get_idx {
template<typename Key, typename Enable = void> static node* get(const std::vector<node*>& /* sequence */,
struct get_idx { 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 &&
return key < sequence.size() ? sequence[key] : 0; !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;
}
static node *get(std::vector<node *>& sequence, const Key& key, shared_memory_holder pMemory) { static node* get(std::vector<node*>& sequence, const Key& key,
if(key > sequence.size()) shared_memory_holder pMemory) {
return 0; if (key > sequence.size())
if(key == sequence.size()) return 0;
sequence.push_back(&pMemory->create_node()); if (key == sequence.size())
return sequence[key]; sequence.push_back(&pMemory->create_node());
} return sequence[key];
}; }
};
template<typename Key>
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) {
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) {
return key >= 0 ? get_idx<std::size_t>::get(sequence, static_cast<std::size_t>(key), pMemory) : 0;
}
};
// indexing template <typename Key>
template<typename Key> struct get_idx<Key, typename boost::enable_if<boost::is_signed<Key> >::type> {
inline node& node_data::get(const Key& key, shared_memory_holder pMemory) const static node* get(const std::vector<node*>& sequence, const Key& key,
{ shared_memory_holder pMemory) {
switch(m_type) { return key >= 0 ? get_idx<std::size_t>::get(
case NodeType::Map: sequence, static_cast<std::size_t>(key), pMemory)
break; : 0;
case NodeType::Undefined: }
case NodeType::Null: static node* get(std::vector<node*>& sequence, const Key& key,
return pMemory->create_node(); shared_memory_holder pMemory) {
case NodeType::Sequence: return key >= 0 ? get_idx<std::size_t>::get(
if(node *pNode = get_idx<Key>::get(m_sequence, key, pMemory)) sequence, static_cast<std::size_t>(key), pMemory)
return *pNode; : 0;
return pMemory->create_node(); }
case NodeType::Scalar: };
throw BadSubscript();
}
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) { // indexing
if(equals(*it->first, key, pMemory)) template <typename Key>
return *it->second; inline node& node_data::get(const Key& key,
} shared_memory_holder pMemory) const {
switch (m_type) {
return pMemory->create_node(); case NodeType::Map:
} break;
case NodeType::Undefined:
template<typename Key> case NodeType::Null:
inline node& node_data::get(const Key& key, shared_memory_holder pMemory) return pMemory->create_node();
{ case NodeType::Sequence:
switch(m_type) { if (node* pNode = get_idx<Key>::get(m_sequence, key, pMemory))
case NodeType::Map: return *pNode;
break; return pMemory->create_node();
case NodeType::Undefined: case NodeType::Scalar:
case NodeType::Null: throw BadSubscript();
case NodeType::Sequence: }
if(node *pNode = get_idx<Key>::get(m_sequence, key, pMemory)) {
m_type = NodeType::Sequence;
return *pNode;
}
convert_to_map(pMemory);
break;
case NodeType::Scalar:
throw BadSubscript();
}
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
if(equals(*it->first, key, pMemory))
return *it->second;
}
node& k = convert_to_node(key, pMemory);
node& v = pMemory->create_node();
insert_map_pair(k, v);
return v;
}
template<typename Key>
inline bool node_data::remove(const Key& key, shared_memory_holder pMemory)
{
if(m_type != NodeType::Map)
return false;
for(node_map::iterator it=m_map.begin();it!=m_map.end();++it) {
if(equals(*it->first, key, pMemory)) {
m_map.erase(it);
return true;
}
}
return false;
}
// map
template<typename Key, typename Value>
inline void node_data::force_insert(const Key& key, const Value& value, shared_memory_holder pMemory)
{
switch(m_type) {
case NodeType::Map:
break;
case NodeType::Undefined:
case NodeType::Null:
case NodeType::Sequence:
convert_to_map(pMemory);
break;
case NodeType::Scalar:
throw BadInsert();
}
node& k = convert_to_node(key, pMemory);
node& v = convert_to_node(value, pMemory);
insert_map_pair(k, v);
}
template<typename T> for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
inline bool node_data::equals(node& node, const T& rhs, shared_memory_holder pMemory) if (equals(*it->first, key, pMemory))
{ return *it->second;
T lhs; }
if(convert<T>::decode(Node(node, pMemory), lhs))
return lhs == rhs;
return false;
}
inline bool node_data::equals(node& node, const char *rhs, shared_memory_holder pMemory)
{
return equals<std::string>(node, rhs, pMemory);
}
template<typename T> return pMemory->create_node();
inline node& node_data::convert_to_node(const T& rhs, shared_memory_holder pMemory)
{
Node value = convert<T>::encode(rhs);
value.EnsureNodeExists();
pMemory->merge(*value.m_pMemory);
return *value.m_pNode;
}
}
} }
#endif // NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 template <typename Key>
inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
switch (m_type) {
case NodeType::Map:
break;
case NodeType::Undefined:
case NodeType::Null:
case NodeType::Sequence:
if (node* pNode = get_idx<Key>::get(m_sequence, key, pMemory)) {
m_type = NodeType::Sequence;
return *pNode;
}
convert_to_map(pMemory);
break;
case NodeType::Scalar:
throw BadSubscript();
}
for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
if (equals(*it->first, key, pMemory))
return *it->second;
}
node& k = convert_to_node(key, pMemory);
node& v = pMemory->create_node();
insert_map_pair(k, v);
return v;
}
template <typename Key>
inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) {
if (m_type != NodeType::Map)
return false;
for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) {
if (equals(*it->first, key, pMemory)) {
m_map.erase(it);
return true;
}
}
return false;
}
// map
template <typename Key, typename Value>
inline void node_data::force_insert(const Key& key, const Value& value,
shared_memory_holder pMemory) {
switch (m_type) {
case NodeType::Map:
break;
case NodeType::Undefined:
case NodeType::Null:
case NodeType::Sequence:
convert_to_map(pMemory);
break;
case NodeType::Scalar:
throw BadInsert();
}
node& k = convert_to_node(key, pMemory);
node& v = convert_to_node(value, pMemory);
insert_map_pair(k, v);
}
template <typename T>
inline bool node_data::equals(node& node, const T& rhs,
shared_memory_holder pMemory) {
T lhs;
if (convert<T>::decode(Node(node, pMemory), lhs))
return lhs == rhs;
return false;
}
inline bool node_data::equals(node& node, const char* rhs,
shared_memory_holder pMemory) {
return equals<std::string>(node, rhs, pMemory);
}
template <typename T>
inline node& node_data::convert_to_node(const T& rhs,
shared_memory_holder pMemory) {
Node value = convert<T>::encode(rhs);
value.EnsureNodeExists();
pMemory->merge(*value.m_pMemory);
return *value.m_pNode;
}
}
}
#endif // NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,64 +1,66 @@
#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, private:
std::forward_iterator_tag, template <typename>
V> friend class iterator_base;
{ struct enabler {};
private: typedef typename iterator_base::base_type base_type;
template<typename> friend class iterator_base;
struct enabler {};
typedef typename iterator_base::base_type base_type;
public:
typedef typename iterator_base::value_type value_type;
public:
iterator_base() {}
explicit iterator_base(base_type rhs, shared_memory_holder pMemory): iterator_base::iterator_adaptor_(rhs), m_pMemory(pMemory) {}
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) {}
private:
friend class boost::iterator_core_access;
void increment() { this->base_reference() = boost::next(this->base()); } public:
typedef typename iterator_base::value_type value_type;
value_type dereference() const {
const typename base_type::value_type& v = *this->base(); public:
if(v.pNode) iterator_base() {}
return value_type(Node(*v, m_pMemory)); explicit iterator_base(base_type rhs, shared_memory_holder pMemory)
if(v.first && v.second) : iterator_base::iterator_adaptor_(rhs), m_pMemory(pMemory) {}
return value_type(Node(*v.first, m_pMemory), Node(*v.second, m_pMemory));
return value_type(); template <class W>
} iterator_base(
const iterator_base<W>& rhs,
private: typename boost::enable_if<boost::is_convertible<W*, V*>, enabler>::type =
shared_memory_holder m_pMemory; enabler())
}; : iterator_base::iterator_adaptor_(rhs.base()),
} m_pMemory(rhs.m_pMemory) {}
private:
friend class boost::iterator_core_access;
void increment() { this->base_reference() = boost::next(this->base()); }
value_type dereference() const {
const typename base_type::value_type& v = *this->base();
if (v.pNode)
return value_type(Node(*v, m_pMemory));
if (v.first && v.second)
return value_type(Node(*v.first, m_pMemory), Node(*v.second, m_pMemory));
return value_type();
}
private:
shared_memory_holder m_pMemory;
};
}
} }
#endif // VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,27 +1,28 @@
#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 {
struct iterator_value;
template<typename V> class iterator_base;
}
typedef detail::iterator_base<detail::iterator_value> iterator; namespace detail {
typedef detail::iterator_base<const detail::iterator_value> const_iterator; struct iterator_value;
template <typename V>
class iterator_base;
} }
#endif // VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66 typedef detail::iterator_base<detail::iterator_value> iterator;
typedef detail::iterator_base<const detail::iterator_value> const_iterator;
}
#endif // VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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,31 +11,29 @@
#include <set> #include <set>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
namespace YAML namespace YAML {
{ namespace detail {
namespace detail class memory {
{ public:
class memory { node& create_node();
public: void merge(const memory& rhs);
node& create_node();
void merge(const memory& rhs);
private:
typedef std::set<shared_node> Nodes;
Nodes m_nodes;
};
class memory_holder { private:
public: typedef std::set<shared_node> Nodes;
memory_holder(): m_pMemory(new memory) {} Nodes m_nodes;
};
node& create_node() { return m_pMemory->create_node(); }
void merge(memory_holder& rhs); class memory_holder {
public:
private: memory_holder() : m_pMemory(new memory) {}
boost::shared_ptr<memory> m_pMemory;
}; node& create_node() { return m_pMemory->create_node(); }
} void merge(memory_holder& rhs);
private:
boost::shared_ptr<memory> m_pMemory;
};
}
} }
#endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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,118 +14,134 @@
#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 {
{ public:
class node: private boost::noncopyable node() : m_pRef(new node_ref) {}
{
public:
node(): m_pRef(new node_ref) {}
bool is(const node& rhs) const { return m_pRef == rhs.m_pRef; } bool is(const node& rhs) const { return m_pRef == rhs.m_pRef; }
const node_ref *ref() const { return m_pRef.get(); } const node_ref* ref() const { return m_pRef.get(); }
bool is_defined() const { return m_pRef->is_defined(); }
NodeType::value type() const { return m_pRef->type(); }
const std::string& scalar() const { return m_pRef->scalar(); }
const std::string& tag() const { return m_pRef->tag(); }
void mark_defined() {
if(is_defined())
return;
m_pRef->mark_defined();
for(nodes::iterator it=m_dependencies.begin();it!=m_dependencies.end();++it)
(*it)->mark_defined();
m_dependencies.clear();
}
void add_dependency(node& rhs) {
if(is_defined())
rhs.mark_defined();
else
m_dependencies.insert(&rhs);
}
void set_ref(const node& rhs) {
if(rhs.is_defined())
mark_defined();
m_pRef = rhs.m_pRef;
}
void set_data(const node& rhs) {
if(rhs.is_defined())
mark_defined();
m_pRef->set_data(*rhs.m_pRef);
}
void set_type(NodeType::value type) {
if(type != NodeType::Undefined)
mark_defined();
m_pRef->set_type(type);
}
void set_null() {
mark_defined();
m_pRef->set_null();
}
void set_scalar(const std::string& scalar) {
mark_defined();
m_pRef->set_scalar(scalar);
}
void set_tag(const std::string& tag) {
mark_defined();
m_pRef->set_tag(tag);
}
// size/iterator bool is_defined() const { return m_pRef->is_defined(); }
std::size_t size() const { return m_pRef->size(); } NodeType::value type() const { return m_pRef->type(); }
const_node_iterator begin() const { return static_cast<const node_ref&>(*m_pRef).begin(); }
node_iterator begin() { return m_pRef->begin(); }
const_node_iterator end() const { return static_cast<const node_ref&>(*m_pRef).end(); }
node_iterator end() { return m_pRef->end(); }
// sequence const std::string& scalar() const { return m_pRef->scalar(); }
void push_back(node& node, shared_memory_holder pMemory) { const std::string& tag() const { return m_pRef->tag(); }
m_pRef->push_back(node, pMemory);
node.add_dependency(*this);
}
void insert(node& key, node& value, shared_memory_holder pMemory) {
m_pRef->insert(key, value, pMemory);
key.add_dependency(*this);
value.add_dependency(*this);
}
// indexing void mark_defined() {
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) const { return static_cast<const node_ref&>(*m_pRef).get(key, pMemory); } if (is_defined())
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) { return;
node& value = m_pRef->get(key, pMemory);
value.add_dependency(*this);
return value;
}
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) {
node& value = m_pRef->get(key, pMemory);
key.add_dependency(*this);
value.add_dependency(*this);
return value;
}
bool remove(node& key, shared_memory_holder pMemory) { return m_pRef->remove(key, pMemory); }
// map m_pRef->mark_defined();
template<typename Key, typename Value> for (nodes::iterator it = m_dependencies.begin();
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory){ m_pRef->force_insert(key, value, pMemory); } it != m_dependencies.end(); ++it)
(*it)->mark_defined();
m_dependencies.clear();
}
private: void add_dependency(node& rhs) {
shared_node_ref m_pRef; if (is_defined())
typedef std::set<node *> nodes; rhs.mark_defined();
nodes m_dependencies; else
}; m_dependencies.insert(&rhs);
} }
void set_ref(const node& rhs) {
if (rhs.is_defined())
mark_defined();
m_pRef = rhs.m_pRef;
}
void set_data(const node& rhs) {
if (rhs.is_defined())
mark_defined();
m_pRef->set_data(*rhs.m_pRef);
}
void set_type(NodeType::value type) {
if (type != NodeType::Undefined)
mark_defined();
m_pRef->set_type(type);
}
void set_null() {
mark_defined();
m_pRef->set_null();
}
void set_scalar(const std::string& scalar) {
mark_defined();
m_pRef->set_scalar(scalar);
}
void set_tag(const std::string& tag) {
mark_defined();
m_pRef->set_tag(tag);
}
// size/iterator
std::size_t size() const { return m_pRef->size(); }
const_node_iterator begin() const {
return static_cast<const node_ref&>(*m_pRef).begin();
}
node_iterator begin() { return m_pRef->begin(); }
const_node_iterator end() const {
return static_cast<const node_ref&>(*m_pRef).end();
}
node_iterator end() { return m_pRef->end(); }
// sequence
void push_back(node& node, shared_memory_holder pMemory) {
m_pRef->push_back(node, pMemory);
node.add_dependency(*this);
}
void insert(node& key, node& value, shared_memory_holder pMemory) {
m_pRef->insert(key, value, pMemory);
key.add_dependency(*this);
value.add_dependency(*this);
}
// 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>
node& get(const Key& key, shared_memory_holder pMemory) {
node& value = m_pRef->get(key, pMemory);
value.add_dependency(*this);
return value;
}
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) {
node& value = m_pRef->get(key, pMemory);
key.add_dependency(*this);
value.add_dependency(*this);
return value;
}
bool remove(node& key, shared_memory_holder pMemory) {
return m_pRef->remove(key, pMemory);
}
// map
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);
}
private:
shared_node_ref m_pRef;
typedef std::set<node*> nodes;
nodes m_dependencies;
};
}
} }
#endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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,96 +16,99 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
namespace YAML namespace YAML {
{ namespace detail {
namespace detail class node_data : private boost::noncopyable {
{ public:
class node_data: private boost::noncopyable node_data();
{
public:
node_data();
void mark_defined();
void set_type(NodeType::value type);
void set_tag(const std::string& tag);
void set_null();
void set_scalar(const std::string& scalar);
bool is_defined() const { return m_isDefined; }
NodeType::value type() const { return m_isDefined ? m_type : NodeType::Undefined; }
const std::string& scalar() const { return m_scalar; }
const std::string& tag() const { return m_tag; }
// size/iterator
std::size_t size() const;
const_node_iterator begin() const;
node_iterator begin();
const_node_iterator end() const;
node_iterator end();
// sequence void mark_defined();
void push_back(node& node, shared_memory_holder pMemory); void set_type(NodeType::value type);
void insert(node& key, node& value, shared_memory_holder pMemory); void set_tag(const std::string& tag);
void set_null();
void set_scalar(const std::string& scalar);
// indexing bool is_defined() const { return m_isDefined; }
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) const; NodeType::value type() const {
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory); return m_isDefined ? m_type : NodeType::Undefined;
template<typename Key> bool remove(const Key& key, shared_memory_holder pMemory); }
const std::string& scalar() const { return m_scalar; }
node& get(node& key, shared_memory_holder pMemory) const; const std::string& tag() const { return m_tag; }
node& get(node& key, shared_memory_holder pMemory);
bool remove(node& key, shared_memory_holder pMemory);
// map
template<typename Key, typename Value>
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory);
public:
static std::string empty_scalar;
private:
void compute_seq_size() const;
void compute_map_size() const;
void reset_sequence(); // size/iterator
void reset_map(); std::size_t size() const;
void insert_map_pair(node& key, node& value);
void convert_to_map(shared_memory_holder pMemory);
void convert_sequence_to_map(shared_memory_holder pMemory);
template<typename T>
static bool equals(node& node, const T& rhs, shared_memory_holder pMemory);
static bool equals(node& node, const char *rhs, shared_memory_holder pMemory);
template<typename T>
static node& convert_to_node(const T& rhs, shared_memory_holder pMemory);
private: const_node_iterator begin() const;
bool m_isDefined; node_iterator begin();
NodeType::value m_type;
std::string m_tag; const_node_iterator end() const;
node_iterator end();
// scalar
std::string m_scalar; // sequence
void push_back(node& node, shared_memory_holder pMemory);
// sequence void insert(node& key, node& value, shared_memory_holder pMemory);
typedef std::vector<node *> node_seq;
node_seq m_sequence; // indexing
template <typename Key>
mutable std::size_t m_seqSize; node& get(const Key& key, shared_memory_holder pMemory) const;
template <typename Key>
// map node& get(const Key& key, shared_memory_holder pMemory);
typedef std::map<node *, node *> node_map; template <typename Key>
node_map m_map; bool remove(const Key& key, shared_memory_holder pMemory);
typedef std::pair<node *, node *> kv_pair; node& get(node& key, shared_memory_holder pMemory) const;
typedef std::list<kv_pair> kv_pairs; node& get(node& key, shared_memory_holder pMemory);
mutable kv_pairs m_undefinedPairs; bool remove(node& key, shared_memory_holder pMemory);
};
} // map
template <typename Key, typename Value>
void force_insert(const Key& key, const Value& value,
shared_memory_holder pMemory);
public:
static std::string empty_scalar;
private:
void compute_seq_size() const;
void compute_map_size() const;
void reset_sequence();
void reset_map();
void insert_map_pair(node& key, node& value);
void convert_to_map(shared_memory_holder pMemory);
void convert_sequence_to_map(shared_memory_holder pMemory);
template <typename T>
static bool equals(node& node, const T& rhs, shared_memory_holder pMemory);
static bool equals(node& node, const char* rhs, shared_memory_holder pMemory);
template <typename T>
static node& convert_to_node(const T& rhs, shared_memory_holder pMemory);
private:
bool m_isDefined;
NodeType::value m_type;
std::string m_tag;
// scalar
std::string m_scalar;
// sequence
typedef std::vector<node*> node_seq;
node_seq m_sequence;
mutable std::size_t m_seqSize;
// map
typedef std::map<node*, node*> node_map;
node_map m_map;
typedef std::pair<node*, node*> kv_pair;
typedef std::list<kv_pair> kv_pairs;
mutable kv_pairs m_undefinedPairs;
};
}
} }
#endif // VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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,126 +15,143 @@
#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,
template<typename V> Map
struct node_iterator_value: public std::pair<V*, V*> { };
typedef std::pair<V*, V*> kv; };
node_iterator_value(): kv(), pNode(0) {}
explicit node_iterator_value(V& rhs): kv(), pNode(&rhs) {}
explicit node_iterator_value(V& key, V& value): kv(&key, &value), pNode(0) {}
V& operator *() const { return *pNode; }
V& operator ->() const { return *pNode; }
V *pNode;
};
typedef std::vector<node *> node_seq;
typedef std::map<node *, node *> node_map;
template<typename V>
struct node_iterator_type {
typedef node_seq::iterator seq;
typedef node_map::iterator map;
};
template<typename V>
struct node_iterator_type<const V> {
typedef node_seq::const_iterator seq;
typedef node_map::const_iterator map;
};
template<typename V> template <typename V>
class node_iterator_base: public boost::iterator_facade< struct node_iterator_value : public std::pair<V*, V*> {
node_iterator_base<V>, typedef std::pair<V*, V*> kv;
node_iterator_value<V>,
std::forward_iterator_tag,
node_iterator_value<V> >
{
private:
struct enabler {};
public:
typedef typename node_iterator_type<V>::seq SeqIter;
typedef typename node_iterator_type<V>::map MapIter;
typedef node_iterator_value<V> value_type;
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(MapIter mapIt, MapIter mapEnd): m_type(iterator_type::Map), m_mapIt(mapIt), m_mapEnd(mapEnd) {
m_mapIt = increment_until_defined(m_mapIt);
}
template<typename W>
node_iterator_base(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:
friend class boost::iterator_core_access;
template<typename> friend class node_iterator_base;
template<typename W>
bool equal(const node_iterator_base<W>& rhs) const {
if(m_type != rhs.m_type)
return false;
switch(m_type) {
case iterator_type::None: return true;
case iterator_type::Sequence: return m_seqIt == rhs.m_seqIt;
case iterator_type::Map: return m_mapIt == rhs.m_mapIt;
}
return true;
}
void increment() {
switch(m_type) {
case iterator_type::None: break;
case iterator_type::Sequence:
++m_seqIt;
break;
case iterator_type::Map:
++m_mapIt;
m_mapIt = increment_until_defined(m_mapIt);
break;
}
}
value_type dereference() const { node_iterator_value() : kv(), pNode(0) {}
switch(m_type) { explicit node_iterator_value(V& rhs) : kv(), pNode(&rhs) {}
case iterator_type::None: return value_type(); explicit node_iterator_value(V& key, V& value) : kv(&key, &value), pNode(0) {}
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();
}
MapIter increment_until_defined(MapIter it) {
while(it != m_mapEnd && !is_defined(it))
++it;
return it;
}
bool is_defined(MapIter it) const {
return it->first->is_defined() && it->second->is_defined();
}
private: V& operator*() const { return *pNode; }
typename iterator_type::value m_type; V& operator->() const { return *pNode; }
SeqIter m_seqIt; V* pNode;
MapIter m_mapIt, m_mapEnd; };
};
typedef node_iterator_base<node> node_iterator; typedef std::vector<node*> node_seq;
typedef node_iterator_base<const node> const_node_iterator; typedef std::map<node*, node*> node_map;
}
template <typename V>
struct node_iterator_type {
typedef node_seq::iterator seq;
typedef node_map::iterator map;
};
template <typename V>
struct node_iterator_type<const V> {
typedef node_seq::const_iterator seq;
typedef node_map::const_iterator map;
};
template <typename V>
class node_iterator_base
: public boost::iterator_facade<
node_iterator_base<V>, node_iterator_value<V>,
std::forward_iterator_tag, node_iterator_value<V> > {
private:
struct enabler {};
public:
typedef typename node_iterator_type<V>::seq SeqIter;
typedef typename node_iterator_type<V>::map MapIter;
typedef node_iterator_value<V> value_type;
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(MapIter mapIt, MapIter mapEnd)
: m_type(iterator_type::Map), m_mapIt(mapIt), m_mapEnd(mapEnd) {
m_mapIt = increment_until_defined(m_mapIt);
}
template <typename W>
node_iterator_base(
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:
friend class boost::iterator_core_access;
template <typename>
friend class node_iterator_base;
template <typename W>
bool equal(const node_iterator_base<W>& rhs) const {
if (m_type != rhs.m_type)
return false;
switch (m_type) {
case iterator_type::None:
return true;
case iterator_type::Sequence:
return m_seqIt == rhs.m_seqIt;
case iterator_type::Map:
return m_mapIt == rhs.m_mapIt;
}
return true;
}
void increment() {
switch (m_type) {
case iterator_type::None:
break;
case iterator_type::Sequence:
++m_seqIt;
break;
case iterator_type::Map:
++m_mapIt;
m_mapIt = increment_until_defined(m_mapIt);
break;
}
}
value_type dereference() const {
switch (m_type) {
case iterator_type::None:
return value_type();
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();
}
MapIter increment_until_defined(MapIter it) {
while (it != m_mapEnd && !is_defined(it))
++it;
return it;
}
bool is_defined(MapIter it) const {
return it->first->is_defined() && it->second->is_defined();
}
private:
typename iterator_type::value m_type;
SeqIter m_seqIt;
MapIter m_mapIt, m_mapEnd;
};
typedef node_iterator_base<node> node_iterator;
typedef node_iterator_base<const node> const_node_iterator;
}
} }
#endif // VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,69 +1,93 @@
#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 {
{ public:
class node_ref: private boost::noncopyable node_ref() : m_pData(new node_data) {}
{
public:
node_ref(): m_pData(new node_data) {}
bool is_defined() const { return m_pData->is_defined(); }
NodeType::value type() const { return m_pData->type(); }
const std::string& scalar() const { return m_pData->scalar(); }
const std::string& tag() const { return m_pData->tag(); }
void mark_defined() { m_pData->mark_defined(); }
void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; }
void set_type(NodeType::value type) { m_pData->set_type(type); }
void set_tag(const std::string& tag) { m_pData->set_tag(tag); }
void set_null() { m_pData->set_null(); }
void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); }
// size/iterator
std::size_t size() const { return m_pData->size(); }
const_node_iterator begin() const { return static_cast<const node_data&>(*m_pData).begin(); }
node_iterator begin() {return m_pData->begin(); }
const_node_iterator end() const { return static_cast<const node_data&>(*m_pData).end(); }
node_iterator end() {return m_pData->end(); }
// sequence bool is_defined() const { return m_pData->is_defined(); }
void push_back(node& node, shared_memory_holder pMemory) { m_pData->push_back(node, pMemory); } NodeType::value type() const { return m_pData->type(); }
void insert(node& key, node& value, shared_memory_holder pMemory) { m_pData->insert(key, value, pMemory); } const std::string& scalar() const { return m_pData->scalar(); }
const std::string& tag() const { return m_pData->tag(); }
// 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> 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) { return m_pData->get(key, pMemory); }
bool remove(node& key, shared_memory_holder pMemory) { return m_pData->remove(key, pMemory); }
// map
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); }
private: void mark_defined() { m_pData->mark_defined(); }
shared_node_data m_pData; void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; }
};
} void set_type(NodeType::value type) { m_pData->set_type(type); }
void set_tag(const std::string& tag) { m_pData->set_tag(tag); }
void set_null() { m_pData->set_null(); }
void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); }
// size/iterator
std::size_t size() const { return m_pData->size(); }
const_node_iterator begin() const {
return static_cast<const node_data&>(*m_pData).begin();
}
node_iterator begin() { return m_pData->begin(); }
const_node_iterator end() const {
return static_cast<const node_data&>(*m_pData).end();
}
node_iterator end() { return m_pData->end(); }
// sequence
void push_back(node& node, shared_memory_holder pMemory) {
m_pData->push_back(node, pMemory);
}
void insert(node& key, node& value, shared_memory_holder pMemory) {
m_pData->insert(key, value, pMemory);
}
// 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>
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) {
return m_pData->get(key, pMemory);
}
bool remove(node& key, shared_memory_holder pMemory) {
return m_pData->remove(key, pMemory);
}
// map
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);
}
private:
shared_node_data m_pData;
};
}
} }
#endif // VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,23 +1,23 @@
#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;
Emitter& operator<<(Emitter& out, const Node& node);
Emitter& operator << (Emitter& out, const Node& node); std::ostream& operator<<(std::ostream& out, const Node& node);
std::ostream& operator << (std::ostream& out, const Node& node);
std::string Dump(const Node& node);
std::string Dump(const Node& node);
} }
#endif // NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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,439 +14,406 @@
#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())
{
m_pNode->set_type(type);
}
template<typename T>
inline Node::Node(const T& rhs): m_isValid(true), m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node())
{
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 Node& rhs): m_isValid(rhs.m_isValid), m_pMemory(rhs.m_pMemory), m_pNode(rhs.m_pNode) inline Node::Node(NodeType::value type)
{ : m_isValid(true),
} m_pMemory(new detail::memory_holder),
m_pNode(&m_pMemory->create_node()) {
inline Node::Node(Zombie): m_isValid(false), m_pNode(NULL) m_pNode->set_type(type);
{
}
inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory): m_isValid(true), m_pMemory(pMemory), m_pNode(&node)
{
}
inline Node::~Node()
{
}
inline void Node::EnsureNodeExists() const
{
if(!m_isValid)
throw InvalidNode();
if(!m_pNode) {
m_pMemory.reset(new detail::memory_holder);
m_pNode = &m_pMemory->create_node();
m_pNode->set_null();
}
}
inline bool Node::IsDefined() const
{
if(!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->is_defined() : true;
}
inline NodeType::value Node::Type() const
{
if(!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->type() : NodeType::Null;
}
// access
// template helpers
template<typename T, typename S>
struct as_if {
explicit as_if(const Node& node_): node(node_) {}
const Node& node;
const T operator()(const S& fallback) const {
if(!node.m_pNode)
return fallback;
T t;
if(convert<T>::decode(node, t))
return t;
return fallback;
}
};
template<typename S>
struct as_if<std::string, S> {
explicit as_if(const Node& node_): node(node_) {}
const Node& node;
const std::string operator()(const S& fallback) const {
if(node.Type() != NodeType::Scalar)
return fallback;
return node.Scalar();
}
};
template<typename T>
struct as_if<T, void> {
explicit as_if(const Node& node_): node(node_) {}
const Node& node;
const T operator()() const {
if(!node.m_pNode)
throw TypedBadConversion<T>();
T t;
if(convert<T>::decode(node, t))
return t;
throw TypedBadConversion<T>();
}
};
template<>
struct as_if<std::string, void> {
explicit as_if(const Node& node_): node(node_) {}
const Node& node;
const std::string operator()() const {
if(node.Type() != NodeType::Scalar)
throw TypedBadConversion<std::string>();
return node.Scalar();
}
};
// access functions
template<typename T>
inline const T Node::as() const
{
if(!m_isValid)
throw InvalidNode();
return as_if<T, void>(*this)();
}
template<typename T, typename S>
inline const T Node::as(const S& fallback) const
{
if(!m_isValid)
throw InvalidNode();
return as_if<T, S>(*this)(fallback);
}
inline const std::string& Node::Scalar() const
{
if(!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar;
}
inline const std::string& Node::Tag() const
{
if(!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar;
}
inline void Node::SetTag(const std::string& tag)
{
if(!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->set_tag(tag);
}
// assignment
inline bool Node::is(const Node& rhs) const
{
if(!m_isValid || !rhs.m_isValid)
throw InvalidNode();
if(!m_pNode || !rhs.m_pNode)
return false;
return m_pNode->is(*rhs.m_pNode);
}
template<typename T>
inline Node& Node::operator=(const T& rhs)
{
if(!m_isValid)
throw InvalidNode();
Assign(rhs);
return *this;
}
inline void Node::reset(const YAML::Node& rhs)
{
if(!m_isValid || !rhs.m_isValid)
throw InvalidNode();
m_pMemory = rhs.m_pMemory;
m_pNode = rhs.m_pNode;
}
template<typename T>
inline void Node::Assign(const T& rhs)
{
if(!m_isValid)
throw InvalidNode();
AssignData(convert<T>::encode(rhs));
}
template<>
inline void Node::Assign(const std::string& rhs)
{
if(!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->set_scalar(rhs);
}
inline void Node::Assign(const char *rhs)
{
if(!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->set_scalar(rhs);
}
inline void Node::Assign(char *rhs)
{
if(!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->set_scalar(rhs);
}
inline Node& Node::operator=(const Node& rhs)
{
if(!m_isValid || !rhs.m_isValid)
throw InvalidNode();
if(is(rhs))
return *this;
AssignNode(rhs);
return *this;
}
inline void Node::AssignData(const Node& rhs)
{
if(!m_isValid || !rhs.m_isValid)
throw InvalidNode();
EnsureNodeExists();
rhs.EnsureNodeExists();
m_pNode->set_data(*rhs.m_pNode);
m_pMemory->merge(*rhs.m_pMemory);
}
inline void Node::AssignNode(const Node& rhs)
{
if(!m_isValid || !rhs.m_isValid)
throw InvalidNode();
rhs.EnsureNodeExists();
if(!m_pNode) {
m_pNode = rhs.m_pNode;
m_pMemory = rhs.m_pMemory;
return;
}
m_pNode->set_ref(*rhs.m_pNode);
m_pMemory->merge(*rhs.m_pMemory);
m_pNode = rhs.m_pNode;
}
// size/iterator
inline std::size_t Node::size() const
{
if(!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->size() : 0;
}
inline const_iterator Node::begin() const
{
if(!m_isValid)
throw InvalidNode();
return m_pNode ? const_iterator(m_pNode->begin(), m_pMemory) : const_iterator();
}
inline iterator Node::begin()
{
if(!m_isValid)
throw InvalidNode();
return m_pNode ? iterator(m_pNode->begin(), m_pMemory) : iterator();
}
inline const_iterator Node::end() const
{
if(!m_isValid)
throw InvalidNode();
return m_pNode ? const_iterator(m_pNode->end(), m_pMemory) : const_iterator();
}
inline iterator Node::end()
{
if(!m_isValid)
throw InvalidNode();
return m_pNode ? iterator(m_pNode->end(), m_pMemory) : iterator();
}
// sequence
template<typename T>
inline void Node::push_back(const T& rhs)
{
if(!m_isValid)
throw InvalidNode();
push_back(Node(rhs));
}
inline void Node::push_back(const Node& rhs)
{
if(!m_isValid || !rhs.m_isValid)
throw InvalidNode();
EnsureNodeExists();
rhs.EnsureNodeExists();
m_pNode->push_back(*rhs.m_pNode, m_pMemory);
m_pMemory->merge(*rhs.m_pMemory);
}
// helpers for indexing
namespace detail {
template<typename T>
struct to_value_t {
explicit to_value_t(const T& t_): t(t_) {}
const T& t;
typedef const T& return_type;
const T& operator()() const { return t; }
};
template<>
struct to_value_t<const char*> {
explicit to_value_t(const char *t_): t(t_) {}
const char *t;
typedef std::string return_type;
const std::string operator()() const { return t; }
};
template<>
struct to_value_t<char*> {
explicit to_value_t(char *t_): t(t_) {}
const char *t;
typedef std::string return_type;
const std::string operator()() const { return t; }
};
template<std::size_t N>
struct to_value_t<char [N]> {
explicit to_value_t(const char *t_): t(t_) {}
const char *t;
typedef std::string return_type;
const std::string operator()() const { return t; }
};
// converts C-strings to std::strings so they can be copied
template<typename T>
inline typename to_value_t<T>::return_type to_value(const T& t) {
return to_value_t<T>(t)();
}
}
// indexing
template<typename Key>
inline const Node Node::operator[](const Key& key) const
{
if(!m_isValid)
throw InvalidNode();
EnsureNodeExists();
detail::node& value = static_cast<const detail::node&>(*m_pNode).get(detail::to_value(key), m_pMemory);
return Node(value, m_pMemory);
}
template<typename Key>
inline Node Node::operator[](const Key& key)
{
if(!m_isValid)
throw InvalidNode();
EnsureNodeExists();
detail::node& value = m_pNode->get(detail::to_value(key), m_pMemory);
return Node(value, m_pMemory);
}
template<typename Key>
inline bool Node::remove(const Key& key)
{
if(!m_isValid)
throw InvalidNode();
EnsureNodeExists();
return m_pNode->remove(detail::to_value(key), m_pMemory);
}
inline const Node Node::operator[](const Node& key) const
{
if(!m_isValid || !key.m_isValid)
throw InvalidNode();
EnsureNodeExists();
key.EnsureNodeExists();
detail::node& value = static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory);
return Node(value, m_pMemory);
}
inline Node Node::operator[](const Node& key)
{
if(!m_isValid || !key.m_isValid)
throw InvalidNode();
EnsureNodeExists();
key.EnsureNodeExists();
detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory);
return Node(value, m_pMemory);
}
inline bool Node::remove(const Node& key)
{
if(!m_isValid || !key.m_isValid)
throw InvalidNode();
EnsureNodeExists();
key.EnsureNodeExists();
return m_pNode->remove(*key.m_pNode, m_pMemory);
}
// map
template<typename Key, typename Value>
inline void Node::force_insert(const Key& key, const Value& value)
{
if(!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->force_insert(detail::to_value(key), detail::to_value(value), m_pMemory);
}
// free functions
inline bool operator==(const Node& lhs, const Node& rhs)
{
return lhs.is(rhs);
}
} }
#endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 template <typename T>
inline Node::Node(const T& rhs)
: m_isValid(true),
m_pMemory(new detail::memory_holder),
m_pNode(&m_pMemory->create_node()) {
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 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(detail::node& node, detail::shared_memory_holder pMemory)
: m_isValid(true), m_pMemory(pMemory), m_pNode(&node) {}
inline Node::~Node() {}
inline void Node::EnsureNodeExists() const {
if (!m_isValid)
throw InvalidNode();
if (!m_pNode) {
m_pMemory.reset(new detail::memory_holder);
m_pNode = &m_pMemory->create_node();
m_pNode->set_null();
}
}
inline bool Node::IsDefined() const {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->is_defined() : true;
}
inline NodeType::value Node::Type() const {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->type() : NodeType::Null;
}
// access
// template helpers
template <typename T, typename S>
struct as_if {
explicit as_if(const Node& node_) : node(node_) {}
const Node& node;
const T operator()(const S& fallback) const {
if (!node.m_pNode)
return fallback;
T t;
if (convert<T>::decode(node, t))
return t;
return fallback;
}
};
template <typename S>
struct as_if<std::string, S> {
explicit as_if(const Node& node_) : node(node_) {}
const Node& node;
const std::string operator()(const S& fallback) const {
if (node.Type() != NodeType::Scalar)
return fallback;
return node.Scalar();
}
};
template <typename T>
struct as_if<T, void> {
explicit as_if(const Node& node_) : node(node_) {}
const Node& node;
const T operator()() const {
if (!node.m_pNode)
throw TypedBadConversion<T>();
T t;
if (convert<T>::decode(node, t))
return t;
throw TypedBadConversion<T>();
}
};
template <>
struct as_if<std::string, void> {
explicit as_if(const Node& node_) : node(node_) {}
const Node& node;
const std::string operator()() const {
if (node.Type() != NodeType::Scalar)
throw TypedBadConversion<std::string>();
return node.Scalar();
}
};
// access functions
template <typename T>
inline const T Node::as() const {
if (!m_isValid)
throw InvalidNode();
return as_if<T, void>(*this)();
}
template <typename T, typename S>
inline const T Node::as(const S& fallback) const {
if (!m_isValid)
throw InvalidNode();
return as_if<T, S>(*this)(fallback);
}
inline const std::string& Node::Scalar() const {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar;
}
inline const std::string& Node::Tag() const {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar;
}
inline void Node::SetTag(const std::string& tag) {
if (!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->set_tag(tag);
}
// assignment
inline bool Node::is(const Node& rhs) const {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode();
if (!m_pNode || !rhs.m_pNode)
return false;
return m_pNode->is(*rhs.m_pNode);
}
template <typename T>
inline Node& Node::operator=(const T& rhs) {
if (!m_isValid)
throw InvalidNode();
Assign(rhs);
return *this;
}
inline void Node::reset(const YAML::Node& rhs) {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode();
m_pMemory = rhs.m_pMemory;
m_pNode = rhs.m_pNode;
}
template <typename T>
inline void Node::Assign(const T& rhs) {
if (!m_isValid)
throw InvalidNode();
AssignData(convert<T>::encode(rhs));
}
template <>
inline void Node::Assign(const std::string& rhs) {
if (!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->set_scalar(rhs);
}
inline void Node::Assign(const char* rhs) {
if (!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->set_scalar(rhs);
}
inline void Node::Assign(char* rhs) {
if (!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->set_scalar(rhs);
}
inline Node& Node::operator=(const Node& rhs) {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode();
if (is(rhs))
return *this;
AssignNode(rhs);
return *this;
}
inline void Node::AssignData(const Node& rhs) {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode();
EnsureNodeExists();
rhs.EnsureNodeExists();
m_pNode->set_data(*rhs.m_pNode);
m_pMemory->merge(*rhs.m_pMemory);
}
inline void Node::AssignNode(const Node& rhs) {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode();
rhs.EnsureNodeExists();
if (!m_pNode) {
m_pNode = rhs.m_pNode;
m_pMemory = rhs.m_pMemory;
return;
}
m_pNode->set_ref(*rhs.m_pNode);
m_pMemory->merge(*rhs.m_pMemory);
m_pNode = rhs.m_pNode;
}
// size/iterator
inline std::size_t Node::size() const {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->size() : 0;
}
inline const_iterator Node::begin() const {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? const_iterator(m_pNode->begin(), m_pMemory)
: const_iterator();
}
inline iterator Node::begin() {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? iterator(m_pNode->begin(), m_pMemory) : iterator();
}
inline const_iterator Node::end() const {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? const_iterator(m_pNode->end(), m_pMemory) : const_iterator();
}
inline iterator Node::end() {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? iterator(m_pNode->end(), m_pMemory) : iterator();
}
// sequence
template <typename T>
inline void Node::push_back(const T& rhs) {
if (!m_isValid)
throw InvalidNode();
push_back(Node(rhs));
}
inline void Node::push_back(const Node& rhs) {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode();
EnsureNodeExists();
rhs.EnsureNodeExists();
m_pNode->push_back(*rhs.m_pNode, m_pMemory);
m_pMemory->merge(*rhs.m_pMemory);
}
// helpers for indexing
namespace detail {
template <typename T>
struct to_value_t {
explicit to_value_t(const T& t_) : t(t_) {}
const T& t;
typedef const T& return_type;
const T& operator()() const { return t; }
};
template <>
struct to_value_t<const char*> {
explicit to_value_t(const char* t_) : t(t_) {}
const char* t;
typedef std::string return_type;
const std::string operator()() const { return t; }
};
template <>
struct to_value_t<char*> {
explicit to_value_t(char* t_) : t(t_) {}
const char* t;
typedef std::string return_type;
const std::string operator()() const { return t; }
};
template <std::size_t N>
struct to_value_t<char[N]> {
explicit to_value_t(const char* t_) : t(t_) {}
const char* t;
typedef std::string return_type;
const std::string operator()() const { return t; }
};
// converts C-strings to std::strings so they can be copied
template <typename T>
inline typename to_value_t<T>::return_type to_value(const T& t) {
return to_value_t<T>(t)();
}
}
// indexing
template <typename Key>
inline const Node Node::operator[](const Key& key) const {
if (!m_isValid)
throw InvalidNode();
EnsureNodeExists();
detail::node& value = static_cast<const detail::node&>(*m_pNode)
.get(detail::to_value(key), m_pMemory);
return Node(value, m_pMemory);
}
template <typename Key>
inline Node Node::operator[](const Key& key) {
if (!m_isValid)
throw InvalidNode();
EnsureNodeExists();
detail::node& value = m_pNode->get(detail::to_value(key), m_pMemory);
return Node(value, m_pMemory);
}
template <typename Key>
inline bool Node::remove(const Key& key) {
if (!m_isValid)
throw InvalidNode();
EnsureNodeExists();
return m_pNode->remove(detail::to_value(key), m_pMemory);
}
inline const Node Node::operator[](const Node& key) const {
if (!m_isValid || !key.m_isValid)
throw InvalidNode();
EnsureNodeExists();
key.EnsureNodeExists();
detail::node& value =
static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory);
return Node(value, m_pMemory);
}
inline Node Node::operator[](const Node& key) {
if (!m_isValid || !key.m_isValid)
throw InvalidNode();
EnsureNodeExists();
key.EnsureNodeExists();
detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory);
return Node(value, m_pMemory);
}
inline bool Node::remove(const Node& key) {
if (!m_isValid || !key.m_isValid)
throw InvalidNode();
EnsureNodeExists();
key.EnsureNodeExists();
return m_pNode->remove(*key.m_pNode, m_pMemory);
}
// map
template <typename Key, typename Value>
inline void Node::force_insert(const Key& key, const Value& value) {
if (!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->force_insert(detail::to_value(key), detail::to_value(value),
m_pMemory);
}
// free functions
inline bool operator==(const Node& lhs, const Node& rhs) { return lhs.is(rhs); }
}
#endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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,15 +15,17 @@
#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)
explicit iterator_value(const Node& rhs): Node(rhs), std::pair<Node, Node>(Node(Node::ZombieNode), Node(Node::ZombieNode)) {} : Node(rhs),
explicit iterator_value(const Node& key, const Node& value): Node(Node::ZombieNode), std::pair<Node, Node>(key, value) {} 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) {}
};
}
} }
#endif // VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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,104 +14,115 @@
#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:
{ friend class NodeBuilder;
public: friend class NodeEvents;
friend class NodeBuilder; friend struct detail::iterator_value;
friend class NodeEvents; friend class detail::node_data;
friend struct detail::iterator_value; template <typename>
friend class detail::node_data; friend class detail::iterator_base;
template<typename> friend class detail::iterator_base; template <typename T, typename S>
template<typename T, typename S> friend struct as_if; friend struct as_if;
typedef YAML::iterator iterator;
typedef YAML::const_iterator const_iterator;
Node();
explicit Node(NodeType::value type);
template<typename T> explicit Node(const T& rhs);
explicit Node(const detail::iterator_value& rhs);
Node(const Node& rhs);
~Node();
NodeType::value Type() const;
bool IsDefined() const;
bool IsNull() const { return Type() == NodeType::Null; }
bool IsScalar() const { return Type() == NodeType::Scalar; }
bool IsSequence() const { return Type() == NodeType::Sequence; }
bool IsMap() const { return Type() == NodeType::Map; }
// bool conversions
YAML_CPP_OPERATOR_BOOL();
bool operator!() const { return !IsDefined(); }
// access
template<typename T> const T as() const;
template<typename T, typename S> const T as(const S& fallback) const;
const std::string& Scalar() const;
const std::string& Tag() const;
void SetTag(const std::string& tag);
// assignment typedef YAML::iterator iterator;
bool is(const Node& rhs) const; typedef YAML::const_iterator const_iterator;
template<typename T> Node& operator=(const T& rhs);
Node& operator=(const Node& rhs);
void reset(const Node& rhs = Node());
// size/iterator
std::size_t size() const;
const_iterator begin() const; Node();
iterator begin(); explicit Node(NodeType::value type);
template <typename T>
const_iterator end() const; explicit Node(const T& rhs);
iterator end(); explicit Node(const detail::iterator_value& rhs);
Node(const Node& rhs);
// sequence ~Node();
template<typename T> void push_back(const T& rhs);
void push_back(const Node& rhs);
// indexing
template<typename Key> const Node operator[](const Key& key) const;
template<typename Key> Node operator[](const Key& key);
template<typename Key> bool remove(const Key& key);
const Node operator[](const Node& key) const; NodeType::value Type() const;
Node operator[](const Node& key); bool IsDefined() const;
bool remove(const Node& key); bool IsNull() const { return Type() == NodeType::Null; }
bool IsScalar() const { return Type() == NodeType::Scalar; }
// map bool IsSequence() const { return Type() == NodeType::Sequence; }
template<typename Key, typename Value> bool IsMap() const { return Type() == NodeType::Map; }
void force_insert(const Key& key, const Value& value);
private: // bool conversions
enum Zombie { ZombieNode }; YAML_CPP_OPERATOR_BOOL();
explicit Node(Zombie); bool operator!() const { return !IsDefined(); }
explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
void EnsureNodeExists() const;
template<typename T> void Assign(const T& rhs);
void Assign(const char *rhs);
void Assign(char *rhs);
void AssignData(const Node& rhs); // access
void AssignNode(const Node& rhs); template <typename T>
const T as() const;
private: template <typename T, typename S>
bool m_isValid; const T as(const S& fallback) const;
mutable detail::shared_memory_holder m_pMemory; const std::string& Scalar() const;
mutable detail::node *m_pNode; const std::string& Tag() const;
}; void SetTag(const std::string& tag);
bool operator==(const Node& lhs, const Node& rhs); // assignment
bool is(const Node& rhs) const;
Node Clone(const Node& node); template <typename T>
Node& operator=(const T& rhs);
template<typename T> Node& operator=(const Node& rhs);
struct convert; void reset(const Node& rhs = Node());
// size/iterator
std::size_t size() const;
const_iterator begin() const;
iterator begin();
const_iterator end() const;
iterator end();
// sequence
template <typename T>
void push_back(const T& rhs);
void push_back(const Node& rhs);
// indexing
template <typename Key>
const Node operator[](const Key& key) const;
template <typename Key>
Node operator[](const Key& key);
template <typename Key>
bool remove(const Key& key);
const Node operator[](const Node& key) const;
Node operator[](const Node& key);
bool remove(const Node& key);
// map
template <typename Key, typename Value>
void force_insert(const Key& key, const Value& value);
private:
enum Zombie {
ZombieNode
};
explicit Node(Zombie);
explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
void EnsureNodeExists() const;
template <typename T>
void Assign(const T& rhs);
void Assign(const char* rhs);
void Assign(char* rhs);
void AssignData(const Node& rhs);
void AssignNode(const Node& rhs);
private:
bool m_isValid;
mutable detail::shared_memory_holder m_pMemory;
mutable detail::node* m_pNode;
};
bool operator==(const Node& lhs, const Node& rhs);
Node Clone(const Node& node);
template <typename T>
struct convert;
} }
#endif // NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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,20 +11,18 @@
#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 char *input);
Node Load(std::istream& input);
Node LoadFile(const std::string& filename);
std::vector<Node> LoadAll(const std::string& input); Node Load(const std::string& input);
std::vector<Node> LoadAll(const char *input); Node Load(const char* input);
std::vector<Node> LoadAll(std::istream& input); Node Load(std::istream& input);
std::vector<Node> LoadAllFromFile(const std::string& filename); Node LoadFile(const std::string& filename);
std::vector<Node> LoadAll(const std::string& input);
std::vector<Node> LoadAll(const char* input);
std::vector<Node> LoadAll(std::istream& input);
std::vector<Node> LoadAllFromFile(const std::string& filename);
} }
#endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,29 +1,29 @@
#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; class node_data;
class node_data; class memory;
class memory; class memory_holder;
class memory_holder;
typedef boost::shared_ptr<node> shared_node; typedef boost::shared_ptr<node> shared_node;
typedef boost::shared_ptr<node_ref> shared_node_ref; typedef boost::shared_ptr<node_ref> shared_node_ref;
typedef boost::shared_ptr<node_data> shared_node_data; typedef boost::shared_ptr<node_data> shared_node_data;
typedef boost::shared_ptr<memory_holder> shared_memory_holder; typedef boost::shared_ptr<memory_holder> shared_memory_holder;
typedef boost::shared_ptr<memory> shared_memory; typedef boost::shared_ptr<memory> shared_memory;
} }
} }
#endif // VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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

View File

@@ -1,47 +1,46 @@
#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); ~Parser();
~Parser();
operator bool() const; operator bool() const;
void Load(std::istream& in); void Load(std::istream& in);
bool HandleNextDocument(EventHandler& eventHandler); bool HandleNextDocument(EventHandler& eventHandler);
void PrintTokens(std::ostream& out); void PrintTokens(std::ostream& out);
private: private:
void ParseDirectives(); void ParseDirectives();
void HandleDirective(const Token& token); void HandleDirective(const Token& token);
void HandleYamlDirective(const Token& token); void HandleYamlDirective(const Token& token);
void HandleTagDirective(const Token& token); void HandleTagDirective(const Token& token);
private: private:
std::auto_ptr<Scanner> m_pScanner; std::auto_ptr<Scanner> m_pScanner;
std::auto_ptr<Directives> m_pDirectives; std::auto_ptr<Directives> m_pDirectives;
}; };
} }
#endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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
@@ -18,4 +20,4 @@
#include "yaml-cpp/node/parse.h" #include "yaml-cpp/node/parse.h"
#include "yaml-cpp/node/emit.h" #include "yaml-cpp/node/emit.h"
#endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -2,82 +2,72 @@
#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::transform(s.begin(), s.end(), s.begin(), ToLower);
std::string s(str); return s;
std::transform(s.begin(), s.end(), s.begin(), ToLower);
return s;
}
template <typename T>
bool IsEntirely(const std::string& str, T func)
{
for(std::size_t i=0;i<str.size();i++)
if(!func(str[i]))
return false;
return true;
}
// IsFlexibleCase
// . Returns true if 'str' is:
// . UPPERCASE
// . lowercase
// . Capitalized
bool IsFlexibleCase(const std::string& str)
{
if(str.empty())
return true;
if(IsEntirely(str, IsLower))
return true;
bool firstcaps = IsUpper(str[0]);
std::string rest = str.substr(1);
return firstcaps && (IsEntirely(rest, IsLower) || IsEntirely(rest, IsUpper));
}
} }
namespace YAML template <typename T>
{ bool IsEntirely(const std::string& str, T func) {
bool convert<bool>::decode(const Node& node, bool& rhs) { for (std::size_t i = 0; i < str.size(); i++)
if(!node.IsScalar()) if (!func(str[i]))
return false; return false;
// we can't use iostream bool extraction operators as they don't return true;
// recognize all possible values in the table below (taken from }
// http://yaml.org/type/bool.html)
static const struct { // IsFlexibleCase
std::string truename, falsename; // . Returns true if 'str' is:
} names[] = { // . UPPERCASE
{ "y", "n" }, // . lowercase
{ "yes", "no" }, // . Capitalized
{ "true", "false" }, bool IsFlexibleCase(const std::string& str) {
{ "on", "off" }, if (str.empty())
}; return true;
if(!IsFlexibleCase(node.Scalar())) if (IsEntirely(str, IsLower))
return false; return true;
for(unsigned i=0;i<sizeof(names)/sizeof(names[0]);i++) { bool firstcaps = IsUpper(str[0]);
if(names[i].truename == tolower(node.Scalar())) { std::string rest = str.substr(1);
rhs = true; return firstcaps && (IsEntirely(rest, IsLower) || IsEntirely(rest, IsUpper));
return true; }
} }
if(names[i].falsename == tolower(node.Scalar())) { namespace YAML {
rhs = false; bool convert<bool>::decode(const Node& node, bool& rhs) {
return true; if (!node.IsScalar())
} return false;
}
// we can't use iostream bool extraction operators as they don't
return false; // recognize all possible values in the table below (taken from
} // http://yaml.org/type/bool.html)
static const struct {
std::string truename, falsename;
} names[] = {{"y", "n"}, {"yes", "no"}, {"true", "false"}, {"on", "off"}, };
if (!IsFlexibleCase(node.Scalar()))
return false;
for (unsigned i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
if (names[i].truename == tolower(node.Scalar())) {
rhs = true;
return true;
}
if (names[i].falsename == tolower(node.Scalar())) {
rhs = false;
return true;
}
}
return false;
}
} }

View File

@@ -3,27 +3,23 @@
#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);
{ NodeEvents events(node);
EmitFromEvents emitFromEvents(out); events.Emit(emitFromEvents);
NodeEvents events(node); return out;
events.Emit(emitFromEvents); }
return out;
} std::ostream& operator<<(std::ostream& out, const Node& node) {
Emitter emitter(out);
std::ostream& operator << (std::ostream& out, const Node& node) emitter << node;
{ return out;
Emitter emitter(out); }
emitter << node;
return out; std::string Dump(const Node& node) {
} Emitter emitter;
emitter << node;
std::string Dump(const Node& node) return emitter.c_str();
{ }
Emitter emitter;
emitter << node;
return emitter.c_str();
}
} }

View File

@@ -1,29 +1,24 @@
#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) {
{ if (m_pMemory == rhs.m_pMemory)
void memory_holder::merge(memory_holder& rhs) return;
{
if(m_pMemory == rhs.m_pMemory) m_pMemory->merge(*rhs.m_pMemory);
return; rhs.m_pMemory = m_pMemory;
}
m_pMemory->merge(*rhs.m_pMemory);
rhs.m_pMemory = m_pMemory; node& memory::create_node() {
} shared_node pNode(new node);
m_nodes.insert(pNode);
node& memory::create_node() return *pNode;
{ }
shared_node pNode(new node);
m_nodes.insert(pNode); void memory::merge(const memory& rhs) {
return *pNode; m_nodes.insert(rhs.m_nodes.begin(), rhs.m_nodes.end());
} }
}
void memory::merge(const memory& rhs)
{
m_nodes.insert(rhs.m_nodes.begin(), rhs.m_nodes.end());
}
}
} }

View File

@@ -2,13 +2,11 @@
#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);
{ NodeBuilder builder;
NodeEvents events(node); events.Emit(builder);
NodeBuilder builder; return builder.Root();
events.Emit(builder); }
return builder.Root();
}
} }

View File

@@ -4,292 +4,280 @@
#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) {
{ m_type = type;
if(type == NodeType::Undefined) { m_isDefined = false;
m_type = type; return;
m_isDefined = false; }
return;
} m_isDefined = true;
if (type == m_type)
return;
m_isDefined = true;
if(type == m_type) m_type = type;
return;
switch (m_type) {
m_type = type; case NodeType::Null:
break;
switch(m_type) { case NodeType::Scalar:
case NodeType::Null: m_scalar.clear();
break; break;
case NodeType::Scalar: case NodeType::Sequence:
m_scalar.clear(); reset_sequence();
break; break;
case NodeType::Sequence: case NodeType::Map:
reset_sequence(); reset_map();
break; break;
case NodeType::Map: case NodeType::Undefined:
reset_map(); assert(false);
break; break;
case NodeType::Undefined: }
assert(false); }
break;
} void node_data::set_tag(const std::string& tag) { m_tag = tag; }
}
void node_data::set_null() {
void node_data::set_tag(const std::string& tag) m_isDefined = true;
{ m_type = NodeType::Null;
m_tag = tag; }
}
void node_data::set_scalar(const std::string& scalar) {
void node_data::set_null() m_isDefined = true;
{ m_type = NodeType::Scalar;
m_isDefined = true; m_scalar = scalar;
m_type = NodeType::Null; }
}
// size/iterator
void node_data::set_scalar(const std::string& scalar) std::size_t node_data::size() const {
{ if (!m_isDefined)
m_isDefined = true; return 0;
m_type = NodeType::Scalar;
m_scalar = scalar; switch (m_type) {
} case NodeType::Sequence:
compute_seq_size();
// size/iterator return m_seqSize;
std::size_t node_data::size() const case NodeType::Map:
{ compute_map_size();
if(!m_isDefined) return m_map.size() - m_undefinedPairs.size();
return 0; default:
return 0;
switch(m_type) { }
case NodeType::Sequence: compute_seq_size(); return m_seqSize; return 0;
case NodeType::Map: compute_map_size(); return m_map.size() - m_undefinedPairs.size(); }
default:
return 0; void node_data::compute_seq_size() const {
} while (m_seqSize < m_sequence.size() && m_sequence[m_seqSize]->is_defined())
return 0; m_seqSize++;
} }
void node_data::compute_seq_size() const void node_data::compute_map_size() const {
{ kv_pairs::iterator it = m_undefinedPairs.begin();
while(m_seqSize < m_sequence.size() && m_sequence[m_seqSize]->is_defined()) while (it != m_undefinedPairs.end()) {
m_seqSize++; kv_pairs::iterator jt = boost::next(it);
} if (it->first->is_defined() && it->second->is_defined())
m_undefinedPairs.erase(it);
void node_data::compute_map_size() const it = jt;
{ }
kv_pairs::iterator it = m_undefinedPairs.begin(); }
while(it != m_undefinedPairs.end()) {
kv_pairs::iterator jt = boost::next(it); const_node_iterator node_data::begin() const {
if(it->first->is_defined() && it->second->is_defined()) if (!m_isDefined)
m_undefinedPairs.erase(it); return const_node_iterator();
it = jt;
} switch (m_type) {
} case NodeType::Sequence:
return const_node_iterator(m_sequence.begin());
const_node_iterator node_data::begin() const case NodeType::Map:
{ return const_node_iterator(m_map.begin(), m_map.end());
if(!m_isDefined) default:
return const_node_iterator(); return const_node_iterator();
}
switch(m_type) { }
case NodeType::Sequence: return const_node_iterator(m_sequence.begin());
case NodeType::Map: return const_node_iterator(m_map.begin(), m_map.end()); node_iterator node_data::begin() {
default: return const_node_iterator(); if (!m_isDefined)
} return node_iterator();
}
switch (m_type) {
node_iterator node_data::begin() case NodeType::Sequence:
{ return node_iterator(m_sequence.begin());
if(!m_isDefined) case NodeType::Map:
return node_iterator(); return node_iterator(m_map.begin(), m_map.end());
default:
switch(m_type) { return node_iterator();
case NodeType::Sequence: return node_iterator(m_sequence.begin()); }
case NodeType::Map: return node_iterator(m_map.begin(), m_map.end()); }
default: return node_iterator();
} const_node_iterator node_data::end() const {
} if (!m_isDefined)
return const_node_iterator();
const_node_iterator node_data::end() const
{ switch (m_type) {
if(!m_isDefined) case NodeType::Sequence:
return const_node_iterator(); return const_node_iterator(m_sequence.end());
case NodeType::Map:
switch(m_type) { return const_node_iterator(m_map.end(), m_map.end());
case NodeType::Sequence: return const_node_iterator(m_sequence.end()); default:
case NodeType::Map: return const_node_iterator(m_map.end(), m_map.end()); return const_node_iterator();
default: return const_node_iterator(); }
} }
}
node_iterator node_data::end() {
node_iterator node_data::end() if (!m_isDefined)
{ return node_iterator();
if(!m_isDefined)
return node_iterator(); switch (m_type) {
case NodeType::Sequence:
switch(m_type) { return node_iterator(m_sequence.end());
case NodeType::Sequence: return node_iterator(m_sequence.end()); case NodeType::Map:
case NodeType::Map: return node_iterator(m_map.end(), m_map.end()); return node_iterator(m_map.end(), m_map.end());
default: return node_iterator(); default:
} return node_iterator();
} }
}
// sequence
void node_data::push_back(node& node, shared_memory_holder /* pMemory */) // sequence
{ 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();
} }
if(m_type != NodeType::Sequence) if (m_type != NodeType::Sequence)
throw BadPushback(); throw BadPushback();
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; case NodeType::Undefined:
case NodeType::Undefined: case NodeType::Null:
case NodeType::Null: case NodeType::Sequence:
case NodeType::Sequence: convert_to_map(pMemory);
convert_to_map(pMemory); break;
break; case NodeType::Scalar:
case NodeType::Scalar: throw BadSubscript();
throw BadSubscript(); }
}
insert_map_pair(key, value);
insert_map_pair(key, value); }
}
// 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)
{ return pMemory->create_node();
if(m_type != NodeType::Map)
return pMemory->create_node(); for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
if (it->first->is(key))
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) { return *it->second;
if(it->first->is(key)) }
return *it->second;
} return pMemory->create_node();
}
return pMemory->create_node();
} node& node_data::get(node& key, shared_memory_holder pMemory) {
switch (m_type) {
node& node_data::get(node& key, shared_memory_holder pMemory) case NodeType::Map:
{ break;
switch(m_type) { case NodeType::Undefined:
case NodeType::Map: case NodeType::Null:
break; case NodeType::Sequence:
case NodeType::Undefined: convert_to_map(pMemory);
case NodeType::Null: break;
case NodeType::Sequence: case NodeType::Scalar:
convert_to_map(pMemory); throw BadSubscript();
break; }
case NodeType::Scalar:
throw BadSubscript(); for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
} if (it->first->is(key))
return *it->second;
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) { }
if(it->first->is(key))
return *it->second; node& value = pMemory->create_node();
} insert_map_pair(key, value);
return value;
node& value = pMemory->create_node(); }
insert_map_pair(key, value);
return value; bool node_data::remove(node& key, shared_memory_holder /* pMemory */) {
} if (m_type != NodeType::Map)
return false;
bool node_data::remove(node& key, shared_memory_holder /* pMemory */)
{ for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) {
if(m_type != NodeType::Map) if (it->first->is(key)) {
return false; m_map.erase(it);
return true;
for(node_map::iterator it=m_map.begin();it!=m_map.end();++it) { }
if(it->first->is(key)) { }
m_map.erase(it);
return true; return false;
} }
}
void node_data::reset_sequence() {
return false; m_sequence.clear();
} m_seqSize = 0;
}
void node_data::reset_sequence()
{ void node_data::reset_map() {
m_sequence.clear(); m_map.clear();
m_seqSize = 0; m_undefinedPairs.clear();
} }
void node_data::reset_map() void node_data::insert_map_pair(node& key, node& value) {
{ m_map[&key] = &value;
m_map.clear(); if (!key.is_defined() || !value.is_defined())
m_undefinedPairs.clear(); m_undefinedPairs.push_back(kv_pair(&key, &value));
} }
void node_data::insert_map_pair(node& key, node& value) void node_data::convert_to_map(shared_memory_holder pMemory) {
{ switch (m_type) {
m_map[&key] = &value; case NodeType::Undefined:
if(!key.is_defined() || !value.is_defined()) case NodeType::Null:
m_undefinedPairs.push_back(kv_pair(&key, &value)); reset_map();
} m_type = NodeType::Map;
break;
void node_data::convert_to_map(shared_memory_holder pMemory) case NodeType::Sequence:
{ convert_sequence_to_map(pMemory);
switch(m_type) { break;
case NodeType::Undefined: case NodeType::Map:
case NodeType::Null: break;
reset_map(); case NodeType::Scalar:
m_type = NodeType::Map; assert(false);
break; break;
case NodeType::Sequence: }
convert_sequence_to_map(pMemory); }
break;
case NodeType::Map: void node_data::convert_sequence_to_map(shared_memory_holder pMemory) {
break; assert(m_type == NodeType::Sequence);
case NodeType::Scalar:
assert(false); reset_map();
break; for (std::size_t i = 0; i < m_sequence.size(); i++) {
} std::stringstream stream;
} stream << i;
void node_data::convert_sequence_to_map(shared_memory_holder pMemory) node& key = pMemory->create_node();
{ key.set_scalar(stream.str());
assert(m_type == NodeType::Sequence); insert_map_pair(key, *m_sequence[i]);
}
reset_map();
for(std::size_t i=0;i<m_sequence.size();i++) { reset_sequence();
std::stringstream stream; m_type = NodeType::Map;
stream << i; }
}
node& key = pMemory->create_node();
key.set_scalar(stream.str());
insert_map_pair(key, *m_sequence[i]);
}
reset_sequence();
m_type = NodeType::Map;
}
}
} }

View File

@@ -4,135 +4,119 @@
#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() {
} if (!m_pRoot)
return Node();
Node NodeBuilder::Root()
{ return Node(*m_pRoot, m_pMemory);
if(!m_pRoot) }
return Node();
void NodeBuilder::OnDocumentStart(const Mark&) {}
return Node(*m_pRoot, m_pMemory);
} void NodeBuilder::OnDocumentEnd() {}
void NodeBuilder::OnDocumentStart(const Mark&) void NodeBuilder::OnNull(const Mark& /* mark */, anchor_t anchor) {
{ detail::node& node = Push(anchor);
} node.set_null();
Pop();
void NodeBuilder::OnDocumentEnd() }
{
} void NodeBuilder::OnAlias(const Mark& /* mark */, anchor_t anchor) {
detail::node& node = *m_anchors[anchor];
void NodeBuilder::OnNull(const Mark& /* mark */, anchor_t anchor) Push(node);
{ Pop();
detail::node& node = Push(anchor); }
node.set_null();
Pop(); void NodeBuilder::OnScalar(const Mark& /* mark */, const std::string& tag,
} anchor_t anchor, const std::string& value) {
detail::node& node = Push(anchor);
void NodeBuilder::OnAlias(const Mark& /* mark */, anchor_t anchor) node.set_scalar(value);
{ node.set_tag(tag);
detail::node& node = *m_anchors[anchor]; Pop();
Push(node); }
Pop();
} void NodeBuilder::OnSequenceStart(const Mark& /* mark */,
const std::string& tag, anchor_t anchor) {
void NodeBuilder::OnScalar(const Mark& /* mark */, const std::string& tag, anchor_t anchor, const std::string& value) detail::node& node = Push(anchor);
{ node.set_tag(tag);
detail::node& node = Push(anchor); node.set_type(NodeType::Sequence);
node.set_scalar(value); }
node.set_tag(tag);
Pop(); void NodeBuilder::OnSequenceEnd() { Pop(); }
}
void NodeBuilder::OnMapStart(const Mark& /* mark */, const std::string& tag,
void NodeBuilder::OnSequenceStart(const Mark& /* mark */, const std::string& tag, anchor_t anchor) anchor_t anchor) {
{ detail::node& node = Push(anchor);
detail::node& node = Push(anchor); node.set_type(NodeType::Map);
node.set_tag(tag); node.set_tag(tag);
node.set_type(NodeType::Sequence); m_mapDepth++;
} }
void NodeBuilder::OnSequenceEnd() void NodeBuilder::OnMapEnd() {
{ assert(m_mapDepth > 0);
Pop(); m_mapDepth--;
} Pop();
}
void NodeBuilder::OnMapStart(const Mark& /* mark */, const std::string& tag, anchor_t anchor)
{ detail::node& NodeBuilder::Push(anchor_t anchor) {
detail::node& node = Push(anchor); detail::node& node = m_pMemory->create_node();
node.set_type(NodeType::Map); RegisterAnchor(anchor, node);
node.set_tag(tag); Push(node);
m_mapDepth++; return node;
} }
void NodeBuilder::OnMapEnd() void NodeBuilder::Push(detail::node& node) {
{ const bool needsKey =
assert(m_mapDepth > 0); (!m_stack.empty() && m_stack.back()->type() == NodeType::Map &&
m_mapDepth--; m_keys.size() < m_mapDepth);
Pop();
} m_stack.push_back(&node);
if (needsKey)
detail::node& NodeBuilder::Push(anchor_t anchor) m_keys.push_back(PushedKey(&node, false));
{ }
detail::node& node = m_pMemory->create_node();
RegisterAnchor(anchor, node); void NodeBuilder::Pop() {
Push(node); assert(!m_stack.empty());
return node; if (m_stack.size() == 1) {
} m_pRoot = m_stack[0];
m_stack.pop_back();
void NodeBuilder::Push(detail::node& node) return;
{ }
const bool needsKey = (!m_stack.empty() && m_stack.back()->type() == NodeType::Map && m_keys.size() < m_mapDepth);
detail::node& node = *m_stack.back();
m_stack.push_back(&node); m_stack.pop_back();
if(needsKey)
m_keys.push_back(PushedKey(&node, false)); detail::node& collection = *m_stack.back();
}
if (collection.type() == NodeType::Sequence) {
void NodeBuilder::Pop() collection.push_back(node, m_pMemory);
{ } else if (collection.type() == NodeType::Map) {
assert(!m_stack.empty()); assert(!m_keys.empty());
if(m_stack.size() == 1) { PushedKey& key = m_keys.back();
m_pRoot = m_stack[0]; if (key.second) {
m_stack.pop_back(); collection.insert(*key.first, node, m_pMemory);
return; m_keys.pop_back();
} } else {
key.second = true;
detail::node& node = *m_stack.back(); }
m_stack.pop_back(); } else {
assert(false);
detail::node& collection = *m_stack.back(); m_stack.clear();
}
if(collection.type() == NodeType::Sequence) { }
collection.push_back(node, m_pMemory);
} else if(collection.type() == NodeType::Map) { void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node) {
assert(!m_keys.empty()); if (anchor) {
PushedKey& key = m_keys.back(); assert(anchor == m_anchors.size());
if(key.second) { m_anchors.push_back(&node);
collection.insert(*key.first, node, m_pMemory); }
m_keys.pop_back(); }
} else {
key.second = true;
}
} else {
assert(false);
m_stack.clear();
}
}
void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node)
{
if(anchor) {
assert(anchor == m_anchors.size());
m_anchors.push_back(&node);
}
}
} }

View File

@@ -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,50 +11,50 @@
#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();
Node Root();
virtual void OnDocumentStart(const Mark& mark);
virtual void OnDocumentEnd();
virtual void OnNull(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 OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor);
virtual void OnSequenceEnd();
virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor);
virtual void OnMapEnd();
private:
detail::node& Push(anchor_t anchor);
void Push(detail::node& node);
void Pop();
void RegisterAnchor(anchor_t anchor, detail::node& node);
private:
detail::shared_memory_holder m_pMemory;
detail::node *m_pRoot;
typedef std::vector<detail::node *> Nodes;
Nodes m_stack;
Nodes m_anchors;
typedef std::pair<detail::node *, bool> PushedKey; Node Root();
std::vector<PushedKey> m_keys;
std::size_t m_mapDepth; virtual void OnDocumentStart(const Mark& mark);
}; virtual void OnDocumentEnd();
virtual void OnNull(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 OnSequenceStart(const Mark& mark, const std::string& tag,
anchor_t anchor);
virtual void OnSequenceEnd();
virtual void OnMapStart(const Mark& mark, const std::string& tag,
anchor_t anchor);
virtual void OnMapEnd();
private:
detail::node& Push(anchor_t anchor);
void Push(detail::node& node);
void Pop();
void RegisterAnchor(anchor_t anchor, detail::node& node);
private:
detail::shared_memory_holder m_pMemory;
detail::node* m_pRoot;
typedef std::vector<detail::node*> Nodes;
Nodes m_stack;
Nodes m_anchors;
typedef std::pair<detail::node*, bool> PushedKey;
std::vector<PushedKey> m_keys;
std::size_t m_mapDepth;
};
} }
#endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -4,98 +4,96 @@
#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());
{ if (it == m_anchorByIdentity.end())
AnchorByIdentity::const_iterator it = m_anchorByIdentity.find(node.ref()); return 0;
if(it == m_anchorByIdentity.end()) return it->second;
return 0; }
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)
{ Setup(*m_root);
if(m_root) }
Setup(*m_root);
} void NodeEvents::Setup(const detail::node& node) {
int& refCount = m_refCount[node.ref()];
void NodeEvents::Setup(const detail::node& node) refCount++;
{ if (refCount > 1)
int& refCount = m_refCount[node.ref()]; return;
refCount++;
if(refCount > 1) if (node.type() == NodeType::Sequence) {
return; for (detail::const_node_iterator it = node.begin(); it != node.end(); ++it)
Setup(**it);
if(node.type() == NodeType::Sequence) { } 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();
Setup(**it); ++it) {
} else if(node.type() == NodeType::Map) { Setup(*it->first);
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) { Setup(*it->second);
Setup(*it->first); }
Setup(*it->second); }
} }
}
} void NodeEvents::Emit(EventHandler& handler) {
AliasManager am;
void NodeEvents::Emit(EventHandler& handler)
{ handler.OnDocumentStart(Mark());
AliasManager am; if (m_root)
Emit(*m_root, handler, am);
handler.OnDocumentStart(Mark()); handler.OnDocumentEnd();
if(m_root) }
Emit(*m_root, handler, am);
handler.OnDocumentEnd(); void NodeEvents::Emit(const detail::node& node, EventHandler& handler,
} AliasManager& am) const {
anchor_t anchor = NullAnchor;
void NodeEvents::Emit(const detail::node& node, EventHandler& handler, AliasManager& am) const if (IsAliased(node)) {
{ anchor = am.LookupAnchor(node);
anchor_t anchor = NullAnchor; if (anchor) {
if(IsAliased(node)) { handler.OnAlias(Mark(), anchor);
anchor = am.LookupAnchor(node); return;
if(anchor) { }
handler.OnAlias(Mark(), anchor);
return; am.RegisterReference(node);
} anchor = am.LookupAnchor(node);
}
am.RegisterReference(node);
anchor = am.LookupAnchor(node); switch (node.type()) {
} case NodeType::Undefined:
break;
switch(node.type()) { case NodeType::Null:
case NodeType::Undefined: handler.OnNull(Mark(), anchor);
break; break;
case NodeType::Null: case NodeType::Scalar:
handler.OnNull(Mark(), anchor); handler.OnScalar(Mark(), node.tag(), anchor, node.scalar());
break; break;
case NodeType::Scalar: case NodeType::Sequence:
handler.OnScalar(Mark(), node.tag(), anchor, node.scalar()); handler.OnSequenceStart(Mark(), node.tag(), anchor);
break; for (detail::const_node_iterator it = node.begin(); it != node.end();
case NodeType::Sequence: ++it)
handler.OnSequenceStart(Mark(), node.tag(), anchor); Emit(**it, handler, am);
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) handler.OnSequenceEnd();
Emit(**it, handler, am); break;
handler.OnSequenceEnd(); case NodeType::Map:
break; handler.OnMapStart(Mark(), node.tag(), anchor);
case NodeType::Map: for (detail::const_node_iterator it = node.begin(); it != node.end();
handler.OnMapStart(Mark(), node.tag(), anchor); ++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); }
} handler.OnMapEnd();
handler.OnMapEnd(); break;
break; }
} }
}
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());
{ return it != m_refCount.end() && it->second > 1;
RefCount::const_iterator it = m_refCount.find(node.ref()); }
return it != m_refCount.end() && it->second > 1;
}
} }

View File

@@ -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,48 +12,46 @@
#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:
{ explicit NodeEvents(const Node& node);
public:
explicit NodeEvents(const Node& node); void Emit(EventHandler& handler);
void Emit(EventHandler& handler); private:
class AliasManager {
private: public:
class AliasManager { AliasManager() : m_curAnchor(0) {}
public:
AliasManager(): m_curAnchor(0) {} void RegisterReference(const detail::node& node);
anchor_t LookupAnchor(const detail::node& node) const;
void RegisterReference(const detail::node& node);
anchor_t LookupAnchor(const detail::node& node) const; private:
anchor_t _CreateNewAnchor() { return ++m_curAnchor; }
private:
anchor_t _CreateNewAnchor() { return ++m_curAnchor; } private:
typedef std::map<const detail::node_ref*, anchor_t> AnchorByIdentity;
private: AnchorByIdentity m_anchorByIdentity;
typedef std::map<const detail::node_ref*, anchor_t> AnchorByIdentity;
AnchorByIdentity m_anchorByIdentity; anchor_t m_curAnchor;
};
anchor_t m_curAnchor;
}; void Setup(const detail::node& node);
void Emit(const detail::node& node, EventHandler& handler,
void Setup(const detail::node& node); 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: detail::shared_memory_holder m_pMemory;
detail::shared_memory_holder m_pMemory; detail::node* m_root;
detail::node* m_root;
typedef std::map<const detail::node_ref*, int> RefCount;
typedef std::map<const detail::node_ref *, int> RefCount; RefCount m_refCount;
RefCount m_refCount; };
};
} }
#endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -2,55 +2,52 @@
#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),
ostream_wrapper::ostream_wrapper(std::ostream& stream): m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false) m_col(0),
{ m_comment(false) {}
}
ostream_wrapper::~ostream_wrapper() ostream_wrapper::ostream_wrapper(std::ostream& stream)
{ : m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false) {}
}
void ostream_wrapper::write(const std::string& str)
{
if(m_pStream) {
m_pStream->write(str.c_str(), str.size());
} else {
m_buffer.resize(std::max(m_buffer.size(), m_pos + str.size() + 1));
std::copy(str.begin(), str.end(), &m_buffer[m_pos]);
}
for(std::size_t i=0;i<str.size();i++)
update_pos(str[i]);
}
void ostream_wrapper::write(const char *str, std::size_t size) ostream_wrapper::~ostream_wrapper() {}
{
if(m_pStream) { void ostream_wrapper::write(const std::string& str) {
m_pStream->write(str, size); if (m_pStream) {
} else { m_pStream->write(str.c_str(), str.size());
m_buffer.resize(std::max(m_buffer.size(), m_pos + size + 1)); } else {
std::copy(str, str + size, &m_buffer[m_pos]); m_buffer.resize(std::max(m_buffer.size(), m_pos + str.size() + 1));
} std::copy(str.begin(), str.end(), &m_buffer[m_pos]);
}
for(std::size_t i=0;i<size;i++)
update_pos(str[i]); for (std::size_t i = 0; i < str.size(); i++)
} update_pos(str[i]);
}
void ostream_wrapper::update_pos(char ch)
{ void ostream_wrapper::write(const char* str, std::size_t size) {
m_pos++; if (m_pStream) {
m_col++; m_pStream->write(str, size);
} else {
if(ch == '\n') { m_buffer.resize(std::max(m_buffer.size(), m_pos + size + 1));
m_row++; std::copy(str, str + size, &m_buffer[m_pos]);
m_col = 0; }
m_comment = false;
} for (std::size_t i = 0; i < size; i++)
} update_pos(str[i]);
}
void ostream_wrapper::update_pos(char ch) {
m_pos++;
m_col++;
if (ch == '\n') {
m_row++;
m_col = 0;
m_comment = false;
}
}
} }

View File

@@ -7,62 +7,61 @@
#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); }
}
Node Load(const char* input) {
Node Load(const char *input) { std::stringstream stream(input);
std::stringstream stream(input); return Load(stream);
return Load(stream); }
}
Node Load(std::istream& input) {
Node Load(std::istream& input) { Parser parser(input);
Parser parser(input); NodeBuilder builder;
NodeBuilder builder; if (!parser.HandleNextDocument(builder))
if(!parser.HandleNextDocument(builder)) return Node();
return Node();
return builder.Root();
return builder.Root(); }
}
Node LoadFile(const std::string& filename) {
Node LoadFile(const std::string& filename) { std::ifstream fin(filename.c_str());
std::ifstream fin(filename.c_str()); if (!fin)
if(!fin) throw BadFile();
throw BadFile(); return Load(fin);
return Load(fin); }
}
std::vector<Node> LoadAll(const std::string& input) {
std::vector<Node> LoadAll(const std::string& input) { std::stringstream stream(input);
std::stringstream stream(input); return LoadAll(stream);
return LoadAll(stream); }
}
std::vector<Node> LoadAll(const char* input) {
std::vector<Node> LoadAll(const char *input) { std::stringstream stream(input);
std::stringstream stream(input); return LoadAll(stream);
return LoadAll(stream); }
}
std::vector<Node> LoadAll(std::istream& input) {
std::vector<Node> LoadAll(std::istream& input) { std::vector<Node> docs;
std::vector<Node> docs;
Parser parser(input);
Parser parser(input); while (1) {
while(1) { NodeBuilder builder;
NodeBuilder builder; if (!parser.HandleNextDocument(builder))
if(!parser.HandleNextDocument(builder)) break;
break; docs.push_back(builder.Root());
docs.push_back(builder.Root()); }
}
return docs;
return docs; }
}
std::vector<Node> LoadAllFromFile(const std::string& filename) {
std::vector<Node> LoadAllFromFile(const std::string& filename) { std::ifstream fin(filename.c_str());
std::ifstream fin(filename.c_str()); if (!fin)
if(!fin) throw BadFile();
throw BadFile(); return LoadAll(fin);
return LoadAll(fin); }
}
} }

View File

@@ -50,21 +50,21 @@ static bool s_introFinalState[] = {false, // uis_start
false, // uis_utfbe_b1 false, // uis_utfbe_b1
false, // uis_utf32be_b2 false, // uis_utf32be_b2
false, // uis_utf32be_bom3 false, // uis_utf32be_bom3
true, // uis_utf32be true, // uis_utf32be
true, // uis_utf16be true, // uis_utf16be
false, // uis_utf16be_bom1 false, // uis_utf16be_bom1
false, // uis_utfle_bom1 false, // uis_utfle_bom1
false, // uis_utf16le_bom2 false, // uis_utf16le_bom2
false, // uis_utf32le_bom3 false, // uis_utf32le_bom3
true, // uis_utf16le true, // uis_utf16le
true, // uis_utf32le true, // uis_utf32le
false, // uis_utf8_imp false, // uis_utf8_imp
false, // uis_utf16le_imp false, // uis_utf16le_imp
false, // uis_utf32le_imp3 false, // uis_utf32le_imp3
false, // uis_utf8_bom1 false, // uis_utf8_bom1
false, // uis_utf8_bom2 false, // uis_utf8_bom2
true, // uis_utf8 true, // uis_utf8
true, // uis_error true, // uis_error
}; };
static UtfIntroState s_introTransitions[][uictMax] = { static UtfIntroState s_introTransitions[][uictMax] = {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,5 @@
#include "parsertests.h" #include "parsertests.h"
namespace Test { namespace Test {
bool RunParserTests() bool RunParserTests() { return true; }
{
return true;
}
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,14 @@
#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
namespace Test { namespace Test {
bool RunNodeTests(); bool RunNodeTests();
} }
#endif // NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A6666 #endif // NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A6666

View File

@@ -9,25 +9,22 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
namespace Test namespace Test {
{ void RunAll() {
void RunAll() bool passed = true;
{ if (!RunParserTests())
bool passed = true; passed = false;
if(!RunParserTests())
passed = false;
if(!RunEmitterTests())
passed = false;
if(!RunSpecTests()) if (!RunEmitterTests())
passed = false; passed = false;
if(!RunNodeTests()) if (!RunSpecTests())
passed = false; passed = false;
if(passed) if (!RunNodeTests())
std::cout << "All tests passed!\n"; passed = false;
}
if (passed)
std::cout << "All tests passed!\n";
}
} }

View File

@@ -5,56 +5,57 @@
#include <vector> #include <vector>
struct Params { struct Params {
bool hasFile; bool hasFile;
std::string fileName; std::string fileName;
}; };
Params ParseArgs(int argc, char **argv) { Params ParseArgs(int argc, char** argv) {
Params p; Params p;
std::vector<std::string> args(argv + 1, argv + argc); std::vector<std::string> args(argv + 1, argv + argc);
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,
virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {} const std::string&) {}
virtual void OnSequenceStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {} virtual void OnSequenceStart(const YAML::Mark&, const std::string&,
virtual void OnSequenceEnd() {} YAML::anchor_t) {}
virtual void OnSequenceEnd() {}
virtual void OnMapStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
virtual void OnMapEnd() {} virtual void OnMapStart(const YAML::Mark&, const std::string&,
YAML::anchor_t) {}
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) {
std::ifstream fin; std::ifstream fin;
fin.open(argv[1]); fin.open(argv[1]);
parse(fin); parse(fin);
} else { } else {
parse(std::cin); parse(std::cin);
} }
return 0; return 0;
} }