- Provided some Selectable filter functors, and some
authorMichael Andres <ma@suse.de>
Wed, 8 Feb 2006 15:13:58 +0000 (15:13 +0000)
committerMichael Andres <ma@suse.de>
Wed, 8 Feb 2006 15:13:58 +0000 (15:13 +0000)
  query to ResPoolProxy

zypp/ResPoolProxy.h
zypp/ui/Makefile.am
zypp/ui/SelFilters.h [new file with mode: 0644]
zypp/ui/Selectable.h

index 683e2e3..d82c438 100644 (file)
@@ -55,14 +55,14 @@ namespace zypp
 
   public:
 
-    /**  */
+    /** True if there are items of a certain kind. */
     bool empty( const ResObject::Kind & kind_r ) const;
 
     template<class _Res>
       bool empty() const
       { return empty( ResTraits<_Res>::kind ); }
 
-    /**  */
+    /** Number of Items of a certain kind.  */
     size_type size( const ResObject::Kind & kind_r ) const;
 
     template<class _Res>
@@ -85,7 +85,23 @@ namespace zypp
       { return byKindEnd( ResTraits<_Res>::kind ); }
     //@}
 
+  public:
+    /** Test whether there is at least one ui::Selectable with
+     * an installed object.
+    */
+    bool hasInstalledObj( const ResObject::Kind & kind_r ) const
+    {
+      return(    make_begin<selfilter::ByHasInstalledObj>()
+              != make_end<selfilter::ByHasInstalledObj>() );
+    }
+
+    template<class _Res>
+      bool hasInstalledObj() const
+      { return hasInstalledObj( ResTraits<_Res>::kind ); }
+
 
+
+  public:
     /** \name Save and restore state.
      * \todo make it work.
     */
@@ -97,6 +113,38 @@ namespace zypp
     //@}
 
   private:
+    template<class _Filter>
+      filter_iterator<_Filter,const_iterator>
+      make_begin( _Filter filter_r, const ResObject::Kind & kind_r ) const
+      {
+        return make_filter_iterator( filter_r,
+                                     byKindBegin(kind_r),
+                                     byKindEnd(kind_r) );
+      }
+    template<class _Filter>
+      filter_iterator<_Filter,const_iterator>
+      make_begin( const ResObject::Kind & kind_r ) const
+      {
+        return make_begin( _Filter(), kind_r );
+      }
+
+
+    template<class _Filter>
+      filter_iterator<_Filter,const_iterator>
+      make_end( _Filter filter_r, const ResObject::Kind & kind_r ) const
+      {
+        return make_filter_iterator( filter_r,
+                                     byKindEnd(kind_r),
+                                     byKindEnd(kind_r) );
+      }
+    template<class _Filter>
+      filter_iterator<_Filter,const_iterator>
+      make_end( const ResObject::Kind & kind_r ) const
+      {
+        return make_end( _Filter(), kind_r );
+      }
+
+
     /** Pointer to implementation */
     RW_pointer<Impl> _pimpl;
   };
index 9cad516..d7972be 100644 (file)
@@ -10,6 +10,7 @@ uiincludedir = $(pkgincludedir)/ui
 uiinclude_HEADERS = \
        Status.h                \
        Selectable.h            \
+       SelFilters.h            \
        SelectableTraits.h      \
        \
        SelectableImpl.h
diff --git a/zypp/ui/SelFilters.h b/zypp/ui/SelFilters.h
new file mode 100644 (file)
index 0000000..dcb560d
--- /dev/null
@@ -0,0 +1,94 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/ui/SelFilters.h
+ *
+*/
+#ifndef ZYPP_UI_SELFILTERS_H
+#define ZYPP_UI_SELFILTERS_H
+
+#include "zypp/base/Functional.h"
+#include "zypp/ui/Selectable.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace ui
+  { /////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////
+    namespace selfilter
+    { /////////////////////////////////////////////////////////////////
+
+      typedef std::unary_function<ui::Selectable::constPtr,bool> SelectableFilterFunctor;
+
+      /** */
+      struct ByKind : public SelectableFilterFunctor
+      {
+        ByKind( const ResObject::Kind & kind_r )
+        : _kind( kind_r )
+        {}
+
+        bool operator()( const ui::Selectable::constPtr & obj ) const
+        {
+          return obj && obj->kind() == _kind;
+        }
+
+        ResObject::Kind _kind;
+      };
+
+      /** */
+      struct ByName : public SelectableFilterFunctor
+      {
+        ByName( const std::string & name_r )
+        : _name( name_r )
+        {}
+
+        bool operator()( const ui::Selectable::constPtr & obj ) const
+        { return obj && obj->name() == _name; }
+
+        std::string _name:
+      };
+
+      /** */
+      struct ByHasInstalledObj : public SelectableFilterFunctor
+      {
+        bool operator()( const ui::Selectable::constPtr & obj ) const
+        { return obj && obj->hasInstalledObj(); }
+      };
+
+      /** */
+      struct ByHasCandidateObj : public SelectableFilterFunctor
+      {
+        bool operator()( const ui::Selectable::constPtr & obj ) const
+        { return obj && obj->hasCandidateObj(); }
+      };
+
+      struct ByStatus : public SelectableFilterFunctor
+      /** */
+      {
+        ByStatus( Status status_r )
+        : _status( status_r )
+        {}
+
+        bool operator()( const ui::Selectable::constPtr & obj ) const
+        { return obj && obj->status() == _status; }
+
+        Status _status:
+      };
+
+      /////////////////////////////////////////////////////////////////
+    } // namespace selfilter
+    ///////////////////////////////////////////////////////////////////
+    /////////////////////////////////////////////////////////////////
+  } // namespace ui
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_UI_SELFILTERS_H
index b24916f..d511112 100644 (file)
@@ -20,6 +20,7 @@
 #include "zypp/base/Iterator.h"
 
 #include "zypp/ui/SelectableTraits.h"
+#include "zypp/ui/SelFilters.h"
 #include "zypp/ui/Status.h"
 
 ///////////////////////////////////////////////////////////////////