node iterator still being worked

pull/40/head
Matchman Green 2012-05-06 23:16:43 +08:00
parent 3584e12152
commit 65ae81bb96
5 changed files with 64 additions and 5 deletions

View File

@ -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 )

View File

@ -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)

View File

@ -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

View File

@ -63,6 +63,9 @@ public :
// TODO: implement iterator begin/end functions instead
std::vector<Node> Attr() const ;
iterator begin() ;
iterator end() ;
private :
class Impl ;
typedef std::vector<Impl*> 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 ;
} ;

View File

@ -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