Author: mlandres
Date: Thu Feb 21 18:34:47 2008
New Revision: 8856
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8856&view=rev
Log:
Add ByLocaleSupport filter to iterate solvables according to their locale support.
Added:
trunk/libzypp/zypp/Filter.h
Modified:
trunk/libzypp/zypp/CMakeLists.txt
trunk/libzypp/zypp/ResPool.h
trunk/libzypp/zypp/sat/Pool.h
trunk/libzypp/zypp/sat/WhatProvides.cc
trunk/libzypp/zypp/sat/WhatProvides.h
Modified: trunk/libzypp/zypp/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=8856&r1=8855&r2=8856&view=diff
==============================================================================
--- trunk/libzypp/zypp/CMakeLists.txt (original)
+++ trunk/libzypp/zypp/CMakeLists.txt Thu Feb 21 18:34:47 2008
@@ -150,6 +150,7 @@
RepoManager.h
Repository.h
RepoStatus.h
+ Filter.h
ResFilters.h
ResKind.h
ResObject.h
Added: trunk/libzypp/zypp/Filter.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Filter.h?rev=8856&view=auto
==============================================================================
--- trunk/libzypp/zypp/Filter.h (added)
+++ trunk/libzypp/zypp/Filter.h Thu Feb 21 18:34:47 2008
@@ -0,0 +1,106 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/Filter.h
+ *
+*/
+#ifndef ZYPP_FILTER_H
+#define ZYPP_FILTER_H
+
+#include <iosfwd>
+
+#include "zypp/base/Functional.h"
+#include "zypp/base/Function.h"
+#include "zypp/ResFilters.h"
+
+#include "zypp/sat/Pool.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace filter
+ { /////////////////////////////////////////////////////////////////
+ /** \defgroup POOLFILTER Collection solvable filter functors.
+ *
+ * All functors should be able to process \ref Solvable as well
+ * as \ref PoolItem.
+ *
+ * \code
+ * // The same filter...
+ * filter::ByLocaleSupport f( Locale("de") );
+ *
+ * // ...can be used to iterate the sat::Pool...
+ * sat::Pool satpool( sat::Pool::instance() );
+ * for_( it, satpool.filterBegin(f), satpool.filterEnd(f) )
+ * {
+ * MIL << *it << endl; // prints sat::Solvable
+ * }
+ *
+ * // ...as well as the ResPool.
+ * ResPool pool ( ResPool::instance() );
+ * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
+ * {
+ * MIL << *it << endl; // prints PoolItem
+ * }
+ * \endcode
+ * \ingroup g_Functor
+ */
+ //@{
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ByLocaleSupport
+ //
+ /** Filter solvables according to their locale support.
+ */
+ class ByLocaleSupport
+ {
+ private:
+ typedef bool (sat::Solvable::*LS1) (const Locale &) const;
+ typedef bool (sat::Solvable::*LS2) (const LocaleSet &) const;
+
+ public:
+ /** Solvables with locale support. */
+ ByLocaleSupport()
+ : _sel( mem_fun_ref( &sat::Solvable::supportsLocales ) )
+ {}
+
+ /** Solvables supporting \c locale_r. */
+ explicit ByLocaleSupport( const Locale & locale_r )
+ : _sel( bind( mem_fun_ref( (LS1)&sat::Solvable::supportsLocale ), _1, locale_r ) )
+ {}
+
+ /** Solvables supporting at least one locale in \c locales_r. */
+ explicit ByLocaleSupport( const LocaleSet & locales_r )
+ : _sel( bind( boost::mem_fun_ref( (LS2)&sat::Solvable::supportsLocale ), _1, locales_r ) )
+ {}
+
+ public:
+ /** Filter on \ref Solvable. */
+ bool operator()( const sat::Solvable & solv_r ) const
+ { return _sel && _sel( solv_r ); }
+
+ /** Filter fitting PoolItem/ResObject. */
+ template<class _Solv>
+ bool operator()( const _Solv & solv_r ) const
+ { return operator()( solv_r.satSolvable() ); }
+
+ private:
+ function _sel;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ //@}
+ /////////////////////////////////////////////////////////////////
+ } // namespace filter
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_FILTER_H
Modified: trunk/libzypp/zypp/ResPool.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ResPool.h?rev=8856&r1=8855&r2=8856&view=diff
==============================================================================
--- trunk/libzypp/zypp/ResPool.h (original)
+++ trunk/libzypp/zypp/ResPool.h Thu Feb 21 18:34:47 2008
@@ -19,7 +19,7 @@
#include "zypp/pool/PoolTraits.h"
#include "zypp/PoolItem.h"
-#include "zypp/ResFilters.h"
+#include "zypp/Filter.h"
///////////////////////////////////////////////////////////////////
namespace zypp
@@ -100,11 +100,11 @@
/** \name Iterate through all PoolItems matching a \c _Filter. */
//@{
template<class _Filter>
- filter_iterator<_Filter,const_iterator> filterBegin( const _Filter & filter_r ) const
+ filter_iterator<_Filter,const_iterator> filterBegin( const _Filter & filter_r ) const
{ return make_filter_begin( filter_r, *this ); }
template<class _Filter>
- filter_iterator<_Filter,const_iterator> filterEnd( const _Filter & filter_r ) const
+ filter_iterator<_Filter,const_iterator> filterEnd( const _Filter & filter_r ) const
{ return make_filter_end( filter_r, *this ); }
//@}
@@ -237,7 +237,26 @@
//@}
public:
- /** \name Iterate through requested/available Locales.
+ /** \name Handle locale support.
+ *
+ * A \ref filter::ByLocaleSupportort is provided to iterate over
+ * all items supporting a specific locale.
+ * \code
+ * ResPool pool( ResPool::instance() );
+ *
+ * filter::ByLocaleSupport f( Locale("de") );
+ * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
+ * {
+ * MIL << *it << endl; // supporting "de"
+ * }
+ *
+ * f = filter::ByLocaleSupport( pool.getRequestedLocales() );
+ * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
+ * {
+ * MIL << *it << endl; // supporting any requested locale
+ * }
+ *
+ * \endcode
*/
//@{
/** Set the requested locales.
Modified: trunk/libzypp/zypp/sat/Pool.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Pool.h?rev=8856&r1=8855&r2=8856&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/Pool.h (original)
+++ trunk/libzypp/zypp/sat/Pool.h Thu Feb 21 18:34:47 2008
@@ -130,6 +130,7 @@
/** Iterator behind the last \ref Solvable. */
SolvableIterator solvablesEnd() const;
+ public:
/** \name Iterate all Solvables matching a \c _Filter. */
//@{
template<class _Filter>
Modified: trunk/libzypp/zypp/sat/WhatProvides.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/WhatProvides.cc?rev=8856&r1=8855&r2=8856&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/WhatProvides.cc (original)
+++ trunk/libzypp/zypp/sat/WhatProvides.cc Thu Feb 21 18:34:47 2008
@@ -20,40 +20,40 @@
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////
-namespace sat
-{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
- WhatProvides::WhatProvides( Capability cap_r )
- : _begin( myPool().whatProvides( cap_r ) )
- {}
+ WhatProvides::WhatProvides( Capability cap_r )
+ : _begin( myPool().whatProvides( cap_r ) )
+ {}
- WhatProvides::size_type WhatProvides::size() const
- {
- if ( ! _begin )
- return 0;
-
- Capabilities::size_type ret = 0;
- for ( const sat::detail::IdType * end = _begin; *end; ++end )
+ WhatProvides::size_type WhatProvides::size() const
{
- ++ret;
+ if ( ! _begin )
+ return 0;
+
+ Capabilities::size_type ret = 0;
+ for ( const sat::detail::IdType * end = _begin; *end; ++end )
+ {
+ ++ret;
+ }
+ return ret;
}
- return ret;
- }
- /******************************************************************
- **
- ** FUNCTION NAME : operator<<
- ** FUNCTION TYPE : std::ostream &
- */
- std::ostream & operator<<( std::ostream & str, const WhatProvides & obj )
- {
- return dumpRange( str << "(" << obj.size() << ")", obj.begin(), obj.end() );
- }
+ /******************************************************************
+ **
+ ** FUNCTION NAME : operator<<
+ ** FUNCTION TYPE : std::ostream &
+ */
+ std::ostream & operator<<( std::ostream & str, const WhatProvides & obj )
+ {
+ return dumpRange( str << "(" << obj.size() << ")", obj.begin(), obj.end() );
+ }
- /////////////////////////////////////////////////////////////////
-} // namespace sat
-///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
Modified: trunk/libzypp/zypp/sat/WhatProvides.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/WhatProvides.h?rev=8856&r1=8855&r2=8856&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/WhatProvides.h (original)
+++ trunk/libzypp/zypp/sat/WhatProvides.h Thu Feb 21 18:34:47 2008
@@ -21,118 +21,118 @@
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////
-namespace sat
-{ /////////////////////////////////////////////////////////////////
-
///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : WhatProvides
- //
- /** Container of \ref Solvable providing a \ref Capability (read only).
- * \code
- * Capability cap("amarok < 1.13");
- * WhatProvides q( cap );
- * if ( ! q.empty() )
- * {
- * cout << "Found " << q.size() << " matches for " << cap << ":" << endl;
- * for_( it, q.begin(), q.end() )
- * cout << *it << end;
- * }
- * \endcode
- */
- class WhatProvides : protected detail::PoolMember
- {
- public:
- typedef Solvable value_type;
- typedef unsigned size_type;
-
- public:
- /** Default ctor */
- WhatProvides()
- : _begin( 0 )
- {}
-
- /** Ctor from Id pointer (friend \ref Solvable). */
- explicit
- WhatProvides( Capability cap_r );
-
- public:
- /** Whether the container is empty. */
- bool empty() const
- { return ! ( _begin && *_begin ); }
-
- /** Number of solvables inside. */
- size_type size() const;
-
- public:
- class const_iterator;
-
- /** Iterator pointing to the first \ref Solvable. */
- const_iterator begin() const;
-
- /** Iterator pointing behind the last \ref Solvable. */
- const_iterator end() const;
-
- private:
- const sat::detail::IdType * _begin;
- };
- ///////////////////////////////////////////////////////////////////
-
- /** \relates WhatProvides Stream output */
- std::ostream & operator<<( std::ostream & str, const WhatProvides & obj );
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : WhatProvides::const_iterator
- //
- /** \ref WhatProvides iterator.
- */
- class WhatProvides::const_iterator : public boost::iterator_adaptor<
- const_iterator // Derived
- , const detail::IdType * // Base
- , const Solvable // Value
- , boost::forward_traversal_tag // CategoryOrTraversal
- , const Solvable // Reference
- >
- {
- public:
- const_iterator()
- : const_iterator::iterator_adaptor_( 0 )
- {}
-
- explicit const_iterator( const sat::detail::IdType * _idx )
- : const_iterator::iterator_adaptor_( _idx )
- {}
-
- private:
- friend class boost::iterator_core_access;
-
- reference dereference() const
- { return ( base() ) ? Solvable( *base() ) : Solvable::nosolvable; }
-
- template
- bool equal( const boost::iterator_adaptor & rhs ) const
- { // NULL pointer is eqal pointer to Id 0
- return ( base() == rhs.base() // includes both NULL...
- || ( !rhs.base() && !*base() )
- || ( !base() && !*rhs.base() ) );
- }
-
- void increment()
- { ++base_reference(); }
- };
- ///////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : WhatProvides
+ //
+ /** Container of \ref Solvable providing a \ref Capability (read only).
+ * \code
+ * Capability cap("amarok < 1.13");
+ * WhatProvides q( cap );
+ * if ( ! q.empty() )
+ * {
+ * cout << "Found " << q.size() << " matches for " << cap << ":" << endl;
+ * for_( it, q.begin(), q.end() )
+ * cout << *it << end;
+ * }
+ * \endcode
+ */
+ class WhatProvides : protected detail::PoolMember
+ {
+ public:
+ typedef Solvable value_type;
+ typedef unsigned size_type;
+
+ public:
+ /** Default ctor */
+ WhatProvides()
+ : _begin( 0 )
+ {}
+
+ /** Ctor from Id pointer (friend \ref Solvable). */
+ explicit
+ WhatProvides( Capability cap_r );
+
+ public:
+ /** Whether the container is empty. */
+ bool empty() const
+ { return ! ( _begin && *_begin ); }
+
+ /** Number of solvables inside. */
+ size_type size() const;
+
+ public:
+ class const_iterator;
+
+ /** Iterator pointing to the first \ref Solvable. */
+ const_iterator begin() const;
+
+ /** Iterator pointing behind the last \ref Solvable. */
+ const_iterator end() const;
+
+ private:
+ const sat::detail::IdType * _begin;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates WhatProvides Stream output */
+ std::ostream & operator<<( std::ostream & str, const WhatProvides & obj );
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : WhatProvides::const_iterator
+ //
+ /** \ref WhatProvides iterator.
+ */
+ class WhatProvides::const_iterator : public boost::iterator_adaptor<
+ const_iterator // Derived
+ , const detail::IdType * // Base
+ , const Solvable // Value
+ , boost::forward_traversal_tag // CategoryOrTraversal
+ , const Solvable // Reference
+ >
+ {
+ public:
+ const_iterator()
+ : const_iterator::iterator_adaptor_( 0 )
+ {}
+
+ explicit const_iterator( const sat::detail::IdType * _idx )
+ : const_iterator::iterator_adaptor_( _idx )
+ {}
+
+ private:
+ friend class boost::iterator_core_access;
+
+ reference dereference() const
+ { return ( base() ) ? Solvable( *base() ) : Solvable::nosolvable; }
+
+ template
+ bool equal( const boost::iterator_adaptor & rhs ) const
+ { // NULL pointer is eqal pointer to Id 0
+ return ( base() == rhs.base() // includes both NULL...
+ || ( !rhs.base() && !*base() )
+ || ( !base() && !*rhs.base() ) );
+ }
+
+ void increment()
+ { ++base_reference(); }
+ };
+ ///////////////////////////////////////////////////////////////////
- inline WhatProvides::const_iterator WhatProvides::begin() const
- { return const_iterator( _begin ); }
+ inline WhatProvides::const_iterator WhatProvides::begin() const
+ { return const_iterator( _begin ); }
- inline WhatProvides::const_iterator WhatProvides::end() const
- { return const_iterator( 0 ); }
+ inline WhatProvides::const_iterator WhatProvides::end() const
+ { return const_iterator( 0 ); }
- /////////////////////////////////////////////////////////////////
-} // namespace sat
-///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org