1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Resolvable.h
12 #ifndef ZYPP_RESOLVABLE_H
13 #define ZYPP_RESOLVABLE_H
18 #include "zypp/base/Deprecated.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 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 #ifndef SWIG // Swig treats it as syntax error
53 /** Whether this represents a valid- or no-solvable. */
54 using sat::Solvable::operator bool_type;
56 /** Whether this represents an installed solvable. */
58 { return sat::Solvable::isSystem(); }
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 /** \deprecated Use \ref multiversionInstall. */
89 bool installOnly() const
90 { return sat::Solvable::multiversionInstall(); }
92 /** \name Dependencies. */
95 Capabilities dep( Dep which_r ) const
96 { return operator[]( which_r ); }
98 Capabilities operator[]( Dep which_r ) const
99 { return sat::Solvable::operator[]( which_r ); }
101 Capabilities provides() const
102 { return sat::Solvable::provides(); }
104 Capabilities requires() const
105 { return sat::Solvable::requires(); }
107 Capabilities conflicts() const
108 { return sat::Solvable::conflicts(); }
110 Capabilities obsoletes() const
111 { return sat::Solvable::obsoletes(); }
113 Capabilities recommends() const
114 { return sat::Solvable::recommends(); }
116 Capabilities suggests() const
117 { return sat::Solvable::suggests(); }
119 Capabilities enhances() const
120 { return sat::Solvable::enhances(); }
122 Capabilities supplements() const
123 { return sat::Solvable::supplements(); }
125 Capabilities prerequires() const
126 { return sat::Solvable::prerequires(); }
128 CapabilitySet providesNamespace( const std::string & namespace_r ) const
129 { return sat::Solvable::providesNamespace( namespace_r ); }
131 CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const
132 { return sat::Solvable::valuesOfNamespace( namespace_r ); }
136 /** Access the corresponding \ref sat:::Solvable. */
137 const sat::Solvable & satSolvable() const { return *this; }
139 /** Access the corresponding \ref PoolItem. */
140 PoolItem poolItem() const;
144 Resolvable( const sat::Solvable & solvable_r );
146 virtual ~Resolvable();
147 /** Helper for stream output */
148 virtual std::ostream & dumpOn( std::ostream & str ) const;
150 ///////////////////////////////////////////////////////////////////
152 /** \relates Resolvable Stream output */
153 inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
154 { return obj.dumpOn( str ); }
156 /** \relates Resolvable More verbose stream output including dependencies */
157 inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
158 { return dumpOn( str, obj.satSolvable() ); }
160 /** Test whether a Resolvable::Ptr is of a certain Kind.
161 * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
162 * of the specified Kind.
163 * \relates Resolvable
165 * isKind<Package>(resPtr);
169 inline bool isKind( const Resolvable::constPtr & p )
170 { return p && p->kind() == ResTraits<_Res>::kind; }
172 // Specialization for Resolvable: Always true.
174 inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
177 // Specialization for ResObject: Always true.
179 inline bool isKind<ResObject>( const Resolvable::constPtr & p )
183 /** Convert Resolvable::Ptr into Ptr of a certain Kind.
184 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
185 * not of the specified Kind.
186 * \relates Resolvable
188 * asKind<Package>(resPtr);
192 inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
193 { return dynamic_pointer_cast<_Res>(p); }
196 inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
197 { return dynamic_pointer_cast<const _Res>(p); }
199 ///////////////////////////////////////////////////////////////////
201 /** \relates Resolvable Compare Resolvable::constPtr according to
202 * \a kind and \a name.
204 inline int compareByN( const Resolvable::constPtr & lhs,
205 const Resolvable::constPtr & rhs )
209 if ( ! (lhs && rhs) )
212 if ( (res = lhs->kind().compare( rhs->kind() )) )
214 return lhs->name().compare( rhs->name() );
217 /** \relates Resolvable Compare Resolvable::constPtr according to
218 * \a kind, \a name and \a edition(compare!).
220 inline int compareByNVR( const Resolvable::constPtr & lhs,
221 const Resolvable::constPtr & rhs )
225 if ( ! (lhs && rhs) )
228 if ( (res = lhs->kind().compare( rhs->kind() )) )
230 if ( (res = lhs->name().compare( rhs->name() )) )
232 return lhs->edition().compare( rhs->edition() );
235 /** \relates Resolvable Compare Resolvable::constPtr according to
236 * \a kind, \a name, \a edition(compare!) and \a arch.
238 inline int compareByNVRA( const Resolvable::constPtr & lhs,
239 const Resolvable::constPtr & rhs )
243 if ( ! (lhs && rhs) )
246 if ( (res = lhs->kind().compare( rhs->kind() )) )
248 if ( (res = lhs->name().compare( rhs->name() )) )
250 if ( (res = lhs->edition().compare( rhs->edition() )) )
252 return lhs->arch().compare( rhs->arch() );
255 /////////////////////////////////////////////////////////////////
257 ///////////////////////////////////////////////////////////////////
258 #endif // ZYPP_RESOLVABLE_H