Commit 0d1b5224 authored by Jesse Beder's avatar Jesse Beder
Browse files

Major switch from Value -> Node. The library compiles with the new API, but...

Major switch from Value -> Node. The library compiles with the new API, but tests are still oldies, and don't compile
parent ac81d7c8
...@@ -35,6 +35,7 @@ enable_testing() ...@@ -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 ( ...@@ -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"
file(GLOB private_headers "include/yaml-cpp/node/detail/[a-zA-Z]*.h"
"src/[a-zA-Z]*.h"
"src/value/[a-zA-Z]*.h"
) )
file(GLOB old_api_public_headers "include/yaml-cpp/old-api/[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")
......
#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 ...@@ -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 ...@@ -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 ...@@ -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
#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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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
...@@ -7,8 +7,8 @@ ...@@ -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>
......
...@@ -5,7 +5,7 @@ ...@@ -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>
......
#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 @@ ...@@ -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 ...@@ -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 ...@@ -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
...@@ -7,9 +7,9 @@ ...@@ -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 ...@@ -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 ...@@ -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;
......
...@@ -7,7 +7,7 @@ ...@@ -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>
......
...@@ -7,9 +7,9 @@ ...@@ -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 ...@@ -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); }
......
#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 @@ ...@@ -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
#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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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
...@@ -7,9 +7,9 @@ ...@@ -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 @@ ...@@ -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) {}
}; };
} }
} }
......
#ifndef VALUE_VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_VALUE_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
...@@ -7,37 +7,37 @@ ...@@ -7,37 +7,37 @@
#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/type.h" #include "yaml-cpp/node/type.h"
#include "yaml-cpp/value/detail/iterator_fwd.h" #include "yaml-cpp/node/detail/iterator_fwd.h"
#include <stdexcept> #include <stdexcept>
namespace YAML namespace YAML
{ {
class Value class Node
{ {
public: public:
friend class ValueBuilder; friend class NodeBuilder;
friend class ValueEvents; friend class NodeEvents;
friend class detail::node_data; friend class detail::node_data;
template<typename, typename, typename> friend class detail::iterator_base; template<typename, typename, typename> friend class detail::iterator_base;
Value(); Node();
explicit Value(ValueType::value type); explicit Node(NodeType::value type);
template<typename T> explicit Value(const T& rhs); template<typename T> explicit Node(const T& rhs);
Value(const Value& rhs); Node(const Node& rhs);
~Value(); ~Node();
ValueType::value Type() const; NodeType::value Type() const;
// access // access
template<typename T> const T as() const; template<typename T> const T as() const;
const std::string& scalar() const; const std::string& scalar() const;
// assignment // assignment
bool is(const Value& rhs) const; bool is(const Node& rhs) const;
template<typename T> Value& operator=(const T& rhs); template<typename T> Node& operator=(const T& rhs);
Value& operator=(const Value& rhs); Node& operator=(const Node& rhs);
// size/iterator // size/iterator
std::size_t size() const; std::size_t size() const;
...@@ -50,47 +50,47 @@ namespace YAML ...@@ -50,47 +50,47 @@ namespace YAML
// sequence // sequence
template<typename T> void append(const T& rhs); template<typename T> void append(const T& rhs);
void append(const Value& rhs); void append(const Node& rhs);
// indexing // indexing
template<typename Key> const Value operator[](const Key& key) const; template<typename Key> const Node operator[](const Key& key) const;
template<typename Key> Value operator[](const Key& key); template<typename Key> Node operator[](const Key& key);
template<typename Key> bool remove(const Key& key); template<typename Key> bool remove(const Key& key);
const Value operator[](const Value& key) const; const Node operator[](const Node& key) const;
Value operator[](const Value& key); Node operator[](const Node& key);
bool remove(const Value& key); bool remove(const Node& key);
const Value operator[](const char *key) const; const Node operator[](const char *key) const;
Value operator[](const char *key); Node operator[](const char *key);
bool remove(const char *key); bool remove(const char *key);
const Value operator[](char *key) const; const Node operator[](char *key) const;
Value operator[](char *key); Node operator[](char *key);
bool remove(char *key); bool remove(char *key);
private: private:
explicit Value(detail::node& node, detail::shared_memory_holder pMemory); explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
template<typename T> void Assign(const T& rhs); template<typename T> void Assign(const T& rhs);
void Assign(const char *rhs); void Assign(const char *rhs);
void Assign(char *rhs); void Assign(char *rhs);
void AssignData(const Value& rhs); void AssignData(const Node& rhs);
void AssignNode(const Value& rhs); void AssignNode(const Node& rhs);
private: private:
detail::shared_memory_holder m_pMemory; detail::shared_memory_holder m_pMemory;
detail::node *m_pNode; detail::node *m_pNode;
}; };
int compare(const Value& lhs, const Value& rhs); int compare(const Node& lhs, const Node& rhs);
bool operator<(const Value& lhs, const Value& rhs); bool operator<(const Node& lhs, const Node& rhs);
bool is(const Value& lhs, const Value& rhs); bool is(const Node& lhs, const Node& rhs);
template<typename T> template<typename T>
struct convert; struct convert;
} }
#endif // VALUE_VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -10,11 +10,11 @@ ...@@ -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
......
...@@ -8,7 +8,7 @@ ...@@ -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
...@@ -32,7 +32,10 @@ namespace YAML ...@@ -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:
......
#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
...@@ -7,11 +7,26 @@ ...@@ -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
#include "yaml-cpp/value/convert.h" #include "yaml-cpp/node/convert.h"
namespace YAML namespace YAML
{ {
......
#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
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment