1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Resolvable.h
12 #ifndef ZYPP_RESOLVABLE_H
13 #define ZYPP_RESOLVABLE_H
18 #include "zypp/base/ReferenceCounted.h"
19 #include "zypp/base/NonCopyable.h"
20 #include "zypp/base/PtrTypes.h"
21 #include "zypp/ResTraits.h"
23 #include "zypp/Edition.h"
24 #include "zypp/Arch.h"
25 #include "zypp/CapSetFwd.h"
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////
37 // CLASS NAME : Resolvable
39 /** Interface base for resolvable objects (identification and dependencies).
40 * \invariant \c provides <tt>name = edition</tt>
41 * \invariant \c prerequires is a subset of \c requires
43 class Resolvable : public base::ReferenceCounted, private base::NonCopyable
46 typedef Resolvable Self;
47 typedef ResTraits<Self> TraitsType;
48 typedef TraitsType::KindType Kind;
49 typedef TraitsType::PtrType Ptr;
50 typedef TraitsType::constPtrType constPtr;
54 const Kind & kind() const;
56 const std::string & name() const;
58 const Edition & edition() const;
60 const Arch & arch() const;
62 /** \name Dependencies. */
65 const CapSet & dep( Dep which_r ) const;
66 /** All dependencies. */
67 const Dependencies & deps() const;
70 /** \name Deprecated. */
72 void injectProvides( const Capability & cap_r );
73 void injectRequires( const Capability & cap_r );
78 Resolvable( const Kind & kind_r,
79 const NVRAD & nvrad_r );
81 virtual ~Resolvable();
82 /** Helper for stream output */
83 virtual std::ostream & dumpOn( std::ostream & str ) const;
88 /** Pointer to implementation */
89 RW_pointer<Impl> _pimpl;
91 ///////////////////////////////////////////////////////////////////
93 /** Test whether a Resolvable::Ptr is of a certain Kind.
94 * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
95 * of the specified Kind.
98 * isKind<Package>(resPtr);
102 inline bool isKind( const Resolvable::constPtr & p )
103 { return p && p->kind() == ResTraits<_Res>::kind; }
105 // Specialization for Resolvable: Always true.
107 inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
110 // Specialization for ResObject: Always true.
112 inline bool isKind<ResObject>( const Resolvable::constPtr & p )
116 /** Convert Resolvable::Ptr into Ptr of a certain Kind.
117 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
118 * not of the specified Kind.
119 * \relates Resolvable
121 * asKind<Package>(resPtr);
125 inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
126 { return dynamic_pointer_cast<_Res>(p); }
129 inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
130 { return dynamic_pointer_cast<const _Res>(p); }
132 ///////////////////////////////////////////////////////////////////
134 /** \relates Resolvable Compare Resolvable::constPtr according to
135 * \a kind and \a name.
137 inline int compareByN( const Resolvable::constPtr & lhs,
138 const Resolvable::constPtr & rhs )
142 if ( ! (lhs && rhs) )
145 if ( (res = lhs->kind().compare( rhs->kind() )) )
147 return lhs->name().compare( rhs->name() );
150 /** \relates Resolvable Compare Resolvable::constPtr according to
151 * \a kind, \a name and \a edition(compare!).
153 inline int compareByNVR( const Resolvable::constPtr & lhs,
154 const Resolvable::constPtr & rhs )
158 if ( ! (lhs && rhs) )
161 if ( (res = lhs->kind().compare( rhs->kind() )) )
163 if ( (res = lhs->name().compare( rhs->name() )) )
165 return lhs->edition().compare( rhs->edition() );
168 /** \relates Resolvable Compare Resolvable::constPtr according to
169 * \a kind, \a name, \a edition(compare!) and \a arch.
171 inline int compareByNVRA( const Resolvable::constPtr & lhs,
172 const Resolvable::constPtr & rhs )
176 if ( ! (lhs && rhs) )
179 if ( (res = lhs->kind().compare( rhs->kind() )) )
181 if ( (res = lhs->name().compare( rhs->name() )) )
183 if ( (res = lhs->edition().compare( rhs->edition() )) )
185 return lhs->arch().compare( rhs->arch() );
188 /////////////////////////////////////////////////////////////////
190 ///////////////////////////////////////////////////////////////////
191 #endif // ZYPP_RESOLVABLE_H