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(); }
83 * Flag in the metadata indicating this should be
84 * installed unsing '-i' (not -U).
86 bool installOnly() const
87 { return sat::Solvable::installOnly(); }
89 /** \name Dependencies. */
92 Capabilities dep( Dep which_r ) const
93 { return operator[]( which_r ); }
95 Capabilities operator[]( Dep which_r ) const
96 { return sat::Solvable::operator[]( which_r ); }
98 Capabilities provides() const
99 { return sat::Solvable::provides(); }
101 Capabilities requires() const
102 { return sat::Solvable::requires(); }
104 Capabilities conflicts() const
105 { return sat::Solvable::conflicts(); }
107 Capabilities obsoletes() const
108 { return sat::Solvable::obsoletes(); }
110 Capabilities recommends() const
111 { return sat::Solvable::recommends(); }
113 Capabilities suggests() const
114 { return sat::Solvable::suggests(); }
116 Capabilities enhances() const
117 { return sat::Solvable::enhances(); }
119 Capabilities supplements() const
120 { return sat::Solvable::supplements(); }
122 Capabilities prerequires() const
123 { return sat::Solvable::prerequires(); }
127 /** Access the corresponding \ref sat:::Solvable. */
128 const sat::Solvable & satSolvable() const { return *this; }
130 /** Access the corresponding \ref PoolItem. */
131 PoolItem poolItem() const;
135 Resolvable( const sat::Solvable & solvable_r );
137 virtual ~Resolvable();
138 /** Helper for stream output */
139 virtual std::ostream & dumpOn( std::ostream & str ) const;
141 ///////////////////////////////////////////////////////////////////
143 /** \relates Resolvable Stream output */
144 inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
145 { return obj.dumpOn( str ); }
147 /** \relates Resolvable More verbose stream output including dependencies */
148 inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
149 { return dumpOn( str, obj.satSolvable() ); }
151 /** Test whether a Resolvable::Ptr is of a certain Kind.
152 * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
153 * of the specified Kind.
154 * \relates Resolvable
156 * isKind<Package>(resPtr);
160 inline bool isKind( const Resolvable::constPtr & p )
161 { return p && p->kind() == ResTraits<_Res>::kind; }
163 // Specialization for Resolvable: Always true.
165 inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
168 // Specialization for ResObject: Always true.
170 inline bool isKind<ResObject>( const Resolvable::constPtr & p )
174 /** Convert Resolvable::Ptr into Ptr of a certain Kind.
175 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
176 * not of the specified Kind.
177 * \relates Resolvable
179 * asKind<Package>(resPtr);
183 inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
184 { return dynamic_pointer_cast<_Res>(p); }
187 inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
188 { return dynamic_pointer_cast<const _Res>(p); }
190 ///////////////////////////////////////////////////////////////////
192 /** \relates Resolvable Compare Resolvable::constPtr according to
193 * \a kind and \a name.
195 inline int compareByN( const Resolvable::constPtr & lhs,
196 const Resolvable::constPtr & rhs )
200 if ( ! (lhs && rhs) )
203 if ( (res = lhs->kind().compare( rhs->kind() )) )
205 return lhs->name().compare( rhs->name() );
208 /** \relates Resolvable Compare Resolvable::constPtr according to
209 * \a kind, \a name and \a edition(compare!).
211 inline int compareByNVR( const Resolvable::constPtr & lhs,
212 const Resolvable::constPtr & rhs )
216 if ( ! (lhs && rhs) )
219 if ( (res = lhs->kind().compare( rhs->kind() )) )
221 if ( (res = lhs->name().compare( rhs->name() )) )
223 return lhs->edition().compare( rhs->edition() );
226 /** \relates Resolvable Compare Resolvable::constPtr according to
227 * \a kind, \a name, \a edition(compare!) and \a arch.
229 inline int compareByNVRA( const Resolvable::constPtr & lhs,
230 const Resolvable::constPtr & rhs )
234 if ( ! (lhs && rhs) )
237 if ( (res = lhs->kind().compare( rhs->kind() )) )
239 if ( (res = lhs->name().compare( rhs->name() )) )
241 if ( (res = lhs->edition().compare( rhs->edition() )) )
243 return lhs->arch().compare( rhs->arch() );
246 /////////////////////////////////////////////////////////////////
248 ///////////////////////////////////////////////////////////////////
249 #endif // ZYPP_RESOLVABLE_H