libzypp  17.25.8
Reader.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_PARSER_XML_READER_H
13 #define ZYPP_PARSER_XML_READER_H
14 
15 #include <iosfwd>
16 
17 #include <zypp/base/NonCopyable.h>
18 #include <zypp/base/InputStream.h>
19 #include <zypp/base/Function.h>
20 
21 #include <zypp/parser/xml/Node.h>
22 
24 namespace zypp
25 {
26  namespace xml
28  {
29 
31  //
32  // CLASS NAME : Validate
33  //
37  struct Validate
38  {
39  static Validate none()
40  { return Validate(); }
41  };
43 
45  //
46  // CLASS NAME : Reader
47  //
96  {
97  public:
99  Reader( const InputStream & stream_r,
100  const Validate & validate_r = Validate::none() );
101 
103  ~Reader();
104 
105  public:
106 
116 
118  bool nextNode();
119 
121  bool nextNodeAttribute();
122 
125  { return( nextNodeAttribute() || nextNode() ); }
126 
128  bool atEnd() const
129  { return( _node.readState() == XML_TEXTREADER_MODE_CLOSED ); }
130 
132  const Node & operator*() const
133  { return _node; }
134 
136  const Node * operator->() const
137  { return &_node; }
138 
139  public:
141  typedef function<bool( Reader & )> ProcessNode;
142 
144  bool foreachNode( ProcessNode fnc_r )
145  {
146  if ( _node.isAttribute() )
147  nextNode();
148  for ( ; ! atEnd(); nextNode() )
149  {
150  if ( ! fnc_r( *this ) )
151  return false;
152  }
153  return true;
154  }
155 
158  {
159  if ( _node.isAttribute() && ! fnc_r( *this ) )
160  return false;
161  while( nextNodeAttribute() )
162  {
163  if ( ! fnc_r( *this ) )
164  return false;
165  }
166  return true;
167  }
168 
171  {
172  for ( ; ! atEnd(); nextNodeOrAttribute() )
173  {
174  if ( ! fnc_r( *this ) )
175  return false;
176  }
177  return true;
178  }
179 
180  public:
182  bool seekToNode( int depth_r, const std::string & name_r );
183 
185  bool seekToEndNode( int depth_r, const std::string & name_r );
186 
187  private:
188  void close();
189 
190  private:
192  xmlTextReaderPtr _reader;
194  };
196 
198  } // namespace xml
201 } // namespace zypp
203 #endif // ZYPP_PARSER_XML_READER_H
zypp::xml::Reader
xmlTextReader based interface to iterate xml streams.
Definition: Reader.h:96
zypp::xml::Reader::_node
Node _node
Definition: Reader.h:193
zypp::xml::Node::readState
ReadState readState() const
Gets the read state of the reader.
Definition: Node.h:139
zypp::xml::Reader::_reader
xmlTextReaderPtr _reader
Definition: Reader.h:192
zypp::xml::Reader::seekToNode
bool seekToNode(int depth_r, const std::string &name_r)
Definition: Reader.cc:212
zypp::xml::Reader::~Reader
~Reader()
Dtor.
Definition: Reader.cc:131
zypp::xml::Reader::foreachNode
bool foreachNode(ProcessNode fnc_r)
Definition: Reader.h:144
zypp::xml::Reader::atEnd
bool atEnd() const
Definition: Reader.h:128
zypp::xml::Reader::foreachNodeOrAttribute
bool foreachNodeOrAttribute(ProcessNode fnc_r)
Definition: Reader.h:170
bool
zypp::xml::Reader::operator->
const Node * operator->() const
Definition: Reader.h:136
zypp::xml::Reader::seekToEndNode
bool seekToEndNode(int depth_r, const std::string &name_r)
Definition: Reader.cc:232
zypp::xml::Node::isAttribute
bool isAttribute() const
Whether this is an Attribute node.
Definition: Node.h:92
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
zypp::xml::Reader::ProcessNode
function< bool(Reader &)> ProcessNode
Definition: Reader.h:141
zypp::xml::Reader::foreachNodeAttribute
bool foreachNodeAttribute(ProcessNode fnc_r)
Definition: Reader.h:157
zypp::xml::Reader::nextNode
bool nextNode()
Definition: Reader.cc:160
zypp::xml::Reader::close
void close()
Definition: Reader.cc:199
Node.h
zypp::InputStream
Helper to create and pass std::istream.
Definition: InputStream.h:57
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::xml::Reader::nextNodeOrAttribute
bool nextNodeOrAttribute()
Definition: Reader.h:124
zypp::xml::Reader::_stream
InputStream _stream
Definition: Reader.h:191
zypp::xml::Validate::none
static Validate none()
Definition: Reader.h:39
zypp::xml::XmlString
xmlChar * wrapper.
Definition: XmlString.h:41
xml
Function.h
zypp::xml::Reader::nodeText
XmlString nodeText()
If the current node is not empty, advances the reader to the next node, and returns the value.
Definition: Reader.cc:140
zypp::xml::Validate
xmlTextReader document validation.
Definition: Reader.h:38
zypp::xml::Node
xmlTextReader based interface to Reader's current node.
Definition: Node.h:36
InputStream.h
zypp::xml::Reader::operator*
const Node & operator*() const
Definition: Reader.h:132
zypp::xml::Reader::Reader
Reader(const InputStream &stream_r, const Validate &validate_r=Validate::none())
Ctor.
Definition: Reader.cc:106
zypp::xml::Reader::nextNodeAttribute
bool nextNodeAttribute()
Definition: Reader.cc:180
NonCopyable.h