Mailinglist Archive: zypp-commit (266 mails)

< Previous Next >
[zypp-commit] r11590 - in /trunk/libzypp/zypp/parser: ProductFileReader.cc xml/ParseDefConsume.cc xml/ParseDefConsume.h
  • From: mlandres@xxxxxxxxxxxxxxxx
  • Date: Thu, 06 Nov 2008 14:17:18 -0000
  • Message-id: <20081106141718.DF29C2F204@xxxxxxxxxxxxxxxx>
Author: mlandres
Date: Thu Nov 6 15:17:18 2008
New Revision: 11590

URL: http://svn.opensuse.org/viewcvs/zypp?rev=11590&view=rev
Log:
Add Specialized ParseDefConsumer to assign values.

Modified:
trunk/libzypp/zypp/parser/ProductFileReader.cc
trunk/libzypp/zypp/parser/xml/ParseDefConsume.cc
trunk/libzypp/zypp/parser/xml/ParseDefConsume.h

Modified: trunk/libzypp/zypp/parser/ProductFileReader.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/ProductFileReader.cc?rev=11590&r1=11589&r2=11590&view=diff
==============================================================================
--- trunk/libzypp/zypp/parser/ProductFileReader.cc (original)
+++ trunk/libzypp/zypp/parser/ProductFileReader.cc Thu Nov 6 15:17:18 2008
@@ -111,8 +111,11 @@

std::ostream & operator<<( std::ostream & str, const
ProductFileData::Upgrade & obj )
{
- str << str::form( "|upgrade|%s|",
- obj.name().c_str() );
+ str << str::form( "|upgrade|%s|%s|%s|%s|",
+ obj.name().c_str(),
+ obj.product().c_str(),
+ obj.status().c_str(),
+ (obj.notify() ? "notify" : "noNotify") );
return str;
}
/////////////////////////////////////////////////////////////////
@@ -121,29 +124,6 @@
//
/////////////////////////////////////////////////////////////////

- /** Assign types constructible from \c char* */
- template <class _Val>
- struct ConsumeVal : public xml::ParseDefConsume
- {
- ConsumeVal( _Val & value_r )
- : _value( &value_r )
- {}
-
- virtual void text( const xml::Node & node_r )
- {
- *_value = _Val( node_r.value().c_str() );
- }
-
- private:
- _Val * _value;
- };
-
- template <class _Val>
- shared_ptr<xml::ParseDefConsume> consumeVal( _Val & value_r )
- { return shared_ptr<xml::ParseDefConsume>( new ConsumeVal<_Val>( value_r )
); }
-
- /////////////////////////////////////////////////////////////////
-
struct ProductNode : public xml::ParseDef, public xml::ParseDefConsume
{
ProductNode( ProductFileData::Impl & pdata_r )
@@ -151,20 +131,20 @@
, _pdata( pdata_r )
{
(*this)
- ("vendor", OPTIONAL, consumeVal( _pdata._vendor ) )
- ("name", MANDTAORY, consumeVal( _pdata._name ) )
- ("version", OPTIONAL, consumeVal( _version ) )
- ("release", OPTIONAL, consumeVal( _release ) )
- ("arch", OPTIONAL, consumeVal( _pdata._arch ) )
- ("productline", OPTIONAL, consumeVal( _pdata._productline ) )
+ ("vendor", OPTIONAL, xml::parseDefAssignText(
_pdata._vendor ) )
+ ("name", MANDTAORY, xml::parseDefAssignText( _pdata._name
) )
+ ("version", OPTIONAL, xml::parseDefAssignText( _version ) )
+ ("release", OPTIONAL, xml::parseDefAssignText( _release ) )
+ ("arch", OPTIONAL, xml::parseDefAssignText( _pdata._arch
) )
+ ("productline", OPTIONAL, xml::parseDefAssignText(
_pdata._productline ) )
("register", OPTIONAL)
- ("updaterepokey", OPTIONAL, consumeVal( _pdata._updaterepokey ) )
+ ("updaterepokey", OPTIONAL, xml::parseDefAssignText(
_pdata._updaterepokey ) )
("upgrades", OPTIONAL)
;

(*this)["register"]
- ("target", OPTIONAL, consumeVal( _pdata._registerTarget ) )
- ("release", OPTIONAL, consumeVal( _pdata._registerRelease )
)
+ ("target", OPTIONAL, xml::parseDefAssignText(
_pdata._registerTarget ) )
+ ("release", OPTIONAL, xml::parseDefAssignText(
_pdata._registerRelease ) )
;

(*this)["upgrades"]
@@ -172,22 +152,24 @@
;

(*this)["upgrades"]["upgrade"]
- ("name", OPTIONAL, consumeVal( _upgrade._name ) )
- ("summary", OPTIONAL, consumeVal( _upgrade._summary ) )
- ("repository", OPTIONAL, consumeVal( _upgrade._product ) )
- ("notify", OPTIONAL) // need consume to bool!
- ("status", OPTIONAL, consumeVal( _upgrade._status ) )
+ ("name", OPTIONAL, xml::parseDefAssignText(
_upgrade._name ) )
+ ("summary", OPTIONAL, xml::parseDefAssignText(
_upgrade._summary ) )
+ ("repository", OPTIONAL, xml::parseDefAssignText(
_upgrade._product ) )
+ ("notify", OPTIONAL, xml::parseDefAssignText(
_upgrade._notify ) )
+ ("status", OPTIONAL, xml::parseDefAssignText(
_upgrade._status ) )
;

- // not a clean way to collect the END_ELEMENT calls, but
+ // Not a clean way to collect the END_ELEMENT calls, but
// works for this case. NEEDS CLEANUP!
+
+ // xml::ParseDef::_debug = true;
setConsumer( *this );
(*this)["upgrades"].setConsumer( *this );
}

virtual void done ( const xml::Node & _node )
{
- //SEC << "DONE.... " << _node.localName() << endl;
+ // SEC << "DONE.... " << _node.localName() << endl;
if ( _node.localName() == name() )
{
// this END node
@@ -198,6 +180,7 @@
// collect upgrade
ProductFileData::Upgrade cdata( new ProductFileData::Upgrade::Impl(
_upgrade ) );
_pdata._upgrades.push_back( cdata );
+ _upgrade = ProductFileData::Upgrade::Impl();
}
}

@@ -219,7 +202,6 @@

try
{
- //xml::ParseDef::_debug = true;
xml::Reader reader( input_r );
ProductNode rootNode( *pdataImpl );
rootNode.take( reader );

Modified: trunk/libzypp/zypp/parser/xml/ParseDefConsume.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/xml/ParseDefConsume.cc?rev=11590&r1=11589&r2=11590&view=diff
==============================================================================
--- trunk/libzypp/zypp/parser/xml/ParseDefConsume.cc (original)
+++ trunk/libzypp/zypp/parser/xml/ParseDefConsume.cc Thu Nov 6 15:17:18 2008
@@ -158,13 +158,13 @@

void ParseDefConsumeCallback::startSubnode( const Node & node_r )
{
- if ( _start )
+ if ( _startSubnode )
_startSubnode( node_r );
}

void ParseDefConsumeCallback::doneSubnode( const Node & node_r )
{
- if ( _done )
+ if ( _doneSubnode )
_doneSubnode( node_r );
}


Modified: trunk/libzypp/zypp/parser/xml/ParseDefConsume.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/xml/ParseDefConsume.h?rev=11590&r1=11589&r2=11590&view=diff
==============================================================================
--- trunk/libzypp/zypp/parser/xml/ParseDefConsume.h (original)
+++ trunk/libzypp/zypp/parser/xml/ParseDefConsume.h Thu Nov 6 15:17:18 2008
@@ -12,8 +12,12 @@
#ifndef ZYPP_PARSER_XML_PARSEDEFCONSUME_H
#define ZYPP_PARSER_XML_PARSEDEFCONSUME_H

-#include <zypp/base/PtrTypes.h>
-#include <zypp/base/Function.h>
+#include "zypp/base/PtrTypes.h"
+#include "zypp/base/Function.h"
+#include "zypp/base/String.h"
+#include "zypp/base/DefaultIntegral.h"
+
+#include "zypp/parser/xml/Node.h"

///////////////////////////////////////////////////////////////////
namespace zypp
@@ -28,7 +32,8 @@
//
// CLASS NAME : ParseDefConsume
//
- /** */
+ /** Base class for ParseDef consumer.
+ */
struct ParseDefConsume
{
virtual ~ParseDefConsume();
@@ -47,7 +52,7 @@
//
// CLASS NAME : ParseDefConsumeRedirect
//
- /**
+ /** ParseDef consumer redirecting all events to another consumer.
* \note Allocated <tt>ParseDefConsume *</tt> passed are
* immediately wraped into a shared_ptr.
*/
@@ -86,7 +91,8 @@
//
// CLASS NAME : ParseDefConsumeCallback
//
- /** */
+ /** ParseDef consumer that invokes callbacks.
+ */
class ParseDefConsumeCallback : public ParseDefConsume
{
public:
@@ -114,6 +120,87 @@
};
///////////////////////////////////////////////////////////////////

+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ParseDefAssignText<_Type>
+ //
+ /** Assign a \ref Node text to types constructible from \c char*.
+ * \code
+ * struct ProductNode : public xml::ParseDef
+ * {
+ * ProductNode( ProductFileData::Impl & pdata_r )
+ * : ParseDef( "product", MANDTAORY )
+ * {
+ * (*this)
+ * ("vendor", OPTIONAL, parseDefAssignText( _vendor ) )
+ * ("name", MANDTAORY, parseDefAssignText( _name ) )
+ * ...
+ * }
+ *
+ * std::string _vendor;
+ * std::string _name;
+ * };
+ * \endcode
+ */
+ template <class _Type>
+ struct ParseDefAssignText : public xml::ParseDefConsume
+ {
+ ParseDefAssignText( _Type & value_r )
+ : _value( &value_r )
+ {}
+
+ virtual void text( const xml::Node & node_r )
+ {
+ *_value = _Type( node_r.value().c_str() );
+ }
+
+ private:
+ _Type * _value;
+ };
+
+ /** \name ParseDefAssignText specialisation for numeric and boolean values.
+ * \relates ParseDefAssignText
+ */
+ //@{
+ template <>
+ inline void ParseDefAssignText<short>::text( const xml::Node & node_r ) {
str::strtonum( node_r.value().c_str(), *_value ); }
+ template <>
+ inline void ParseDefAssignText<int>::text( const xml::Node & node_r ) {
str::strtonum( node_r.value().c_str(), *_value ); }
+ template <>
+ inline void ParseDefAssignText<long>::text( const xml::Node & node_r ) {
str::strtonum( node_r.value().c_str(), *_value ); }
+ template <>
+ inline void ParseDefAssignText<long long>::text( const xml::Node & node_r
) { str::strtonum( node_r.value().c_str(), *_value ); }
+ template <>
+ inline void ParseDefAssignText<unsigned short>::text( const xml::Node &
node_r ) { str::strtonum( node_r.value().c_str(), *_value ); }
+ template <>
+ inline void ParseDefAssignText<unsigned>::text( const xml::Node & node_r )
{ str::strtonum( node_r.value().c_str(), *_value ); }
+ template <>
+ inline void ParseDefAssignText<unsigned long>::text( const xml::Node &
node_r ) { str::strtonum( node_r.value().c_str(), *_value ); }
+ template <>
+ inline void ParseDefAssignText<unsigned long long>::text( const xml::Node
& node_r ) { str::strtonum( node_r.value().c_str(), *_value ); }
+ template <>
+ inline void ParseDefAssignText<bool>::text( const xml::Node & node_r ) {
str::strToBoolNodefault( node_r.value().c_str(), *_value ); }
+ //@}
+
+ /** \name ParseDefAssignText Convenience constructor.
+ * \relates ParseDefAssignText
+ *
+ * This returns a \c shared_ptr<xml::ParseDefConsume> ready to be passed
+ * to a \ref ParseDef node.
+ */
+ //@{
+ template <class _Type>
+ shared_ptr<xml::ParseDefConsume> parseDefAssignText( _Type & value_r )
+ { return shared_ptr<xml::ParseDefConsume>( new ParseDefAssignText<_Type>(
value_r ) ); }
+
+ template<class _Tp, _Tp _Initial>
+ shared_ptr<xml::ParseDefConsume> parseDefAssignText(
DefaultIntegral<_Tp,_Initial> & value_r )
+ { return shared_ptr<xml::ParseDefConsume>( new ParseDefAssignText<_Tp>(
value_r.get() ) ); }
+ //@}
+
+ ///////////////////////////////////////////////////////////////////
+
+
/////////////////////////////////////////////////////////////////
} // namespace xml
///////////////////////////////////////////////////////////////////

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages