mirror of https://github.com/vitalif/grive2
added copy ctor & op= to NodeSet
parent
c1c1916eb7
commit
444bf61c73
|
@ -95,15 +95,22 @@ void Entry::Update( const Json& entry )
|
||||||
|
|
||||||
void Entry::Update( const xml::Node& n )
|
void Entry::Update( const xml::Node& n )
|
||||||
{
|
{
|
||||||
m_title = n["title"] ;
|
m_title = n["title"] ;
|
||||||
m_etag = n["@gd:etag"] ;
|
m_etag = n["@gd:etag"] ;
|
||||||
m_filename = n["docs:suggestedFilename"] ;
|
m_filename = n["docs:suggestedFilename"] ;
|
||||||
m_content_src = n["content"]["@src"] ;
|
m_content_src = n["content"]["@src"] ;
|
||||||
m_self_href = n["link"].Find( "@rel", "self" )["@href"] ;
|
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" ) ;
|
xml::NodeSet parents = n["link"].Find( "@rel", "http://schemas.google.com/docs/2007#parent" ) ;
|
||||||
m_parent_hrefs.resize( parents.size() ) ;
|
for ( xml::NodeSet::iterator i = parents.begin() ; i != parents.end() ; ++i )
|
||||||
std::copy( parents.begin(), parents.end(), m_parent_hrefs.begin() ) ;
|
m_parent_hrefs.push_back( (*i)["@href"] ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Entry::Parent( const Json& entry )
|
std::string Entry::Parent( const Json& entry )
|
||||||
|
@ -113,6 +120,11 @@ std::string Entry::Parent( const Json& entry )
|
||||||
node["href"].Str() : std::string() ;
|
node["href"].Str() : std::string() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<std::string>& Entry::ParentHrefs() const
|
||||||
|
{
|
||||||
|
return m_parent_hrefs ;
|
||||||
|
}
|
||||||
|
|
||||||
std::string Entry::Title() const
|
std::string Entry::Title() const
|
||||||
{
|
{
|
||||||
return m_title ;
|
return m_title ;
|
||||||
|
|
|
@ -62,6 +62,8 @@ public :
|
||||||
std::string SelfHref() const ;
|
std::string SelfHref() const ;
|
||||||
std::string ParentHref() 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 ;
|
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 ) ;
|
bool Upload( gr::http::Agent* http, std::streambuf *file, const http::Headers& auth ) ;
|
||||||
void Delete( gr::http::Agent* http, const gr::http::Headers& auth ) ;
|
void Delete( gr::http::Agent* http, const gr::http::Headers& auth ) ;
|
||||||
|
|
|
@ -238,10 +238,15 @@ Node::~Node()
|
||||||
Node& Node::operator=( const Node& node )
|
Node& Node::operator=( const Node& node )
|
||||||
{
|
{
|
||||||
Node tmp( node ) ;
|
Node tmp( node ) ;
|
||||||
std::swap( tmp.m_ptr, m_ptr ) ;
|
Swap( tmp ) ;
|
||||||
return *this ;
|
return *this ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::Swap( Node& node )
|
||||||
|
{
|
||||||
|
std::swap( node.m_ptr, m_ptr ) ;
|
||||||
|
}
|
||||||
|
|
||||||
bool Node::IsCompatible( Type parent, Type child )
|
bool Node::IsCompatible( Type parent, Type child )
|
||||||
{
|
{
|
||||||
static const bool map[][3] =
|
static const bool map[][3] =
|
||||||
|
|
|
@ -48,6 +48,7 @@ public :
|
||||||
static Node Text( const std::string& name ) ;
|
static Node Text( const std::string& name ) ;
|
||||||
|
|
||||||
Node& operator=( const Node& node ) ;
|
Node& operator=( const Node& node ) ;
|
||||||
|
void Swap( Node& node ) ;
|
||||||
|
|
||||||
Node AddElement( const std::string& name ) ;
|
Node AddElement( const std::string& name ) ;
|
||||||
Node AddText( const std::string& text ) ;
|
Node AddText( const std::string& text ) ;
|
||||||
|
|
|
@ -37,7 +37,28 @@ NodeSet::NodeSet( iterator first, iterator last ) :
|
||||||
m_last( 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
|
NodeSet::iterator NodeSet::begin() const
|
||||||
{
|
{
|
||||||
return m_first ;
|
return m_first ;
|
||||||
|
@ -96,7 +117,7 @@ NodeSet NodeSet::operator[]( const std::string& name ) const
|
||||||
if ( !r.empty() )
|
if ( !r.empty() )
|
||||||
return r ;
|
return r ;
|
||||||
}
|
}
|
||||||
throw std::runtime_error( "can't find node " + name ) ;
|
return NodeSet() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node NodeSet::front() const
|
Node NodeSet::front() const
|
||||||
|
|
|
@ -34,8 +34,12 @@ public :
|
||||||
|
|
||||||
public :
|
public :
|
||||||
NodeSet() ;
|
NodeSet() ;
|
||||||
|
NodeSet( const NodeSet& n ) ;
|
||||||
NodeSet( iterator first, iterator last ) ;
|
NodeSet( iterator first, iterator last ) ;
|
||||||
|
|
||||||
|
NodeSet& operator=( const NodeSet& ns ) ;
|
||||||
|
void Swap( NodeSet& ns ) ;
|
||||||
|
|
||||||
void Add( const Node& n ) ;
|
void Add( const Node& n ) ;
|
||||||
|
|
||||||
iterator begin() const ;
|
iterator begin() const ;
|
||||||
|
|
|
@ -87,7 +87,7 @@ namespace grut {
|
||||||
CPPUNIT_SOURCELINE(), \
|
CPPUNIT_SOURCELINE(), \
|
||||||
"["#actualFirst","#actualLast") == "#expectFirst) )
|
"["#actualFirst","#actualLast") == "#expectFirst) )
|
||||||
|
|
||||||
#define GRUT_ASSERT_EQUAL(actual, expected) \
|
#define GRUT_ASSERT_EQUAL(expected, actual) \
|
||||||
( grut::AssertEquals( (expected), \
|
( grut::AssertEquals( (expected), \
|
||||||
(actual), \
|
(actual), \
|
||||||
CPPUNIT_SOURCELINE(), \
|
CPPUNIT_SOURCELINE(), \
|
||||||
|
|
|
@ -47,6 +47,12 @@ void EntryTest::TestXml( )
|
||||||
GRUT_ASSERT_EQUAL( "\"WxYPGE8CDyt7ImBk\"", subject.ETag() ) ;
|
GRUT_ASSERT_EQUAL( "\"WxYPGE8CDyt7ImBk\"", subject.ETag() ) ;
|
||||||
GRUT_ASSERT_EQUAL( "https://docs.google.com/feeds/default/private/full/folder%3A0B5KhdsbryVeGMl83OEV1ZVc3cUE",
|
GRUT_ASSERT_EQUAL( "https://docs.google.com/feeds/default/private/full/folder%3A0B5KhdsbryVeGMl83OEV1ZVc3cUE",
|
||||||
subject.SelfHref() ) ;
|
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
|
} // end of namespace grut
|
||||||
|
|
Loading…
Reference in New Issue