From cf198080d01f7522c21510de05ad6d297d062c02 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Fri, 9 Sep 2011 19:22:17 -0500 Subject: [PATCH] Sequence iterator works\! --- include/yaml-cpp/value/detail/iterator.h | 6 ++-- include/yaml-cpp/value/detail/iterator_fwd.h | 1 - include/yaml-cpp/value/value.h | 1 + util/value.cpp | 29 ++++---------------- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/include/yaml-cpp/value/detail/iterator.h b/include/yaml-cpp/value/detail/iterator.h index eafab01..191056f 100644 --- a/include/yaml-cpp/value/detail/iterator.h +++ b/include/yaml-cpp/value/detail/iterator.h @@ -29,7 +29,7 @@ namespace YAML explicit iterator_base(shared_memory_holder pMemory, MapIter mapIt): m_type(iterator_type::Map), m_pMemory(pMemory), m_mapIt(mapIt) {} template - explicit iterator_base(const iterator_base& rhs, typename boost::enable_if, enabler>::type = enabler()) + iterator_base(const iterator_base& rhs, typename boost::enable_if, enabler>::type = enabler()) : m_type(rhs.m_type), m_pMemory(rhs.m_pMemory), m_seqIt(rhs.m_seqIt), m_mapIt(rhs.m_mapIt) {} private: @@ -65,10 +65,10 @@ namespace YAML } } - V dereference() { + V dereference() const { switch(m_type) { case iterator_type::None: return V(); - case iterator_type::Sequence: return V(Value(*m_seqIt, m_pMemory)); + case iterator_type::Sequence: return V(Value(**m_seqIt, m_pMemory)); case iterator_type::Map: return V(Value(*m_mapIt->first, m_pMemory), Value(*m_mapIt->second, m_pMemory)); } return V(); diff --git a/include/yaml-cpp/value/detail/iterator_fwd.h b/include/yaml-cpp/value/detail/iterator_fwd.h index 023e5af..b717a33 100644 --- a/include/yaml-cpp/value/detail/iterator_fwd.h +++ b/include/yaml-cpp/value/detail/iterator_fwd.h @@ -31,7 +31,6 @@ namespace YAML } typedef detail::iterator_base iterator; - typedef detail::iterator_base const_iterator; } diff --git a/include/yaml-cpp/value/value.h b/include/yaml-cpp/value/value.h index bb4f404..5be19b2 100644 --- a/include/yaml-cpp/value/value.h +++ b/include/yaml-cpp/value/value.h @@ -18,6 +18,7 @@ namespace YAML { public: friend class detail::node_data; + template friend class detail::iterator_base; Value(); explicit Value(ValueType::value type); diff --git a/util/value.cpp b/util/value.cpp index 5c3e401..dccc040 100644 --- a/util/value.cpp +++ b/util/value.cpp @@ -3,30 +3,13 @@ int main() { - YAML::Value value; - value["key"] = "value"; - std::cout << value["key"].as() << "\n"; - value["key"]["key"] = "value"; - std::cout << value["key"]["key"].as() << "\n"; - value[5] = "monkey"; - std::cout << value[5].as() << "\n"; - value["monkey"] = 5; - std::cout << value["monkey"].as() << "\n"; + YAML::Value value(YAML::ValueType::Sequence); + for(int i=0;i<5;i++) + value.append(i); - std::map names; - names[1] = "one"; - names[2] = "two"; - names[3] = "three"; - names[4] = "four"; - value["names"] = names; - - value["this"] = value; - value["this"]["change"] = value; - - value["seq"] = YAML::Value(YAML::ValueType::Sequence); - value["seq"].append(2); - value["seq"].append(3); - value["seq"].append("five"); + for(YAML::const_iterator it=value.begin();it!=value.end();++it) { + std::cout << it->as() << "\n"; + } return 0; }