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/ReferenceCounted.h"
00019 #include "zypp/base/NonCopyable.h"
00020 #include "zypp/base/PtrTypes.h"
00021 #include "zypp/ResTraits.h"
00022 
00023 #include "zypp/Edition.h"
00024 #include "zypp/Arch.h"
00025 #include "zypp/CapSetFwd.h"
00026 #include "zypp/Dep.h"
00027 
00029 namespace zypp
00030 { 
00031 
00032   struct NVRAD;
00033   class Dependencies;
00034 
00036   //
00037   //    CLASS NAME : Resolvable
00038   //
00043   class Resolvable : public base::ReferenceCounted, private base::NonCopyable
00044   {
00045   public:
00046     typedef Resolvable               Self;
00047     typedef ResTraits<Self>          TraitsType;
00048     typedef TraitsType::KindType     Kind;
00049     typedef TraitsType::PtrType      Ptr;
00050     typedef TraitsType::constPtrType constPtr;
00051 
00052   public:
00054     const Kind & kind() const;
00056     const std::string & name() const;
00058     const Edition & edition() const;
00060     const Arch & arch() const;
00061 
00065     const CapSet & dep( Dep which_r ) const;
00067     const Dependencies & deps() const;
00069 
00072     void injectProvides( const Capability & cap_r );
00073     void injectRequires( const Capability & cap_r );
00075 
00076   protected:
00078     Resolvable( const Kind & kind_r,
00079                 const NVRAD & nvrad_r );
00081     virtual ~Resolvable();
00083     virtual std::ostream & dumpOn( std::ostream & str ) const;
00084 
00085   private:
00087     struct Impl;
00089     RW_pointer<Impl> _pimpl;
00090   };
00092 
00101   template<class _Res>
00102     inline bool isKind( const Resolvable::constPtr & p )
00103     { return p && p->kind() == ResTraits<_Res>::kind; }
00104 
00105   // Specialization for Resolvable: Always true.
00106   template<>
00107     inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
00108     { return p; }
00109 
00110   // Specialization for ResObject: Always true.
00111   template<>
00112     inline bool isKind<ResObject>( const Resolvable::constPtr & p )
00113     { return p; }
00114 
00115 
00124   template<class _Res>
00125     inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
00126     { return dynamic_pointer_cast<_Res>(p); }
00127 
00128   template<class _Res>
00129     inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
00130     { return dynamic_pointer_cast<const _Res>(p); }
00131 
00133 
00137   inline int compareByN( const Resolvable::constPtr & lhs,
00138                          const Resolvable::constPtr & rhs )
00139   {
00140     if ( lhs == rhs )
00141       return 0;
00142     if ( ! (lhs && rhs) )
00143       return lhs ? 1 : -1;
00144     int res = 0;
00145     if ( (res = lhs->kind().compare( rhs->kind() )) )
00146       return res;
00147     return lhs->name().compare( rhs->name() );
00148   }
00149 
00153   inline int compareByNVR( const Resolvable::constPtr & lhs,
00154                            const Resolvable::constPtr & rhs )
00155   {
00156     if ( lhs == rhs )
00157       return 0;
00158     if ( ! (lhs && rhs) )
00159       return lhs ? 1 : -1;
00160     int res = 0;
00161     if ( (res = lhs->kind().compare( rhs->kind() )) )
00162       return res;
00163     if ( (res = lhs->name().compare( rhs->name() )) )
00164       return res;
00165     return lhs->edition().compare( rhs->edition() );
00166   }
00167 
00171   inline int compareByNVRA( const Resolvable::constPtr & lhs,
00172                             const Resolvable::constPtr & rhs )
00173   {
00174     if ( lhs == rhs )
00175       return 0;
00176     if ( ! (lhs && rhs) )
00177       return lhs ? 1 : -1;
00178     int res = 0;
00179     if ( (res = lhs->kind().compare( rhs->kind() )) )
00180       return res;
00181     if ( (res = lhs->name().compare( rhs->name() )) )
00182       return res;
00183     if ( (res = lhs->edition().compare( rhs->edition() )) )
00184       return res;
00185     return lhs->arch().compare( rhs->arch() );
00186   }
00187 
00189 } // namespace zypp
00191 #endif // ZYPP_RESOLVABLE_H

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