Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/cxxtools/include/cxxtools/xml/xmlreader.h

00001 /*
00002  * Copyright (C) 2009 Marc Boris Duerner
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 #ifndef cxxtools_Xml_XmlReader_h
00029 #define cxxtools_Xml_XmlReader_h
00030 
00031 #include <cxxtools/string.h>
00032 #include <cxxtools/textstream.h>
00033 #include <cxxtools/xml/api.h>
00034 #include <cxxtools/xml/node.h>
00035 #include <cxxtools/xml/enddocument.h>
00036 #include <iosfwd>
00037 
00038 namespace cxxtools {
00039 
00040 namespace xml {
00041 
00042     class Node;
00043     class StartElement;
00044     class EntityResolver;
00045 
00081 class CXXTOOLS_XML_API XmlReader
00082 {
00083     public:
00084         class Iterator
00085         {
00086             public:
00087                 Iterator()
00088                 : _stream(0)
00089                 , _node(0)
00090                 { }
00091 
00092                 Iterator(XmlReader& xis)
00093                 : _stream(&xis)
00094                 , _node(0)
00095                 { _node = &_stream->get(); }
00096 
00097                 Iterator(const Iterator& it)
00098                 : _stream(it._stream), _node(it._node)
00099                 { }
00100 
00101                 ~Iterator()
00102                 { }
00103 
00104                 Iterator& operator=(const Iterator& it)
00105                 {
00106                     _stream = it._stream;
00107                     _node = it._node;
00108                     return *this;
00109                 }
00110 
00111                 inline const Node& operator*() const
00112                 { return *_node; }
00113 
00114                 inline const Node* operator->() const
00115                 { return _node; }
00116 
00117                 Iterator& operator++()
00118                 {
00119                     if(_node->type() == Node::EndDocument)
00120                         _node = 0;
00121                     else
00122                         _node = &_stream->next();
00123 
00124                     return *this;
00125                 }
00126 
00127                 inline bool operator==(const Iterator& it) const
00128                 { return _node == it._node; }
00129 
00130                 inline bool operator!=(const Iterator& it) const
00131                 { return _node != it._node; }
00132 
00133             private:
00134                 XmlReader* _stream;
00135                 const Node* _node;
00136         };
00137 
00138     public:
00139         /* TODO: Consider the following processing flags:
00140                      - ReportProcessingInstructions
00141                      - IgnoreWhitespace
00142                      - ReportComments
00143                      - ReportDocumentStart
00144         */
00145         XmlReader(std::istream& is, int flags = 0);
00146 
00147         XmlReader(std::basic_istream<Char>& is, int flags = 0);
00148 
00149         ~XmlReader();
00150 
00151         void reset(std::basic_istream<Char>& is, int flags = 0);
00152 
00153         void reset(std::istream& is, int flags = 0);
00154 
00155         const cxxtools::String& documentVersion() const;
00156 
00157         const cxxtools::String& documentEncoding() const;
00158 
00159         bool standaloneDocument() const;
00160 
00161         EntityResolver& entityResolver();
00162 
00163         const EntityResolver& entityResolver() const;
00164 
00165         size_t depth() const;
00166 
00167         Iterator current()
00168         {
00169             return Iterator(*this);
00170         }
00171 
00172         Iterator end() const
00173         {
00174             return Iterator();
00175         }
00176 
00178         const Node& get();
00179 
00181         const Node& next();
00182 
00183         bool advance();
00184 
00185         const StartElement& nextElement();
00186 
00187         const Node& nextTag();
00188 
00189         std::size_t line() const;
00190 
00191     private:
00192         class XmlReaderImpl* _impl;
00193 };
00194 
00195 }
00196 
00197 }
00198 
00199 #endif
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6