)
SET( zypp_base_HEADERS
+ base/Collector.h
base/SerialNumber.h
base/Easy.h
base/Random.h
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/base/Collector.h
+ *
+*/
+#ifndef ZYPP_BASE_COLLECTOR_H
+#define ZYPP_BASE_COLLECTOR_H
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+namespace functor
+{ /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : _Collector<_OutputIterator>
+ //
+ /** Functor feeding values to an output_iterator.
+ *
+ * \code
+ * LocaleSet locales;
+ * for_each( begin(), end(),
+ * Collector( std::inserter( locales_r, locales_r.begin() ) ) );
+ * \endcode
+ *
+ * \see Convenience constructor \ref Collector.
+ */
+ template<class _OutputIterator>
+ struct _Collector
+ {
+ _Collector( _OutputIterator iter_r ) : _iter( iter_r ) {}
+
+ template<class _Tp>
+ bool operator()( const _Tp & value_r ) const
+ {
+ *_iter++ = value_r;
+ return true;
+ }
+
+ private:
+ mutable _OutputIterator _iter;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates _Collector Convenience constructor. */
+ template<class _OutputIterator>
+ inline _Collector<_OutputIterator> Collector( _OutputIterator iter_r )
+ { return _Collector<_OutputIterator>( iter_r ); }
+
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+} // namespace functor
+///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_BASE_COLLECTOR_H
#ifndef ZYPP_BASE_FUNCTIONAL_H
#define ZYPP_BASE_FUNCTIONAL_H
-//#include <functional>
#include <boost/functional.hpp>
+#include "zypp/base/Function.h"
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
using boost::mem_fun;
using boost::mem_fun_ref;
-
///////////////////////////////////////////////////////////////////
namespace functor
{ /////////////////////////////////////////////////////////////////
#define ZYPP_BASE_ITERATOR_H
#include <iterator>
-#include <functional>
#include <utility>
+#include <boost/functional.hpp>
#include <boost/iterator/filter_iterator.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/function_output_iterator.hpp>
/** Iterator behind the last \ref Solvable. */
SolvableIterator solvablesEnd() const;
- public:
+ /** \name Iterate all Solvables matching a \c _Filter. */
+ //@{
+ template<class _Filter>
+ filter_iterator<_Filter,SolvableIterator> filterBegin( const _Filter & filter_r ) const
+ { return make_filter_iterator( filter_r, solvablesBegin(), solvablesEnd() ); }
+
+ template<class _Filter>
+ filter_iterator<_Filter,SolvableIterator> filterEnd( const _Filter & filter_r ) const
+ { return make_filter_iterator( filter_r, solvablesEnd(), solvablesEnd() ); }
+ //@}
+
+ public:
/** Conainer of all \ref Solvable providing \c cap_r. */
WhatProvides whatProvides( Capability cap_r ) const
{ return WhatProvides( cap_r ); }
#include "zypp/base/Logger.h"
#include "zypp/base/Gettext.h"
#include "zypp/base/Exception.h"
-#include "zypp/base/Function.h"
#include "zypp/base/Functional.h"
+#include "zypp/base/Collector.h"
#include "zypp/sat/detail/PoolImpl.h"
#include "zypp/sat/Solvable.h"
///////////////////////////////////////////////////////////////////
namespace
{ /////////////////////////////////////////////////////////////////
+ /** Expand \ref Capability and call \c fnc_r for each namescpace:language
+ * dependency. Return #invocations of fnc_r, negative if fnc_r returned
+ * false to indicate abort.
+ */
int invokeOnEachSupportedLocale( Capability cap_r, function<bool (const Locale &)> fnc_r )
{
CapDetail detail( cap_r );
return 0;
}
- // return #invocations of fnc_r, negative if fnc_r returned false to indicate abort.
+ /** Expand \ref Capability and call \c fnc_r for each namescpace:language
+ * dependency. Return #invocations of fnc_r, negative if fnc_r returned
+ * false to indicate abort.
+ */
inline int invokeOnEachSupportedLocale( Capabilities cap_r, function<bool (const Locale &)> fnc_r )
{
int cnt = 0;
}
return cnt;
}
+ //@}
// Functor returning false if a Locale is in the set.
struct NoMatchIn
const LocaleSet & _locales;
};
- template<class _OutputIterator>
- struct _Collector
- {
- _Collector( _OutputIterator iter_r ) : _iter( iter_r ) {}
-
- template<class _Tp>
- bool operator()( const _Tp & value_r ) const
- {
- *_iter++ = value_r;
- return true;
- }
-
- mutable _OutputIterator _iter;
- };
-
- template<class _OutputIterator>
- inline _Collector<_OutputIterator> Collector( _OutputIterator iter_r )
- { return _Collector<_OutputIterator>( iter_r ); }
-
} /////////////////////////////////////////////////////////////////
bool Solvable::supportsLocales() const
void Solvable::getSupportedLocales( LocaleSet & locales_r ) const
{
invokeOnEachSupportedLocale( supplements(),
- Collector( std::inserter( locales_r, locales_r.begin() ) ) );
+ functor::Collector( std::inserter( locales_r, locales_r.begin() ) ) );
}
/******************************************************************