Start of moving Value -> Node and Node -> old API Node (with a #define toggle)

This commit is contained in:
Jesse Beder
2011-09-10 17:18:15 -05:00
parent 78b7a1b8a9
commit ac81d7c883
40 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
#ifndef VALUE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_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
#pragma once
#endif
#include "yaml-cpp/value/value.h"
#include <map>
#include <sstream>
namespace YAML
{
// std::string
template<>
struct convert<std::string> {
static Value encode(const std::string& rhs) {
return Value(rhs);
}
static bool decode(const Value& value, std::string& rhs) {
if(value.Type() != ValueType::Scalar)
return false;
rhs = value.scalar();
return true;
}
};
#define YAML_DEFINE_CONVERT_STREAMABLE(type)\
template<>\
struct convert<type> {\
static Value encode(const type& rhs) {\
std::stringstream stream;\
stream << rhs;\
return Value(stream.str());\
}\
\
static bool decode(const Value& value, type& rhs) {\
if(value.Type() != ValueType::Scalar)\
return false;\
std::stringstream stream(value.scalar());\
stream >> rhs;\
return !!stream;\
}\
}
YAML_DEFINE_CONVERT_STREAMABLE(int);
YAML_DEFINE_CONVERT_STREAMABLE(unsigned);
YAML_DEFINE_CONVERT_STREAMABLE(short);
YAML_DEFINE_CONVERT_STREAMABLE(unsigned short);
YAML_DEFINE_CONVERT_STREAMABLE(long);
YAML_DEFINE_CONVERT_STREAMABLE(unsigned long);
YAML_DEFINE_CONVERT_STREAMABLE(long long);
YAML_DEFINE_CONVERT_STREAMABLE(unsigned long long);
YAML_DEFINE_CONVERT_STREAMABLE(char);
YAML_DEFINE_CONVERT_STREAMABLE(unsigned char);
YAML_DEFINE_CONVERT_STREAMABLE(float);
YAML_DEFINE_CONVERT_STREAMABLE(double);
YAML_DEFINE_CONVERT_STREAMABLE(long double);
#undef YAML_DEFINE_CONVERT_STREAMABLE
template<typename K, typename V>
struct convert<std::map<K, V> > {
static Value encode(const std::map<K, V>& rhs) {
Value value(ValueType::Map);
for(typename std::map<K, V>::const_iterator it=rhs.begin();it!=rhs.end();++it)
value[it->first] = it->second;
return value;
}
static bool decode(const Value& value, std::map<K, V>& rhs) {
rhs.clear();
return false;
}
};
}
#endif // VALUE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

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

View File

@@ -0,0 +1,62 @@
#ifndef 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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/detail/node_iterator.h"
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/utility.hpp>
namespace YAML
{
namespace detail
{
struct iterator_value;
template<typename V>
class iterator_base: public boost::iterator_adaptor<
iterator_base<V>,
node_iterator,
V,
std::bidirectional_iterator_tag>
{
private:
template<typename> friend class iterator_base;
struct enabler {};
typedef typename iterator_base::iterator_adaptor_::base_type base_type;
typedef typename iterator_base::iterator_adaptor_::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()); }
void decrement() { this->base_reference() = boost::prior(this->base()); }
value_type dereference() const {
const typename base_type::value_type& v = *this->base();
if(v.pNode)
return value_type(Value(*v, m_pMemory));
if(v.first && v.second)
return value_type(Value(*v.first, m_pMemory), Value(*v.second, m_pMemory));
return value_type();
}
private:
shared_memory_holder m_pMemory;
};
}
}
#endif // VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -0,0 +1,27 @@
#ifndef 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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include <list>
#include <utility>
#include <vector>
namespace YAML
{
class node;
namespace detail {
class iterator_value;
template<typename V> class iterator_base;
}
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

@@ -0,0 +1,39 @@
#ifndef 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
#pragma once
#endif
#include "yaml-cpp/value/ptr.h"
#include <set>
#include <boost/shared_ptr.hpp>
namespace YAML
{
namespace detail
{
class memory {
public:
node& create_node();
void merge(const memory& rhs);
private:
typedef std::set<shared_node> Nodes;
Nodes m_nodes;
};
class memory_holder {
public:
memory_holder(): m_pMemory(new memory) {}
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

View File

@@ -0,0 +1,68 @@
#ifndef VALUE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/type.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/detail/node_ref.h"
#include <boost/utility.hpp>
namespace YAML
{
namespace detail
{
class node: private boost::noncopyable
{
public:
node(): m_pRef(new node_ref) {}
bool is(const node& rhs) const { return m_pRef == rhs.m_pRef; }
const node_ref *ref() const { return m_pRef.get(); }
ValueType::value type() const { return m_pRef->type(); }
const std::string& scalar() const { return m_pRef->scalar(); }
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_type(ValueType::value type) { m_pRef->set_type(type); }
void set_null() { m_pRef->set_null(); }
void set_scalar(const std::string& scalar) { m_pRef->set_scalar(scalar); }
// 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 append(node& node, shared_memory_holder pMemory) { m_pRef->append(node, pMemory); }
void insert(node& key, node& value, shared_memory_holder pMemory) {
m_pRef->insert(key, value, pMemory);
}
// 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) { return m_pRef->get(key, pMemory); }
template<typename Key> bool remove(const Key& key, shared_memory_holder pMemory) { return m_pRef->remove(key, pMemory); }
node& get(node& key, shared_memory_holder pMemory) const { return static_cast<const node_ref&>(*m_pRef).get(key, pMemory); }
node& get(node& key, shared_memory_holder pMemory) { return m_pRef->get(key, pMemory); }
bool remove(node& key, shared_memory_holder pMemory) { return m_pRef->remove(key, pMemory); }
private:
shared_node_ref m_pRef;
};
}
}
#endif // VALUE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -0,0 +1,87 @@
#ifndef 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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/iterator.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/type.h"
#include <boost/utility.hpp>
#include <list>
#include <utility>
#include <vector>
namespace YAML
{
namespace detail
{
class node_data: private boost::noncopyable
{
public:
node_data();
void set_type(ValueType::value type);
void set_null();
void set_scalar(const std::string& scalar);
ValueType::value type() const { return m_isDefined ? m_type : ValueType::Undefined; }
const std::string& scalar() const { return m_scalar; }
// 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 append(node& node, shared_memory_holder pMemory);
void insert(node& key, node& value, shared_memory_holder pMemory);
// indexing
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) const;
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory);
template<typename Key> bool remove(const Key& key, shared_memory_holder pMemory);
node& get(node& key, shared_memory_holder pMemory) const;
node& get(node& key, shared_memory_holder pMemory);
bool remove(node& key, shared_memory_holder pMemory);
public:
static std::string empty_scalar;
private:
void convert_sequence_to_map(shared_memory_holder pMemory);
template<typename T>
static bool equals(node& node, const T& rhs, shared_memory_holder pMemory);
template<typename T>
static node& convert_to_node(const T& rhs, shared_memory_holder pMemory);
private:
bool m_isDefined;
ValueType::value m_type;
// scalar
std::string m_scalar;
// sequence
typedef std::vector<node *> node_seq;
node_seq m_sequence;
// map
typedef std::pair<node *, node *> kv_pair;
typedef std::list<kv_pair> node_map;
node_map m_map;
};
}
}
#endif // VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -0,0 +1,131 @@
#ifndef 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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/ptr.h"
#include <boost/iterator/iterator_facade.hpp>
#include <boost/utility/enable_if.hpp>
#include <list>
#include <utility>
#include <vector>
namespace YAML
{
namespace detail
{
struct iterator_type { enum value { None, Sequence, Map }; };
template<typename V>
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::pair<node *, node *> kv_pair;
typedef std::list<kv_pair> 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::bidirectional_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): m_type(iterator_type::Map), m_mapIt(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) {}
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; break;
}
}
void decrement() {
switch(m_type) {
case iterator_type::None: break;
case iterator_type::Sequence: --m_seqIt; break;
case iterator_type::Map: --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();
}
private:
typename iterator_type::value m_type;
SeqIter m_seqIt;
MapIter m_mapIt;
};
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

View File

@@ -0,0 +1,66 @@
#ifndef 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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/type.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/detail/node_data.h"
#include <boost/utility.hpp>
namespace YAML
{
namespace detail
{
class node_ref: private boost::noncopyable
{
public:
node_ref() {}
ValueType::value type() const { return m_pData ? m_pData->type() : ValueType::Undefined; }
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_type(ValueType::value type) { ensure_data_exists(); m_pData->set_type(type); }
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); }
// size/iterator
std::size_t size() const { return m_pData ? m_pData->size() : 0; }
const_node_iterator begin() const { return m_pData ? static_cast<const node_data&>(*m_pData).begin() : const_node_iterator(); }
node_iterator begin() {return m_pData ? m_pData->begin() : node_iterator(); }
const_node_iterator end() const { return m_pData ? static_cast<const node_data&>(*m_pData).end() : const_node_iterator(); }
node_iterator end() {return m_pData ? m_pData->end() : node_iterator(); }
// sequence
void append(node& node, shared_memory_holder pMemory) { ensure_data_exists(); m_pData->append(node, pMemory); }
void insert(node& key, node& value, shared_memory_holder pMemory) {
ensure_data_exists(); m_pData->insert(key, value, pMemory);
}
// indexing
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) const { return m_pData ? static_cast<const node_data&>(*m_pData).get(key, pMemory) : pMemory->create_node(); }
template<typename Key> node& get(const Key& key, shared_memory_holder pMemory) { ensure_data_exists(); return m_pData->get(key, pMemory); }
template<typename Key> bool remove(const Key& key, shared_memory_holder pMemory) { return m_pData ? m_pData->remove(key, pMemory) : false; }
node& get(node& key, shared_memory_holder pMemory) const { return m_pData ? static_cast<const node_data&>(*m_pData).get(key, pMemory) : pMemory->create_node(); }
node& get(node& key, shared_memory_holder pMemory) { ensure_data_exists(); return m_pData->get(key, pMemory); }
bool remove(node& key, shared_memory_holder pMemory) { return m_pData ? m_pData->remove(key, pMemory) : false; }
private:
void ensure_data_exists() { if(!m_pData) m_pData.reset(new node_data); }
private:
shared_node_data m_pData;
};
}
}
#endif // VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -0,0 +1,21 @@
#ifndef VALUE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_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
#pragma once
#endif
#include <string>
#include <iosfwd>
namespace YAML
{
class Emitter;
class Value;
Emitter& operator << (Emitter& out, const foo& value);
std::ostream& operator << (std::ostream& out, const Value& value);
}
#endif // VALUE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

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

View File

@@ -0,0 +1,28 @@
#ifndef 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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/value.h"
#include "yaml-cpp/value/detail/iterator_fwd.h"
#include "yaml-cpp/value/detail/iterator.h"
#include <list>
#include <utility>
#include <vector>
namespace YAML
{
namespace detail {
struct iterator_value: public Value, std::pair<Value, Value> {
iterator_value() {}
explicit iterator_value(const Value& rhs): Value(rhs) {}
explicit iterator_value(const Value& key, const Value& value): std::pair<Value, Value>(key, value) {}
};
}
}
#endif // VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -0,0 +1,21 @@
#ifndef 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
#pragma once
#endif
#include <string>
#include <iosfwd>
namespace YAML
{
class Value;
Value Parse(const std::string& input);
Value Parse(const char *input);
Value Parse(std::istream& input);
}
#endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -0,0 +1,29 @@
#ifndef 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
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include <boost/shared_ptr.hpp>
namespace YAML
{
namespace detail {
class node;
class node_ref;
class node_data;
class memory;
class memory_holder;
typedef boost::shared_ptr<node> shared_node;
typedef boost::shared_ptr<node_ref> shared_node_ref;
typedef boost::shared_ptr<node_data> shared_node_data;
typedef boost::shared_ptr<memory_holder> shared_memory_holder;
typedef boost::shared_ptr<memory> shared_memory;
}
}
#endif // VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -0,0 +1,14 @@
#ifndef 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
#pragma once
#endif
namespace YAML
{
struct ValueType { enum value { Undefined, Null, Scalar, Sequence, Map }; };
}
#endif // VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -0,0 +1,96 @@
#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