libzypp: zypp::xml::ParseDef Class Reference

libzypp 17.38.5

zypp::xml::ParseDef Class Reference

Define a xml node structure to parse. More...

`#include <zypp/parser/xml/ParseDef.h>`

Inheritance diagram for zypp::xml::ParseDef:

## Classes
class | Impl
| ParseDef implementation. More...

## 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 (std::string name_r, Mode mode_r)
| ParseDef (std::string name_r, Mode mode_r, shared_ptr< ParseDefConsume > target_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 & | addNode (const std::string &name_r, Mode mode_r, const shared_ptr< ParseDefConsume > &target_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, Mode mode_r, const shared_ptr< ParseDefConsume > &target_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
using | Traits = ParseDefTraits

## 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 Symbols
(Note that these are not member symbols.)
std::ostream & | operator<< (std::ostream &str, ParseDef::Mode obj)
| ParseDef::Mode stream output.
std::ostream & | operator<< (std::ostream &str, const ParseDef &obj)
| Stream output.

## Detailed Description

Define a xml node structure to parse.

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>
zypp::xml::ParseDef::name
const std::string & name() const
Definition ParseDef.cc:394
zypp::syscontent
Definition SysContent.cc:27
zypp::xml
Definition libxmlfwd.cc:22
zypp::kind
const ResKind ResTraits< Package >::kind(ResKind::package)

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)
;
}
};
zypp::xml::ParseDef::ParseDef
ParseDef(std::string name_r, Mode mode_r)
Definition ParseDef.cc:374
zypp::xml::ParseDef::Mode
Mode
Definition ParseDef.h:134
zypp::xml::ParseDef::OPTIONAL
@ OPTIONAL
Definition ParseDef.h:135
zypp::xml::ParseDef::MULTIPLE_OPTIONAL
@ MULTIPLE_OPTIONAL
Definition ParseDef.h:137

To parse it using an xml::Reader:

xml::Reader reader( input_r );
SycontentNode rootNode( xml::ParseDef::MANDTAORY );
// Define data consumers here.
rootNode.take( reader );
zypp::xml::ParseDef::MANDTAORY
@ MANDTAORY
Definition ParseDef.h:136
zypp::xml::Reader
xmlTextReader based interface to iterate xml streams.
Definition Reader.h:96

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;
};
zypp::Edition
Edition represents [epoch:]version[-release].
Definition Edition.h:61
zypp::xml::Node
xmlTextReader based interface to Reader's current node.
Definition Node.h:36
zypp::xml::Node::getAttribute
XmlString getAttribute(const char *name_r) const
Provides a copy of the attribute value with the specified qualified name.
Definition Node.h:71
zypp::xml::XmlString::asString
std::string asString() const
Explicit conversion to std::string.
Definition XmlString.h:77
zypp::xml::ParseDefConsume
Base class for ParseDef consumer.
Definition ParseDefConsume.h:40
zypp::xml::ParseDefConsume::start
virtual void start(const Node &_node)
Definition ParseDefConsume.cc:30

See also
  xml::ParseDefConsume

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.

## Member Typedef Documentation

## ◆ Traits

using zypp::xml::ParseDef::Traits = ParseDefTraits
| private

Definition at line 130 of file ParseDef.h.

## Member Enumeration Documentation

## ◆ Mode

enum zypp::xml::ParseDef::Mode

Enumerator
OPTIONAL |
MANDTAORY |
MULTIPLE_OPTIONAL |
MULTIPLE_MANDTAORY |

Definition at line 133 of file ParseDef.h.

## Constructor & Destructor Documentation

## ◆ ParseDef() [1/3]

zypp::xml::ParseDef::ParseDef | ( | std::string | name_r,
|  | Mode | mode_r )

Definition at line 374 of file ParseDef.cc.

## ◆ ParseDef() [2/3]

zypp::xml::ParseDef::ParseDef | ( | std::string | name_r,
|  | Mode | mode_r,
|  | shared_ptr< ParseDefConsume > | target_r )

Definition at line 378 of file ParseDef.cc.

## ◆ ~ParseDef()

zypp::xml::ParseDef::~ParseDef | ( |  | ) |
| virtual

Definition at line 391 of file ParseDef.cc.

## ◆ ParseDef() [3/3]

zypp::xml::ParseDef::ParseDef | ( | const shared_ptr< Impl > & | pimpl_r | ) |
| private

Definition at line 382 of file ParseDef.cc.

## Member Function Documentation

## ◆ name()

const std::string & zypp::xml::ParseDef::name | ( |  | ) | const

Definition at line 394 of file ParseDef.cc.

## ◆ mode()

ParseDef::Mode zypp::xml::ParseDef::mode | ( |  | ) | const

Definition at line 397 of file ParseDef.cc.

## ◆ isOptional()

bool zypp::xml::ParseDef::isOptional | ( |  | ) | const

Definition at line 400 of file ParseDef.cc.

## ◆ isMandatory()

bool zypp::xml::ParseDef::isMandatory | ( |  | ) | const

Definition at line 403 of file ParseDef.cc.

## ◆ singleDef()

bool zypp::xml::ParseDef::singleDef | ( |  | ) | const

Definition at line 406 of file ParseDef.cc.

## ◆ multiDef()

bool zypp::xml::ParseDef::multiDef | ( |  | ) | const

Definition at line 409 of file ParseDef.cc.

## ◆ visited()

unsigned zypp::xml::ParseDef::visited | ( |  | ) | const

Definition at line 412 of file ParseDef.cc.

## ◆ addNode() [1/3]

ParseDef & zypp::xml::ParseDef::addNode | ( | ParseDef & | subnode_r | ) |

Add subnode definition.

Note
  As ParseDef copies share their implementation you can not add the same subnode to multiple parents.

Returns
  *this.

Exceptions

  ParseDefBuildException | if a subnode with the same name is already defined, or if the subnode is already subnode of an other ParseDef.

Definition at line 415 of file ParseDef.cc.

## ◆ addNode() [2/3]

ParseDef & zypp::xml::ParseDef::addNode | ( | const std::string & | name_r,
|  | Mode | mode_r )
| inline

Definition at line 167 of file ParseDef.h.

## ◆ addNode() [3/3]

ParseDef & zypp::xml::ParseDef::addNode | ( | const std::string & | name_r,
|  | Mode | mode_r,
|  | const shared_ptr< ParseDefConsume > & | target_r )
| inline

Definition at line 170 of file ParseDef.h.

## ◆ operator()() [1/3]

ParseDef & zypp::xml::ParseDef::operator() | ( | ParseDef & | subnode_r | ) |
| inline

Add subnode definition.

See also
  addNode.

Definition at line 176 of file ParseDef.h.

## ◆ operator()() [2/3]

ParseDef & zypp::xml::ParseDef::operator() | ( | const std::string & | name_r,
|  | Mode | mode_r )
| inline

Definition at line 179 of file ParseDef.h.

## ◆ operator()() [3/3]

ParseDef & zypp::xml::ParseDef::operator() | ( | const std::string & | name_r,
|  | Mode | mode_r,
|  | const shared_ptr< ParseDefConsume > & | target_r )
| inline

Definition at line 182 of file ParseDef.h.

## ◆ operator[]()

ParseDef zypp::xml::ParseDef::operator[] | ( | const std::string & | name_r | ) |

Get subnode by name.

Exceptions

  ParseDefBuildException | if no subnode with name_r exists.

Definition at line 418 of file ParseDef.cc.

## ◆ setConsumer() [1/3]

void zypp::xml::ParseDef::setConsumer | ( | const shared_ptr< ParseDefConsume > & | target_r | ) |

Set data consumer.

Definition at line 428 of file ParseDef.cc.

## ◆ setConsumer() [2/3]

void zypp::xml::ParseDef::setConsumer | ( | ParseDefConsume * | allocatedTarget_r | ) |

Set data consumer.

Note
  allocatedTarget_r is immediately wraped into a shared_ptr.

Definition at line 431 of file ParseDef.cc.

## ◆ setConsumer() [3/3]

void zypp::xml::ParseDef::setConsumer | ( | ParseDefConsume & | target_r | ) |

Set data consumer.

Definition at line 434 of file ParseDef.cc.

## ◆ cancelConsumer()

void zypp::xml::ParseDef::cancelConsumer | ( |  | ) |

Unset data consumer.

Definition at line 437 of file ParseDef.cc.

## ◆ getConsumer()

shared_ptr< ParseDefConsume > zypp::xml::ParseDef::getConsumer | ( |  | ) | const

Get data consumer.

Definition at line 440 of file ParseDef.cc.

## ◆ take()

void zypp::xml::ParseDef::take | ( | Reader & | reader_r | ) |

Parse the node.

This parses the node and all defined subnodes. Unknown subnodes are skipped and leave a warning in the logfile.

Precondition
  Current node must be XML_READER_TYPE_ELEMENT matching this ParseDefs name.

Postcondition
  All data parsed. At the corresponding end node. (XML_READER_TYPE_END_ELEMENT or atill at the same node, if it'a an empty element <node />).

Exceptions

  ParseDefException | on error.

Definition at line 444 of file ParseDef.cc.

## Friends And Related Symbol Documentation

## ◆ operator<< [1/4]

std::ostream & operator<< | ( | std::ostream & | str,
|  | const ParseDef & | obj )
| friend

Definition at line 471 of file ParseDef.cc.

## ◆ operator<< [2/4]

std::ostream & operator<< | ( | std::ostream & | str,
|  | const ParseDef::Impl & | obj )
| friend

Definition at line 353 of file ParseDef.cc.

## ◆ operator<<() [3/4]

std::ostream & operator<< | ( | std::ostream & | str,
|  | ParseDef::Mode | obj )
| related

ParseDef::Mode stream output.

Definition at line 452 of file ParseDef.cc.

## ◆ operator<<() [4/4]

std::ostream & operator<< | ( | std::ostream & | str,
|  | const ParseDef & | obj )
| related

Stream output.

Definition at line 471 of file ParseDef.cc.

## Member Data Documentation

## ◆ _pimpl

RW_pointer<Impl> zypp::xml::ParseDef::_pimpl
| private

Pointer to implementation (shared!).

Definition at line 222 of file ParseDef.h.

## ◆ _debug

bool zypp::xml::ParseDef::_debug = false
| static

Definition at line 229 of file ParseDef.h.

The documentation for this class was generated from the following files:

- zypp/parser/xml/ParseDef.h
- zypp/parser/xml/ParseDef.cc