From 3c072270b5ea5d5b7133123a4b4089ffee0c59ff Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Sun, 22 Jan 2006 22:08:54 +0000 Subject: [PATCH] - Adjusted Filters --- zypp/ResFilters.h | 4 ++ zypp/base/FunctorRef.h | 86 ++++++++++++++++++++++++++------------ zypp/base/LogicalFilters.h | 7 ++-- 3 files changed, 67 insertions(+), 30 deletions(-) diff --git a/zypp/ResFilters.h b/zypp/ResFilters.h index 9d9b7fa92..0e0117de6 100644 --- a/zypp/ResFilters.h +++ b/zypp/ResFilters.h @@ -12,6 +12,10 @@ #ifndef ZYPP_RESFILTERS_H #define ZYPP_RESFILTERS_H +#include + +#include "zypp/base/FunctorRef.h" +#include "zypp/base/LogicalFilters.h" #include "zypp/Resolvable.h" /////////////////////////////////////////////////////////////////// diff --git a/zypp/base/FunctorRef.h b/zypp/base/FunctorRef.h index a7ce713ef..60e0ad529 100644 --- a/zypp/base/FunctorRef.h +++ b/zypp/base/FunctorRef.h @@ -12,6 +12,8 @@ #ifndef ZYPP_BASE_FUNCTORREF_H #define ZYPP_BASE_FUNCTORREF_H +#include + /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// @@ -28,46 +30,78 @@ namespace zypp * * \code * // Counts invokations of operator(). - * struct Counter - * { - * template - * void operator()( Tp ) + * template + * struct Counter : public std::unary_function<_Tp, void> + * { + * void operator()( _Tp ) * { ++_value; } * - * Counter() : _value( 0 ) {} - * unsigned _value; - * }; + * Counter() : _value( 0 ) {} * - * Counter counter; + * unsigned _value; + * }; + * + * std::set c; + * Counter counter; * // Invokations of FunctorRef are forwarded to counter: * std::for_each( c.begin, c.end(), functorRef(counter) ); - * \endcode + * \endcode + * + * \note FunctorRef must be able to deduce the signature of \c _Functor::operator(). + * Per default the tyedefs \c _Functor::argument_type and \c _Functor::result_type + * are expected. They are e.g. provided by deriving your \c _Functor from + * \c std::unary_function. In case these typedefs are not provided, you have to + * specify them as additional template arguments: + * + * \code + * // Counts invokations of operator(). + * struct Counter + * { + * template + * void operator()( _Tp ) + * { ++_value; } + * + * Counter() : _value( 0 ) {} + * + * unsigned _value; + * }; + * + * std::set c; + * Counter counter; + * // Invokations of FunctorRef are forwarded to counter: + * std::for_each( c.begin, c.end(), + * functorRef(counter) ); + * \endcode */ - template - class FunctorRef : public std::unary_function - { - public: - FunctorRef( _Functor & f_r ) - : _f( f_r ) - {} - - result_type operator()( argument_type a1 ) const + template + class FunctorRef : public std::unary_function { - return _f.operator()( a1 ); - } + public: + FunctorRef( _Functor & f_r ) + : _f( f_r ) + {} + + typename FunctorRef::result_type operator()( typename FunctorRef::argument_type a1 ) const + { + return _f( a1 ); + } - private: - _Functor & _f; - }; + private: + _Functor & _f; + }; /** Convenience function creating a \ref FunctorRef. */ template FunctorRef<_Functor> functorRef( _Functor & f_r ) { return FunctorRef<_Functor>( f_r ); } - ///////////////////////////////////////////////////////////////// - } // namespace functor + template + FunctorRef<_Functor,argument_type,result_type> functorRef( _Functor & f_r ) + { return FunctorRef<_Functor,argument_type,result_type>( f_r ); } + + ///////////////////////////////////////////////////////////////// +} // namespace functor /////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// } // namespace zypp diff --git a/zypp/base/LogicalFilters.h b/zypp/base/LogicalFilters.h index a2120045f..e2b09a7b8 100644 --- a/zypp/base/LogicalFilters.h +++ b/zypp/base/LogicalFilters.h @@ -12,6 +12,8 @@ #ifndef ZYPP_BASE_LOGICALFILTERS_H #define ZYPP_BASE_LOGICALFILTERS_H +#include + /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// @@ -45,12 +47,9 @@ namespace zypp * struct Print; // functor priniting elements * struct Count; // functor counting number of elements * - * * std::for_each( c.begin(), c.end(), - * - * + * chain( Print(), Count() ) ); * \endcode - * */ //@{ /////////////////////////////////////////////////////////////////// -- 2.34.1