libzypp  10.5.0
PoolStats.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_POOL_POOLSTATS_H
00013 #define ZYPP_POOL_POOLSTATS_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/base/Iterator.h"
00018 #include "zypp/base/Functional.h"
00019 #include "zypp/base/Counter.h"
00020 #include "zypp/ResObject.h"
00021 
00023 namespace zypp
00024 { 
00025 
00026   namespace pool
00027   { 
00028 
00030     //
00031     //  CLASS NAME : PoolStats
00032     //
00044     struct PoolStats : public std::unary_function<ResObject::constPtr, void>
00045     {
00046       void operator()( ResObject::constPtr ptr )
00047       {
00048         ++_total;
00049         ++_perKind[ptr->kind()];
00050       }
00051     public:
00052       typedef std::map<ResKind,Counter<unsigned> > KindMap;
00053       Counter<unsigned> _total;
00054       KindMap           _perKind;
00055     };
00057 
00059     std::ostream & operator<<( std::ostream & str, const PoolStats & obj );
00060 
00062   } // namespace pool
00064 
00069   template <class _Iterator>
00070     std::ostream & dumpPoolStats( std::ostream & str,
00071                                   _Iterator begin_r, _Iterator end_r )
00072     {
00073       pool::PoolStats stats;
00074       std::for_each( begin_r, end_r,
00075                      functor::functorRef<void,ResObject::constPtr>(stats) );
00076       return str << stats;
00077     }
00078 
00080 } // namespace zypp
00082 #endif // ZYPP_POOL_POOLSTATS_H