82 DBG << tag_r << node_r << endl;
99 typedef std::map<std::string, ImplPtr>
SubNodes;
102 Impl(
const std::string & name_r,
Mode mode_r,
const shared_ptr<ParseDefConsume> & target_r = shared_ptr<ParseDefConsume>() )
115 it->second->_parent = NULL;
136 SubNodes::const_iterator it =
_subnodes.find( name_r );
155 std::string
exstr(
const std::string & what_r,
const Impl & impl_r )
const
157 std::ostringstream str;
158 str << impl_r <<
": " << what_r;
161 std::string
exstr(
const std::string & what_r,
const Impl & impl_r,
const Reader & reader_r )
const
163 std::ostringstream str;
164 str << impl_r <<
": " << what_r <<
" |reading " << *reader_r;
188 std::pair<SubNodes::iterator, bool> res
189 =
_subnodes.insert( std::make_pair( subnode_r->_name, subnode_r ) );
195 if ( res.first->second->_parent )
199 res.first->second->_parent =
this;
209 if ( reader_r->
nodeType() != XML_READER_TYPE_ELEMENT )
211 if ( reader_r->
depth() == 0 )
220 }
while( reader_r->
nodeType() != XML_READER_TYPE_ELEMENT );
227 if ( reader_r->
name() != _name )
231 if ( _visited >= 1 && !
multiDef() )
238 _parseDepth = reader_r->
depth();
241 _callback.start( *reader_r );
250 for (
bool done =
false; ! done ; )
260 case XML_READER_TYPE_ELEMENT:
267 _callback.startSubnode( *reader_r );
268 sub->take( reader_r );
269 _callback.doneSubnode( *reader_r );
274 WAR <<
"Skip unknown node " << *reader_r <<
" in "<< *
this << endl;
275 skipNode( reader_r );
280 case XML_READER_TYPE_END_ELEMENT:
282 if ( reader_r->
depth() == _parseDepth
283 && reader_r->
name() == _name )
293 case XML_READER_TYPE_TEXT:
295 _callback.text( *reader_r );
298 case XML_READER_TYPE_CDATA:
300 _callback.cdata( *reader_r );
312 for ( SubNodes::iterator it = _subnodes.begin(); it != _subnodes.end(); ++it )
314 if ( ! it->second->_visited && it->second->isMandatory() )
318 it->second->_visited = 0;
321 _callback.done( *reader_r );
335 ( exstr(
str::form(
"EOF while looking for [%d] <\\%s>",
350 return str <<
"ParseDef(" << obj.
_name
374 : _pimpl( new
Impl( name_r, mode_r, target_r ) )
396 {
return _pimpl->isOptional(); }
399 {
return _pimpl->isMandatory(); }
402 {
return _pimpl->singleDef(); }
405 {
return _pimpl->multiDef(); }
408 {
return _pimpl->_visited; }
411 {
_pimpl->addNode( subnode_r.
_pimpl.getPtr() );
return *
this; }
415 shared_ptr<Impl> retimpl(
_pimpl->getNode( name_r ) );
424 {
_pimpl->_callback.setRedirect( target_r ); }
427 {
_pimpl->_callback.setRedirect( allocatedTarget_r ); }
430 {
_pimpl->_callback.setRedirect( target_r ); }
433 {
_pimpl->_callback.cancelRedirect(); }
436 {
return _pimpl->_callback.getRedirect(); }
440 {
_pimpl->take( reader_r ); }
451 #define X(T) case ParseDef::T: return str << #T
454 X(MULTIPLE_OPTIONAL);
455 X(MULTIPLE_MANDTAORY);
friend std::ostream & operator<<(std::ostream &str, const ParseDef::Impl &obj)
virtual void start(const Node &node_r)
RW_pointer< Impl > _pimpl
Pointer to implementation (shared!)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
ParseDef(const std::string &name_r, Mode mode_r)
Define a xml node structure to parse.
virtual void done(const Node &_node)
virtual void doneSubnode(const Node &_node)
virtual void startSubnode(const Node &_node)
virtual void text(const Node &_node)
int isEmptyElement() const
Check if the current node is empty.
shared_ptr< Impl > ImplPtr
int depth() const
The depth of the node in the tree.
bool skipNode(Reader &reader_r)
Skip the current node.
DefaultIntegral< int,-1 > _parseDepth
shared_ptr< ParseDefConsume > getConsumer() const
Get data consumer.
const std::string & name() const
virtual void cdata(const Node &_node)
Assign a vaiable a certain value when going out of scope.
Parse exceptions related to the documents node structure.
xmlTextReader based interface to Reader's current node.
virtual void done(const Node &node_r)
std::map< std::string, ImplPtr > SubNodes
void take(Reader &reader_r)
Parse the node.
DefaultIntegral< unsigned, 0 > _visited
void addNode(const ImplPtr &subnode_r)
ImplPtr getNode(const std::string &name_r) const
Exceptions when building a ParseDef tree.
XmlString name() const
The qualified name of the node, equal to Prefix :LocalName.
bool seekToEndNode(int depth_r, const std::string &name_r)
virtual void startSubnode(const Node &node_r)
Base class for ParseDef consumer.
const char * c_str() const
Explicit conversion to const char *.
void take(Reader &reader_r)
ParseDefImplConsume _callback
std::string asString() const
Explicit conversion to std::string.
ParseDef & addNode(ParseDef &subnode_r)
Add subnode definition.
bit::BitField< ModeBitsType > ModeBits
std::string form(const char *format,...)
Printf style construction of std::string.
virtual void doneSubnode(const Node &node_r)
ParseDef consumer redirecting all events to another consumer.
virtual void cdata(const Node &node_r)
std::string exstr(const std::string &what_r, const Impl &impl_r, const Reader &reader_r) const
std::ostream & operator<<(std::ostream &str, const ReadState &obj)
void cancelConsumer()
Unset data consumer.
friend std::ostream & operator<<(std::ostream &str, const ParseDef &obj)
ParseDef operator[](const std::string &name_r)
Get subnode by name.
virtual void start(const Node &_node)
void setConsumer(const shared_ptr< ParseDefConsume > &target_r)
Set data consumer.
void debuglog(const char *const tag_r, const Node &node_r)
virtual void text(const Node &node_r)
Range of bits starting at bit _begin with length _size.
NodeType nodeType() const
Get the node type of the current node.
void setRedirect(const shared_ptr< ParseDefConsume > &target_r)
std::string exstr(const std::string &what_r, const Impl &impl_r) const
xmlTextReader based interface to iterate xml streams.