Major switch from Value -> Node. The library compiles with the new API, but tests are still oldies, and don't compile

This commit is contained in:
Jesse Beder
2011-09-10 17:57:23 -05:00
parent ac81d7c883
commit 0d1b5224c8
30 changed files with 387 additions and 364 deletions

View File

@@ -35,6 +35,7 @@ enable_testing()
## Project stuff ## Project stuff
option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" ON) option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" ON)
option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON) option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON)
option(YAML_CPP_BUILD_OLD_API "Enable building the old API" OFF)
## Build options ## Build options
# --> General # --> General
@@ -55,21 +56,35 @@ option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (
### ###
### Sources, headers, directories and libs ### Sources, headers, directories and libs
### ###
file(GLOB sources file(GLOB common_sources "src/[a-zA-Z]*.cpp")
"src/[a-zA-Z]*.cpp" file(GLOB new_api_sources
"src/value/[a-zA-Z]*.cpp" "src/node/[a-zA-Z]*.cpp"
"src/value/detail/[a-zA-Z]*.cpp" "src/node/detail/[a-zA-Z]*.cpp"
) )
file(GLOB public_headers file(GLOB old_api_sources "src/old-api/[a-zA-Z]*.cpp")
"include/yaml-cpp/[a-zA-Z]*.h"
"include/yaml-cpp/value/[a-zA-Z]*.h" file(GLOB common_public_headers "include/yaml-cpp/[a-zA-Z]*.h")
"include/yaml-cpp/value/detail/[a-zA-Z]*.h" file(GLOB new_api_public_headers
"include/yaml-cpp/node/[a-zA-Z]*.h"
"include/yaml-cpp/node/detail/[a-zA-Z]*.h"
) )
file(GLOB private_headers file(GLOB old_api_public_headers "include/yaml-cpp/old-api/[a-zA-Z]*.h")
"src/[a-zA-Z]*.h"
"src/value/[a-zA-Z]*.h" file(GLOB common_private_headers "include/yaml-cpp/[a-zA-Z]*.h")
) file(GLOB new_api_private_headers "src/node/[a-zA-Z]*.h")
file(GLOB old_api_private_headers "src/old-api/[a-zA-Z]*.h")
if(YAML_CPP_BUILD_OLD_API)
list(APPEND sources ${common_sources} ${old_api_sources})
list(APPEND public_headers ${common_public_headers} ${old_api_public_headers})
list(APPEND private_headers ${common_private_headers} ${old_api_private_headers})
add_definitions(-DYAML_CPP_OLD_API)
else()
list(APPEND sources ${common_sources} ${new_api_sources})
list(APPEND public_headers ${common_public_headers} ${new_api_public_headers})
list(APPEND private_headers ${common_private_headers} ${new_api_private_headers})
endif()
if(YAML_CPP_BUILD_CONTRIB) if(YAML_CPP_BUILD_CONTRIB)
file(GLOB contrib_sources "src/contrib/[a-zA-Z]*.cpp") file(GLOB contrib_sources "src/contrib/[a-zA-Z]*.cpp")
file(GLOB contrib_public_headers "include/yaml-cpp/contrib/[a-zA-Z]*.h") file(GLOB contrib_public_headers "include/yaml-cpp/contrib/[a-zA-Z]*.h")

View File

@@ -1,12 +1,12 @@
#ifndef VALUE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_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/value/value.h" #include "yaml-cpp/node/node.h"
#include <map> #include <map>
#include <sstream> #include <sstream>
@@ -15,12 +15,12 @@ namespace YAML
// std::string // std::string
template<> template<>
struct convert<std::string> { struct convert<std::string> {
static Value encode(const std::string& rhs) { static Node encode(const std::string& rhs) {
return Value(rhs); return Node(rhs);
} }
static bool decode(const Value& value, std::string& rhs) { static bool decode(const Node& value, std::string& rhs) {
if(value.Type() != ValueType::Scalar) if(value.Type() != NodeType::Scalar)
return false; return false;
rhs = value.scalar(); rhs = value.scalar();
return true; return true;
@@ -30,14 +30,14 @@ namespace YAML
#define YAML_DEFINE_CONVERT_STREAMABLE(type)\ #define YAML_DEFINE_CONVERT_STREAMABLE(type)\
template<>\ template<>\
struct convert<type> {\ struct convert<type> {\
static Value encode(const type& rhs) {\ static Node encode(const type& rhs) {\
std::stringstream stream;\ std::stringstream stream;\
stream << rhs;\ stream << rhs;\
return Value(stream.str());\ return Node(stream.str());\
}\ }\
\ \
static bool decode(const Value& value, type& rhs) {\ static bool decode(const Node& value, type& rhs) {\
if(value.Type() != ValueType::Scalar)\ if(value.Type() != NodeType::Scalar)\
return false;\ return false;\
std::stringstream stream(value.scalar());\ std::stringstream stream(value.scalar());\
stream >> rhs;\ stream >> rhs;\
@@ -65,18 +65,18 @@ namespace YAML
template<typename K, typename V> template<typename K, typename V>
struct convert<std::map<K, V> > { struct convert<std::map<K, V> > {
static Value encode(const std::map<K, V>& rhs) { static Node encode(const std::map<K, V>& rhs) {
Value value(ValueType::Map); Node value(NodeType::Map);
for(typename std::map<K, V>::const_iterator it=rhs.begin();it!=rhs.end();++it) for(typename std::map<K, V>::const_iterator it=rhs.begin();it!=rhs.end();++it)
value[it->first] = it->second; value[it->first] = it->second;
return value; return value;
} }
static bool decode(const Value& value, std::map<K, V>& rhs) { static bool decode(const Node& value, std::map<K, V>& rhs) {
rhs.clear(); rhs.clear();
return false; return false;
} }
}; };
} }
#endif // VALUE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,13 +1,13 @@
#ifndef VALUE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_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/value/detail/node.h" #include "yaml-cpp/node/detail/node.h"
#include "yaml-cpp/value/detail/node_data.h" #include "yaml-cpp/node/detail/node_data.h"
namespace YAML namespace YAML
{ {
@@ -17,7 +17,7 @@ namespace YAML
template<typename Key> template<typename Key>
inline node& node_data::get(const Key& key, shared_memory_holder pMemory) const inline node& node_data::get(const Key& key, shared_memory_holder pMemory) const
{ {
if(m_type != ValueType::Map) if(m_type != NodeType::Map)
return pMemory->create_node(); return pMemory->create_node();
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) { for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
@@ -34,16 +34,16 @@ namespace YAML
// TODO: check if 'key' is index-like, and we're a sequence // TODO: check if 'key' is index-like, and we're a sequence
switch(m_type) { switch(m_type) {
case ValueType::Undefined: case NodeType::Undefined:
case ValueType::Null: case NodeType::Null:
case ValueType::Scalar: case NodeType::Scalar:
m_type = ValueType::Map; m_type = NodeType::Map;
m_map.clear(); m_map.clear();
break; break;
case ValueType::Sequence: case NodeType::Sequence:
convert_sequence_to_map(pMemory); convert_sequence_to_map(pMemory);
break; break;
case ValueType::Map: case NodeType::Map:
break; break;
} }
@@ -61,7 +61,7 @@ namespace YAML
template<typename Key> template<typename Key>
inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) inline bool node_data::remove(const Key& key, shared_memory_holder pMemory)
{ {
if(m_type != ValueType::Map) if(m_type != NodeType::Map)
return false; return false;
for(node_map::iterator it=m_map.begin();it!=m_map.end();++it) { for(node_map::iterator it=m_map.begin();it!=m_map.end();++it) {
@@ -78,7 +78,7 @@ namespace YAML
inline bool node_data::equals(node& node, const T& rhs, shared_memory_holder pMemory) inline bool node_data::equals(node& node, const T& rhs, shared_memory_holder pMemory)
{ {
T lhs; T lhs;
if(convert<T>::decode(Value(node, pMemory), lhs)) if(convert<T>::decode(Node(node, pMemory), lhs))
return lhs == rhs; return lhs == rhs;
return false; return false;
} }
@@ -86,11 +86,11 @@ namespace YAML
template<typename T> template<typename T>
inline node& node_data::convert_to_node(const T& rhs, shared_memory_holder pMemory) inline node& node_data::convert_to_node(const T& rhs, shared_memory_holder pMemory)
{ {
Value value = convert<T>::encode(rhs); Node value = convert<T>::encode(rhs);
pMemory->merge(*value.m_pMemory); pMemory->merge(*value.m_pMemory);
return *value.m_pNode; return *value.m_pNode;
} }
} }
} }
#endif // VALUE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -7,8 +7,8 @@
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/value/ptr.h" #include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/value/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>

View File

@@ -5,7 +5,7 @@
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/value/ptr.h" #include "yaml-cpp/node/ptr.h"
#include <set> #include <set>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>

View File

@@ -1,5 +1,5 @@
#ifndef VALUE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_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
@@ -7,9 +7,9 @@
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/value/type.h" #include "yaml-cpp/node/type.h"
#include "yaml-cpp/value/ptr.h" #include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/value/detail/node_ref.h" #include "yaml-cpp/node/detail/node_ref.h"
#include <boost/utility.hpp> #include <boost/utility.hpp>
namespace YAML namespace YAML
@@ -24,14 +24,14 @@ namespace YAML
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(); }
ValueType::value type() const { return m_pRef->type(); } NodeType::value type() const { return m_pRef->type(); }
const std::string& scalar() const { return m_pRef->scalar(); } const std::string& scalar() const { return m_pRef->scalar(); }
void set_ref(const node& rhs) { m_pRef = rhs.m_pRef; } void set_ref(const node& rhs) { m_pRef = rhs.m_pRef; }
void set_data(const node& rhs) { m_pRef->set_data(*rhs.m_pRef); } void set_data(const node& rhs) { m_pRef->set_data(*rhs.m_pRef); }
void set_type(ValueType::value type) { m_pRef->set_type(type); } void set_type(NodeType::value type) { m_pRef->set_type(type); }
void set_null() { m_pRef->set_null(); } void set_null() { m_pRef->set_null(); }
void set_scalar(const std::string& scalar) { m_pRef->set_scalar(scalar); } void set_scalar(const std::string& scalar) { m_pRef->set_scalar(scalar); }
@@ -65,4 +65,4 @@ namespace YAML
} }
} }
#endif // VALUE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -7,9 +7,9 @@
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/value/iterator.h" #include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/value/ptr.h" #include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/value/type.h" #include "yaml-cpp/node/type.h"
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include <list> #include <list>
#include <utility> #include <utility>
@@ -24,11 +24,11 @@ namespace YAML
public: public:
node_data(); node_data();
void set_type(ValueType::value type); void set_type(NodeType::value type);
void set_null(); void set_null();
void set_scalar(const std::string& scalar); void set_scalar(const std::string& scalar);
ValueType::value type() const { return m_isDefined ? m_type : ValueType::Undefined; } NodeType::value type() const { return m_isDefined ? m_type : NodeType::Undefined; }
const std::string& scalar() const { return m_scalar; } const std::string& scalar() const { return m_scalar; }
// size/iterator // size/iterator
@@ -67,7 +67,7 @@ namespace YAML
private: private:
bool m_isDefined; bool m_isDefined;
ValueType::value m_type; NodeType::value m_type;
// scalar // scalar
std::string m_scalar; std::string m_scalar;

View File

@@ -7,7 +7,7 @@
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/value/ptr.h" #include "yaml-cpp/node/ptr.h"
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
#include <boost/utility/enable_if.hpp> #include <boost/utility/enable_if.hpp>
#include <list> #include <list>

View File

@@ -7,9 +7,9 @@
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/value/type.h" #include "yaml-cpp/node/type.h"
#include "yaml-cpp/value/ptr.h" #include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/value/detail/node_data.h" #include "yaml-cpp/node/detail/node_data.h"
#include <boost/utility.hpp> #include <boost/utility.hpp>
namespace YAML namespace YAML
@@ -21,12 +21,12 @@ namespace YAML
public: public:
node_ref() {} node_ref() {}
ValueType::value type() const { return m_pData ? m_pData->type() : ValueType::Undefined; } NodeType::value type() const { return m_pData ? m_pData->type() : NodeType::Undefined; }
const std::string& scalar() const { return m_pData ? m_pData->scalar() : node_data::empty_scalar; } const std::string& scalar() const { return m_pData ? m_pData->scalar() : node_data::empty_scalar; }
void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; } void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; }
void set_type(ValueType::value type) { ensure_data_exists(); m_pData->set_type(type); } void set_type(NodeType::value type) { ensure_data_exists(); m_pData->set_type(type); }
void set_null() { ensure_data_exists(); m_pData->set_null(); } void set_null() { ensure_data_exists(); m_pData->set_null(); }
void set_scalar(const std::string& scalar) { ensure_data_exists(); m_pData->set_scalar(scalar); } void set_scalar(const std::string& scalar) { ensure_data_exists(); m_pData->set_scalar(scalar); }

View File

@@ -1,5 +1,5 @@
#ifndef VALUE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_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
@@ -11,11 +11,11 @@
namespace YAML namespace YAML
{ {
class Emitter; class Emitter;
class Value; class Node;
Emitter& operator << (Emitter& out, const foo& value); Emitter& operator << (Emitter& out, const Node& node);
std::ostream& operator << (std::ostream& out, const Value& value); std::ostream& operator << (std::ostream& out, const Node& node);
} }
#endif // VALUE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,54 +1,54 @@
#ifndef VALUE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_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/value/value.h" #include "yaml-cpp/node/node.h"
#include "yaml-cpp/value/iterator.h" #include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/value/detail/memory.h" #include "yaml-cpp/node/detail/memory.h"
#include "yaml-cpp/value/detail/node.h" #include "yaml-cpp/node/detail/node.h"
#include <string> #include <string>
namespace YAML namespace YAML
{ {
inline Value::Value(): m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node()) inline Node::Node(): m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node())
{ {
} }
inline Value::Value(ValueType::value type): m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node()) inline Node::Node(NodeType::value type): m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node())
{ {
m_pNode->set_type(type); m_pNode->set_type(type);
} }
template<typename T> template<typename T>
inline Value::Value(const T& rhs): m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node()) inline Node::Node(const T& rhs): m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node())
{ {
Assign(rhs); Assign(rhs);
} }
inline Value::Value(const Value& rhs): m_pMemory(rhs.m_pMemory), m_pNode(rhs.m_pNode) inline Node::Node(const Node& rhs): m_pMemory(rhs.m_pMemory), m_pNode(rhs.m_pNode)
{ {
} }
inline Value::Value(detail::node& node, detail::shared_memory_holder pMemory): m_pMemory(pMemory), m_pNode(&node) inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory): m_pMemory(pMemory), m_pNode(&node)
{ {
} }
inline Value::~Value() inline Node::~Node()
{ {
} }
inline ValueType::value Value::Type() const inline NodeType::value Node::Type() const
{ {
return m_pNode->type(); return m_pNode->type();
} }
// access // access
template<typename T> template<typename T>
inline const T Value::as() const inline const T Node::as() const
{ {
T t; T t;
if(convert<T>::decode(*this, t)) if(convert<T>::decode(*this, t))
@@ -57,54 +57,54 @@ namespace YAML
} }
template<> template<>
inline const std::string Value::as() const inline const std::string Node::as() const
{ {
if(Type() != ValueType::Scalar) if(Type() != NodeType::Scalar)
throw std::runtime_error("Unable to convert to string, not a scalar"); throw std::runtime_error("Unable to convert to string, not a scalar");
return scalar(); return scalar();
} }
inline const std::string& Value::scalar() const inline const std::string& Node::scalar() const
{ {
return m_pNode->scalar(); return m_pNode->scalar();
} }
// assignment // assignment
inline bool Value::is(const Value& rhs) const inline bool Node::is(const Node& rhs) const
{ {
return m_pNode->is(*rhs.m_pNode); return m_pNode->is(*rhs.m_pNode);
} }
template<typename T> template<typename T>
inline Value& Value::operator=(const T& rhs) inline Node& Node::operator=(const T& rhs)
{ {
Assign(rhs); Assign(rhs);
return *this; return *this;
} }
template<typename T> template<typename T>
inline void Value::Assign(const T& rhs) inline void Node::Assign(const T& rhs)
{ {
AssignData(convert<T>::encode(rhs)); AssignData(convert<T>::encode(rhs));
} }
template<> template<>
inline void Value::Assign(const std::string& rhs) inline void Node::Assign(const std::string& rhs)
{ {
m_pNode->set_scalar(rhs); m_pNode->set_scalar(rhs);
} }
inline void Value::Assign(const char *rhs) inline void Node::Assign(const char *rhs)
{ {
m_pNode->set_scalar(rhs); m_pNode->set_scalar(rhs);
} }
inline void Value::Assign(char *rhs) inline void Node::Assign(char *rhs)
{ {
m_pNode->set_scalar(rhs); m_pNode->set_scalar(rhs);
} }
inline Value& Value::operator=(const Value& rhs) inline Node& Node::operator=(const Node& rhs)
{ {
if(is(rhs)) if(is(rhs))
return *this; return *this;
@@ -112,13 +112,13 @@ namespace YAML
return *this; return *this;
} }
inline void Value::AssignData(const Value& rhs) inline void Node::AssignData(const Node& rhs)
{ {
m_pNode->set_data(*rhs.m_pNode); m_pNode->set_data(*rhs.m_pNode);
m_pMemory->merge(*rhs.m_pMemory); m_pMemory->merge(*rhs.m_pMemory);
} }
inline void Value::AssignNode(const Value& rhs) inline void Node::AssignNode(const Node& rhs)
{ {
m_pNode->set_ref(*rhs.m_pNode); m_pNode->set_ref(*rhs.m_pNode);
m_pMemory->merge(*rhs.m_pMemory); m_pMemory->merge(*rhs.m_pMemory);
@@ -126,39 +126,39 @@ namespace YAML
} }
// size/iterator // size/iterator
inline std::size_t Value::size() const inline std::size_t Node::size() const
{ {
return m_pNode->size(); return m_pNode->size();
} }
inline const_iterator Value::begin() const inline const_iterator Node::begin() const
{ {
return const_iterator(m_pNode->begin(), m_pMemory); return const_iterator(m_pNode->begin(), m_pMemory);
} }
inline iterator Value::begin() inline iterator Node::begin()
{ {
return iterator(m_pNode->begin(), m_pMemory); return iterator(m_pNode->begin(), m_pMemory);
} }
inline const_iterator Value::end() const inline const_iterator Node::end() const
{ {
return const_iterator(m_pNode->end(), m_pMemory); return const_iterator(m_pNode->end(), m_pMemory);
} }
inline iterator Value::end() inline iterator Node::end()
{ {
return iterator(m_pNode->end(), m_pMemory); return iterator(m_pNode->end(), m_pMemory);
} }
// sequence // sequence
template<typename T> template<typename T>
inline void Value::append(const T& rhs) inline void Node::append(const T& rhs)
{ {
append(Value(rhs)); append(Node(rhs));
} }
inline void Value::append(const Value& rhs) inline void Node::append(const Node& rhs)
{ {
m_pNode->append(*rhs.m_pNode, m_pMemory); m_pNode->append(*rhs.m_pNode, m_pMemory);
m_pMemory->merge(*rhs.m_pMemory); m_pMemory->merge(*rhs.m_pMemory);
@@ -166,87 +166,87 @@ namespace YAML
// indexing // indexing
template<typename Key> template<typename Key>
inline const Value Value::operator[](const Key& key) const inline const Node Node::operator[](const Key& key) const
{ {
detail::node& value = static_cast<const detail::node&>(*m_pNode).get(key, m_pMemory); detail::node& value = static_cast<const detail::node&>(*m_pNode).get(key, m_pMemory);
return Value(value, m_pMemory); return Node(value, m_pMemory);
} }
template<typename Key> template<typename Key>
inline Value Value::operator[](const Key& key) inline Node Node::operator[](const Key& key)
{ {
detail::node& value = m_pNode->get(key, m_pMemory); detail::node& value = m_pNode->get(key, m_pMemory);
return Value(value, m_pMemory); return Node(value, m_pMemory);
} }
template<typename Key> template<typename Key>
inline bool Value::remove(const Key& key) inline bool Node::remove(const Key& key)
{ {
return m_pNode->remove(key, m_pMemory); return m_pNode->remove(key, m_pMemory);
} }
inline const Value Value::operator[](const Value& key) const inline const Node Node::operator[](const Node& key) const
{ {
detail::node& value = static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory); detail::node& value = static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory);
return Value(value, m_pMemory); return Node(value, m_pMemory);
} }
inline Value Value::operator[](const Value& key) inline Node Node::operator[](const Node& key)
{ {
detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory); detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory);
return Value(value, m_pMemory); return Node(value, m_pMemory);
} }
inline bool Value::remove(const Value& key) inline bool Node::remove(const Node& key)
{ {
return m_pNode->remove(*key.m_pNode, m_pMemory); return m_pNode->remove(*key.m_pNode, m_pMemory);
} }
inline const Value Value::operator[](const char *key) const inline const Node Node::operator[](const char *key) const
{ {
return operator[](std::string(key)); return operator[](std::string(key));
} }
inline Value Value::operator[](const char *key) inline Node Node::operator[](const char *key)
{ {
return operator[](std::string(key)); return operator[](std::string(key));
} }
inline bool Value::remove(const char *key) inline bool Node::remove(const char *key)
{ {
return remove(std::string(key)); return remove(std::string(key));
} }
inline const Value Value::operator[](char *key) const inline const Node Node::operator[](char *key) const
{ {
return operator[](static_cast<const char *>(key)); return operator[](static_cast<const char *>(key));
} }
inline Value Value::operator[](char *key) inline Node Node::operator[](char *key)
{ {
return operator[](static_cast<const char *>(key)); return operator[](static_cast<const char *>(key));
} }
inline bool Value::remove(char *key) inline bool Node::remove(char *key)
{ {
return remove(static_cast<const char *>(key)); return remove(static_cast<const char *>(key));
} }
// free functions // free functions
inline int compare(const Value& lhs, const Value& rhs) inline int compare(const Node& lhs, const Node& rhs)
{ {
return 0; return 0;
} }
inline bool operator<(const Value& lhs, const Value& rhs) inline bool operator<(const Node& lhs, const Node& rhs)
{ {
return false; return false;
} }
inline bool is(const Value& lhs, const Value& rhs) inline bool is(const Node& lhs, const Node& rhs)
{ {
return lhs.is(rhs); return lhs.is(rhs);
} }
} }
#endif // VALUE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -7,9 +7,9 @@
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/value/value.h" #include "yaml-cpp/node/node.h"
#include "yaml-cpp/value/detail/iterator_fwd.h" #include "yaml-cpp/node/detail/iterator_fwd.h"
#include "yaml-cpp/value/detail/iterator.h" #include "yaml-cpp/node/detail/iterator.h"
#include <list> #include <list>
#include <utility> #include <utility>
#include <vector> #include <vector>
@@ -17,10 +17,10 @@
namespace YAML namespace YAML
{ {
namespace detail { namespace detail {
struct iterator_value: public Value, std::pair<Value, Value> { struct iterator_value: public Node, std::pair<Node, Node> {
iterator_value() {} iterator_value() {}
explicit iterator_value(const Value& rhs): Value(rhs) {} explicit iterator_value(const Node& rhs): Node(rhs) {}
explicit iterator_value(const Value& key, const Value& value): std::pair<Value, Value>(key, value) {} explicit iterator_value(const Node& key, const Node& value): std::pair<Node, Node>(key, value) {}
}; };
} }
} }

View File

@@ -0,0 +1,96 @@
#ifndef 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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/node/type.h"
#include "yaml-cpp/node/detail/iterator_fwd.h"
#include <stdexcept>
namespace YAML
{
class Node
{
public:
friend class NodeBuilder;
friend class NodeEvents;
friend class detail::node_data;
template<typename, typename, typename> friend class detail::iterator_base;
Node();
explicit Node(NodeType::value type);
template<typename T> explicit Node(const T& rhs);
Node(const Node& rhs);
~Node();
NodeType::value Type() const;
// access
template<typename T> const T as() const;
const std::string& scalar() const;
// assignment
bool is(const Node& rhs) const;
template<typename T> Node& operator=(const T& rhs);
Node& operator=(const Node& rhs);
// size/iterator
std::size_t size() const;
const_iterator begin() const;
iterator begin();
const_iterator end() const;
iterator end();
// sequence
template<typename T> void append(const T& rhs);
void append(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);
const Node operator[](const char *key) const;
Node operator[](const char *key);
bool remove(const char *key);
const Node operator[](char *key) const;
Node operator[](char *key);
bool remove(char *key);
private:
explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
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:
detail::shared_memory_holder m_pMemory;
detail::node *m_pNode;
};
int compare(const Node& lhs, const Node& rhs);
bool operator<(const Node& lhs, const Node& rhs);
bool is(const Node& lhs, const Node& rhs);
template<typename T>
struct convert;
}
#endif // NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -10,11 +10,11 @@
namespace YAML namespace YAML
{ {
class Value; class Node;
Value Parse(const std::string& input); Node Parse(const std::string& input);
Value Parse(const char *input); Node Parse(const char *input);
Value Parse(std::istream& input); Node Parse(std::istream& input);
} }
#endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -8,7 +8,7 @@
namespace YAML namespace YAML
{ {
struct ValueType { enum value { Undefined, Null, Scalar, Sequence, Map }; }; struct NodeType { enum value { 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,96 +0,0 @@
#ifndef VALUE_VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_VALUE_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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/type.h"
#include "yaml-cpp/value/detail/iterator_fwd.h"
#include <stdexcept>
namespace YAML
{
class Value
{
public:
friend class ValueBuilder;
friend class ValueEvents;
friend class detail::node_data;
template<typename, typename, typename> friend class detail::iterator_base;
Value();
explicit Value(ValueType::value type);
template<typename T> explicit Value(const T& rhs);
Value(const Value& rhs);
~Value();
ValueType::value Type() const;
// access
template<typename T> const T as() const;
const std::string& scalar() const;
// assignment
bool is(const Value& rhs) const;
template<typename T> Value& operator=(const T& rhs);
Value& operator=(const Value& rhs);
// size/iterator
std::size_t size() const;
const_iterator begin() const;
iterator begin();
const_iterator end() const;
iterator end();
// sequence
template<typename T> void append(const T& rhs);
void append(const Value& rhs);
// indexing
template<typename Key> const Value operator[](const Key& key) const;
template<typename Key> Value operator[](const Key& key);
template<typename Key> bool remove(const Key& key);
const Value operator[](const Value& key) const;
Value operator[](const Value& key);
bool remove(const Value& key);
const Value operator[](const char *key) const;
Value operator[](const char *key);
bool remove(const char *key);
const Value operator[](char *key) const;
Value operator[](char *key);
bool remove(char *key);
private:
explicit Value(detail::node& node, detail::shared_memory_holder pMemory);
template<typename T> void Assign(const T& rhs);
void Assign(const char *rhs);
void Assign(char *rhs);
void AssignData(const Value& rhs);
void AssignNode(const Value& rhs);
private:
detail::shared_memory_holder m_pMemory;
detail::node *m_pNode;
};
int compare(const Value& lhs, const Value& rhs);
bool operator<(const Value& lhs, const Value& rhs);
bool is(const Value& lhs, const Value& rhs);
template<typename T>
struct convert;
}
#endif // VALUE_VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -32,7 +32,10 @@ namespace YAML
void Load(std::istream& in); void Load(std::istream& in);
bool HandleNextDocument(EventHandler& eventHandler); bool HandleNextDocument(EventHandler& eventHandler);
#if YAML_CPP_OLD_API
bool GetNextDocument(Node& document); bool GetNextDocument(Node& document);
#endif
void PrintTokens(std::ostream& out); void PrintTokens(std::ostream& out);
private: private:

View File

@@ -1,17 +0,0 @@
#ifndef VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_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
#pragma once
#endif
#include "yaml-cpp/value/value.h"
#include "yaml-cpp/value/impl.h"
#include "yaml-cpp/value/convert.h"
#include "yaml-cpp/value/iterator.h"
#include "yaml-cpp/value/detail/impl.h"
#include "yaml-cpp/value/parse.h"
#include "yaml-cpp/value/emit.h"
#endif // VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -7,11 +7,26 @@
#include "yaml-cpp/parser.h" #include "yaml-cpp/parser.h"
#include "yaml-cpp/node.h"
#include "yaml-cpp/stlnode.h"
#include "yaml-cpp/iterator.h"
#include "yaml-cpp/emitter.h" #include "yaml-cpp/emitter.h"
#include "yaml-cpp/stlemitter.h" #include "yaml-cpp/stlemitter.h"
#include "yaml-cpp/exceptions.h" #include "yaml-cpp/exceptions.h"
#ifdef YAML_CPP_OLD_API
#include "yaml-cpp/old-api/node.h"
#include "yaml-cpp/old-api/stlnode.h"
#include "yaml-cpp/old-api/iterator.h"
#else
#include "yaml-cpp/node/node.h"
#include "yaml-cpp/node/impl.h"
#include "yaml-cpp/node/convert.h"
#include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/node/detail/impl.h"
#include "yaml-cpp/node/parse.h"
#include "yaml-cpp/node/emit.h"
#endif // YAML_CPP_OLD_API
#endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,4 +1,4 @@
#include "yaml-cpp/value/convert.h" #include "yaml-cpp/node/convert.h"
namespace YAML namespace YAML
{ {

View File

@@ -1,5 +1,5 @@
#include "yaml-cpp/value/detail/memory.h" #include "yaml-cpp/node/detail/memory.h"
#include "yaml-cpp/value/detail/node.h" #include "yaml-cpp/node/detail/node.h"
namespace YAML namespace YAML
{ {

View File

@@ -1,6 +1,6 @@
#include "yaml-cpp/value/detail/node_data.h" #include "yaml-cpp/node/detail/node_data.h"
#include "yaml-cpp/value/detail/memory.h" #include "yaml-cpp/node/detail/memory.h"
#include "yaml-cpp/value/detail/node.h" #include "yaml-cpp/node/detail/node.h"
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
@@ -10,13 +10,13 @@ namespace YAML
{ {
std::string node_data::empty_scalar; std::string node_data::empty_scalar;
node_data::node_data(): m_isDefined(false), m_type(ValueType::Null) node_data::node_data(): m_isDefined(false), m_type(NodeType::Null)
{ {
} }
void node_data::set_type(ValueType::value type) void node_data::set_type(NodeType::value type)
{ {
if(type == ValueType::Undefined) { if(type == NodeType::Undefined) {
m_type = type; m_type = type;
m_isDefined = false; m_isDefined = false;
return; return;
@@ -30,18 +30,18 @@ namespace YAML
m_type = type; m_type = type;
switch(m_type) { switch(m_type) {
case ValueType::Null: case NodeType::Null:
break; break;
case ValueType::Scalar: case NodeType::Scalar:
m_scalar.clear(); m_scalar.clear();
break; break;
case ValueType::Sequence: case NodeType::Sequence:
m_sequence.clear(); m_sequence.clear();
break; break;
case ValueType::Map: case NodeType::Map:
m_map.clear(); m_map.clear();
break; break;
case ValueType::Undefined: case NodeType::Undefined:
assert(false); assert(false);
break; break;
} }
@@ -50,13 +50,13 @@ namespace YAML
void node_data::set_null() void node_data::set_null()
{ {
m_isDefined = true; m_isDefined = true;
m_type = ValueType::Null; m_type = NodeType::Null;
} }
void node_data::set_scalar(const std::string& scalar) void node_data::set_scalar(const std::string& scalar)
{ {
m_isDefined = true; m_isDefined = true;
m_type = ValueType::Scalar; m_type = NodeType::Scalar;
m_scalar = scalar; m_scalar = scalar;
} }
@@ -69,8 +69,8 @@ namespace YAML
const_node_iterator node_data::begin() const const_node_iterator node_data::begin() const
{ {
switch(m_type) { switch(m_type) {
case ValueType::Sequence: return const_node_iterator(m_sequence.begin()); case NodeType::Sequence: return const_node_iterator(m_sequence.begin());
case ValueType::Map: return const_node_iterator(m_map.begin()); case NodeType::Map: return const_node_iterator(m_map.begin());
default: return const_node_iterator(); default: return const_node_iterator();
} }
} }
@@ -78,8 +78,8 @@ namespace YAML
node_iterator node_data::begin() node_iterator node_data::begin()
{ {
switch(m_type) { switch(m_type) {
case ValueType::Sequence: return node_iterator(m_sequence.begin()); case NodeType::Sequence: return node_iterator(m_sequence.begin());
case ValueType::Map: return node_iterator(m_map.begin()); case NodeType::Map: return node_iterator(m_map.begin());
default: return node_iterator(); default: return node_iterator();
} }
} }
@@ -87,8 +87,8 @@ namespace YAML
const_node_iterator node_data::end() const const_node_iterator node_data::end() const
{ {
switch(m_type) { switch(m_type) {
case ValueType::Sequence: return const_node_iterator(m_sequence.end()); case NodeType::Sequence: return const_node_iterator(m_sequence.end());
case ValueType::Map: return const_node_iterator(m_map.end()); case NodeType::Map: return const_node_iterator(m_map.end());
default: return const_node_iterator(); default: return const_node_iterator();
} }
} }
@@ -96,8 +96,8 @@ namespace YAML
node_iterator node_data::end() node_iterator node_data::end()
{ {
switch(m_type) { switch(m_type) {
case ValueType::Sequence: return node_iterator(m_sequence.end()); case NodeType::Sequence: return node_iterator(m_sequence.end());
case ValueType::Map: return node_iterator(m_map.end()); case NodeType::Map: return node_iterator(m_map.end());
default: return node_iterator(); default: return node_iterator();
} }
} }
@@ -105,7 +105,7 @@ namespace YAML
// sequence // sequence
void node_data::append(node& node, shared_memory_holder /* pMemory */) void node_data::append(node& node, shared_memory_holder /* pMemory */)
{ {
if(m_type != ValueType::Sequence) if(m_type != NodeType::Sequence)
throw std::runtime_error("Can't append to a non-sequence node"); throw std::runtime_error("Can't append to a non-sequence node");
m_sequence.push_back(&node); m_sequence.push_back(&node);
@@ -113,7 +113,7 @@ namespace YAML
void node_data::insert(node& key, node& value, shared_memory_holder /* pMemory */) void node_data::insert(node& key, node& value, shared_memory_holder /* pMemory */)
{ {
if(m_type != ValueType::Map) if(m_type != NodeType::Map)
throw std::runtime_error("Can't insert into a non-map node"); throw std::runtime_error("Can't insert into a non-map node");
m_map.push_back(kv_pair(&key, &value)); m_map.push_back(kv_pair(&key, &value));
@@ -122,7 +122,7 @@ namespace YAML
// indexing // indexing
node& node_data::get(node& key, shared_memory_holder pMemory) const node& node_data::get(node& key, shared_memory_holder pMemory) const
{ {
if(m_type != ValueType::Map) if(m_type != NodeType::Map)
return pMemory->create_node(); return pMemory->create_node();
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) { for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
@@ -136,16 +136,16 @@ namespace YAML
node& node_data::get(node& key, shared_memory_holder pMemory) node& node_data::get(node& key, shared_memory_holder pMemory)
{ {
switch(m_type) { switch(m_type) {
case ValueType::Undefined: case NodeType::Undefined:
case ValueType::Null: case NodeType::Null:
case ValueType::Scalar: case NodeType::Scalar:
m_type = ValueType::Map; m_type = NodeType::Map;
m_map.clear(); m_map.clear();
break; break;
case ValueType::Sequence: case NodeType::Sequence:
convert_sequence_to_map(pMemory); convert_sequence_to_map(pMemory);
break; break;
case ValueType::Map: case NodeType::Map:
break; break;
} }
@@ -161,7 +161,7 @@ namespace YAML
bool node_data::remove(node& key, shared_memory_holder /* pMemory */) bool node_data::remove(node& key, shared_memory_holder /* pMemory */)
{ {
if(m_type != ValueType::Map) if(m_type != NodeType::Map)
return false; return false;
for(node_map::iterator it=m_map.begin();it!=m_map.end();++it) { for(node_map::iterator it=m_map.begin();it!=m_map.end();++it) {
@@ -176,7 +176,7 @@ namespace YAML
void node_data::convert_sequence_to_map(shared_memory_holder pMemory) void node_data::convert_sequence_to_map(shared_memory_holder pMemory)
{ {
assert(m_type == ValueType::Sequence); assert(m_type == NodeType::Sequence);
m_map.clear(); m_map.clear();
for(std::size_t i=0;i<m_sequence.size();i++) { for(std::size_t i=0;i<m_sequence.size();i++) {
@@ -189,7 +189,7 @@ namespace YAML
} }
m_sequence.clear(); m_sequence.clear();
m_type = ValueType::Map; m_type = NodeType::Map;
} }
} }
} }

View File

@@ -1,22 +1,22 @@
#include "yaml-cpp/value/emit.h" #include "yaml-cpp/node/emit.h"
#include "yaml-cpp/emitfromevents.h" #include "yaml-cpp/emitfromevents.h"
#include "yaml-cpp/emitter.h" #include "yaml-cpp/emitter.h"
#include "valueevents.h" #include "nodeevents.h"
namespace YAML namespace YAML
{ {
Emitter& operator << (Emitter& out, const Value& value) Emitter& operator << (Emitter& out, const Node& node)
{ {
EmitFromEvents emitFromEvents(out); EmitFromEvents emitFromEvents(out);
ValueEvents events(value); NodeEvents events(node);
events.Emit(emitFromEvents); events.Emit(emitFromEvents);
return out; return out;
} }
std::ostream& operator << (std::ostream& out, const Value& value) std::ostream& operator << (std::ostream& out, const Node& node)
{ {
Emitter emitter; Emitter emitter;
emitter << value; emitter << node;
out << emitter.c_str(); out << emitter.c_str();
return out; return out;
} }

View File

@@ -1,84 +1,85 @@
#include "valuebuilder.h" #include "nodebuilder.h"
#include "yaml-cpp/mark.h" #include "yaml-cpp/mark.h"
#include "yaml-cpp/value.h" #include "yaml-cpp/node/node.h"
#include "yaml-cpp/node/impl.h"
#include <cassert> #include <cassert>
namespace YAML namespace YAML
{ {
ValueBuilder::ValueBuilder(): m_pMemory(new detail::memory_holder), m_pRoot(0), m_mapDepth(0) NodeBuilder::NodeBuilder(): 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
} }
ValueBuilder::~ValueBuilder() NodeBuilder::~NodeBuilder()
{ {
} }
Value ValueBuilder::Root() Node NodeBuilder::Root()
{ {
if(!m_pRoot) if(!m_pRoot)
return Value(); return Node();
return Value(*m_pRoot, m_pMemory); return Node(*m_pRoot, m_pMemory);
} }
void ValueBuilder::OnDocumentStart(const Mark&) void NodeBuilder::OnDocumentStart(const Mark&)
{ {
} }
void ValueBuilder::OnDocumentEnd() void NodeBuilder::OnDocumentEnd()
{ {
} }
void ValueBuilder::OnNull(const Mark& mark, anchor_t anchor) void NodeBuilder::OnNull(const Mark& mark, anchor_t anchor)
{ {
detail::node& node = Push(anchor); detail::node& node = Push(anchor);
node.set_null(); node.set_null();
Pop(); Pop();
} }
void ValueBuilder::OnAlias(const Mark& /*mark*/, anchor_t anchor) void NodeBuilder::OnAlias(const Mark& /*mark*/, anchor_t anchor)
{ {
detail::node& node = *m_anchors[anchor]; detail::node& node = *m_anchors[anchor];
m_stack.push_back(&node); m_stack.push_back(&node);
Pop(); Pop();
} }
void ValueBuilder::OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value) void NodeBuilder::OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value)
{ {
detail::node& node = Push(anchor); detail::node& node = Push(anchor);
node.set_scalar(value); node.set_scalar(value);
Pop(); Pop();
} }
void ValueBuilder::OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor) void NodeBuilder::OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor)
{ {
detail::node& node = Push(anchor); detail::node& node = Push(anchor);
node.set_type(ValueType::Sequence); node.set_type(NodeType::Sequence);
} }
void ValueBuilder::OnSequenceEnd() void NodeBuilder::OnSequenceEnd()
{ {
Pop(); Pop();
} }
void ValueBuilder::OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor) void NodeBuilder::OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor)
{ {
detail::node& node = Push(anchor); detail::node& node = Push(anchor);
node.set_type(ValueType::Map); node.set_type(NodeType::Map);
m_mapDepth++; m_mapDepth++;
} }
void ValueBuilder::OnMapEnd() void NodeBuilder::OnMapEnd()
{ {
assert(m_mapDepth > 0); assert(m_mapDepth > 0);
m_mapDepth--; m_mapDepth--;
Pop(); Pop();
} }
detail::node& ValueBuilder::Push(anchor_t anchor) detail::node& NodeBuilder::Push(anchor_t anchor)
{ {
const bool needsKey = (!m_stack.empty() && m_stack.back()->type() == ValueType::Map && m_keys.size() < m_mapDepth); const bool needsKey = (!m_stack.empty() && m_stack.back()->type() == NodeType::Map && m_keys.size() < m_mapDepth);
detail::node& node = m_pMemory->create_node(); detail::node& node = m_pMemory->create_node();
m_stack.push_back(&node); m_stack.push_back(&node);
@@ -90,7 +91,7 @@ namespace YAML
return node; return node;
} }
void ValueBuilder::Pop() void NodeBuilder::Pop()
{ {
assert(!m_stack.empty()); assert(!m_stack.empty());
if(m_stack.size() == 1) { if(m_stack.size() == 1) {
@@ -104,9 +105,9 @@ namespace YAML
detail::node& collection = *m_stack.back(); detail::node& collection = *m_stack.back();
if(collection.type() == ValueType::Sequence) { if(collection.type() == NodeType::Sequence) {
collection.append(node, m_pMemory); collection.append(node, m_pMemory);
} else if(collection.type() == ValueType::Map) { } else if(collection.type() == NodeType::Map) {
detail::node& key = *m_keys.back(); detail::node& key = *m_keys.back();
if(&key != &node) { if(&key != &node) {
m_keys.pop_back(); m_keys.pop_back();
@@ -118,7 +119,7 @@ namespace YAML
} }
} }
void ValueBuilder::RegisterAnchor(anchor_t anchor, detail::node& node) void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node)
{ {
if(anchor) { if(anchor) {
assert(anchor == m_anchors.size()); assert(anchor == m_anchors.size());

View File

@@ -1,25 +1,25 @@
#ifndef VALUE_VALUEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_VALUEBUILDER_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
#include "yaml-cpp/eventhandler.h" #include "yaml-cpp/eventhandler.h"
#include "yaml-cpp/value/ptr.h" #include "yaml-cpp/node/ptr.h"
#include <vector> #include <vector>
namespace YAML namespace YAML
{ {
class Value; class Node;
class ValueBuilder: public EventHandler class NodeBuilder: public EventHandler
{ {
public: public:
ValueBuilder(); NodeBuilder();
virtual ~ValueBuilder(); virtual ~NodeBuilder();
Value Root(); Node Root();
virtual void OnDocumentStart(const Mark& mark); virtual void OnDocumentStart(const Mark& mark);
virtual void OnDocumentEnd(); virtual void OnDocumentEnd();
@@ -52,5 +52,5 @@ namespace YAML
}; };
} }
#endif // VALUE_VALUEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,16 +1,17 @@
#include "valueevents.h" #include "nodeevents.h"
#include "yaml-cpp/value.h" #include "yaml-cpp/node/node.h"
#include "yaml-cpp/node/impl.h"
#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 ValueEvents::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 ValueEvents::AliasManager::LookupAnchor(const detail::node& node) const anchor_t NodeEvents::AliasManager::LookupAnchor(const detail::node& node) const
{ {
AnchorByIdentity::const_iterator it = m_anchorByIdentity.find(node.ref()); AnchorByIdentity::const_iterator it = m_anchorByIdentity.find(node.ref());
if(it == m_anchorByIdentity.end()) if(it == m_anchorByIdentity.end())
@@ -18,22 +19,22 @@ namespace YAML
return it->second; return it->second;
} }
ValueEvents::ValueEvents(const Value& value): m_pMemory(value.m_pMemory), m_root(*value.m_pNode) NodeEvents::NodeEvents(const Node& node): m_pMemory(node.m_pMemory), m_root(*node.m_pNode)
{ {
Setup(m_root); Setup(m_root);
} }
void ValueEvents::Setup(const detail::node& node) void NodeEvents::Setup(const detail::node& node)
{ {
int& refCount = m_refCount[node.ref()]; int& refCount = m_refCount[node.ref()];
refCount++; refCount++;
if(refCount > 1) if(refCount > 1)
return; return;
if(node.type() == ValueType::Sequence) { if(node.type() == NodeType::Sequence) {
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) for(detail::const_node_iterator it=node.begin();it!=node.end();++it)
Setup(**it); Setup(**it);
} else if(node.type() == ValueType::Map) { } else if(node.type() == NodeType::Map) {
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) { for(detail::const_node_iterator it=node.begin();it!=node.end();++it) {
Setup(*it->first); Setup(*it->first);
Setup(*it->second); Setup(*it->second);
@@ -41,7 +42,7 @@ namespace YAML
} }
} }
void ValueEvents::Emit(EventHandler& handler) void NodeEvents::Emit(EventHandler& handler)
{ {
AliasManager am; AliasManager am;
@@ -50,7 +51,7 @@ namespace YAML
handler.OnDocumentEnd(); handler.OnDocumentEnd();
} }
void ValueEvents::Emit(const detail::node& node, EventHandler& handler, AliasManager& am) const void NodeEvents::Emit(const detail::node& node, EventHandler& handler, AliasManager& am) const
{ {
anchor_t anchor = NullAnchor; anchor_t anchor = NullAnchor;
if(IsAliased(node)) { if(IsAliased(node)) {
@@ -65,21 +66,21 @@ namespace YAML
} }
switch(node.type()) { switch(node.type()) {
case ValueType::Undefined: case NodeType::Undefined:
break; break;
case ValueType::Null: case NodeType::Null:
handler.OnNull(Mark(), anchor); handler.OnNull(Mark(), anchor);
break; break;
case ValueType::Scalar: case NodeType::Scalar:
handler.OnScalar(Mark(), "", anchor, node.scalar()); handler.OnScalar(Mark(), "", anchor, node.scalar());
break; break;
case ValueType::Sequence: case NodeType::Sequence:
handler.OnSequenceStart(Mark(), "", anchor); handler.OnSequenceStart(Mark(), "", anchor);
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) for(detail::const_node_iterator it=node.begin();it!=node.end();++it)
Emit(**it, handler, am); Emit(**it, handler, am);
handler.OnSequenceEnd(); handler.OnSequenceEnd();
break; break;
case ValueType::Map: case NodeType::Map:
handler.OnMapStart(Mark(), "", anchor); handler.OnMapStart(Mark(), "", anchor);
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) { for(detail::const_node_iterator it=node.begin();it!=node.end();++it) {
Emit(*it->first, handler, am); Emit(*it->first, handler, am);
@@ -90,7 +91,7 @@ namespace YAML
} }
} }
bool ValueEvents::IsAliased(const detail::node& node) const bool NodeEvents::IsAliased(const detail::node& node) const
{ {
RefCount::const_iterator it = m_refCount.find(node.ref()); RefCount::const_iterator it = m_refCount.find(node.ref());
return it != m_refCount.end() && it->second > 1; return it != m_refCount.end() && it->second > 1;

View File

@@ -1,24 +1,24 @@
#ifndef VALUE_VALUEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_VALUEEVENTS_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
#include "yaml-cpp/anchor.h" #include "yaml-cpp/anchor.h"
#include "yaml-cpp/value/ptr.h" #include "yaml-cpp/node/ptr.h"
#include <map> #include <map>
#include <vector> #include <vector>
namespace YAML namespace YAML
{ {
class Value;
class EventHandler; class EventHandler;
class Node;
class ValueEvents class NodeEvents
{ {
public: public:
explicit ValueEvents(const Value& value); explicit NodeEvents(const Node& node);
void Emit(EventHandler& handler); void Emit(EventHandler& handler);
@@ -53,5 +53,5 @@ namespace YAML
}; };
} }
#endif // VALUE_VALUEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,28 +1,28 @@
#include "yaml-cpp/value/parse.h" #include "yaml-cpp/node/parse.h"
#include "yaml-cpp/value/value.h" #include "yaml-cpp/node/node.h"
#include "yaml-cpp/value/impl.h" #include "yaml-cpp/node/impl.h"
#include "yaml-cpp/parser.h" #include "yaml-cpp/parser.h"
#include "valuebuilder.h" #include "nodebuilder.h"
#include <sstream> #include <sstream>
namespace YAML namespace YAML
{ {
Value Parse(const std::string& input) { Node Parse(const std::string& input) {
std::stringstream stream(input); std::stringstream stream(input);
return Parse(stream); return Parse(stream);
} }
Value Parse(const char *input) { Node Parse(const char *input) {
std::stringstream stream(input); std::stringstream stream(input);
return Parse(stream); return Parse(stream);
} }
Value Parse(std::istream& input) { Node Parse(std::istream& input) {
Parser parser(input); Parser parser(input);
ValueBuilder builder; NodeBuilder builder;
if(!parser.HandleNextDocument(builder)) if(!parser.HandleNextDocument(builder))
return Value(); return Node();
return builder.Root(); return builder.Root();
} }

View File

@@ -3,7 +3,6 @@
#include "yaml-cpp/eventhandler.h" #include "yaml-cpp/eventhandler.h"
#include "yaml-cpp/exceptions.h" #include "yaml-cpp/exceptions.h"
#include "yaml-cpp/node.h" #include "yaml-cpp/node.h"
#include "nodebuilder.h"
#include "scanner.h" #include "scanner.h"
#include "singledocparser.h" #include "singledocparser.h"
#include "tag.h" #include "tag.h"
@@ -11,6 +10,10 @@
#include <sstream> #include <sstream>
#include <cstdio> #include <cstdio>
#if YAML_CPP_OLD_API
#include "old-api/nodebuilder.h"
#endif
namespace YAML namespace YAML
{ {
Parser::Parser() Parser::Parser()
@@ -55,6 +58,7 @@ namespace YAML
return true; return true;
} }
#if YAML_CPP_OLD_API
// GetNextDocument // GetNextDocument
// . Reads the next document in the queue (of tokens). // . Reads the next document in the queue (of tokens).
// . Throws a ParserException on error. // . Throws a ParserException on error.
@@ -63,6 +67,7 @@ namespace YAML
NodeBuilder builder(document); NodeBuilder builder(document);
return HandleNextDocument(builder); return HandleNextDocument(builder);
} }
#endif
// ParseDirectives // ParseDirectives
// . Reads any directives that are next in the queue. // . Reads any directives that are next in the queue.

View File

@@ -1,10 +1,10 @@
#include "yaml-cpp/value.h" #include "yaml-cpp/yaml.h"
#include <map> #include <map>
int main() int main()
{ {
YAML::Value value = YAML::Parse("{foo: bar, monkey: value}"); YAML::Node node = YAML::Parse("{foo: bar, monkey: value}");
std::cout << value << "\n"; std::cout << node << "\n";
return 0; return 0;
} }