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:
00107       bool nextNode();
00108 
00110       bool nextNodeAttribute();
00111 
00113       bool nextNodeOrAttribute()
00114       { return( nextNodeAttribute() || nextNode() ); }
00115 
00117       bool atEnd() const
00118       { return( _node.readState() == XML_TEXTREADER_MODE_CLOSED ); }
00119 
00121       const Node & operator*() const
00122       { return _node; }
00123 
00125       const Node *const operator->() const
00126       { return &_node; }
00127 
00128     public:
00130       typedef function<bool( Reader & )> ProcessNode;
00131 
00133       bool foreachNode( ProcessNode fnc_r )
00134       {
00135         if ( _node.isAttribute() )
00136           nextNode();
00137         for ( ; ! atEnd(); nextNode() )
00138           {
00139             if ( ! fnc_r( *this ) )
00140               return false;
00141           }
00142         return true;
00143       }
00144 
00146       bool foreachNodeAttribute( ProcessNode fnc_r )
00147       {
00148         if ( _node.isAttribute() && ! fnc_r( *this ) )
00149           return false;
00150         while( nextNodeAttribute() )
00151           {
00152             if ( ! fnc_r( *this ) )
00153               return false;
00154           }
00155         return true;
00156       }
00157 
00159       bool foreachNodeOrAttribute( ProcessNode fnc_r )
00160       {
00161         for ( ; ! atEnd(); nextNodeOrAttribute() )
00162           {
00163             if ( ! fnc_r( *this ) )
00164               return false;
00165           }
00166         return true;
00167       }
00168 
00169     public:
00171       bool seekToNode( int depth_r, const std::string & name_r );
00172 
00174       bool seekToEndNode( int depth_r, const std::string & name_r );
00175 
00176     private:
00177       void close();
00178 
00179     private:
00180       InputStream      _stream;
00181       xmlTextReaderPtr _reader;
00182       Node             _node;
00183     };
00185 
00187   } // namespace xml
00190 } // namespace zypp
00192 #endif // ZYPP_PARSER_XML_READER_H

Generated on Fri Jul 4 16:57:57 2008 for zypp by  doxygen 1.5.0