libzypp  10.5.0
Reader.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_PARSER_XML_READER_H
00013 #define ZYPP_PARSER_XML_READER_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/base/NonCopyable.h"
00018 #include "zypp/base/InputStream.h"
00019 #include "zypp/base/Function.h"
00020 
00021 #include "zypp/parser/xml/Node.h"
00022 
00024 namespace zypp
00025 { 
00026 
00027   namespace xml
00028   { 
00029 
00031     //
00032     //  CLASS NAME : Validate
00033     //
00037     struct Validate
00038     {
00039       static Validate none()
00040       { return Validate(); }
00041     };
00043 
00045     //
00046     //  CLASS NAME : Reader
00047     //
00095     class Reader : private zypp::base::NonCopyable
00096     {
00097     public:
00099       Reader( const InputStream & stream_r,
00100               const Validate & validate_r = Validate::none() );
00101 
00103       ~Reader();
00104 
00105     public:
00106 
00115       XmlString nodeText();
00116 
00118       bool nextNode();
00119 
00121       bool nextNodeAttribute();
00122 
00124       bool nextNodeOrAttribute()
00125       { return( nextNodeAttribute() || nextNode() ); }
00126 
00128       bool atEnd() const
00129       { return( _node.readState() == XML_TEXTREADER_MODE_CLOSED ); }
00130 
00132       const Node & operator*() const
00133       { return _node; }
00134 
00136       const Node * operator->() const
00137       { return &_node; }
00138 
00139     public:
00141       typedef function<bool( Reader & )> ProcessNode;
00142 
00144       bool foreachNode( ProcessNode fnc_r )
00145       {
00146         if ( _node.isAttribute() )
00147           nextNode();
00148         for ( ; ! atEnd(); nextNode() )
00149           {
00150             if ( ! fnc_r( *this ) )
00151               return false;
00152           }
00153         return true;
00154       }
00155 
00157       bool foreachNodeAttribute( ProcessNode fnc_r )
00158       {
00159         if ( _node.isAttribute() && ! fnc_r( *this ) )
00160           return false;
00161         while( nextNodeAttribute() )
00162           {
00163             if ( ! fnc_r( *this ) )
00164               return false;
00165           }
00166         return true;
00167       }
00168 
00170       bool foreachNodeOrAttribute( ProcessNode fnc_r )
00171       {
00172         for ( ; ! atEnd(); nextNodeOrAttribute() )
00173           {
00174             if ( ! fnc_r( *this ) )
00175               return false;
00176           }
00177         return true;
00178       }
00179 
00180     public:
00182       bool seekToNode( int depth_r, const std::string & name_r );
00183 
00185       bool seekToEndNode( int depth_r, const std::string & name_r );
00186 
00187     private:
00188       void close();
00189 
00190     private:
00191       InputStream      _stream;
00192       xmlTextReaderPtr _reader;
00193       Node             _node;
00194     };
00196 
00198   } // namespace xml
00201 } // namespace zypp
00203 #endif // ZYPP_PARSER_XML_READER_H