grive2/libgrive/src/xml/Node.hh

108 lines
2.6 KiB
C++
Raw Normal View History

2012-05-03 21:44:52 +04:00
/*
grive: an GPL program to sync a local directory with Google Drive
Copyright (C) 2012 Wan Wai Ho
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2
of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#pragma once
2012-05-09 18:25:42 +04:00
#include <iosfwd>
2012-05-03 21:44:52 +04:00
#include <string>
#include <vector>
2012-05-06 20:03:33 +04:00
#include <utility>
2012-05-03 21:44:52 +04:00
namespace gr { namespace xml {
class Node
{
2012-05-06 13:13:48 +04:00
public :
class iterator ;
2012-05-06 20:03:33 +04:00
typedef std::pair<Node::iterator, Node::iterator> Range ;
2012-05-06 13:13:48 +04:00
2012-05-03 21:44:52 +04:00
public :
Node() ;
Node( const Node& node ) ;
~Node() ;
static Node Element( const std::string& name ) ;
static Node Text( const std::string& name ) ;
Node& operator=( const Node& node ) ;
Node AddElement( const std::string& name ) ;
Node AddText( const std::string& text ) ;
2012-05-05 09:01:23 +04:00
void AddNode( const Node& node ) ;
void AddAttribute( const std::string& name, const std::string& val ) ;
2012-05-03 21:44:52 +04:00
Node operator[]( const std::string& name ) const ;
2012-05-05 09:01:23 +04:00
const std::string& Name() const ;
std::string Value() const ;
2012-05-03 21:44:52 +04:00
// read-only access to the reference counter. for checking.
std::size_t RefCount() const ;
enum Type { element, attr, text } ;
Type GetType() const ;
2012-05-05 09:01:23 +04:00
static bool IsCompatible( Type parent, Type child ) ;
2012-05-09 18:25:42 +04:00
static std::ostream& PrintChar( std::ostream& os, char c ) ;
static std::ostream& PrintString( std::ostream& os, const std::string& s ) ;
2012-05-06 20:03:33 +04:00
iterator begin() const ;
iterator end() const ;
2012-05-03 21:44:52 +04:00
2012-05-06 20:03:33 +04:00
Range Attr() const ;
2012-05-06 19:16:43 +04:00
2012-05-03 21:44:52 +04:00
private :
class Impl ;
2012-05-06 13:13:48 +04:00
typedef std::vector<Impl*> ImplVec ;
public :
class iterator
{
public :
2012-05-06 20:03:33 +04:00
iterator() ;
2012-05-06 19:16:43 +04:00
explicit iterator( std::vector< gr::xml::Node::Impl* >::iterator it ) ;
2012-05-06 18:27:52 +04:00
2012-05-06 20:03:33 +04:00
typedef Node value_type ;
typedef std::forward_iterator_tag iterator_category ;
typedef std::ptrdiff_t difference_type;
typedef Node* pointer;
typedef Node& reference;
2012-05-06 18:27:52 +04:00
value_type operator*() const ;
2012-05-06 19:16:43 +04:00
iterator operator++() ;
iterator operator++(int) ;
bool operator==( const iterator& i ) const ;
bool operator!=( const iterator& i ) const ;
2012-05-06 18:27:52 +04:00
2012-05-06 13:13:48 +04:00
private :
2012-05-06 19:16:43 +04:00
ImplVec::iterator m_it ;
2012-05-06 13:13:48 +04:00
} ;
2012-05-03 21:44:52 +04:00
private :
explicit Node( Impl *impl ) ;
private :
Impl *m_ptr ;
} ;
std::ostream& operator<<( std::ostream& os, const Node& node ) ;
2012-05-03 21:44:52 +04:00
} } // end of namespace