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>
{ 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.
*/
//@}
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;
};
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ 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