12 #ifndef ZYPP_PARSER_XML_PARSEDEFCONSUME_H
13 #define ZYPP_PARSER_XML_PARSEDEFCONSUME_H
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
138 virtual void assign(
const char * text_r )
145 template <
class _Type>
146 struct Assigner :
public Assigner<void>
152 virtual void assign(
const char * text_r )
153 { *
_value = _Type( text_r ); }
186 template <
class _Type>
188 {
return AssignerRef(
new Assigner<_Type>( value_r ) ); }
190 template <
class _Tp, _Tp _Initial>
191 inline AssignerRef assigner( DefaultIntegral<_Tp,_Initial> & value_r )
192 {
return AssignerRef(
new Assigner<_Tp>( value_r.get() ) ); }
217 {
_text.push_back( assigner_r ); }
221 {
_attr[attr_r].push_back( assigner_r ); }
236 if ( !
_attr.empty() )
243 if ( !
_text.empty() )
254 void assign(
const std::vector<AssignerRef> & vec_r,
const char * value_r )
257 for_( it, vec_r.begin(), vec_r.end() )
258 (*it)->assign( value_r );
262 std::tr1::unordered_map<std::string, std::vector<AssignerRef> >
_attr;
264 function<void ( const Node & )>
_pre;
265 function<void ( const Node & )>
_post;
289 template <
class _Type>
295 template <
class _Type>
296 Builder(
const std::string & attr_r, _Type & value_r )
301 template <
class _Type>
303 {
_ptr->add( assigner( value_r ) );
return *
this; }
306 template <
class _Type>
308 {
_ptr->add( attr_r, assigner( value_r ) );
return *
this; }
311 Builder & operator<<( function<void ( const Node & )> done_r )
312 {
_ptr->prenotify( done_r );
return *
this; }
316 {
_ptr->postnotify( done_r );
return *
this; }
319 operator shared_ptr<ParseDefConsume> ()
const
359 template <
class _Type>
360 inline parse_def_assign::Builder parseDefAssign( _Type & value_r )
361 {
return parse_def_assign::Builder( value_r ); }
363 template <
class _Type>
364 inline parse_def_assign::Builder parseDefAssign(
const std::string & attr_r, _Type & value_r )
365 {
return parse_def_assign::Builder( attr_r, value_r ); }
374 #endif // ZYPP_PARSER_XML_PARSEDEFCONSUME_H
function< void(const Node &)> _post
virtual void start(const Node &node_r)
void add(const std::string &attr_r, const AssignerRef &assigner_r)
Extend Consumer.
bool strToBoolNodefault(const C_Str &str, bool &return_r)
Parse str into a bool if it's a legal true or false string.
virtual void done(const Node &_node)
virtual void text(const Node &node_r)
Builder & operator()(_Type &value_r)
Extend Consumer.
virtual void doneSubnode(const Node &_node)
virtual void startSubnode(const Node &_node)
virtual void text(const Node &_node)
shared_ptr< ParseDefConsume > _target
shared_ptr< Assigner< void > > AssignerRef
virtual void text(const xml::Node &node_r)
shared_ptr< Consumer > _ptr
virtual void doneSubnode(const Node &_node)
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
ParseDef consumer that invokes callbacks.
Helper class to build a Consumer.
void postnotify(function< void(const Node &)> post_r)
Set post notification callback.
virtual void cdata(const Node &_node)
std::tr1::unordered_map< std::string, std::vector< AssignerRef > > _attr
virtual void cdata(const Node &_node)
XmlString value() const
Provides the text value of the node if present.
virtual ~ParseDefConsumeRedirect()
xmlTextReader based interface to Reader's current node.
virtual void assign(const char *text_r)
virtual ~ParseDefConsume()
virtual void cdata(const Node &node_r)
virtual void assign(const char *text_r)
virtual void text(const Node &_node)
virtual void done(const Node &node_r)
void assign(const std::vector< AssignerRef > &vec_r, const char *value_r)
function< void(const Node &)> Callback
virtual void start(const xml::Node &node_r)
Builder(const std::string &attr_r, _Type &value_r)
Contruct Consumer.
Builder(_Type &value_r)
Contruct Consumer.
Base class for ParseDef consumer.
_It strtonum(const C_Str &str)
Parsing numbers from string.
ParseDef consumer assigning Node text and attribues values to variables.
const char * c_str() const
Explicit conversion to const char *.
std::vector< AssignerRef > _text
ParseDefConsumeCallback()
void prenotify(function< void(const Node &)> pre_r)
Set pre notification callback.
virtual void doneSubnode(const Node &node_r)
shared_ptr< ParseDefConsume > getRedirect() const
XmlString getAttribute(const char *name_r) const
Provides a copy of the attribute value with the specified qualified name.
function< void(const Node &)> _pre
ParseDef consumer redirecting all events to another consumer.
virtual void done(const xml::Node &node_r)
virtual ~ParseDefConsumeCallback()
Builder & operator()(const std::string &attr_r, _Type &value_r)
Extend Consumer.
ParseDefConsumeRedirect()
virtual void start(const Node &_node)
virtual void startSubnode(const Node &node_r)
virtual void done(const Node &_node)
virtual void startSubnode(const Node &_node)
virtual void start(const Node &_node)
void add(const AssignerRef &assigner_r)
Extend Consumer.
Builder()
Contruct Consumer.
Builder & operator>>(function< void(const Node &)> done_r)
Set post notification callback.
void setRedirect(const shared_ptr< ParseDefConsume > &target_r)
Assigner assigns text to types constructible from char*.