#include <XMLNodeIterator.h>
Public Member Functions | |
| XMLNodeIteratorBase (std::istream &input, const std::string &baseUrl, const char *validationPath, parser::ParserProgress::Ptr progress) | |
| Constructor. | |
| XMLNodeIteratorBase (const Pathname xml_file_path, const std::string &baseUrl, const char *validationPath, parser::ParserProgress::Ptr progress) | |
| 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 XMLParserError * | 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. | |
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 | |
| XMLNodeIteratorBase & | operator= (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. | |
| FILE * | _file |
| contains the file 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 | |
| parser::ParserProgress::Ptr | _progress |
| last progress information | |
| long int | _stream_size |
| size of the stream to parse | |
| long int | _bytes_consumed |
| bytes consumed in last report | |
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 135 of file XMLNodeIterator.h.
| zypp::parser::XMLNodeIteratorBase::XMLNodeIteratorBase | ( | std::istream & | input, | |
| const std::string & | baseUrl, | |||
| const char * | validationPath, | |||
| parser::ParserProgress::Ptr | progress | |||
| ) |
Constructor.
Derived classes must call fetchNext() here.
| 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 156 of file XMLNodeIterator.cc.
References _reader, errorHandler(), and WAR.
| zypp::parser::XMLNodeIteratorBase::XMLNodeIteratorBase | ( | const Pathname | xml_file_path, | |
| const std::string & | baseUrl, | |||
| const char * | validationPath, | |||
| parser::ParserProgress::Ptr | progress | |||
| ) |
Constructor.
Derived classes must call fetchNext() here.
| xml_file_path | is the xml file | |
| baseUrl | is the base URL of the xml document FIXME: use XMLParserError::operator<< instead of doing it on my own. |
Definition at line 129 of file XMLNodeIterator.cc.
References _reader, errorHandler(), WAR, and ZYPP_THROW.
| 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 181 of file XMLNodeIterator.cc.
| zypp::parser::XMLNodeIteratorBase::~XMLNodeIteratorBase | ( | ) | [virtual] |
| 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.
| otherNode |
| bool zypp::parser::XMLNodeIteratorBase::atEnd | ( | ) | const |
Have we reached the end? A parser error also means "end reached".
Definition at line 195 of file XMLNodeIterator.cc.
References _error, _progress, and getCurrent().
Referenced by zypp::parser::XMLNodeIterator< shared_ptr >::operator *(), zypp::parser::XMLNodeIterator< shared_ptr >::operator++(), zypp::parser::XMLNodeIterator< shared_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.
| other | the other iterator |
Definition at line 208 of file XMLNodeIterator.cc.
References atEnd().
Referenced by operator!=().
| bool zypp::parser::XMLNodeIteratorBase::operator!= | ( | const XMLNodeIteratorBase & | otherNode | ) | const [inline] |
Opposit of operator==.
| other | the other iterator |
Definition at line 194 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.
Definition at line 218 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.
| nodePtr | points to the xml node in question. Only the node is available, not the subtree. See libxml2 documentation. |
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::XMLNodeIterator< XMLProductData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatternData_Ptr >, zypp::parser::XMLNodeIterator< XMLLanguageData_Ptr >, zypp::parser::XMLNodeIterator< XMLPatchData_Ptr >, and zypp::parser::XMLNodeIterator< shared_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().
| 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< XMLPatchData_Ptr >, and zypp::parser::XMLNodeIterator< shared_ptr >.
Referenced by fetchNext().
| void zypp::parser::XMLNodeIteratorBase::fetchNext | ( | ) | [protected] |
Fetch the next element and save it as next element.
Definition at line 224 of file XMLNodeIterator.cc.
References _bytes_consumed, _error, _process(), _progress, _reader, errorHandler(), isInterested(), setCurrent(), and xml_assert.
Referenced by zypp::parser::XMLNodeIterator< shared_ptr >::operator++(), zypp::parser::xmlstore::XMLLanguageParser::XMLLanguageParser(), zypp::parser::xmlstore::XMLPatchParser::XMLPatchParser(), zypp::parser::xmlstore::XMLPatternParser::XMLPatternParser(), zypp::parser::xmlstore::XMLProductParser::XMLProductParser(), and zypp::parser::xmlstore::XMLSourceCacheParser::XMLSourceCacheParser().
| 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().
| arg | set to this with xmlReaderSetErrorHandler() | |
| msg | the error message | |
| severity | the severity | |
| locator | as defined by libxml2 |
Definition at line 276 of file XMLNodeIterator.cc.
References _baseUrl, _error, _reader, 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< XMLPatchData_Ptr >, and zypp::parser::XMLNodeIterator< shared_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< XMLPatchData_Ptr >, and zypp::parser::XMLNodeIterator< shared_ptr >.
Referenced by atEnd().
| XMLNodeIteratorBase& zypp::parser::XMLNodeIteratorBase::operator= | ( | const XMLNodeIteratorBase & | otherNode | ) | [private] |
assignment is forbidden.
Reason: We can't copy an xmlTextReader
std::auto_ptr<XMLParserError> zypp::parser::XMLNodeIteratorBase::_error [private] |
if an error occured, this contains the error.
Definition at line 286 of file XMLNodeIterator.h.
Referenced by atEnd(), errorHandler(), errorStatus(), fetchNext(), and zypp::parser::XMLNodeIterator< shared_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 292 of file XMLNodeIterator.h.
FILE* zypp::parser::XMLNodeIteratorBase::_file [private] |
contains the file 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 298 of file XMLNodeIterator.h.
contains the xmlTextReader used to parse the xml file.
Definition at line 304 of file XMLNodeIterator.h.
Referenced by errorHandler(), fetchNext(), XMLNodeIteratorBase(), and ~XMLNodeIteratorBase().
std::string zypp::parser::XMLNodeIteratorBase::_baseUrl [private] |
contains the base URL of the xml documentation
Definition at line 309 of file XMLNodeIterator.h.
Referenced by errorHandler().
last progress information
Definition at line 314 of file XMLNodeIterator.h.
Referenced by atEnd(), and fetchNext().
long int zypp::parser::XMLNodeIteratorBase::_stream_size [private] |
long int zypp::parser::XMLNodeIteratorBase::_bytes_consumed [private] |
bytes consumed in last report
Definition at line 323 of file XMLNodeIterator.h.
Referenced by fetchNext().
1.5.3