[zypp-commit] r9386 - in /trunk/libzypp/zypp/sat: LookupAttr.cc LookupAttr.h
Author: mlandres
Date: Fri Apr 4 17:33:23 2008
New Revision: 9386
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9386&view=rev
Log:
backup
Modified:
trunk/libzypp/zypp/sat/LookupAttr.cc
trunk/libzypp/zypp/sat/LookupAttr.h
Modified: trunk/libzypp/zypp/sat/LookupAttr.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/LookupAttr.cc?rev=9386&r1=9385&r2=9386&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/LookupAttr.cc (original)
+++ trunk/libzypp/zypp/sat/LookupAttr.cc Fri Apr 4 17:33:23 2008
@@ -9,6 +9,7 @@
/** \file zypp/sat/LookupAttr.cc
*
*/
+#include <cstring>
#include <iostream>
#include "zypp/base/Logger.h"
@@ -27,16 +28,20 @@
LookupAttr::iterator LookupAttr::begin() const
{
-#warning pool search still disabled.
- if ( ! (_attr && _repo ) )
- return iterator();
+// if ( ! (_attr ) )
+// return iterator();
- ::Dataiterator di;
+ scoped_ptr< ::_Dataiterator> dip( new ::Dataiterator );
+ ::memset( dip.get(), 0, sizeof(::_Dataiterator) );
if ( _solv )
- ::dataiterator_init( &di, _solv.repository().id(), _solv.id(), _attr.id(), 0, SEARCH_NO_STORAGE_SOLVABLE );
+ ::dataiterator_init( dip.get(), _solv.repository().id(), _solv.id(), _attr.id(), 0, SEARCH_NO_STORAGE_SOLVABLE );
+ else if ( _repo )
+ ::dataiterator_init( dip.get(), _repo.id(), 0, _attr.id(), 0, SEARCH_NO_STORAGE_SOLVABLE );
else
- ::dataiterator_init( &di, _repo.id(), 0, _attr.id(), 0, SEARCH_NO_STORAGE_SOLVABLE );
- return iterator( /*di*/ );
+#warning pool search still disabled.
+ return iterator(); // pool search not yet s
+
+ return iterator( dip ); // iterator takes over ownership!
}
LookupAttr::iterator LookupAttr::end() const
@@ -57,12 +62,63 @@
return str << "pool";
}
- ///////////////////////////////////////////////////////////////////
+ std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj )
+ {
+ str << obj << endl;
+ for_( it, obj.begin(), obj.end() )
+ {
+ str << " " << it << endl;
+ }
+ return str << "<EndOfSerach>";
+ }
+
+ ///////////////////////////////////////////////////////////////////
//
// CLASS NAME : LookupAttr::iterator
//
///////////////////////////////////////////////////////////////////
+ ::_Dataiterator * LookupAttr::iterator::cloneFrom( const ::_Dataiterator * rhs )
+ {
+ if ( ! rhs )
+ return 0;
+ ::_Dataiterator * ret( new ::_Dataiterator );
+ *ret = *rhs;
+ return ret;
+ }
+
+ bool LookupAttr::iterator::dip_equal( const ::_Dataiterator & lhs, const ::_Dataiterator & rhs ) const
+ {
+ return ::memcmp( &lhs, &rhs, sizeof(::_Dataiterator) ) == 0;
+ }
+
+ detail::IdType LookupAttr::iterator::dereference() const
+ {
+ return _dip ? ::repodata_globalize_id( _dip->data, _dip->kv.id )
+ : detail::noId;
+ }
+
+ void LookupAttr::iterator::increment()
+ {
+ if ( _dip && ! ::dataiterator_step( _dip.get() ) )
+ {
+ _dip.reset();
+ base_reference() = 0;
+ }
+ }
+
+ std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj )
+ {
+ const ::_Dataiterator * dip = obj.get();
+ if ( ! dip )
+ return str << "EndOfQuery" << endl;
+
+ str << Solvable( dip->solvid )
+ << '<' << SolvAttr( dip->keyname )
+ << "> = " << IdString( dip->key->type )
+ << "(" << dip->kv.id << ")";
+ return str;
+ }
/////////////////////////////////////////////////////////////////
} // namespace sat
Modified: trunk/libzypp/zypp/sat/LookupAttr.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/LookupAttr.h?rev=9386&r1=9385&r2=9386&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/LookupAttr.h (original)
+++ trunk/libzypp/zypp/sat/LookupAttr.h Fri Apr 4 17:33:23 2008
@@ -12,6 +12,10 @@
#ifndef ZYPP_SAT_LOOKUPATTR_H
#define ZYPP_SAT_LOOKUPATTR_H
+extern "C"
+{
+struct _Dataiterator;
+}
#include <iosfwd>
#include "zypp/base/PtrTypes.h"
@@ -29,6 +33,13 @@
// CLASS NAME : LookupAttr
//
/** Lightweight attribute lookup.
+ *
+ * Search for an attribute \ref Pool, one \ref Repository or
+ * one \ref Solvable. \ref LookupAttr builds the query,
+ * \ref LookupAttr::iterator iterates over the result.
+ *
+ * Modifying the query will not affect any running
+ * iterator.
*/
class LookupAttr
{
@@ -40,7 +51,7 @@
LookupAttr( SolvAttr attr_r )
: _attr( attr_r )
{}
- /** Lookup \ref SolvAttr in one \ref Repository. */
+ /** Lookup \ref SolvAttr in one\ref Repository. */
LookupAttr( SolvAttr attr_r, Repository repo_r )
: _attr( attr_r ), _repo( repo_r )
{}
@@ -119,20 +130,90 @@
};
///////////////////////////////////////////////////////////////////
- /** \relates Arch stream output. */
+ /** \relates LookupAttr Stream output. */
std::ostream & operator<<( std::ostream & str, const LookupAttr & obj );
+ /** \relates LookupAttr Verbose stream output including the query result. */
+ std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj );
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : LookupAttr::iterator
//
/** Result iterator.
- */
- struct LookupAttr::iterator
+ * \note Implementation: Keep iterator_adaptor base and _dip in sync!
+ */
+ class LookupAttr::iterator : public boost::iterator_adaptor<
+ iterator // Derived
+ , ::_Dataiterator * // Base
+ , detail::IdType // Value
+ , boost::forward_traversal_tag // CategoryOrTraversal
+ , detail::IdType // Reference
+ >
{
+ public:
+ iterator()
+ : iterator_adaptor_( 0 )
+ {}
+
+ public:
+
+
+ public:
+ iterator( const iterator & rhs )
+ : iterator_adaptor_( cloneFrom( rhs.base() ) )
+ , _dip( base() )
+ {}
+
+ iterator & operator=( const iterator & rhs )
+ {
+ if ( &rhs != this )
+ {
+ _dip.reset( cloneFrom( rhs.base() ) );
+ base_reference() = _dip.get();
+ }
+ return *this;
+ }
+
+ private:
+ friend class LookupAttr;
+ iterator( scoped_ptr< ::_Dataiterator> & dip_r )
+ : iterator_adaptor_( dip_r.get() )
+ {
+ _dip.swap( dip_r ); // take ownership!
+ increment();
+ }
+
+ ::_Dataiterator * cloneFrom( const ::_Dataiterator * rhs );
+
+ private:
+ friend class boost::iterator_core_access;
+
+ template
participants (1)
-
mlandres@svn.opensuse.org