NameKindProxy.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 //#include "zypp/base/Logger.h"
00014 
00015 #include "zypp/NameKindProxy.h"
00016 
00017 using std::endl;
00018 
00020 namespace zypp
00021 { 
00022 
00023   namespace
00024   {
00026     template<class _Tp>
00027       struct PrintOn : public std::unary_function<_Tp, bool>
00028       {
00029         bool operator()( const _Tp & obj )
00030         {
00031           _str << _prfx << obj << std::endl;
00032           return true;
00033         }
00034 
00035         PrintOn( std::ostream & str, const std::string & prfx = std::string() )
00036         : _str( str )
00037         , _prfx( prfx )
00038         {}
00039         std::ostream & _str;
00040         std::string _prfx;
00041       };
00042   }
00043 
00045   //
00046   //    CLASS NAME : NameKindProxy
00047   //
00049 
00051   //
00052   //    METHOD NAME : NameKindProxy::NameKindProxy
00053   //    METHOD TYPE : Ctor
00054   //
00055   NameKindProxy::NameKindProxy( ResPool pool_r, const std::string & name_r, Resolvable::Kind kind_r )
00056     : _kind( kind_r )
00057     , _name( name_r )
00058     {
00059       for ( ResPool::byName_iterator it = pool_r.byNameBegin( _name );
00060             it != pool_r.byNameEnd( _name ); ++it )
00061         {
00062           if ( (*it)->kind() == _kind )
00063             {
00064               if ( it->status().isInstalled() )
00065                 _installed.insert( *it ) ;
00066               else
00067                 _available.insert( *it );
00068             }
00069         }
00070     }
00071 
00072   /******************************************************************
00073   **
00074   **    FUNCTION NAME : operator<<
00075   **    FUNCTION TYPE : std::ostream &
00076   */
00077   std::ostream & operator<<( std::ostream & str, const NameKindProxy & obj )
00078   {
00079     str << "[" << obj.kind() << "] " << obj.name()
00080         << " {" << obj.installedSize() << "/" << obj.availableSize() << "}" << endl;
00081     std::for_each( obj.installedBegin(), obj.installedEnd(), PrintOn<PoolItem>(str,"  ") );
00082     std::for_each( obj.availableBegin(), obj.availableEnd(), PrintOn<PoolItem>(str,"  ") );
00083     return str;
00084   }
00085 
00087 } // namespace zypp

Generated on Thu Jul 6 00:07:21 2006 for zypp by  doxygen 1.4.6