1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/pool/PoolStats.h
12 #ifndef ZYPP_POOL_POOLSTATS_H
13 #define ZYPP_POOL_POOLSTATS_H
17 #include "zypp/base/Iterator.h"
18 #include "zypp/base/Functional.h"
19 #include "zypp/base/Counter.h"
20 #include "zypp/ResObject.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : PoolStats
33 /** Functor counting ResObjects per Kind.
44 struct PoolStats : public std::unary_function<ResObject::constPtr, void>
46 void operator()( ResObject::constPtr ptr )
49 ++_perKind[ptr->kind()];
52 typedef std::map<ResKind,Counter<unsigned> > KindMap;
53 Counter<unsigned> _total;
56 ///////////////////////////////////////////////////////////////////
58 /** \relates PoolStats Stream output */
59 std::ostream & operator<<( std::ostream & str, const PoolStats & obj );
61 /////////////////////////////////////////////////////////////////
63 ///////////////////////////////////////////////////////////////////
65 /** \relates pool::PoolStats Convenience to count and print out the
66 * number of ResObjects per Kind in a container.
67 * Fits container of ResObject::Ptr or PoolItem.
69 template <class TIterator>
70 std::ostream & dumpPoolStats( std::ostream & str,
71 TIterator begin_r, TIterator end_r )
73 pool::PoolStats stats;
74 std::for_each( begin_r, end_r,
75 functor::functorRef<void,ResObject::constPtr>(stats) );
79 /////////////////////////////////////////////////////////////////
81 ///////////////////////////////////////////////////////////////////
82 #endif // ZYPP_POOL_POOLSTATS_H