ref: refs/heads/master
commit 1b677fb9e2247ebbd64b24771d7f772a7d6fd0fe
Author: Michael Andres
Date: Fri Feb 6 13:25:24 2009 +0100
Fix ProductFile parser to use parseDefAssign end_element callbacks.
---
tests/parser/ProductFileReader_test.cc | 2 +-
zypp/parser/ProductFileReader.cc | 60 +++++++++++++++-----------------
2 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/tests/parser/ProductFileReader_test.cc b/tests/parser/ProductFileReader_test.cc
index 6c7cd18..b050458 100644
--- a/tests/parser/ProductFileReader_test.cc
+++ b/tests/parser/ProductFileReader_test.cc
@@ -23,7 +23,7 @@ BOOST_AUTO_TEST_CASE(basic)
BOOST_CHECK_EQUAL( data.registerRelease(), "whatever" );
BOOST_CHECK_EQUAL( data.updaterepokey(), "A43242DKD" );
- BOOST_CHECK_EQUAL( data.upgrades().size(), 2 );
+ BOOST_REQUIRE_EQUAL( data.upgrades().size(), 2 );
BOOST_CHECK_EQUAL( data.upgrades()[0].name(), "openSUSE_11.1" );
BOOST_CHECK_EQUAL( data.upgrades()[0].summary(), "openSUSE 11.1" );
diff --git a/zypp/parser/ProductFileReader.cc b/zypp/parser/ProductFileReader.cc
index 1f5bdfb..d3c8ec3 100644
--- a/zypp/parser/ProductFileReader.cc
+++ b/zypp/parser/ProductFileReader.cc
@@ -124,7 +124,7 @@ namespace zypp
//
/////////////////////////////////////////////////////////////////
- struct ProductNode : public xml::ParseDef, public xml::ParseDefConsume
+ struct ProductNode : public xml::ParseDef
{
ProductNode( ProductFileData::Impl & pdata_r )
: ParseDef( "product", MANDTAORY )
@@ -148,7 +148,8 @@ namespace zypp
;
(*this)["upgrades"]
- ("upgrade", MULTIPLE_OPTIONAL)
+ ("upgrade", MULTIPLE_OPTIONAL, xml::parseDefAssign()
+ >> bind( &ProductNode::doneUpgrade, this, _1 ))
;
(*this)["upgrades"]["upgrade"]
@@ -159,37 +160,32 @@ namespace zypp
("status", OPTIONAL, xml::parseDefAssign( _upgrade._status ) )
;
- // Not a clean way to collect the END_ELEMENT calls, but
- // works for this case. NEEDS CLEANUP!
-
+ // </product> callback to build edition.
+ setConsumer( xml::parseDefAssign() >> bind( &ProductNode::done, this, _1 ) );
// xml::ParseDef::_debug = true;
- setConsumer( *this );
- (*this)["upgrades"].setConsumer( *this );
- }
-
- virtual void done ( const xml::Node & _node )
- {
- // SEC << "DONE.... " << _node.localName() << endl;
- if ( _node.localName() == name() )
- {
- // this END node
- _pdata._edition = Edition( _version, _release );
- }
- else if ( _node.localName() == "upgrade" )
- {
- // collect upgrade
- ProductFileData::Upgrade cdata( new ProductFileData::Upgrade::Impl( _upgrade ) );
- _pdata._upgrades.push_back( cdata );
- _upgrade = ProductFileData::Upgrade::Impl();
- }
- }
-
- ProductFileData::Impl & _pdata;
-
- std::string _version;
- std::string _release;
-
- ProductFileData::Upgrade::Impl _upgrade;
+ }
+
+ /** collect _upgrade */
+ void doneUpgrade( const xml::Node & _node )
+ {
+ ProductFileData::Upgrade cdata( new ProductFileData::Upgrade::Impl( _upgrade ) );
+ _pdata._upgrades.push_back( cdata );
+ _upgrade = ProductFileData::Upgrade::Impl();
+ }
+
+ /** finaly */
+ void done( const xml::Node & _node )
+ {
+ _pdata._edition = Edition( _version, _release );
+ }
+
+ private:
+ ProductFileData::Impl & _pdata;
+
+ std::string _version;
+ std::string _release;
+
+ ProductFileData::Upgrade::Impl _upgrade;
};
bool ProductFileReader::parse( const InputStream & input_r ) const
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org