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 #include "zypp/Dependencies.h"
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////
36 // CLASS NAME : Resolvable
38 /** Interface base for resolvable objects (identification and dependencies).
39 * \todo Merge with ResObject
41 class Resolvable : protected sat::Solvable,
42 public base::ReferenceCounted, private base::NonCopyable
44 friend std::ostream & operator<<( std::ostream & str, const Resolvable & obj );
47 typedef Resolvable Self;
48 typedef ResTraits<Self> TraitsType;
49 typedef TraitsType::KindType Kind;
50 typedef TraitsType::PtrType Ptr;
51 typedef TraitsType::constPtrType constPtr;
54 /** Whether this represents a valid- or no-solvable. */
55 using sat::Solvable::operator bool_type;
56 /** Whether this represents an installed solvable. */
57 using sat::Solvable::isSystem;
59 using sat::Solvable::ident;
61 using sat::Solvable::kind;
62 using sat::Solvable::name;
63 using sat::Solvable::edition;
64 using sat::Solvable::arch;
66 /** \name Dependencies. */
69 Capabilities dep( Dep which_r ) const
70 { return operator[]( which_r ); }
71 using sat::Solvable::operator[];
72 using sat::Solvable::provides;
73 using sat::Solvable::requires;
74 using sat::Solvable::conflicts;
75 using sat::Solvable::obsoletes;
76 using sat::Solvable::recommends;
77 using sat::Solvable::suggests;
78 using sat::Solvable::freshens;
79 using sat::Solvable::enhances;
80 using sat::Solvable::supplements;
81 using sat::Solvable::prerequires;
85 /** Returns true if the solvable is satisfied */
86 using sat::Solvable::isSatisfied;
88 /** Returns true if the solvable is satisfied */
89 using sat::Solvable::isBroken;
91 /** Returns true if the solvable is relevant which means e.G. for patches
92 * that at least one package of the patch is installed.
94 using sat::Solvable::isRelevant;
97 const sat::Solvable & satSolvable() const { return *this; }
101 Resolvable( const sat::Solvable & solvable_r );
103 virtual ~Resolvable();
104 /** Helper for stream output */
105 virtual std::ostream & dumpOn( std::ostream & str ) const;
107 ///////////////////////////////////////////////////////////////////
109 /** \relates Resolvable Stream output */
110 inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
111 { return obj.dumpOn( str ); }
113 /** \relates Resolvable More verbose stream output including dependencies */
114 inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
115 { return dumpOn( str, obj.satSolvable() ); }
117 /** Test whether a Resolvable::Ptr is of a certain Kind.
118 * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
119 * of the specified Kind.
120 * \relates Resolvable
122 * isKind<Package>(resPtr);
126 inline bool isKind( const Resolvable::constPtr & p )
127 { return p && p->kind() == ResTraits<_Res>::kind; }
129 // Specialization for Resolvable: Always true.
131 inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
134 // Specialization for ResObject: Always true.
136 inline bool isKind<ResObject>( const Resolvable::constPtr & p )
140 /** Convert Resolvable::Ptr into Ptr of a certain Kind.
141 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
142 * not of the specified Kind.
143 * \relates Resolvable
145 * asKind<Package>(resPtr);
149 inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
150 { return dynamic_pointer_cast<_Res>(p); }
153 inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
154 { return dynamic_pointer_cast<const _Res>(p); }
156 ///////////////////////////////////////////////////////////////////
158 /** \relates Resolvable Compare Resolvable::constPtr according to
159 * \a kind and \a name.
161 inline int compareByN( const Resolvable::constPtr & lhs,
162 const Resolvable::constPtr & rhs )
166 if ( ! (lhs && rhs) )
169 if ( (res = lhs->kind().compare( rhs->kind() )) )
171 return lhs->name().compare( rhs->name() );
174 /** \relates Resolvable Compare Resolvable::constPtr according to
175 * \a kind, \a name and \a edition(compare!).
177 inline int compareByNVR( const Resolvable::constPtr & lhs,
178 const Resolvable::constPtr & rhs )
182 if ( ! (lhs && rhs) )
185 if ( (res = lhs->kind().compare( rhs->kind() )) )
187 if ( (res = lhs->name().compare( rhs->name() )) )
189 return lhs->edition().compare( rhs->edition() );
192 /** \relates Resolvable Compare Resolvable::constPtr according to
193 * \a kind, \a name, \a edition(compare!) and \a arch.
195 inline int compareByNVRA( const Resolvable::constPtr & lhs,
196 const Resolvable::constPtr & rhs )
200 if ( ! (lhs && rhs) )
203 if ( (res = lhs->kind().compare( rhs->kind() )) )
205 if ( (res = lhs->name().compare( rhs->name() )) )
207 if ( (res = lhs->edition().compare( rhs->edition() )) )
209 return lhs->arch().compare( rhs->arch() );
212 /////////////////////////////////////////////////////////////////
214 ///////////////////////////////////////////////////////////////////
215 #endif // ZYPP_RESOLVABLE_H