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 /** \name Dependencies. */
91 Capabilities dep( Dep which_r ) const
92 { return operator[]( which_r ); }
94 Capabilities operator[]( Dep which_r ) const
95 { return sat::Solvable::operator[]( which_r ); }
97 Capabilities provides() const
98 { return sat::Solvable::provides(); }
100 Capabilities requires() const
101 { return sat::Solvable::requires(); }
103 Capabilities conflicts() const
104 { return sat::Solvable::conflicts(); }
106 Capabilities obsoletes() const
107 { return sat::Solvable::obsoletes(); }
109 Capabilities recommends() const
110 { return sat::Solvable::recommends(); }
112 Capabilities suggests() const
113 { return sat::Solvable::suggests(); }
115 Capabilities enhances() const
116 { return sat::Solvable::enhances(); }
118 Capabilities supplements() const
119 { return sat::Solvable::supplements(); }
121 Capabilities prerequires() const
122 { return sat::Solvable::prerequires(); }
124 CapabilitySet providesNamespace( const std::string & namespace_r ) const
125 { return sat::Solvable::providesNamespace( namespace_r ); }
127 CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const
128 { return sat::Solvable::valuesOfNamespace( namespace_r ); }
132 /** Access the corresponding \ref sat:::Solvable. */
133 const sat::Solvable & satSolvable() const { return *this; }
135 /** Access the corresponding \ref PoolItem. */
136 PoolItem poolItem() const;
140 Resolvable( const sat::Solvable & solvable_r );
142 virtual ~Resolvable();
143 /** Helper for stream output */
144 virtual std::ostream & dumpOn( std::ostream & str ) const;
146 ///////////////////////////////////////////////////////////////////
148 /** \relates Resolvable Stream output */
149 inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
150 { return obj.dumpOn( str ); }
152 /** \relates Resolvable More verbose stream output including dependencies */
153 inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
154 { return dumpOn( str, obj.satSolvable() ); }
156 /** Test whether a Resolvable::Ptr is of a certain Kind.
157 * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
158 * of the specified Kind.
159 * \relates Resolvable
161 * isKind<Package>(resPtr);
165 inline bool isKind( const Resolvable::constPtr & p )
166 { return p && p->kind() == ResTraits<_Res>::kind; }
168 // Specialization for Resolvable: Always true.
170 inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
173 // Specialization for ResObject: Always true.
175 inline bool isKind<ResObject>( const Resolvable::constPtr & p )
179 /** Convert Resolvable::Ptr into Ptr of a certain Kind.
180 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
181 * not of the specified Kind.
182 * \relates Resolvable
184 * asKind<Package>(resPtr);
188 inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
189 { return dynamic_pointer_cast<_Res>(p); }
192 inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
193 { return dynamic_pointer_cast<const _Res>(p); }
195 ///////////////////////////////////////////////////////////////////
197 /** \relates Resolvable Compare Resolvable::constPtr according to
198 * \a kind and \a name.
200 inline int compareByN( const Resolvable::constPtr & lhs,
201 const Resolvable::constPtr & rhs )
205 if ( ! (lhs && rhs) )
208 if ( (res = lhs->kind().compare( rhs->kind() )) )
210 return lhs->name().compare( rhs->name() );
213 /** \relates Resolvable Compare Resolvable::constPtr according to
214 * \a kind, \a name and \a edition(compare!).
216 inline int compareByNVR( const Resolvable::constPtr & lhs,
217 const Resolvable::constPtr & rhs )
221 if ( ! (lhs && rhs) )
224 if ( (res = lhs->kind().compare( rhs->kind() )) )
226 if ( (res = lhs->name().compare( rhs->name() )) )
228 return lhs->edition().compare( rhs->edition() );
231 /** \relates Resolvable Compare Resolvable::constPtr according to
232 * \a kind, \a name, \a edition(compare!) and \a arch.
234 inline int compareByNVRA( const Resolvable::constPtr & lhs,
235 const Resolvable::constPtr & rhs )
239 if ( ! (lhs && rhs) )
242 if ( (res = lhs->kind().compare( rhs->kind() )) )
244 if ( (res = lhs->name().compare( rhs->name() )) )
246 if ( (res = lhs->edition().compare( rhs->edition() )) )
248 return lhs->arch().compare( rhs->arch() );
251 /////////////////////////////////////////////////////////////////
253 ///////////////////////////////////////////////////////////////////
254 #endif // ZYPP_RESOLVABLE_H