1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Resolvable.h
12 #ifndef ZYPP_RESOLVABLE_H
13 #define ZYPP_RESOLVABLE_H
18 #include "zypp/APIConfig.h"
20 #include "zypp/base/ReferenceCounted.h"
21 #include "zypp/base/NonCopyable.h"
22 #include "zypp/base/PtrTypes.h"
24 #include "zypp/sat/Solvable.h"
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 // CLASS NAME : Resolvable
36 /** Interface base for resolvable objects (identification and dependencies).
37 * \todo Merge with ResObject
39 class Resolvable : protected zypp::sat::Solvable, // Note: gcc bug #52841 prohibits using just sat::Solvable
40 public base::ReferenceCounted, private base::NonCopyable
42 friend std::ostream & operator<<( std::ostream & str, const Resolvable & obj );
45 typedef Resolvable Self;
46 typedef ResTraits<Self> TraitsType;
47 typedef TraitsType::KindType Kind;
48 typedef TraitsType::PtrType Ptr;
49 typedef TraitsType::constPtrType constPtr;
52 /** Whether this represents an installed solvable. */
54 { return sat::Solvable::isSystem(); }
56 /** \copydoc sat::Solvable::onSystemByUser() */
57 bool onSystemByUser() const
58 { return sat::Solvable::onSystemByUser(); }
60 IdString ident() const
61 { return sat::Solvable::ident(); }
64 { return sat::Solvable::kind(); }
66 bool isKind( const ResKind & kind_r ) const
67 { return sat::Solvable::isKind( kind_r ); }
71 { return sat::Solvable::isKind<_Res>(); }
73 std::string name() const
74 { return sat::Solvable::name(); }
76 Edition edition() const
77 { return sat::Solvable::edition(); }
80 { return sat::Solvable::arch(); }
82 /** Whether different versions of this package can be installed at the same time.
83 * Per default \c false. \see also \ref ZConfig::multiversion.
85 bool multiversionInstall() const
86 { return sat::Solvable::multiversionInstall(); }
88 using sat::Solvable::asString;
89 using sat::Solvable::asUserString;
91 /** \name Dependencies. */
94 Capabilities dep( Dep which_r ) const
95 { return operator[]( which_r ); }
97 Capabilities operator[]( Dep which_r ) const
98 { return sat::Solvable::operator[]( which_r ); }
100 Capabilities provides() const
101 { return sat::Solvable::provides(); }
103 Capabilities requires() const
104 { return sat::Solvable::requires(); }
106 Capabilities conflicts() const
107 { return sat::Solvable::conflicts(); }
109 Capabilities obsoletes() const
110 { return sat::Solvable::obsoletes(); }
112 Capabilities recommends() const
113 { return sat::Solvable::recommends(); }
115 Capabilities suggests() const
116 { return sat::Solvable::suggests(); }
118 Capabilities enhances() const
119 { return sat::Solvable::enhances(); }
121 Capabilities supplements() const
122 { return sat::Solvable::supplements(); }
124 Capabilities prerequires() const
125 { return sat::Solvable::prerequires(); }
127 CapabilitySet providesNamespace( const std::string & namespace_r ) const
128 { return sat::Solvable::providesNamespace( namespace_r ); }
130 CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const
131 { return sat::Solvable::valuesOfNamespace( namespace_r ); }
135 /** Access the corresponding \ref sat:::Solvable. */
136 const sat::Solvable & satSolvable() const { return *this; }
138 /** Access the corresponding \ref PoolItem. */
139 PoolItem poolItem() const;
143 Resolvable( const sat::Solvable & solvable_r );
145 virtual ~Resolvable();
146 /** Helper for stream output */
147 virtual std::ostream & dumpOn( std::ostream & str ) const;
149 ///////////////////////////////////////////////////////////////////
151 /** \relates Resolvable Stream output */
152 inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
153 { return obj.dumpOn( str ); }
155 /** \relates Resolvable More verbose stream output including dependencies */
156 inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
157 { return dumpOn( str, obj.satSolvable() ); }
159 /** Test whether a Resolvable::Ptr is of a certain Kind.
160 * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
161 * of the specified Kind.
162 * \relates Resolvable
164 * isKind<Package>(resPtr);
168 inline bool isKind( const Resolvable::constPtr & p )
169 { return p && p->kind() == ResTraits<_Res>::kind; }
171 // Specialization for Resolvable: Always true.
173 inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
176 // Specialization for ResObject: Always true.
178 inline bool isKind<ResObject>( const Resolvable::constPtr & p )
182 /** Convert Resolvable::Ptr into Ptr of a certain Kind.
183 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
184 * not of the specified Kind.
185 * \relates Resolvable
187 * asKind<Package>(resPtr);
191 inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
192 { return dynamic_pointer_cast<_Res>(p); }
195 inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
196 { return dynamic_pointer_cast<const _Res>(p); }
198 ///////////////////////////////////////////////////////////////////
200 /** \relates Resolvable Compare Resolvable::constPtr according to
201 * \a kind and \a name.
203 inline int compareByN( const Resolvable::constPtr & lhs,
204 const Resolvable::constPtr & rhs )
208 if ( ! (lhs && rhs) )
211 if ( (res = lhs->kind().compare( rhs->kind() )) )
213 return lhs->name().compare( rhs->name() );
216 /** \relates Resolvable Compare Resolvable::constPtr according to
217 * \a kind, \a name and \a edition(compare!).
219 inline int compareByNVR( const Resolvable::constPtr & lhs,
220 const Resolvable::constPtr & rhs )
224 if ( ! (lhs && rhs) )
227 if ( (res = lhs->kind().compare( rhs->kind() )) )
229 if ( (res = lhs->name().compare( rhs->name() )) )
231 return lhs->edition().compare( rhs->edition() );
234 /** \relates Resolvable Compare Resolvable::constPtr according to
235 * \a kind, \a name, \a edition(compare!) and \a arch.
237 inline int compareByNVRA( const Resolvable::constPtr & lhs,
238 const Resolvable::constPtr & rhs )
242 if ( ! (lhs && rhs) )
245 if ( (res = lhs->kind().compare( rhs->kind() )) )
247 if ( (res = lhs->name().compare( rhs->name() )) )
249 if ( (res = lhs->edition().compare( rhs->edition() )) )
251 return lhs->arch().compare( rhs->arch() );
254 /////////////////////////////////////////////////////////////////
256 ///////////////////////////////////////////////////////////////////
257 #endif // ZYPP_RESOLVABLE_H