#include <ParseDef.h>
Public Types | |
| enum | Mode { OPTIONAL = Traits::BIT_OPTIONAL | Traits::BIT_ONCE, MANDTAORY = Traits::BIT_MANDTAORY | Traits::BIT_ONCE, MULTIPLE_OPTIONAL = Traits::BIT_OPTIONAL | Traits::BIT_MULTIPLE, MULTIPLE_MANDTAORY = Traits::BIT_MANDTAORY | Traits::BIT_MULTIPLE } |
Public Member Functions | |
| ParseDef (const std::string &name_r, Mode mode_r) | |
| virtual | ~ParseDef () |
| const std::string & | name () const |
| Mode | mode () const |
| bool | isOptional () const |
| bool | isMandatory () const |
| bool | singleDef () const |
| bool | multiDef () const |
| unsigned | visited () const |
| ParseDef & | addNode (ParseDef &subnode_r) |
| Add subnode definition. | |
| ParseDef & | addNode (const std::string &name_r, Mode mode_r) |
| ParseDef & | operator() (ParseDef &subnode_r) |
| Add subnode definition. | |
| ParseDef & | operator() (const std::string &name_r, Mode mode_r) |
| ParseDef | operator[] (const std::string &name_r) |
| Get subnode by name. | |
| void | setConsumer (const shared_ptr< ParseDefConsume > &target_r) |
| Set data consumer. | |
| void | setConsumer (ParseDefConsume *allocatedTarget_r) |
| Set data consumer. | |
| void | setConsumer (ParseDefConsume &target_r) |
| Set data consumer. | |
| void | cancelConsumer () |
| Unset data consumer. | |
| shared_ptr< ParseDefConsume > | getConsumer () const |
| Get data consumer. | |
| void | take (Reader &reader_r) |
| Parse the node. | |
Static Public Attributes | |
| static bool | _debug = false |
Private Types | |
| typedef ParseDefTraits | Traits |
Private Member Functions | |
| ParseDef (const shared_ptr< Impl > &pimpl_r) | |
Private Attributes | |
| RW_pointer< Impl > | _pimpl |
| Pointer to implementation (shared!). | |
Friends | |
| std::ostream & | operator<< (std::ostream &str, const ParseDef &obj) |
| std::ostream & | operator<< (std::ostream &str, const ParseDef::Impl &obj) |
Related Functions | |
| (Note that these are not member functions.) | |
| std::ostream & | operator<< (std::ostream &str, ParseDef::Mode obj) |
Classes | |
| class | Impl |
| ParseDef implementation. More... | |
An xml file like this:
<?xml version="1.0" encoding="UTF-8"?> <syscontent> <ident> <name>mycollection</name> <version epoch="0" ver="1.0" rel="1"/> <description>All the cool stuff...</description> <created>1165270942</created> </ident> <onsys> <entry kind="package" name="pax" epoch="0" ver="3.4" rel="12" arch="x86_64"/> <entry kind="product" name="SUSE_SLES" epoch="0" ver="10" arch="x86_64"/> <entry ... </onsys> </syscontent>
Could be described by:
using namespace xml; struct SycontentNode : public ParseDef { SycontentNode( Mode mode_r ) : ParseDef( "syscontent", mode_r ) { (*this)("ident", OPTIONAL) ("onsys", OPTIONAL) ; (*this)["ident"] ("name", OPTIONAL) ("version", OPTIONAL) ("description", OPTIONAL) ("created", OPTIONAL) ; (*this)["onsys"] ("entry", MULTIPLE_OPTIONAL) ; } };
To parse it using an xml::Reader:
xml::Reader reader( input_r ); SycontentNode rootNode( xml::ParseDef::MANDTAORY ); // Define data consumers here. rootNode.take( reader );
Whithout data consumers this will just parse the file but not retrieve any data. You may attach a consumer derived from xml::ParseDefConsume to each node:
// Parse Edition from ver/rel/eopch attributes. struct ConsumeEdition : public ParseDefConsume { ConsumeEdition( Edition & value_r ) : _value( & value_r ) {} virtual void start( const Node & node_r ) { *_value = Edition( node_r.getAttribute("ver").asString(), node_r.getAttribute("rel").asString(), node_r.getAttribute("epoch").asString() ); } Edition *_value; };
xml::Reader reader( input_r ); SycontentNode rootNode( xml::ParseDef::MANDTAORY ); // Define data consumers here. Edition _edition; rootNode["ident"]["version"].setConsumer ( new ConsumeEdition( _edition ) ); rootNode.take( reader );
That's just one way to collect the data. You could as well use a xml::ParseDefConsumeCallback, and redirect the start call to some arbitrary function or method.
Definition at line 128 of file ParseDef.h.
|
|
Definition at line 130 of file ParseDef.h. |
|
|
Definition at line 133 of file ParseDef.h. |
|
||||||||||||
|
Definition at line 383 of file ParseDef.cc. |
|
|
Definition at line 396 of file ParseDef.cc. |
|
|
Definition at line 387 of file ParseDef.cc. |
|
|
Definition at line 399 of file ParseDef.cc. References _pimpl. |
|
|
Definition at line 402 of file ParseDef.cc. References _pimpl. |
|
|
Definition at line 405 of file ParseDef.cc. References _pimpl. |
|
|
Definition at line 408 of file ParseDef.cc. References _pimpl. |
|
|
Definition at line 411 of file ParseDef.cc. References _pimpl. |
|
|
Definition at line 414 of file ParseDef.cc. References _pimpl. |
|
|
Definition at line 417 of file ParseDef.cc. References _pimpl. |
|
|
Add subnode definition.
Definition at line 420 of file ParseDef.cc. References _pimpl, and zypp::RW_pointer< _D, _Traits >::getPtr(). Referenced by addNode(), and operator()(). |
|
||||||||||||
|
Definition at line 166 of file ParseDef.h. References addNode(). |
|
|
Add subnode definition.
Definition at line 172 of file ParseDef.h. References addNode(). |
|
||||||||||||
|
Definition at line 175 of file ParseDef.h. References addNode(). |
|
|
Get subnode by name.
Definition at line 423 of file ParseDef.cc. References _pimpl, and ZYPP_THROW. |
|
|
Set data consumer.
Definition at line 433 of file ParseDef.cc. References _pimpl. |
|
|
Set data consumer.
Definition at line 436 of file ParseDef.cc. References _pimpl. |
|
|
Set data consumer.
Definition at line 439 of file ParseDef.cc. References _pimpl. |
|
|
Unset data consumer.
Definition at line 442 of file ParseDef.cc. References _pimpl. |
|
|
Get data consumer.
Definition at line 445 of file ParseDef.cc. References _pimpl. |
|
|
Parse the node. This parses the node and all defined subnodes. Unknown subnodes are skipped and leave a warning in the logfile.
Definition at line 449 of file ParseDef.cc. References _pimpl. |
|
||||||||||||
|
Stream output. Definition at line 476 of file ParseDef.cc. |
|
||||||||||||
|
Definition at line 362 of file ParseDef.cc. |
|
||||||||||||
|
ParseDef::Mode stream output. |
|
|
Pointer to implementation (shared!).
Definition at line 213 of file ParseDef.h. Referenced by addNode(), cancelConsumer(), getConsumer(), isMandatory(), isOptional(), mode(), multiDef(), name(), zypp::xml::operator<<(), operator[](), setConsumer(), singleDef(), take(), and visited(). |
|
|
Definition at line 222 of file ParseDef.h. Referenced by zypp::xml::ParseDefImplConsume::debuglog(). |
1.4.6