ref: refs/heads/ma-tmp-pqt
commit 0057071c0ae5526b5de8604046407f6b57037d3a
Author: Michael Andres
Date: Thu Apr 16 13:34:20 2009 +0200
add DIWrap
---
zypp/sat/LookupAttr.cc | 42 +++++++++++++++++++++++++++++++-
zypp/sat/LookupAttr.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+), 1 deletions(-)
diff --git a/zypp/sat/LookupAttr.cc b/zypp/sat/LookupAttr.cc
index d942487..aa2a710 100644
--- a/zypp/sat/LookupAttr.cc
+++ b/zypp/sat/LookupAttr.cc
@@ -272,6 +272,46 @@ namespace zypp
///////////////////////////////////////////////////////////////////
//
+ // CLASS NAME : detail::DIWrap
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ namespace detail
+ {
+ DIWrap::DIWrap( const DIWrap & rhs )
+ : _dip( 0 )
+ , _mstring( rhs._mstring )
+ {
+ if ( rhs._dip )
+ {
+ _dip = new ::Dataiterator;
+ *_dip = *rhs._dip;
+ // now we have to manually clone any allocated regex data matcher.
+ ::Datamatcher & matcher( _dip->matcher );
+ if ( matcher.match && ( matcher.flags & SEARCH_STRINGMASK ) == SEARCH_REGEX )
+ {
+ ::datamatcher_init( &matcher, _mstring.c_str(), matcher.flags );
+ }
+ else if ( matcher.match && matcher.match != _mstring.c_str() )
+ throw( "this cant be!" );
+ }
+ }
+
+ DIWrap::~DIWrap()
+ {
+ if ( _dip )
+ {
+ ::dataiterator_free( _dip );
+ delete _dip;
+ }
+ }
+
+ std::ostream & operator<<( std::ostream & str, const DIWrap & obj )
+ { return str << obj.get(); }
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
// CLASS NAME : LookupAttr::iterator
//
///////////////////////////////////////////////////////////////////
@@ -626,7 +666,7 @@ namespace zypp
if ( _dip && ! ::dataiterator_step( _dip.get() ) )
{
#warning MEMLEAK - DATAITERATOR FREE NEEDS TO BE EXTENDED - DTOR ASSIGN
- if ( _dip )
+ if ( 0 && _dip )
::dataiterator_free( _dip.get() );
_dip.reset();
base_reference() = 0;
diff --git a/zypp/sat/LookupAttr.h b/zypp/sat/LookupAttr.h
index a412d8f..f7def2d 100644
--- a/zypp/sat/LookupAttr.h
+++ b/zypp/sat/LookupAttr.h
@@ -249,6 +249,69 @@ namespace zypp
};
///////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ /** Wrapper around sat dataiterator.
+ *
+ * Manages copy and assign, and release of allocated
+ * resources like datamatcher inside the dataiterator.
+ * Also maintains a copy of the matchstring in order to
+ * keep the char* passed to the dataiterator valid.
+ */
+ class DIWrap : private base::SafeBool<DIWrap>
+ {
+ public:
+ DIWrap()
+ : _dip( 0 )
+ {}
+ /** Ctor takes over ownership of \b allocated dataiterator. */
+ explicit DIWrap( ::_Dataiterator * allocated_r )
+ : _dip( allocated_r )
+ {}
+ /** Ctor takes over ownership of \b allocated dataiterator. */
+ DIWrap( ::_Dataiterator * allocated_r, const std::string & mstring_r )
+ : _dip( allocated_r ), _mstring( mstring_r )
+ {}
+ DIWrap( const DIWrap & rhs );
+ ~DIWrap();
+ public:
+ void swap( DIWrap & rhs )
+ {
+ if ( &rhs != this ) // prevent self assign!
+ {
+ std::swap( _dip, rhs._dip );
+ std::swap( _mstring, rhs._mstring );
+ }
+ }
+ DIWrap & operator=( const DIWrap & rhs )
+ {
+ if ( &rhs != this ) // prevent self assign!
+ DIWrap( rhs ).swap( *this );
+ return *this;
+ }
+ void reset()
+ { DIWrap().swap( *this ); }
+ public:
+#ifndef SWIG // Swig treats it as syntax error
+ /** Evaluate in a boolean context <tt>( _dip != NULL )</tt>. */
+ using base::SafeBool<DIWrap>::operator bool_type;
+#endif
+ public:
+ ::_Dataiterator * operator->() const { return _dip; }
+ ::_Dataiterator * get() const { return _dip; }
+ const std::string & getstr() const { return _mstring; }
+ private:
+ friend base::SafeBool<DIWrap>::operator bool_type() const;
+ bool boolTest() const
+ { return _dip; }
+ private:
+ ::_Dataiterator * _dip;
+ std::string _mstring;
+ };
+ /** \relates DIWrap Stream output. */
+ std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
+ }
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : LookupAttr::iterator
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org