Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / ResFilters.h
index ed12082..1b4ffd0 100644 (file)
 #include <boost/function.hpp>
 
 #include "zypp/base/Functional.h"
+#include "zypp/Filter.h"
 #include "zypp/Resolvable.h"
-#include "zypp/CapFilters.h"
 
 #include "zypp/PoolItem.h"
-#include "zypp/CapAndItem.h"
+#include "zypp/Repository.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
-  class Repository;
   ///////////////////////////////////////////////////////////////////
   namespace resfilter
   { /////////////////////////////////////////////////////////////////
@@ -76,19 +75,19 @@ namespace zypp
      *
      * // print and count all Packages named "kernel"
      * counter = 0;
-     * store.forEach( chain( ByKind(ResTraits<Package>::kind),
+     * store.forEach( chain( ByKind(ResKind::package),
      *                       ByName("kernel") ),
      *                PrintAndCount(counter) );
      *
      * // print and count all Packages not named "kernel"
      * counter = 0;
-     * store.forEach( chain( ByKind(ResTraits<Package>::kind),
+     * store.forEach( chain( ByKind(ResKind::package),
      *                       not_c(ByName("kernel")) ),
      *                PrintAndCount(counter) );
      *
      * // same as above ;)
      * counter = 0;
-     * store.forEach( chain( ByKind(ResTraits<Package>::kind),
+     * store.forEach( chain( ByKind(ResKind::package),
      *                       chain( not_c(ByName("kernel")),
      *                              PrintAndCount(counter) ) ),
      *                true_c() );
@@ -138,6 +137,8 @@ namespace zypp
      * If you look at a functor, you'll see that it contains both, the function
      * to call (it's <tt>operator()</tt> ) and the data you'd otherwise pass as
      * <tt>void * data</tt>. That's nice and safe.
+     *
+     * \todo migrate to namespace filter and enhance to support Solvables as well.
     */
     //@{
     ///////////////////////////////////////////////////////////////////
@@ -150,29 +151,17 @@ namespace zypp
     typedef std::unary_function<ResObject::constPtr, bool> ResObjectFilterFunctor;
     typedef boost::function<bool ( ResObject::constPtr )> ResFilter;
 
-    /** Select ResObject by kind. */
-    struct ByKind : public ResObjectFilterFunctor
-    {
-      ByKind( const ResObject::Kind & kind_r )
-      : _kind( kind_r )
-      {}
-
-      bool operator()( ResObject::constPtr p ) const
-      {
-        return p->kind() == _kind;
-      }
-
-      ResObject::Kind _kind;
-    };
-
     /** */
-    template<class _Res>
-      inline ByKind byKind()
-      { return ByKind( ResTraits<_Res>::kind ); }
+    template<class TRes>
+      inline filter::ByKind byKind()
+      { return filter::ByKind( ResTraits<TRes>::kind ); }
 
     /** Select ResObject by name. */
     struct ByName : public ResObjectFilterFunctor
     {
+      ByName()
+      {}
+
       ByName( const std::string & name_r )
       : _name( name_r )
       {}
@@ -185,7 +174,6 @@ namespace zypp
       std::string _name;
     };
 
-
     /** Select ResObject by repository or repository alias. */
     struct ByRepository : public ResObjectFilterFunctor
     {
@@ -205,10 +193,9 @@ namespace zypp
       std::string _alias;
     };
 
-
-    /** Select ResObject by Edition using \a _Compare functor.
+    /** Select ResObject by Edition using \a TCompare functor.
      *
-     * Selects ResObject if <tt>_Compare( ResObject->edition(), _edition )</tt>
+     * Selects ResObject if <tt>TCompare( ResObject->edition(), _edition )</tt>
      * is \c true.
      * \code
      * // use the convenience funktions to create ByEdition:
@@ -218,11 +205,10 @@ namespace zypp
      * byEdition( someedition, CompareByGT<Edition>() ) //  edition >  someedition
      * \endcode
     */
-    template<class _Compare = CompareByEQ<Edition> >
+    template<class TCompare = CompareByEQ<Edition> >
       struct ByEdition : public ResObjectFilterFunctor
       {
-        ByEdition( const Edition & edition_r,
-                   _Compare cmp_r )
+        ByEdition( const Edition & edition_r, TCompare cmp_r )
         : _edition( edition_r )
         , _cmp( cmp_r )
         {}
@@ -233,23 +219,23 @@ namespace zypp
         }
 
         Edition  _edition;
-        _Compare _cmp;
+        TCompare _cmp;
       };
 
     /** */
-    template<class _Compare>
-      ByEdition<_Compare> byEdition( const Edition & edition_r, _Compare cmp_r )
-      { return ByEdition<_Compare>( edition_r, cmp_r ); }
+    template<class TCompare>
+      ByEdition<TCompare> byEdition( const Edition & edition_r, TCompare cmp_r )
+      { return ByEdition<TCompare>( edition_r, cmp_r ); }
 
     /** */
-    template<class _Compare>
-      ByEdition<_Compare> byEdition( const Edition & edition_r )
-      { return byEdition( edition_r, _Compare() ); }
+    template<class TCompare>
+      ByEdition<TCompare> byEdition( const Edition & edition_r )
+      { return byEdition( edition_r, TCompare() ); }
 
 
-    /** Select ResObject by Arch using \a _Compare functor.
+    /** Select ResObject by Arch using \a TCompare functor.
      *
-     * Selects ResObject if <tt>_Compare( ResObject->arch(), _arch )</tt>
+     * Selects ResObject if <tt>TCompare( ResObject->arch(), _arch )</tt>
      * is \c true.
      * \code
      * // use the convenience funktions to create ByArch:
@@ -259,11 +245,10 @@ namespace zypp
      * byArch( somearch, CompareByGT<Arch>() ) //  arch >  somearch
      * \endcode
     */
-    template<class _Compare = CompareByEQ<Arch> >
+    template<class TCompare = CompareByEQ<Arch> >
       struct ByArch : public ResObjectFilterFunctor
       {
-        ByArch( const Arch & arch_r,
-                   _Compare cmp_r )
+        ByArch( const Arch & arch_r, TCompare cmp_r )
         : _arch( arch_r )
         , _cmp( cmp_r )
         {}
@@ -274,18 +259,18 @@ namespace zypp
         }
 
         Arch  _arch;
-        _Compare _cmp;
+        TCompare _cmp;
       };
 
     /** */
-    template<class _Compare>
-      ByArch<_Compare> byArch( const Arch & arch_r, _Compare cmp_r )
-      { return ByArch<_Compare>( arch_r, cmp_r ); }
+    template<class TCompare>
+      ByArch<TCompare> byArch( const Arch & arch_r, TCompare cmp_r )
+      { return ByArch<TCompare>( arch_r, cmp_r ); }
 
     /** */
-    template<class _Compare>
-      ByArch<_Compare> byArch( const Arch & arch_r )
-      { return byArch( arch_r, _Compare() ); }
+    template<class TCompare>
+      ByArch<TCompare> byArch( const Arch & arch_r )
+      { return byArch( arch_r, TCompare() ); }
 
 
     ///////////////////////////////////////////////////////////////////
@@ -306,7 +291,6 @@ namespace zypp
       {
        return p.status().isInstalled();
       }
-
     };
 
     /** Select PoolItem by uninstalled. */
@@ -345,97 +329,24 @@ namespace zypp
       }
     };
 
-
-
-    ///////////////////////////////////////////////////////////////////
-
-    /** Select ResObject if at least one Capability with
-     *  index \a index_r was found in dependency \a depType_r.
-    */
-    struct ByCapabilityIndex
-    {
-      bool operator()( const CapAndItem & /*cai*/ ) const
-      {
-       return true;                    // its all in the PoolImpl !
-      }
-    };
-
-
-    /** Select ResObject if at least one Capability with
-     *  index \a index_r was found in dependency \a depType_r.
-    */
-    struct ByCapMatch
-    {
-      bool operator()( const CapAndItem & cai ) const
-      {
-       return cai.cap.matches( _cap ) == CapMatch::yes;
-      }
-      ByCapMatch( const Capability & cap_r )
-       : _cap( cap_r )
-      {}
-      Capability _cap;
-    };
-
-
-    /** Select PoolItem by uninstalled. */
-    struct ByCaIUninstalled
-    {
-      bool operator()( const CapAndItem & cai ) const
-      {
-       return cai.item.status().isUninstalled();
-      }
-    };
-
-    /** Select PoolItem by installed. */
-    struct ByCaIInstalled
-    {
-      bool operator()( const CapAndItem & cai ) const
-      {
-       return cai.item.status().isInstalled();
-      }
-    };
-
-    /** Select PoolItem by transact. */
-    struct ByCaITransact
+    /** PoolItem which is recommended. */
+    struct ByRecommended : public PoolItemFilterFunctor
     {
-      bool operator()( const CapAndItem & cai ) const
-      {
-       return cai.item.status().transacts();
-      }
-    };
-
-    /** Select PoolItem by not transact. */
-    struct ByCaINotTransact
-    {
-      bool operator()( const CapAndItem & cai ) const
+      bool operator()( const PoolItem & p ) const
       {
-       return !(cai.item.status().transacts());
+       return p.status().isRecommended();
       }
     };
 
-
-    /** Select CapAndItem by kind. */
-    struct ByCaIKind
+    /** PoolItem which is suggested. */
+    struct BySuggested : public PoolItemFilterFunctor
     {
-      ByCaIKind( const ResObject::Kind & kind_r )
-      : _kind( kind_r )
-      {}
-
-      bool operator()( const CapAndItem & cai ) const
+      bool operator()( const PoolItem & p ) const
       {
-        return cai.item->kind() == _kind;
+       return p.status().isSuggested();
       }
-
-      ResObject::Kind _kind;
     };
 
-    /** */
-    template<class _Res>
-      inline ByCaIKind byCaIKind()
-      { return ByCaIKind( ResTraits<_Res>::kind ); }
-
-    ///////////////////////////////////////////////////////////////////
-
     //@}
     /////////////////////////////////////////////////////////////////
   } // namespace resfilter