diff --git a/include/yaml-cpp/value/detail/node.h b/include/yaml-cpp/value/detail/node.h index 0eb8014..21c147f 100644 --- a/include/yaml-cpp/value/detail/node.h +++ b/include/yaml-cpp/value/detail/node.h @@ -32,6 +32,8 @@ namespace YAML 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); } + + void append(node& node, shared_memory_holder pMemory) { m_pRef->append(node, pMemory); } // indexing template node& get(const Key& key, shared_memory_holder pMemory) const { return static_cast(*m_pRef).get(key, pMemory); } diff --git a/include/yaml-cpp/value/detail/node_data.h b/include/yaml-cpp/value/detail/node_data.h index ce097b2..ab5de66 100644 --- a/include/yaml-cpp/value/detail/node_data.h +++ b/include/yaml-cpp/value/detail/node_data.h @@ -30,6 +30,8 @@ namespace YAML ValueType::value type() const { return m_isDefined ? m_type : ValueType::Undefined; } const std::string& scalar() const { return m_scalar; } + void append(node& node, shared_memory_holder pMemory); + // indexing template node& get(const Key& key, shared_memory_holder pMemory) const; template node& get(const Key& key, shared_memory_holder pMemory); diff --git a/include/yaml-cpp/value/detail/node_ref.h b/include/yaml-cpp/value/detail/node_ref.h index 0164dd2..84dbbdb 100644 --- a/include/yaml-cpp/value/detail/node_ref.h +++ b/include/yaml-cpp/value/detail/node_ref.h @@ -30,6 +30,8 @@ namespace YAML void set_null() { m_pData->set_null(); } void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); } + void append(node& node, shared_memory_holder pMemory) { m_pData->append(node, pMemory); } + // indexing template node& get(const Key& key, shared_memory_holder pMemory) const { return static_cast(*m_pData).get(key, pMemory); } template node& get(const Key& key, shared_memory_holder pMemory) { return m_pData->get(key, pMemory); } diff --git a/include/yaml-cpp/value/impl.h b/include/yaml-cpp/value/impl.h index f3dbbc4..9e0086e 100644 --- a/include/yaml-cpp/value/impl.h +++ b/include/yaml-cpp/value/impl.h @@ -150,6 +150,19 @@ namespace YAML return iterator(); } + // sequence + template + 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 inline const Value Value::operator[](const Key& key) const diff --git a/include/yaml-cpp/value/value.h b/include/yaml-cpp/value/value.h index c84ea2f..fa64ea6 100644 --- a/include/yaml-cpp/value/value.h +++ b/include/yaml-cpp/value/value.h @@ -45,6 +45,10 @@ namespace YAML const_iterator end() const; iterator end(); + // sequence + template void append(const T& rhs); + void append(const Value& rhs); + // indexing template const Value operator[](const Key& key) const; template Value operator[](const Key& key); diff --git a/src/value/detail/node_data.cpp b/src/value/detail/node_data.cpp index 03eeec7..5107811 100644 --- a/src/value/detail/node_data.cpp +++ b/src/value/detail/node_data.cpp @@ -2,6 +2,7 @@ #include "yaml-cpp/value/detail/memory.h" #include "yaml-cpp/value/detail/node.h" #include +#include namespace YAML { @@ -57,6 +58,14 @@ namespace YAML m_scalar = scalar; } + void node_data::append(node& node, shared_memory_holder /* pMemory */) + { + if(m_type != ValueType::Sequence) + throw std::runtime_error("Can't append to a non-sequence node"); + + m_sequence.push_back(&node); + } + // indexing node& node_data::get(node& key, shared_memory_holder pMemory) const { diff --git a/util/value.cpp b/util/value.cpp index 14f206b..5c3e401 100644 --- a/util/value.cpp +++ b/util/value.cpp @@ -22,7 +22,11 @@ int main() value["this"] = value; value["this"]["change"] = value; - value["this"]["change"] = 5; + + value["seq"] = YAML::Value(YAML::ValueType::Sequence); + value["seq"].append(2); + value["seq"].append(3); + value["seq"].append("five"); return 0; }