12#ifndef ZYPP_PARSER_XML_PARSEDEFCONSUME_H
13#define ZYPP_PARSER_XML_PARSEDEFCONSUME_H
15#include <zypp/base/PtrTypes.h>
16#include <zypp/base/Function.h>
17#include <zypp/base/Hash.h>
18#include <zypp/base/String.h>
19#include <zypp-core/base/DefaultIntegral>
43 virtual void text (
const Node & _node );
45 virtual void done (
const Node & _node );
71 void setRedirect(
const shared_ptr<ParseDefConsume> & target_r );
80 virtual void text (
const Node & _node );
82 virtual void done (
const Node & _node );
107 virtual void start(
const Node & node_r );
108 virtual void text(
const Node & node_r );
109 virtual void cdata(
const Node & node_r );
110 virtual void done(
const Node & node_r );
126 namespace parse_def_assign
128 template <
class Tp>
struct Assigner;
138 virtual void assign(
const char * text_r )
152 virtual void assign(
const char * text_r )
153 { *
_value = Tp( text_r ); }
187 {
return AssignerRef(
new Assigner<Tp>( value_r ) ); }
189 template <
class Tp, Tp TInitial>
190 inline AssignerRef assigner( DefaultIntegral<Tp,TInitial> & value_r )
191 {
return AssignerRef(
new Assigner<Tp>( value_r.get() ) ); }
216 {
_text.push_back( assigner_r ); }
220 {
_attr[attr_r].push_back( assigner_r ); }
235 if ( !
_attr.empty() )
242 if ( !
_text.empty() )
253 void assign(
const std::vector<AssignerRef> & vec_r,
const char * value_r )
256 for_( it, vec_r.begin(), vec_r.end() )
257 (*it)->assign( value_r );
261 std::unordered_map<std::string, std::vector<AssignerRef> >
_attr;
295 Builder(
const std::string & attr_r, Tp & value_r )
302 {
_ptr->add( assigner( value_r ) );
return *
this; }
307 {
_ptr->add( attr_r, assigner( value_r ) );
return *
this; }
311 {
_ptr->prenotify( done_r );
return *
this; }
315 {
_ptr->postnotify( done_r );
return *
this; }
318 operator shared_ptr<ParseDefConsume> ()
const
359 inline parse_def_assign::Builder parseDefAssign( Tp & value_r )
360 {
return parse_def_assign::Builder( value_r ); }
363 inline parse_def_assign::Builder parseDefAssign(
const std::string & attr_r, Tp & value_r )
364 {
return parse_def_assign::Builder( attr_r, value_r ); }
xmlTextReader based interface to Reader's current node.
XmlString value() const
Provides the text value of the node if present.
XmlString getAttribute(const char *name_r) const
Provides a copy of the attribute value with the specified qualified name.
ParseDef consumer that invokes callbacks.
virtual void done(const Node &node_r)
virtual ~ParseDefConsumeCallback()
virtual void text(const Node &node_r)
virtual void start(const Node &node_r)
ParseDefConsumeCallback()
virtual void cdata(const Node &node_r)
virtual void startSubnode(const Node &node_r)
virtual void doneSubnode(const Node &node_r)
function< void(const Node &)> Callback
ParseDef consumer redirecting all events to another consumer.
virtual void start(const Node &_node)
virtual void startSubnode(const Node &_node)
virtual void doneSubnode(const Node &_node)
virtual ~ParseDefConsumeRedirect()
virtual void done(const Node &_node)
shared_ptr< ParseDefConsume > getRedirect() const
ParseDefConsumeRedirect()
virtual void text(const Node &_node)
shared_ptr< ParseDefConsume > _target
void setRedirect(const shared_ptr< ParseDefConsume > &target_r)
virtual void cdata(const Node &_node)
const char * c_str() const
Explicit conversion to const char *.
TInt strtonum(const C_Str &str)
Parsing numbers from string.
bool strToBoolNodefault(const C_Str &str, bool &return_r)
Parse str into a bool if it's a legal true or false string.
shared_ptr< Assigner< void > > AssignerRef
Easy-to use interface to the ZYPP dependency resolver.
Base class for ParseDef consumer.
virtual void start(const Node &_node)
virtual void text(const Node &_node)
virtual void cdata(const Node &_node)
virtual ~ParseDefConsume()
virtual void doneSubnode(const Node &_node)
virtual void done(const Node &_node)
virtual void startSubnode(const Node &_node)
virtual void assign(const char *text_r)
Assigner assigns text to types constructible from char*.
virtual void assign(const char *text_r)
Helper class to build a Consumer.
Builder & operator<<(function< void(const Node &)> done_r)
Set pre notification callback.
Builder()
Contruct Consumer.
Builder & operator()(const std::string &attr_r, Tp &value_r)
Extend Consumer.
Builder & operator>>(function< void(const Node &)> done_r)
Set post notification callback.
Builder(const std::string &attr_r, Tp &value_r)
Contruct Consumer.
Builder & operator()(Tp &value_r)
Extend Consumer.
shared_ptr< Consumer > _ptr
Builder(Tp &value_r)
Contruct Consumer.
ParseDef consumer assigning Node text and attribues values to variables.
virtual void done(const xml::Node &node_r)
void add(const AssignerRef &assigner_r)
Extend Consumer.
std::unordered_map< std::string, std::vector< AssignerRef > > _attr
function< void(const Node &)> _pre
std::vector< AssignerRef > _text
void add(const std::string &attr_r, const AssignerRef &assigner_r)
Extend Consumer.
virtual void text(const xml::Node &node_r)
void postnotify(function< void(const Node &)> post_r)
Set post notification callback.
void prenotify(function< void(const Node &)> pre_r)
Set pre notification callback.
virtual void start(const xml::Node &node_r)
function< void(const Node &)> _post
void assign(const std::vector< AssignerRef > &vec_r, const char *value_r)
#define for_(IT, BEG, END)
Convenient for-loops using iterator.