zypp::parser::XMLNodeIteratorBase Class Reference

Abstract class to iterate over an xml stream. More...

#include <XMLNodeIterator.h>

Inheritance diagram for zypp::parser::XMLNodeIteratorBase:

zypp::parser::XMLNodeIterator< ENTRYTYPE > zypp::parser::XMLNodeIterator< SourceData_Ptr > zypp::parser::XMLNodeIterator< XMLLanguageData_Ptr > zypp::parser::XMLNodeIterator< XMLPatchData_Ptr > zypp::parser::XMLNodeIterator< XMLPatternData_Ptr > zypp::parser::XMLNodeIterator< XMLProductData_Ptr > zypp::parser::XMLNodeIterator< YUMFileListData_Ptr > zypp::parser::XMLNodeIterator< YUMGroupData_Ptr > zypp::parser::XMLNodeIterator< YUMOtherData_Ptr > zypp::parser::XMLNodeIterator< YUMPatchData_Ptr > zypp::parser::XMLNodeIterator< YUMPatchesData_Ptr > zypp::parser::XMLNodeIterator< YUMPatternData_Ptr > zypp::parser::XMLNodeIterator< YUMPrimaryData_Ptr > zypp::parser::XMLNodeIterator< YUMProductData_Ptr > zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr > List of all members.

Public Member Functions

 XMLNodeIteratorBase (std::istream &input, const std::string &baseUrl, const char *validationPath=0)
 Constructor.
 XMLNodeIteratorBase ()
 Constructor for an empty iterator.
virtual ~XMLNodeIteratorBase ()
 Destructor.
bool atEnd () const
 Have we reached the end? A parser error also means "end reached".
bool operator== (const XMLNodeIteratorBase &other) const
 Two iterators are equal if both are at the end or if they are identical.
bool operator!= (const XMLNodeIteratorBase &otherNode) const
 Opposit of operator==.
const XMLParserErrorerrorStatus () const
 returns the error status or 0 if no error the returned pointer is not-owning, it will be deleted upon destruction of the XMLNodeIterator.

Protected Member Functions

virtual bool isInterested (const xmlNodePtr nodePtr)=0
 filter for the xml nodes The derived class decides which xml nodes it is actually interested in.
virtual void _process (const xmlTextReaderPtr readerPtr)=0
 process an xml node and set it as next element The derived class has to produce the ENTRYTYPE object here.
void fetchNext ()
 Fetch the next element and save it as next element.
virtual void setCurrent (const void *data)=0
virtual void * getCurrent () const =0

Static Protected Member Functions

static void errorHandler (void *arg, const char *msg, int severity, xmlTextReaderLocatorPtr locator)
 Internal function to set the _error variable in case of a parser error.

Private Member Functions

XMLNodeIteratorBaseoperator= (const XMLNodeIteratorBase &otherNode)
 assignment is forbidden.
 XMLNodeIteratorBase (const XMLNodeIteratorBase &otherNode)
 copy constructor is forbidden.

Private Attributes

std::auto_ptr< XMLParserError_error
 if an error occured, this contains the error.
std::istream * _input
 contains the istream to read the xml file from.
xmlTextReaderPtr _reader
 contains the xmlTextReader used to parse the xml file.
std::string _baseUrl
 contains the base URL of the xml documentation

Detailed Description

Abstract class to iterate over an xml stream.

Derive from XMLNodeIterator<ENTRYTYPE> to get an iterator that returns ENTRYTYPE objects. A derived class must provide isInterested() and process(). It should also provide a Constructor Derived(std::stream,std::string baseUrl) which must call fetchNext().

The derived iterator class should be compatible with an stl input iterator. Use like this:

for (Iterator iter(anIstream, baseUrl), iter != Iterator.end(), // or: iter() != 0, or ! iter.atEnd() ++iter) { doSomething(*iter) }

The iterator owns the pointer (i.e., caller must not delete it) until the next ++ operator is called. At this time, it will be destroyed (and a new ENTRYTYPE is created.)

If the input is fundamentally flawed so that it makes no sense to continue parsing, XMLNodeIterator will log it and consider the input as finished. You can query the exit status with errorStatus().

Definition at line 133 of file XMLNodeIterator.h.


Constructor & Destructor Documentation

zypp::parser::XMLNodeIteratorBase::XMLNodeIteratorBase std::istream &  input,
const std::string &  baseUrl,
const char *  validationPath = 0
 

Constructor.

Derived classes must call fetchNext() here.

Parameters:
input is the input stream (contains the xml stuff)
baseUrl is the base URL of the xml document FIXME: use XMLParserError::operator<< instead of doing it on my own.

Definition at line 122 of file XMLNodeIterator.cc.

References _reader, errorHandler(), and WAR.

zypp::parser::XMLNodeIteratorBase::XMLNodeIteratorBase  ) 
 

Constructor for an empty iterator.

An empty iterator is already at its end. This is what end() returns ...

Definition at line 147 of file XMLNodeIterator.cc.

zypp::parser::XMLNodeIteratorBase::~XMLNodeIteratorBase  )  [virtual]
 

Destructor.

Definition at line 153 of file XMLNodeIterator.cc.

References _reader.

zypp::parser::XMLNodeIteratorBase::XMLNodeIteratorBase const XMLNodeIteratorBase otherNode  )  [private]
 

copy constructor is forbidden.

Reason: We can't copy an xmlTextReader FIXME: This prevents implementing the end() method for derived classes.

Parameters:
otherNode 
Returns:


Member Function Documentation

bool zypp::parser::XMLNodeIteratorBase::atEnd  )  const
 

Have we reached the end? A parser error also means "end reached".

Returns:
whether the end has been reached.

Definition at line 161 of file XMLNodeIterator.cc.

References _error, and getCurrent().

Referenced by zypp::source::yum::YUMSourceImpl::checkMetadataChecksums(), zypp::source::yum::YUMSourceImpl::createResolvables(), zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr >::operator *(), zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr >::operator++(), zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr >::operator->(), operator==(), and zypp::storage::XMLFilesBackend::resolvablesFromFile().

bool zypp::parser::XMLNodeIteratorBase::operator== const XMLNodeIteratorBase other  )  const
 

Two iterators are equal if both are at the end or if they are identical.

Since you cannot copy an XMLNodeIterator, everything else is not equal.

Parameters:
other the other iterator
Returns:
true if equal

Definition at line 169 of file XMLNodeIterator.cc.

References atEnd().

Referenced by operator!=().

bool zypp::parser::XMLNodeIteratorBase::operator!= const XMLNodeIteratorBase otherNode  )  const [inline]
 

Opposit of operator==.

Parameters:
other the other iterator
Returns:
true if not equal

Definition at line 181 of file XMLNodeIterator.h.

References operator==().

const XMLParserError * zypp::parser::XMLNodeIteratorBase::errorStatus  )  const
 

returns the error status or 0 if no error the returned pointer is not-owning, it will be deleted upon destruction of the XMLNodeIterator.

Returns:
pointer to error status (if exists)

Definition at line 179 of file XMLNodeIterator.cc.

References _error.

virtual bool zypp::parser::XMLNodeIteratorBase::isInterested const xmlNodePtr  nodePtr  )  [protected, pure virtual]
 

filter for the xml nodes The derived class decides which xml nodes it is actually interested in.

For each that is selected, process() will be called an the resulting ENTRYTYPE object used as the next value for the iterator. Documentation for the node structure can be found in the libxml2 documentation. Have a look at LibXMLHelper to access node attributes and contents.

Parameters:
nodePtr points to the xml node in question. Only the node is available, not the subtree. See libxml2 documentation.
Returns:
true if interested

Implemented in zypp::parser::XMLNodeIterator< ENTRYTYPE >, zypp::parser::xmlstore::XMLLanguageParser, zypp::parser::xmlstore::XMLPatchParser, zypp::parser::xmlstore::XMLPatternParser, zypp::parser::xmlstore::XMLProductParser, zypp::parser::xmlstore::XMLSourceCacheParser, zypp::parser::yum::YUMFileListParser, zypp::parser::yum::YUMGroupParser, zypp::parser::yum::YUMOtherParser, zypp::parser::yum::YUMPatchesParser, zypp::parser::yum::YUMPatchParser, zypp::parser::yum::YUMPatternParser, zypp::parser::yum::YUMPrimaryParser, zypp::parser::yum::YUMProductParser, zypp::parser::yum::YUMRepomdParser, zypp::parser::XMLNodeIterator< XMLProductData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatternData_Ptr >, zypp::parser::XMLNodeIterator< XMLLanguageData_Ptr >, zypp::parser::XMLNodeIterator< YUMOtherData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatchData_Ptr >, zypp::parser::XMLNodeIterator< YUMGroupData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatchesData_Ptr >, zypp::parser::XMLNodeIterator< SourceData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatchData_Ptr >, zypp::parser::XMLNodeIterator< YUMPrimaryData_Ptr >, zypp::parser::XMLNodeIterator< YUMFileListData_Ptr >, zypp::parser::XMLNodeIterator< YUMProductData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatternData_Ptr >, and zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr >.

Referenced by fetchNext().

virtual void zypp::parser::XMLNodeIteratorBase::_process const xmlTextReaderPtr  readerPtr  )  [protected, pure virtual]
 

process an xml node and set it as next element The derived class has to produce the ENTRYTYPE object here.

Details about the xml reader is in the libxml2 documentation. You'll most probably want to use xmlTextReaderExpand(reader) to request the full subtree, and then use the links in the resulting node structure to traverse, and class LibXMLHelper to access the attributes and element contents. fetchNext() cannot throw an error since it will be called in the constructor. Instead, in case of a fundamental syntax error the error is saved and will be thrown with the next checkError().

Parameters:
readerPtr points to the xmlTextReader that reads the xml stream.

Implemented in zypp::parser::XMLNodeIterator< ENTRYTYPE >, zypp::parser::XMLNodeIterator< XMLProductData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatternData_Ptr >, zypp::parser::XMLNodeIterator< XMLLanguageData_Ptr >, zypp::parser::XMLNodeIterator< YUMOtherData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatchData_Ptr >, zypp::parser::XMLNodeIterator< YUMGroupData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatchesData_Ptr >, zypp::parser::XMLNodeIterator< SourceData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatchData_Ptr >, zypp::parser::XMLNodeIterator< YUMPrimaryData_Ptr >, zypp::parser::XMLNodeIterator< YUMFileListData_Ptr >, zypp::parser::XMLNodeIterator< YUMProductData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatternData_Ptr >, and zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr >.

Referenced by fetchNext().

void zypp::parser::XMLNodeIteratorBase::fetchNext  )  [protected]
 

Fetch the next element and save it as next element.

Definition at line 185 of file XMLNodeIterator.cc.

References _error, _process(), _reader, errorHandler(), isInterested(), setCurrent(), and xml_assert.

Referenced by zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr >::operator++().

void zypp::parser::XMLNodeIteratorBase::errorHandler void *  arg,
const char *  msg,
int  severity,
xmlTextReaderLocatorPtr  locator
[static, protected]
 

Internal function to set the _error variable in case of a parser error.

It logs the message and saves errors in _error, so that they will be thrown by checkError().

Parameters:
arg set to this with xmlReaderSetErrorHandler()
msg the error message
severity the severity
locator as defined by libxml2

Definition at line 221 of file XMLNodeIterator.cc.

References ERR, WAR, and xml_assert.

Referenced by fetchNext(), and XMLNodeIteratorBase().

virtual void zypp::parser::XMLNodeIteratorBase::setCurrent const void *  data  )  [protected, pure virtual]
 

Implemented in zypp::parser::XMLNodeIterator< ENTRYTYPE >, zypp::parser::XMLNodeIterator< XMLProductData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatternData_Ptr >, zypp::parser::XMLNodeIterator< XMLLanguageData_Ptr >, zypp::parser::XMLNodeIterator< YUMOtherData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatchData_Ptr >, zypp::parser::XMLNodeIterator< YUMGroupData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatchesData_Ptr >, zypp::parser::XMLNodeIterator< SourceData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatchData_Ptr >, zypp::parser::XMLNodeIterator< YUMPrimaryData_Ptr >, zypp::parser::XMLNodeIterator< YUMFileListData_Ptr >, zypp::parser::XMLNodeIterator< YUMProductData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatternData_Ptr >, and zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr >.

Referenced by fetchNext().

virtual void* zypp::parser::XMLNodeIteratorBase::getCurrent  )  const [protected, pure virtual]
 

Implemented in zypp::parser::XMLNodeIterator< ENTRYTYPE >, zypp::parser::XMLNodeIterator< XMLProductData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatternData_Ptr >, zypp::parser::XMLNodeIterator< XMLLanguageData_Ptr >, zypp::parser::XMLNodeIterator< YUMOtherData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatchData_Ptr >, zypp::parser::XMLNodeIterator< YUMGroupData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatchesData_Ptr >, zypp::parser::XMLNodeIterator< SourceData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatchData_Ptr >, zypp::parser::XMLNodeIterator< YUMPrimaryData_Ptr >, zypp::parser::XMLNodeIterator< YUMFileListData_Ptr >, zypp::parser::XMLNodeIterator< YUMProductData_Ptr >, zypp::parser::XMLNodeIterator< YUMPatternData_Ptr >, and zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr >.

Referenced by atEnd().

XMLNodeIteratorBase& zypp::parser::XMLNodeIteratorBase::operator= const XMLNodeIteratorBase otherNode  )  [private]
 

assignment is forbidden.

Reason: We can't copy an xmlTextReader


Member Data Documentation

std::auto_ptr<XMLParserError> zypp::parser::XMLNodeIteratorBase::_error [private]
 

if an error occured, this contains the error.

Definition at line 273 of file XMLNodeIterator.h.

Referenced by atEnd(), errorStatus(), fetchNext(), and zypp::parser::XMLNodeIterator< YUMRepomdData_Ptr >::operator()().

std::istream* zypp::parser::XMLNodeIteratorBase::_input [private]
 

contains the istream to read the xml file from.

Can be 0 if at end or if the current element is the only element left.

Definition at line 279 of file XMLNodeIterator.h.

xmlTextReaderPtr zypp::parser::XMLNodeIteratorBase::_reader [private]
 

contains the xmlTextReader used to parse the xml file.

Definition at line 284 of file XMLNodeIterator.h.

Referenced by fetchNext(), XMLNodeIteratorBase(), and ~XMLNodeIteratorBase().

std::string zypp::parser::XMLNodeIteratorBase::_baseUrl [private]
 

contains the base URL of the xml documentation

Definition at line 289 of file XMLNodeIterator.h.


The documentation for this class was generated from the following files:
Generated on Thu Jul 6 00:07:32 2006 for zypp by  doxygen 1.4.6