From f0174ca08b67d69f29b4b7bc82051e3f53d7bfaa Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Wed, 7 Sep 2011 02:59:58 -0500 Subject: [PATCH] Reorganized so that we don't have cyclic include problems --- include/yaml-cpp/value.h | 13 ++++++ include/yaml-cpp/value/detail/impl.h | 43 ++++++++++++++++++ include/yaml-cpp/value/detail/memory.h | 53 +++++------------------ include/yaml-cpp/value/detail/node.h | 7 +++ include/yaml-cpp/value/detail/node_data.h | 2 +- include/yaml-cpp/value/detail/nodedata.h | 0 include/yaml-cpp/value/impl.h | 1 + include/yaml-cpp/value/value.h | 2 - src/value/detail/memory.cpp | 29 +++++++++++++ util/value.cpp | 2 +- 10 files changed, 105 insertions(+), 47 deletions(-) create mode 100644 include/yaml-cpp/value.h create mode 100644 include/yaml-cpp/value/detail/impl.h delete mode 100644 include/yaml-cpp/value/detail/nodedata.h create mode 100644 src/value/detail/memory.cpp diff --git a/include/yaml-cpp/value.h b/include/yaml-cpp/value.h new file mode 100644 index 0000000..87587e9 --- /dev/null +++ b/include/yaml-cpp/value.h @@ -0,0 +1,13 @@ +#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/detail/impl.h" + +#endif // VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/value/detail/impl.h b/include/yaml-cpp/value/detail/impl.h new file mode 100644 index 0000000..a1906db --- /dev/null +++ b/include/yaml-cpp/value/detail/impl.h @@ -0,0 +1,43 @@ +#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 + inline shared_node node_data::operator[](const Key& key) const + { + if(m_type != ValueType::Map) + return shared_node(new node); + + for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) { + if(it->first->equals(key)) + return it->second; + } + + return shared_node(new node); + } + + template + inline shared_node node_data::operator[](const Key& key) + { + } + + template + inline bool node_data::remove(const Key& key) + { + } + } +} + +#endif // VALUE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/value/detail/memory.h b/include/yaml-cpp/value/detail/memory.h index 2a7ba14..475a341 100644 --- a/include/yaml-cpp/value/detail/memory.h +++ b/include/yaml-cpp/value/detail/memory.h @@ -6,7 +6,6 @@ #endif #include "yaml-cpp/value/ptr.h" -#include "yaml-cpp/value/detail/node.h" #include #include @@ -14,19 +13,6 @@ namespace YAML { namespace detail { - class memory; - - class memory_holder { - public: - memory_holder(); - - shared_node create_node(); - void merge(memory_holder& rhs); - - private: - boost::shared_ptr m_pMemory; - }; - class memory { public: shared_node create_node(); @@ -36,36 +22,17 @@ namespace YAML typedef std::set Nodes; Nodes m_nodes; }; - - inline memory_holder::memory_holder(): m_pMemory(new memory) - { - } - - inline shared_node memory_holder::create_node() - { - return m_pMemory->create_node(); - } - - inline void memory_holder::merge(memory_holder& rhs) - { - if(m_pMemory == rhs.m_pMemory) - return; + + class memory_holder { + public: + memory_holder(): m_pMemory(new memory) {} - m_pMemory->merge(*rhs.m_pMemory); - rhs.m_pMemory = m_pMemory; - } - - shared_node memory::create_node() - { - shared_node pNode(new node); - m_nodes.insert(pNode); - return pNode; - } - - inline void memory::merge(const memory& rhs) - { - m_nodes.insert(rhs.m_nodes.begin(), rhs.m_nodes.end()); - } + shared_node create_node() { return m_pMemory->create_node(); } + void merge(memory_holder& rhs); + + private: + boost::shared_ptr m_pMemory; + }; } } diff --git a/include/yaml-cpp/value/detail/node.h b/include/yaml-cpp/value/detail/node.h index ed736fa..ddbd1bc 100644 --- a/include/yaml-cpp/value/detail/node.h +++ b/include/yaml-cpp/value/detail/node.h @@ -28,6 +28,8 @@ namespace YAML void set_null() { m_pData->set_null(); } void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); } + template bool equals(const T& rhs) const; + // indexing template shared_node operator[](const Key& key) const { return (static_cast(*m_pData))[key]; } template shared_node operator[](const Key& key) { return (*m_pData)[key]; } @@ -40,6 +42,11 @@ namespace YAML private: shared_node_data m_pData; }; + + template + inline bool node::equals(const T& rhs) const + { + } } } diff --git a/include/yaml-cpp/value/detail/node_data.h b/include/yaml-cpp/value/detail/node_data.h index 61c7907..eb524b7 100644 --- a/include/yaml-cpp/value/detail/node_data.h +++ b/include/yaml-cpp/value/detail/node_data.h @@ -7,8 +7,8 @@ #include "yaml-cpp/dll.h" -#include "yaml-cpp/value/type.h" #include "yaml-cpp/value/ptr.h" +#include "yaml-cpp/value/type.h" #include #include #include diff --git a/include/yaml-cpp/value/detail/nodedata.h b/include/yaml-cpp/value/detail/nodedata.h deleted file mode 100644 index e69de29..0000000 diff --git a/include/yaml-cpp/value/impl.h b/include/yaml-cpp/value/impl.h index 8527c69..319c772 100644 --- a/include/yaml-cpp/value/impl.h +++ b/include/yaml-cpp/value/impl.h @@ -8,6 +8,7 @@ #include "yaml-cpp/value/value.h" #include "yaml-cpp/value/detail/memory.h" +#include "yaml-cpp/value/detail/node.h" #include namespace YAML diff --git a/include/yaml-cpp/value/value.h b/include/yaml-cpp/value/value.h index e9bbee9..510cce8 100644 --- a/include/yaml-cpp/value/value.h +++ b/include/yaml-cpp/value/value.h @@ -85,6 +85,4 @@ namespace YAML bool convert(const Value& value, T& rhs); } -#include "yaml-cpp/value/impl.h" - #endif // VALUE_VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/value/detail/memory.cpp b/src/value/detail/memory.cpp new file mode 100644 index 0000000..3e529a8 --- /dev/null +++ b/src/value/detail/memory.cpp @@ -0,0 +1,29 @@ +#include "yaml-cpp/value/detail/memory.h" +#include "yaml-cpp/value/detail/node.h" + +namespace YAML +{ + namespace detail + { + void memory_holder::merge(memory_holder& rhs) + { + if(m_pMemory == rhs.m_pMemory) + return; + + m_pMemory->merge(*rhs.m_pMemory); + rhs.m_pMemory = m_pMemory; + } + + shared_node memory::create_node() + { + shared_node pNode(new node); + m_nodes.insert(pNode); + return pNode; + } + + void memory::merge(const memory& rhs) + { + m_nodes.insert(rhs.m_nodes.begin(), rhs.m_nodes.end()); + } + } +} diff --git a/util/value.cpp b/util/value.cpp index 8d8f460..e8f57a8 100644 --- a/util/value.cpp +++ b/util/value.cpp @@ -1,4 +1,4 @@ -#include "yaml-cpp/value/value.h" +#include "yaml-cpp/value.h" int main() {