From 5be27cb546d2be121f2b75ffbb0c1e2b53292673 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 25 Jan 2006 10:27:22 +0000 Subject: [PATCH] - Added Capability iterator to ResPool. - Added compare functions compareByN, compareByNVR, compareByNVRA based on Resolvable::constPtr. (Resolvable.h) --- devel/devel.ma/Main.cc | 66 ++++---------------------------------------------- zypp/Arch.h | 12 +++++++-- zypp/CapFilters.h | 57 +++++++++++++++++++++++++++++++++++++++++++ zypp/Edition.h | 10 +++++++- zypp/Makefile.am | 1 + zypp/ResFilters.h | 29 ++++++++++++---------- zypp/ResPool.h | 33 +++++++++++++++++++------ zypp/Resolvable.h | 56 ++++++++++++++++++++++++++++++++++++++++++ zypp/base/KindOf.h | 8 ++++++ 9 files changed, 187 insertions(+), 85 deletions(-) create mode 100644 zypp/CapFilters.h diff --git a/devel/devel.ma/Main.cc b/devel/devel.ma/Main.cc index a634849..060d066 100644 --- a/devel/devel.ma/Main.cc +++ b/devel/devel.ma/Main.cc @@ -35,6 +35,7 @@ using namespace std; using namespace zypp; using namespace zypp::functor; +using namespace zypp::resfilter; /////////////////////////////////////////////////////////////////// namespace zypp @@ -160,63 +161,6 @@ namespace zypp { namespace functor { - /** */ - typedef std::unary_function CapabilityFilterFunctor; - - /** */ - struct ByIndex : public CapabilityFilterFunctor - { - bool operator()( Capability c ) const - { - return c.index() == _index; - } - - ByIndex( const std::string & index_r ) - : _index( index_r ) - {} - ByIndex( const Capability & cap_r ) - : _index( cap_r.index() ) - {} - std::string _index; - }; - - } - - - namespace functor { - - /** \todo enumerate dependencies. */ - struct ByProvidesIndex : public ResObjectFilterFunctor - { - ByProvidesIndex( const std::string & index_r ) - : _index( index_r ) - {} - - bool operator()( ResObject::constPtr p ) const - { - return( make_filter_begin( ByIndex(_index), p->dep( Dep::PROVIDES ) ) - != make_filter_end( ByIndex(_index), p->dep( Dep::PROVIDES ) ) ); - } - - std::string _index; - }; - - /** \todo enumerate dependencies. */ - struct ByRequiresIndex : public ResObjectFilterFunctor - { - ByRequiresIndex( const std::string & index_r ) - : _index( index_r ) - {} - - bool operator()( ResObject::constPtr p ) const - { - return( make_filter_begin( ByIndex(_index), p->dep( Dep::REQUIRES ) ) - != make_filter_end( ByIndex(_index), p->dep( Dep::REQUIRES ) ) ); - } - - std::string _index; - }; - } // namespace functor @@ -267,12 +211,12 @@ int main( int argc, char * argv[] ) xPrint() ) << endl; std::string i( "3ddiag" ); - SEC << invokeOnEach( make_filter_begin( ByProvidesIndex(i), query ), - make_filter_end( ByProvidesIndex(i), query ), + SEC << invokeOnEach( make_filter_begin( ByCapabilityIndex(i,Dep::PROVIDES), query ), + make_filter_end( ByCapabilityIndex(i,Dep::PROVIDES), query ), Print() ) << endl; i = "/bin/sh"; - SEC << invokeOnEach( make_filter_begin( ByRequiresIndex(i), query ), - make_filter_end( ByRequiresIndex(i), query ), + SEC << invokeOnEach( make_filter_begin( ByCapabilityIndex(i,Dep::REQUIRES), query ), + make_filter_end( ByCapabilityIndex(i,Dep::REQUIRES), query ), Print() ) << endl; diff --git a/zypp/Arch.h b/zypp/Arch.h index 3ab49b1..26b5ac6 100644 --- a/zypp/Arch.h +++ b/zypp/Arch.h @@ -49,10 +49,18 @@ namespace zypp */ bool compatibleWith( const Arch & rhs ) const; + /** Order on Arch (arbitrary). + * \todo Adjust logical operators below to follow compare. + */ + int compare( const Arch & rhs ) const + { return _value.compare( rhs._value ); } + /** Architecture of the current working system * \return \c Arch. - */ - static const Arch System; + * \todo Eliminate this, it's not task of a data type to + * detect and define what the system architecture is. + */ + static const Arch System; private: /** String representation of Arch. */ diff --git a/zypp/CapFilters.h b/zypp/CapFilters.h new file mode 100644 index 0000000..9c034e6 --- /dev/null +++ b/zypp/CapFilters.h @@ -0,0 +1,57 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/CapFilters.h + * +*/ +#ifndef ZYPP_CAPFILTERS_H +#define ZYPP_CAPFILTERS_H + +#include "zypp/base/Functional.h" +#include "zypp/Capability.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace capfilter + { ///////////////////////////////////////////////////////////////// + + /** \defgroup CAPFILTERS Filter functors operating on Capability. + * \ingroup g_Functor + */ + //@{ + + /** */ + typedef std::unary_function CapabilityFilterFunctor; + + /** */ + struct ByIndex : public CapabilityFilterFunctor + { + bool operator()( const Capability & c ) const + { + return c.index() == _index; + } + + ByIndex( const std::string & index_r ) + : _index( index_r ) + {} + ByIndex( const Capability & cap_r ) + : _index( cap_r.index() ) + {} + std::string _index; + }; + + //@} + ///////////////////////////////////////////////////////////////// + } // namespace capfilter + ///////////////////////////////////////////////////////////////////^ + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_CAPFILTERS_H diff --git a/zypp/Edition.h b/zypp/Edition.h index 06d5432..b8e4e47 100644 --- a/zypp/Edition.h +++ b/zypp/Edition.h @@ -125,9 +125,13 @@ namespace zypp * \attention An empty version or release string is not treated * specialy. It's the least possible value. If you want an empty * string treated as \c ANY, use \ref match. - */ + */ static int compare( const Edition & lhs, const Edition & rhs ); + /** */ + int compare( const Edition & rhs ) const + { return compare( *this, rhs ); } + /** \ref compare functor. * \see \ref RelCompare. */ @@ -145,6 +149,10 @@ namespace zypp */ static int match( const Edition & lhs, const Edition & rhs ); + /** */ + int match( const Edition & rhs ) const + { return match( *this, rhs ); } + /** \ref match functor. * \see \ref RelCompare. */ diff --git a/zypp/Makefile.am b/zypp/Makefile.am index 36bfd7e..9ce917f 100644 --- a/zypp/Makefile.am +++ b/zypp/Makefile.am @@ -15,6 +15,7 @@ pkginclude_HEADERS = NeedAType.h \ CapMatch.h \ CapSet.h \ CapSetFwd.h \ + CapFilters.h \ CountryCode.h \ Date.h \ Dep.h \ diff --git a/zypp/ResFilters.h b/zypp/ResFilters.h index f9c8029..d0023b2 100644 --- a/zypp/ResFilters.h +++ b/zypp/ResFilters.h @@ -14,13 +14,15 @@ #include "zypp/base/Functional.h" #include "zypp/Resolvable.h" +#include "zypp/CapFilters.h" /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - namespace functor + namespace resfilter { ///////////////////////////////////////////////////////////////// + /** \defgroup RESFILTERS Filter functors operating on ResObjects. * \ingroup g_Functor * @@ -141,7 +143,7 @@ namespace zypp /** */ typedef std::unary_function ResObjectFilterFunctor; - /** */ + /** Select ResObject by kind. */ struct ByKind : public ResObjectFilterFunctor { ByKind( const ResObject::Kind & kind_r ) @@ -161,7 +163,7 @@ namespace zypp inline ByKind byKind() { return ByKind( ResTraits<_Res>::kind ); } - /** */ + /** Select ResObject by name. */ struct ByName : public ResObjectFilterFunctor { ByName( const std::string & name_r ) @@ -176,31 +178,32 @@ namespace zypp std::string _name; }; -#if 0 - /** \todo enumerate dependencies. */ + /** Select ResObject if at least one Capability with + * index \a index_r was found in dependency \a depType_r. + */ struct ByCapabilityIndex : public ResObjectFilterFunctor { - ByCapabilityIndex( const std::string & index_r ) - : _index( index_r ) + ByCapabilityIndex( const std::string & index_r, Dep depType_r ) + : _dep( depType_r ) + , _index( index_r ) {} bool operator()( ResObject::constPtr p ) const { - p->provides() - - return p->index() == _index; - + using capfilter::ByIndex; + return( make_filter_begin( ByIndex(_index), p->dep( _dep ) ) + != make_filter_end( ByIndex(_index), p->dep( _dep ) ) ); } + Dep _dep; std::string _index; }; -#endif /////////////////////////////////////////////////////////////////// //@} ///////////////////////////////////////////////////////////////// - } // namespace functor + } // namespace resfilter /////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// } // namespace zypp diff --git a/zypp/ResPool.h b/zypp/ResPool.h index bab0111..c151ea6 100644 --- a/zypp/ResPool.h +++ b/zypp/ResPool.h @@ -16,7 +16,6 @@ #include "zypp/pool/PoolTraits.h" #include "zypp/base/Iterator.h" -#include "zypp/ResTraits.h" #include "zypp/ResFilters.h" /////////////////////////////////////////////////////////////////// @@ -27,7 +26,14 @@ namespace zypp // // CLASS NAME : ResPool // - /** Access to ResObject pool. */ + /** Access to ResObject pool. + * + * \note Filter iterators provided by ResPool are intended to + * operate on internal index tables for faster access. If the + * the index is not yet implemented, they are realized as + * an ordinary filter iterator. Do not provide filter iterators + * here, if there is no index table for it. + */ class ResPool { friend std::ostream & operator<<( std::ostream & str, const ResPool & obj ); @@ -49,6 +55,7 @@ namespace zypp size_type size() const; public: + /** \name Iterate through all ResObjects (all kinds). */ //@{ /** */ @@ -60,7 +67,7 @@ namespace zypp public: /** \name Iterate through all ResObjects of a certain kind. */ //@{ - typedef functor::ByKind ByKind; + typedef resfilter::ByKind ByKind; typedef filter_iterator byKind_iterator; byKind_iterator byKindBegin( const ResObject::Kind & kind_r ) const @@ -68,7 +75,7 @@ namespace zypp template byKind_iterator byKindBegin() const - { return make_filter_begin( functor::byKind<_Res>(), *this ); } + { return make_filter_begin( resfilter::byKind<_Res>(), *this ); } byKind_iterator byKindEnd( const ResObject::Kind & kind_r ) const @@ -76,13 +83,13 @@ namespace zypp template byKind_iterator byKindEnd() const - { return make_filter_end( functor::byKind<_Res>(), *this ); } + { return make_filter_end( resfilter::byKind<_Res>(), *this ); } //@} public: - /** \name Iterate through all ResObjects with a certain name. */ + /** \name Iterate through all ResObjects with a certain name (all kinds). */ //@{ - typedef functor::ByName ByName; + typedef resfilter::ByName ByName; typedef filter_iterator byName_iterator; byName_iterator byNameBegin( const std::string & name_r ) const @@ -93,8 +100,18 @@ namespace zypp //@} public: - /** \name Iterate through dependency tables. */ + /** \name Iterate through all ResObjects which have at least + * one Capability with index \a index_r in dependency \a depType_r. + */ //@{ + typedef resfilter::ByCapabilityIndex ByCapabilityIndex; + typedef filter_iterator byCapabilityIndex_iterator; + + byCapabilityIndex_iterator byCapabilityIndexBegin( const std::string & index_r, Dep depType_r ) const + { return make_filter_begin( ByCapabilityIndex(index_r,depType_r), *this ); } + + byCapabilityIndex_iterator byCapabilityIndexEnd( const std::string & index_r, Dep depType_r ) const + { return make_filter_end( ByCapabilityIndex(index_r,depType_r), *this ); } //@} private: diff --git a/zypp/Resolvable.h b/zypp/Resolvable.h index 45045c6..6722401 100644 --- a/zypp/Resolvable.h +++ b/zypp/Resolvable.h @@ -130,6 +130,62 @@ namespace zypp inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p ) { return dynamic_pointer_cast(p); } + /////////////////////////////////////////////////////////////////// + + /** \relates Resolvable Compare Resolvable::constPtr according to + * \a kind and \a name. + */ + inline int compareByN( const Resolvable::constPtr & lhs, + const Resolvable::constPtr & rhs ) + { + if ( lhs == rhs ) + return 0; + if ( ! (lhs && rhs) ) + return lhs ? 1 : -1; + int res = 0; + if ( (res = lhs->kind().compare( rhs->kind() )) ) + return res; + return lhs->name().compare( rhs->name() ); + } + + /** \relates Resolvable Compare Resolvable::constPtr according to + * \a kind, \a name and \a edition(compare!). + */ + inline int compareByNVR( const Resolvable::constPtr & lhs, + const Resolvable::constPtr & rhs ) + { + if ( lhs == rhs ) + return 0; + if ( ! (lhs && rhs) ) + return lhs ? 1 : -1; + int res = 0; + if ( (res = lhs->kind().compare( rhs->kind() )) ) + return res; + if ( (res = lhs->name().compare( rhs->name() )) ) + return res; + return lhs->edition().compare( rhs->edition() ); + } + + /** \relates Resolvable Compare Resolvable::constPtr according to + * \a kind, \a name, \a edition(compare!) and \a arch. + */ + inline int compareByNVRA( const Resolvable::constPtr & lhs, + const Resolvable::constPtr & rhs ) + { + if ( lhs == rhs ) + return 0; + if ( ! (lhs && rhs) ) + return lhs ? 1 : -1; + int res = 0; + if ( (res = lhs->kind().compare( rhs->kind() )) ) + return res; + if ( (res = lhs->name().compare( rhs->name() )) ) + return res; + if ( (res = lhs->edition().compare( rhs->edition() )) ) + return res; + return lhs->arch().compare( rhs->arch() ); + } + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/base/KindOf.h b/zypp/base/KindOf.h index 615f8d3..1ab459c 100644 --- a/zypp/base/KindOf.h +++ b/zypp/base/KindOf.h @@ -63,6 +63,14 @@ namespace zypp const std::string & asString() const { return _value; } + /** Order on KindOf (arbitrary). + * Not necessarily lexicographical. + * \todo Enable class _Tp to define the order, + * Fix logical operators below to use compare, + */ + int compare( const KindOf & rhs ) const + { return _value.compare( rhs._value ); } + private: /** */ std::string _value; -- 2.7.4