ignore
[platform/upstream/libzypp.git] / zypp / NameKindProxy.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/NameKindProxy.cc
10  *
11 */
12 #include <iostream>
13 //#include "zypp/base/Logger.h"
14
15 #include "zypp/NameKindProxy.h"
16
17 using std::endl;
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22
23   namespace
24   {
25     /** \todo Move it to base/IOStream.h */
26     template<class _Tp>
27       struct PrintOn : public std::unary_function<_Tp, bool>
28       {
29         bool operator()( const _Tp & obj )
30         {
31           _str << _prfx << obj << std::endl;
32           return true;
33         }
34
35         PrintOn( std::ostream & str, const std::string & prfx = std::string() )
36         : _str( str )
37         , _prfx( prfx )
38         {}
39         std::ostream & _str;
40         std::string _prfx;
41       };
42   }
43
44   ///////////////////////////////////////////////////////////////////
45   //
46   //    CLASS NAME : NameKindProxy
47   //
48   ///////////////////////////////////////////////////////////////////
49
50   ///////////////////////////////////////////////////////////////////
51   //
52   //    METHOD NAME : NameKindProxy::NameKindProxy
53   //    METHOD TYPE : Ctor
54   //
55   NameKindProxy::NameKindProxy( ResPool pool_r, const std::string & name_r, Resolvable::Kind kind_r )
56     : _kind( kind_r )
57     , _name( name_r )
58     {
59       for ( ResPool::byName_iterator it = pool_r.byNameBegin( _name );
60             it != pool_r.byNameEnd( _name ); ++it )
61         {
62           if ( (*it)->kind() == _kind )
63             {
64               if ( it->status().isInstalled() )
65                 _installed.insert( *it ) ;
66               else
67                 _available.insert( *it );
68             }
69         }
70     }
71
72   /******************************************************************
73   **
74   **    FUNCTION NAME : operator<<
75   **    FUNCTION TYPE : std::ostream &
76   */
77   std::ostream & operator<<( std::ostream & str, const NameKindProxy & obj )
78   {
79     str << "[" << obj.kind() << "] " << obj.name()
80         << " {" << obj.installedSize() << "/" << obj.availableSize() << "}" << endl;
81     std::for_each( obj.installedBegin(), obj.installedEnd(), PrintOn<PoolItem>(str,"  ") );
82     std::for_each( obj.availableBegin(), obj.availableEnd(), PrintOn<PoolItem>(str,"  ") );
83     return str;
84   }
85
86   /////////////////////////////////////////////////////////////////
87 } // namespace zypp
88 ///////////////////////////////////////////////////////////////////