Remove obsolete ResStatus bits.
[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
14 #include "zypp/base/Easy.h"
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 C_Str & name_r, Resolvable::Kind kind_r )
56     : _kind( kind_r )
57     , _name( name_r )
58     {
59       for_( it, pool_r.byIdentBegin( kind_r, _name ), pool_r.byIdentEnd( kind_r, _name ) )
60       {
61         if ( it->status().isInstalled() )
62           _installed.insert( *it ) ;
63         else
64           _available.insert( *it );
65       }
66     }
67
68    NameKindProxy::NameKindProxy( ResPool pool_r, IdString name_r, Resolvable::Kind kind_r )
69     : _kind( kind_r )
70     , _name( name_r )
71     {
72       for_( it, pool_r.byIdentBegin( kind_r, _name ), pool_r.byIdentEnd( kind_r, _name ) )
73       {
74         if ( it->status().isInstalled() )
75           _installed.insert( *it ) ;
76         else
77           _available.insert( *it );
78       }
79     }
80
81   /******************************************************************
82   **
83   **    FUNCTION NAME : operator<<
84   **    FUNCTION TYPE : std::ostream &
85   */
86   std::ostream & operator<<( std::ostream & str, const NameKindProxy & obj )
87   {
88     str << "[" << obj.kind() << "] " << obj.name()
89         << " {" << obj.installedSize() << "/" << obj.availableSize() << "}" << endl;
90     std::for_each( obj.installedBegin(), obj.installedEnd(), PrintOn<PoolItem>(str,"  ") );
91     std::for_each( obj.availableBegin(), obj.availableEnd(), PrintOn<PoolItem>(str,"  ") );
92     return str;
93   }
94
95   /////////////////////////////////////////////////////////////////
96 } // namespace zypp
97 ///////////////////////////////////////////////////////////////////