libzypp  10.5.0
Resolvable.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_RESOLVABLE_H
00013 #define ZYPP_RESOLVABLE_H
00014 
00015 #include <iosfwd>
00016 #include <string>
00017 
00018 #include "zypp/base/Deprecated.h"
00019 
00020 #include "zypp/base/ReferenceCounted.h"
00021 #include "zypp/base/NonCopyable.h"
00022 #include "zypp/base/PtrTypes.h"
00023 
00024 #include "zypp/sat/Solvable.h"
00025 
00027 namespace zypp
00028 { 
00029 
00030   class PoolItem;
00031 
00033   //
00034   //    CLASS NAME : Resolvable
00035   //
00039   class Resolvable : protected sat::Solvable,
00040                      public base::ReferenceCounted, private base::NonCopyable
00041   {
00042     friend std::ostream & operator<<( std::ostream & str, const Resolvable & obj );
00043 
00044   public:
00045     typedef Resolvable               Self;
00046     typedef ResTraits<Self>          TraitsType;
00047     typedef TraitsType::KindType     Kind;
00048     typedef TraitsType::PtrType      Ptr;
00049     typedef TraitsType::constPtrType constPtr;
00050 
00051   public:
00052 #ifndef SWIG // Swig treats it as syntax error
00053 
00054     using sat::Solvable::operator bool_type;
00055 #endif
00056 
00057     bool isSystem() const
00058     { return sat::Solvable::isSystem(); }
00059 
00061     bool onSystemByUser() const
00062     { return sat::Solvable::onSystemByUser(); }
00063 
00064     IdString ident() const
00065     { return sat::Solvable::ident(); }
00066 
00067     ResKind kind() const
00068     { return sat::Solvable::kind(); }
00069 
00070     bool isKind( const ResKind & kind_r ) const
00071     { return sat::Solvable::isKind( kind_r ); }
00072 
00073     template<class _Res>
00074     bool isKind() const
00075     { return sat::Solvable::isKind<_Res>(); }
00076 
00077     std::string name() const
00078     { return sat::Solvable::name(); }
00079 
00080     Edition edition() const
00081     { return sat::Solvable::edition(); }
00082 
00083     Arch arch() const
00084     { return sat::Solvable::arch(); }
00085 
00089     bool multiversionInstall() const
00090     { return sat::Solvable::multiversionInstall(); }
00091 
00095     Capabilities dep( Dep which_r ) const
00096     { return operator[]( which_r ); }
00097 
00098     Capabilities operator[]( Dep which_r ) const
00099     { return sat::Solvable::operator[]( which_r ); }
00100 
00101     Capabilities provides()    const
00102     { return sat::Solvable::provides(); }
00103 
00104     Capabilities requires()    const
00105     { return sat::Solvable::requires(); }
00106 
00107     Capabilities conflicts()   const
00108     { return sat::Solvable::conflicts(); }
00109 
00110     Capabilities obsoletes()   const
00111     { return sat::Solvable::obsoletes(); }
00112 
00113     Capabilities recommends()  const
00114     { return sat::Solvable::recommends(); }
00115 
00116     Capabilities suggests()    const
00117     { return sat::Solvable::suggests(); }
00118 
00119     Capabilities enhances()    const
00120     { return sat::Solvable::enhances(); }
00121 
00122     Capabilities supplements() const
00123     { return sat::Solvable::supplements(); }
00124 
00125     Capabilities prerequires() const
00126     { return sat::Solvable::prerequires(); }
00127 
00128     CapabilitySet providesNamespace( const std::string & namespace_r ) const
00129     { return sat::Solvable::providesNamespace( namespace_r ); }
00130 
00131     CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const
00132     { return sat::Solvable::valuesOfNamespace( namespace_r ); }
00134 
00135   public:
00137     const sat::Solvable & satSolvable() const { return *this; }
00138 
00140     PoolItem poolItem() const;
00141 
00142   protected:
00144     Resolvable( const sat::Solvable & solvable_r );
00146     virtual ~Resolvable();
00148     virtual std::ostream & dumpOn( std::ostream & str ) const;
00149  };
00151 
00153  inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
00154  { return obj.dumpOn( str ); }
00155 
00157  inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
00158  { return dumpOn( str, obj.satSolvable() ); }
00159 
00168   template<class _Res>
00169     inline bool isKind( const Resolvable::constPtr & p )
00170     { return p && p->kind() == ResTraits<_Res>::kind; }
00171 
00172   // Specialization for Resolvable: Always true.
00173   template<>
00174     inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
00175     { return p; }
00176 
00177   // Specialization for ResObject: Always true.
00178   template<>
00179     inline bool isKind<ResObject>( const Resolvable::constPtr & p )
00180     { return p; }
00181 
00182 
00191   template<class _Res>
00192     inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
00193     { return dynamic_pointer_cast<_Res>(p); }
00194 
00195   template<class _Res>
00196     inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
00197     { return dynamic_pointer_cast<const _Res>(p); }
00198 
00200 
00204   inline int compareByN( const Resolvable::constPtr & lhs,
00205                          const Resolvable::constPtr & rhs )
00206   {
00207     if ( lhs == rhs )
00208       return 0;
00209     if ( ! (lhs && rhs) )
00210       return lhs ? 1 : -1;
00211     int res = 0;
00212     if ( (res = lhs->kind().compare( rhs->kind() )) )
00213       return res;
00214     return lhs->name().compare( rhs->name() );
00215   }
00216 
00220   inline int compareByNVR( const Resolvable::constPtr & lhs,
00221                            const Resolvable::constPtr & rhs )
00222   {
00223     if ( lhs == rhs )
00224       return 0;
00225     if ( ! (lhs && rhs) )
00226       return lhs ? 1 : -1;
00227     int res = 0;
00228     if ( (res = lhs->kind().compare( rhs->kind() )) )
00229       return res;
00230     if ( (res = lhs->name().compare( rhs->name() )) )
00231       return res;
00232     return lhs->edition().compare( rhs->edition() );
00233   }
00234 
00238   inline int compareByNVRA( const Resolvable::constPtr & lhs,
00239                             const Resolvable::constPtr & rhs )
00240   {
00241     if ( lhs == rhs )
00242       return 0;
00243     if ( ! (lhs && rhs) )
00244       return lhs ? 1 : -1;
00245     int res = 0;
00246     if ( (res = lhs->kind().compare( rhs->kind() )) )
00247       return res;
00248     if ( (res = lhs->name().compare( rhs->name() )) )
00249       return res;
00250     if ( (res = lhs->edition().compare( rhs->edition() )) )
00251       return res;
00252     return lhs->arch().compare( rhs->arch() );
00253   }
00254 
00256 } // namespace zypp
00258 #endif // ZYPP_RESOLVABLE_H