mirror of https://github.com/vitalif/grive2
Use vector<Entry> instead of iterator_adaptor to hide implementation details
parent
dabaaac38f
commit
717a6a4793
|
@ -39,12 +39,12 @@ Feed::Feed( )
|
||||||
|
|
||||||
Feed::iterator Feed::begin() const
|
Feed::iterator Feed::begin() const
|
||||||
{
|
{
|
||||||
return iterator( m_entries.begin() ) ;
|
return m_entries.begin() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed::iterator Feed::end() const
|
Feed::iterator Feed::end() const
|
||||||
{
|
{
|
||||||
return iterator( m_entries.end() ) ;
|
return m_entries.end() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Feed::Start( http::Agent *http, const std::string& url )
|
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() ) ;
|
http->Get( url, &log, http::Header() ) ;
|
||||||
|
|
||||||
m_root = xrsp.Response() ;
|
m_root = xrsp.Response() ;
|
||||||
m_entries = m_root["entry"] ;
|
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 )
|
bool Feed::GetNext( http::Agent *http )
|
||||||
|
@ -78,28 +83,12 @@ bool Feed::GetNext( http::Agent *http )
|
||||||
return false ;
|
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 )
|
void Feed::EnableLog( const std::string& prefix, const std::string& suffix )
|
||||||
{
|
{
|
||||||
m_log.reset( new LogInfo ) ;
|
m_log.reset( new LogInfo ) ;
|
||||||
m_log->prefix = prefix ;
|
m_log->prefix = prefix ;
|
||||||
m_log->suffix = suffix ;
|
m_log->suffix = suffix ;
|
||||||
m_log->sequence = 0 ;
|
m_log->sequence = 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
} } // end of namespace gr::v1
|
} } // end of namespace gr::v1
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "xml/Node.hh"
|
#include "xml/Node.hh"
|
||||||
#include "xml/NodeSet.hh"
|
#include "xml/NodeSet.hh"
|
||||||
|
|
||||||
#include <boost/iterator_adaptors.hpp>
|
#include <vector>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -40,13 +40,13 @@ namespace v1 {
|
||||||
class Feed
|
class Feed
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
class iterator ;
|
typedef std::vector<Entry> Entries;
|
||||||
|
typedef std::vector<Entry>::const_iterator iterator;
|
||||||
|
|
||||||
public :
|
public :
|
||||||
Feed( ) ;
|
Feed( ) ;
|
||||||
void Start( http::Agent *http, const std::string& url ) ;
|
void Start( http::Agent *http, const std::string& url ) ;
|
||||||
bool GetNext( http::Agent *http ) ;
|
bool GetNext( http::Agent *http ) ;
|
||||||
|
|
||||||
iterator begin() const ;
|
iterator begin() const ;
|
||||||
iterator end() const ;
|
iterator end() const ;
|
||||||
|
|
||||||
|
@ -61,25 +61,7 @@ private :
|
||||||
std::auto_ptr<LogInfo> m_log ;
|
std::auto_ptr<LogInfo> m_log ;
|
||||||
|
|
||||||
xml::Node m_root ;
|
xml::Node m_root ;
|
||||||
xml::NodeSet m_entries ;
|
Entries m_entries ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
class Feed::iterator : public boost::iterator_adaptor<
|
} } // end of namespace gr::v1
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in New Issue