diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c7d1c0..f6b216a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) -set( GRIVE_VERSION "0.0.4" ) +set( GRIVE_VERSION "0.0.5-pre" ) add_subdirectory( libgrive ) add_subdirectory( grive ) diff --git a/libgrive/CMakeLists.txt b/libgrive/CMakeLists.txt index 58cc885..71903d2 100644 --- a/libgrive/CMakeLists.txt +++ b/libgrive/CMakeLists.txt @@ -52,7 +52,7 @@ target_link_libraries( grive ) set_target_properties(grive PROPERTIES - SOVERSION 0 VERSION 0.0.4 + SOVERSION 0 VERSION ${GRIVE_VERSION} ) install(TARGETS grive LIBRARY DESTINATION lib) diff --git a/libgrive/src/xml/Node.cc b/libgrive/src/xml/Node.cc index eb32efb..082cf2a 100644 --- a/libgrive/src/xml/Node.cc +++ b/libgrive/src/xml/Node.cc @@ -177,6 +177,38 @@ private : ImplVec m_children ; } ; +Node::iterator::iterator( ImplVec::iterator it ) : m_it( it ) +{ +} + +Node::iterator::value_type Node::iterator::operator*() const +{ + return Node( *m_it ) ; +} + +Node::iterator Node::iterator::operator++() +{ + m_it++ ; + return *this ; +} + +Node::iterator Node::iterator::operator++(int) +{ + iterator tmp( *this ) ; + ++tmp ; + return tmp ; +} + +bool Node::iterator::operator==( const iterator& i ) const +{ + return m_it == i.m_it ; +} + +bool Node::iterator::operator!=( const iterator& i ) const +{ + return m_it != i.m_it ; +} + Node::Node() : m_ptr( new Impl ) { } @@ -322,4 +354,15 @@ std::ostream& operator<<( std::ostream& os, const Node& node ) return os ; } +Node::iterator Node::begin() +{ + return iterator( m_ptr->Begin() ) ; +} + +Node::iterator Node::end() +{ + return iterator( m_ptr->End() ) ; +} + + } } // end namespace diff --git a/libgrive/src/xml/Node.hh b/libgrive/src/xml/Node.hh index a3dd538..64c4fec 100644 --- a/libgrive/src/xml/Node.hh +++ b/libgrive/src/xml/Node.hh @@ -63,6 +63,9 @@ public : // TODO: implement iterator begin/end functions instead std::vector Attr() const ; + iterator begin() ; + iterator end() ; + private : class Impl ; typedef std::vector ImplVec ; @@ -71,15 +74,19 @@ public : class iterator { public : - iterator( ImplVec::iterator *impl ) ; + explicit iterator( std::vector< gr::xml::Node::Impl* >::iterator it ) ; typedef Node value_type ; value_type operator*() const ; -// value_type operator*() const ; + iterator operator++() ; + iterator operator++(int) ; + + bool operator==( const iterator& i ) const ; + bool operator!=( const iterator& i ) const ; private : - ImplVec::iterator *m_node ; + ImplVec::iterator m_it ; } ; diff --git a/libgrive/test/xml/NodeTest.cc b/libgrive/test/xml/NodeTest.cc index dfcbbd3..0f36ad1 100644 --- a/libgrive/test/xml/NodeTest.cc +++ b/libgrive/test/xml/NodeTest.cc @@ -61,6 +61,15 @@ void NodeTest::TestParseFile( ) CPPUNIT_ASSERT_EQUAL( std::string("q"), n["entry"]["link"]["@href"].Value() ) ; CPPUNIT_ASSERT_EQUAL( Node::element, n["entry"]["link"]["href"].GetType() ) ; CPPUNIT_ASSERT_EQUAL( std::string("abc"), n["entry"]["link"]["href"].Value() ) ; +/* + Node el = n["entry"]["link"] ; + Node::iterator i = el.begin() ; + while ( i != el.end() ) + { + CPPUNIT_ASSERT_EQUAL( std::string("href"), (*i).Name() ) ; + ++i ; + } +*/ } } // end of namespace grut