Added (another) layer - now 'node_ref' is between node and node_data, and it decrees whether nodes are identical
This commit is contained in:
parent
d1eca90216
commit
e225509210
@ -9,8 +9,7 @@
|
|||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/value/type.h"
|
#include "yaml-cpp/value/type.h"
|
||||||
#include "yaml-cpp/value/ptr.h"
|
#include "yaml-cpp/value/ptr.h"
|
||||||
#include "yaml-cpp/value/value.h"
|
#include "yaml-cpp/value/detail/node_ref.h"
|
||||||
#include "yaml-cpp/value/detail/node_data.h"
|
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
@ -19,27 +18,28 @@ namespace YAML
|
|||||||
class node
|
class node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
node(): m_pData(new node_data) {}
|
node(): m_pRef(new node_ref) {}
|
||||||
|
|
||||||
ValueType::value type() const { return m_pData->type(); }
|
ValueType::value type() const { return m_pRef->type(); }
|
||||||
|
|
||||||
void set_data(const node& rhs) { m_pData = rhs.m_pData; }
|
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_pData->set_type(type); }
|
void set_type(ValueType::value type) { m_pRef->set_type(type); }
|
||||||
void set_null() { m_pData->set_null(); }
|
void set_null() { m_pRef->set_null(); }
|
||||||
void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); }
|
void set_scalar(const std::string& scalar) { m_pRef->set_scalar(scalar); }
|
||||||
|
|
||||||
// indexing
|
// indexing
|
||||||
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory) const { return static_cast<const node_data&>(*m_pData).get(key, pMemory); }
|
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory) const { return static_cast<const node_ref&>(*m_pRef).get(key, pMemory); }
|
||||||
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory) { return m_pData->get(key, pMemory); }
|
template<typename Key> shared_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_pData->remove(key, pMemory); }
|
template<typename Key> bool remove(const Key& key, shared_memory_holder pMemory) { return m_pRef->remove(key, pMemory); }
|
||||||
|
|
||||||
shared_node get(shared_node pKey) const { return static_cast<const node_data&>(*m_pData).get(pKey); }
|
shared_node get(shared_node pKey) const { return static_cast<const node_ref&>(*m_pRef).get(pKey); }
|
||||||
shared_node get(shared_node pKey) { return m_pData->get(pKey); }
|
shared_node get(shared_node pKey) { return m_pRef->get(pKey); }
|
||||||
bool remove(shared_node pKey) { return m_pData->remove(pKey); }
|
bool remove(shared_node pKey) { return m_pRef->remove(pKey); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
shared_node_data m_pData;
|
shared_node_ref m_pRef;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
46
include/yaml-cpp/value/detail/node_ref.h
Normal file
46
include/yaml-cpp/value/detail/node_ref.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#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"
|
||||||
|
|
||||||
|
namespace YAML
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
class node_ref
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
node_ref(): m_pData(new node_data) {}
|
||||||
|
|
||||||
|
ValueType::value type() const { return m_pData->type(); }
|
||||||
|
|
||||||
|
void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; }
|
||||||
|
|
||||||
|
void set_type(ValueType::value type) { m_pData->set_type(type); }
|
||||||
|
void set_null() { m_pData->set_null(); }
|
||||||
|
void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); }
|
||||||
|
|
||||||
|
// indexing
|
||||||
|
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory) const { return static_cast<const node_data&>(*m_pData).get(key, pMemory); }
|
||||||
|
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory) { return m_pData->get(key, pMemory); }
|
||||||
|
template<typename Key> bool remove(const Key& key, shared_memory_holder pMemory) { return m_pData->remove(key, pMemory); }
|
||||||
|
|
||||||
|
shared_node get(shared_node pKey) const { return static_cast<const node_data&>(*m_pData).get(pKey); }
|
||||||
|
shared_node get(shared_node pKey) { return m_pData->get(pKey); }
|
||||||
|
bool remove(shared_node pKey) { return m_pData->remove(pKey); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
shared_node_data m_pData;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
@ -102,7 +102,7 @@ namespace YAML
|
|||||||
|
|
||||||
void Value::AssignNode(const Value& rhs)
|
void Value::AssignNode(const Value& rhs)
|
||||||
{
|
{
|
||||||
m_pNode = rhs.m_pNode;
|
m_pNode->set_ref(*rhs.m_pNode);
|
||||||
m_pMemory->merge(*rhs.m_pMemory);
|
m_pMemory->merge(*rhs.m_pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,11 +13,13 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
namespace detail {
|
namespace detail {
|
||||||
class node;
|
class node;
|
||||||
|
class node_ref;
|
||||||
class node_data;
|
class node_data;
|
||||||
class memory;
|
class memory;
|
||||||
class memory_holder;
|
class memory_holder;
|
||||||
|
|
||||||
typedef boost::shared_ptr<node> shared_node;
|
typedef boost::shared_ptr<node> shared_node;
|
||||||
|
typedef boost::shared_ptr<node_ref> shared_node_ref;
|
||||||
typedef boost::shared_ptr<node_data> shared_node_data;
|
typedef boost::shared_ptr<node_data> shared_node_data;
|
||||||
typedef boost::shared_ptr<memory_holder> shared_memory_holder;
|
typedef boost::shared_ptr<memory_holder> shared_memory_holder;
|
||||||
typedef boost::shared_ptr<memory> shared_memory;
|
typedef boost::shared_ptr<memory> shared_memory;
|
||||||
|
Loading…
Reference in New Issue
Block a user