added copy ctor & op= to NodeSet

pull/40/head
Matchman Green 2012-05-12 12:27:35 +08:00
parent c1c1916eb7
commit 444bf61c73
8 changed files with 63 additions and 12 deletions

View File

@ -95,15 +95,22 @@ void Entry::Update( const Json& entry )
void Entry::Update( const xml::Node& n )
{
m_title = n["title"] ;
m_etag = n["@gd:etag"] ;
m_filename = n["docs:suggestedFilename"] ;
m_content_src = n["content"]["@src"] ;
m_self_href = n["link"].Find( "@rel", "self" )["@href"] ;
m_title = n["title"] ;
m_etag = n["@gd:etag"] ;
m_filename = n["docs:suggestedFilename"] ;
m_content_src = n["content"]["@src"] ;
m_self_href = n["link"].Find( "@rel", "self" )["@href"] ;
m_server_modified = DateTime( n["updated"] ) ;
m_resource_id = n["gd:resourceId"] ;
m_server_md5 = n["docs:md5Checksum"] ;
m_kind = n["category"].Find( "@scheme", "http://schemas.google.com/g/2005#kind" )["@label"] ;
m_upload_link = n["link"].Find( "!rel", "http://schemas.google.com/g/2005#resumable-edit-media")["href"] ;
m_parent_hrefs.clear( ) ;
xml::NodeSet parents = n["link"].Find( "@rel", "http://schemas.google.com/docs/2007#parent" ) ;
m_parent_hrefs.resize( parents.size() ) ;
std::copy( parents.begin(), parents.end(), m_parent_hrefs.begin() ) ;
for ( xml::NodeSet::iterator i = parents.begin() ; i != parents.end() ; ++i )
m_parent_hrefs.push_back( (*i)["@href"] ) ;
}
std::string Entry::Parent( const Json& entry )
@ -113,6 +120,11 @@ std::string Entry::Parent( const Json& entry )
node["href"].Str() : std::string() ;
}
const std::vector<std::string>& Entry::ParentHrefs() const
{
return m_parent_hrefs ;
}
std::string Entry::Title() const
{
return m_title ;

View File

@ -62,6 +62,8 @@ public :
std::string SelfHref() const ;
std::string ParentHref() const ;
const std::vector<std::string>& ParentHrefs() const ;
void Download( gr::http::Agent* http, const Path& file, const http::Headers& auth ) const ;
bool Upload( gr::http::Agent* http, std::streambuf *file, const http::Headers& auth ) ;
void Delete( gr::http::Agent* http, const gr::http::Headers& auth ) ;

View File

@ -238,10 +238,15 @@ Node::~Node()
Node& Node::operator=( const Node& node )
{
Node tmp( node ) ;
std::swap( tmp.m_ptr, m_ptr ) ;
Swap( tmp ) ;
return *this ;
}
void Node::Swap( Node& node )
{
std::swap( node.m_ptr, m_ptr ) ;
}
bool Node::IsCompatible( Type parent, Type child )
{
static const bool map[][3] =

View File

@ -48,6 +48,7 @@ public :
static Node Text( const std::string& name ) ;
Node& operator=( const Node& node ) ;
void Swap( Node& node ) ;
Node AddElement( const std::string& name ) ;
Node AddText( const std::string& text ) ;

View File

@ -37,7 +37,28 @@ NodeSet::NodeSet( iterator first, iterator last ) :
m_last( last )
{
}
NodeSet::NodeSet( const NodeSet& n ) :
m_tmp( n.m_tmp ),
m_first( m_tmp.begin() + (n.m_first - n.m_tmp.begin()) ),
m_last( m_tmp.begin() + (n.m_last - n.m_tmp.begin()) )
{
}
NodeSet& NodeSet::operator=( const NodeSet& ns )
{
NodeSet tmp( ns ) ;
Swap( tmp ) ;
return *this ;
}
void NodeSet::Swap( NodeSet& ns )
{
m_tmp.Swap( ns.m_tmp ) ;
std::swap( m_first, ns.m_first ) ;
std::swap( m_last, ns.m_last ) ;
}
NodeSet::iterator NodeSet::begin() const
{
return m_first ;
@ -96,7 +117,7 @@ NodeSet NodeSet::operator[]( const std::string& name ) const
if ( !r.empty() )
return r ;
}
throw std::runtime_error( "can't find node " + name ) ;
return NodeSet() ;
}
Node NodeSet::front() const

View File

@ -34,8 +34,12 @@ public :
public :
NodeSet() ;
NodeSet( const NodeSet& n ) ;
NodeSet( iterator first, iterator last ) ;
NodeSet& operator=( const NodeSet& ns ) ;
void Swap( NodeSet& ns ) ;
void Add( const Node& n ) ;
iterator begin() const ;

View File

@ -87,7 +87,7 @@ namespace grut {
CPPUNIT_SOURCELINE(), \
"["#actualFirst","#actualLast") == "#expectFirst) )
#define GRUT_ASSERT_EQUAL(actual, expected) \
#define GRUT_ASSERT_EQUAL(expected, actual) \
( grut::AssertEquals( (expected), \
(actual), \
CPPUNIT_SOURCELINE(), \

View File

@ -47,6 +47,12 @@ void EntryTest::TestXml( )
GRUT_ASSERT_EQUAL( "\"WxYPGE8CDyt7ImBk\"", subject.ETag() ) ;
GRUT_ASSERT_EQUAL( "https://docs.google.com/feeds/default/private/full/folder%3A0B5KhdsbryVeGMl83OEV1ZVc3cUE",
subject.SelfHref() ) ;
GRUT_ASSERT_EQUAL( 1, subject.ParentHrefs().size() ) ;
GRUT_ASSERT_EQUAL( "https://docs.google.com/feeds/default/private/full/folder%3A0B5KhdsbryVeGNEZjdUxzZHl3Sjg",
subject.ParentHrefs().front() ) ;
GRUT_ASSERT_EQUAL( "folder", subject.Kind() ) ;
}
} // end of namespace grut