2
grive: an GPL program to sync a local directory with Google Drive
3
Copyright (C) 2012 Wan Wai Ho
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation version 2
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
namespace gr { namespace xml {
31
m_first( m_tmp.begin() ),
36
NodeSet::NodeSet( iterator first, iterator last ) :
42
NodeSet::NodeSet( const NodeSet& n ) :
44
m_first( m_tmp.begin() + (n.m_first - n.m_tmp.begin()) ),
45
m_last( m_tmp.begin() + (n.m_last - n.m_tmp.begin()) )
49
NodeSet& NodeSet::operator=( const NodeSet& ns )
56
void NodeSet::Swap( NodeSet& ns )
58
m_tmp.Swap( ns.m_tmp ) ;
59
std::swap( m_first, ns.m_first ) ;
60
std::swap( m_last, ns.m_last ) ;
63
NodeSet::iterator NodeSet::begin() const
68
NodeSet::iterator NodeSet::end() const
73
/*! This function search the members in the node set. If any members in the node
74
set has a children named \a name , with value equal to \a value , it will
76
\param name name to be found. prefix with '@' for attributes
77
\param value value to be matched.
78
\return the node set contained all children nodes that matches \a name and \a value
80
NodeSet NodeSet::Find( const std::string& name, const std::string& value ) const
83
for ( iterator i = m_first ; i != m_last ; ++i )
85
NodeSet cand = (*i)[name] ;
86
for ( iterator j = cand.m_first ; j != cand.m_last ; ++j )
88
if ( j->Value() == value )
98
void NodeSet::Add( const Node& n )
100
// the tmp node is not used, that means the first,last iterators points to elsewhere
101
if ( m_tmp.size() == 0 )
103
m_tmp.AddNode( m_first, m_last ) ;
108
// the iterators may be invalidated after adding the node
109
m_first = m_tmp.begin() ;
110
m_last = m_tmp.end() ;
113
NodeSet NodeSet::operator[]( const std::string& name ) const
115
for ( iterator i = m_first ; i != m_last ; ++i )
117
NodeSet r = (*i)[name] ;
124
Node NodeSet::front() const
127
throw Error() << expt::ErrMsg( "empty node set" ) ;
132
NodeSet::operator std::string() const
134
return empty() ? "" : front().Value() ;
137
bool NodeSet::operator==( const std::string& value ) const
139
return operator std::string() == value ;
142
bool NodeSet::empty() const
144
return m_first == m_last ;
147
std::size_t NodeSet::size() const
149
return m_last - m_first ;
152
std::ostream& operator<<( std::ostream& os, const NodeSet& node )
154
std::copy( node.begin(), node.end(), std::ostream_iterator<Node>(os, " ") ) ;
158
} } // end of namespace