From 717a6a47930aeb431d728ebe0ecd4b47181e3092 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 17 May 2015 14:32:04 +0300 Subject: [PATCH] Use vector instead of iterator_adaptor to hide implementation details --- libgrive/src/drive/Feed.cc | 35 ++++++++++++----------------------- libgrive/src/drive/Feed.hh | 28 +++++----------------------- 2 files changed, 17 insertions(+), 46 deletions(-) diff --git a/libgrive/src/drive/Feed.cc b/libgrive/src/drive/Feed.cc index 1ce3563..087defd 100644 --- a/libgrive/src/drive/Feed.cc +++ b/libgrive/src/drive/Feed.cc @@ -39,12 +39,12 @@ Feed::Feed( ) Feed::iterator Feed::begin() const { - return iterator( m_entries.begin() ) ; + return m_entries.begin() ; } Feed::iterator Feed::end() const { - return iterator( m_entries.end() ) ; + return m_entries.end() ; } void Feed::Start( http::Agent *http, const std::string& url ) @@ -60,8 +60,13 @@ void Feed::Start( http::Agent *http, const std::string& url ) http->Get( url, &log, http::Header() ) ; - m_root = xrsp.Response() ; - m_entries = m_root["entry"] ; + m_root = xrsp.Response() ; + xml::NodeSet xe = m_root["entry"] ; + m_entries.clear() ; + for ( xml::NodeSet::iterator i = xe.begin() ; i != xe.end() ; ++i ) + { + m_entries.push_back( Entry1( *i ) ); + } } bool Feed::GetNext( http::Agent *http ) @@ -78,28 +83,12 @@ bool Feed::GetNext( http::Agent *http ) return false ; } -Feed::iterator::iterator( ) -{ -} - -Feed::iterator::iterator( xml::Node::iterator i ) -{ - // for some reason, gcc 4.4.4 doesn't allow me to initialize the base class - // in the initializer. I have no choice but to initialize here. - base_reference() = i ; -} - -Feed::iterator::reference Feed::iterator::dereference() const -{ - return Entry1( *base_reference() ) ; -} - void Feed::EnableLog( const std::string& prefix, const std::string& suffix ) { m_log.reset( new LogInfo ) ; - m_log->prefix = prefix ; - m_log->suffix = suffix ; - m_log->sequence = 0 ; + m_log->prefix = prefix ; + m_log->suffix = suffix ; + m_log->sequence = 0 ; } } } // end of namespace gr::v1 diff --git a/libgrive/src/drive/Feed.hh b/libgrive/src/drive/Feed.hh index ef87a27..db27137 100644 --- a/libgrive/src/drive/Feed.hh +++ b/libgrive/src/drive/Feed.hh @@ -24,7 +24,7 @@ #include "xml/Node.hh" #include "xml/NodeSet.hh" -#include +#include #include @@ -40,13 +40,13 @@ namespace v1 { class Feed { public : - class iterator ; + typedef std::vector Entries; + typedef std::vector::const_iterator iterator; public : Feed( ) ; void Start( http::Agent *http, const std::string& url ) ; bool GetNext( http::Agent *http ) ; - iterator begin() const ; iterator end() const ; @@ -61,25 +61,7 @@ private : std::auto_ptr m_log ; xml::Node m_root ; - xml::NodeSet m_entries ; + Entries m_entries ; } ; -class Feed::iterator : public boost::iterator_adaptor< - Feed::iterator, - xml::Node::iterator, - Entry, - boost::random_access_traversal_tag, - Entry -> -{ -public : - iterator() ; - explicit iterator( xml::Node::iterator i ) ; - -private : - friend class boost::iterator_core_access; - - reference dereference() const ; -} ; - -} } // end of namespace +} } // end of namespace gr::v1