libzypp  10.5.0
ByIdent.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_POOL_BYIDENT_H
00013 #define ZYPP_POOL_BYIDENT_H
00014 
00015 #include "zypp/PoolItem.h"
00016 
00018 namespace zypp
00019 { 
00020 
00021   namespace pool
00022   { 
00023 
00026     class ByIdent
00027     {
00028       public:
00029         ByIdent()
00030         : _id( 0 )
00031         {}
00032 
00033         explicit ByIdent( sat::Solvable slv_r )
00034         : _id( makeIdent( slv_r ) )
00035         {}
00036 
00037         explicit ByIdent( IdString ident_r )
00038         : _id( ident_r.id() )
00039         {}
00040 
00041         ByIdent( ResKind kind_r, IdString name_r )
00042         : _id( makeIdent( kind_r, name_r ) )
00043         {}
00044 
00045         ByIdent( ResKind kind_r, const C_Str & name_r )
00046         : _id( makeIdent( kind_r, name_r ) )
00047         {}
00048 
00049       public:
00050         bool operator()( sat::Solvable slv_r ) const
00051         {
00052           return _id >= 0 ? ( slv_r.ident().id() == _id && ! slv_r.isKind( ResKind::srcpackage ) )
00053             : ( slv_r.ident().id() == -_id && slv_r.isKind( ResKind::srcpackage ) );
00054         }
00055 
00056         bool operator()( const PoolItem & pi_r ) const
00057         { return operator()( pi_r.satSolvable() ); }
00058 
00059         bool operator()( ResObject::constPtr p_r ) const
00060         { return p_r ? operator()( p_r->satSolvable() ) : !_id; }
00061 
00062       private:
00063         sat::detail::IdType makeIdent( sat::Solvable slv_r )
00064         {
00065           return slv_r.isKind( ResKind::srcpackage ) ? -slv_r.ident().id()
00066             : slv_r.ident().id();
00067         }
00068 
00069         sat::detail::IdType makeIdent( ResKind kind_r, IdString name_r )
00070         {
00071           if ( kind_r == ResKind::package )
00072             return name_r.id();
00073           else if ( kind_r == ResKind::srcpackage )
00074             return -name_r.id();
00075           return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
00076         }
00077 
00078         sat::detail::IdType makeIdent( ResKind kind_r, const C_Str & name_r )
00079         {
00080           if ( kind_r == ResKind::package )
00081             return IdString( name_r ).id();
00082           else if ( kind_r == ResKind::srcpackage )
00083             return -(IdString( name_r ).id());
00084           return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
00085         }
00086 
00087       public:
00088         sat::detail::IdType get() const { return _id; }
00089 
00090       private:
00094         sat::detail::IdType _id;
00095     };
00096 
00098   } // namespace pool
00101 } // namespace zypp
00103 #endif // ZYPP_POOL_BYIDENT_H