1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Solvable.h
12 #ifndef ZYPP_SAT_SOLVABLE_H
13 #define ZYPP_SAT_SOLVABLE_H
17 #include "zypp/base/SafeBool.h"
19 #include "zypp/sat/detail/PoolMember.h"
20 #include "zypp/sat/SolvAttr.h"
21 #include "zypp/ResTraits.h"
22 #include "zypp/IdString.h"
23 #include "zypp/Edition.h"
24 #include "zypp/Arch.h"
26 #include "zypp/Capabilities.h"
27 #include "zypp/Capability.h"
28 #include "zypp/Locale.h"
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
35 class OnMediaLocation;
37 ///////////////////////////////////////////////////////////////////
39 { /////////////////////////////////////////////////////////////////
41 ///////////////////////////////////////////////////////////////////
43 // CLASS NAME : Solvable
45 /** A \ref Solvable object within the sat \ref Pool.
47 * \note Unfortunately libsatsolver combines the objects kind and
48 * name in a single identifier \c "pattern:kde_multimedia",
49 * \b except for packages and source packes. They are not prefixed
50 * by any kind string. Instead the architecture is abused to store
51 * \c "src" and \c "nosrc" values.
53 * \ref Solvable will hide this inconsistency by treating source
54 * packages as an own kind of solvable and map their arch to
57 class Solvable : protected detail::PoolMember,
58 private base::SafeBool<Solvable>
61 typedef sat::detail::SolvableIdType IdType;
64 /** Default ctor creates \ref noSolvable.*/
66 : _id( detail::noSolvableId ) {}
68 /** \ref PoolImpl ctor. */
69 explicit Solvable( IdType id_r )
73 /** Represents no \ref Solvable. */
74 static const Solvable noSolvable;
76 /** Evaluate \ref Solvable in a boolean context (\c != \c noSolvable). */
77 using base::SafeBool<Solvable>::operator bool_type;
79 /** Return whether this \ref Solvable belongs to the system repo.
80 * \note This includes the otherwise hidden systemSolvable.
82 bool isSystem() const;
84 /** The \ref Repository this \ref Solvable belongs to. */
85 Repository repository() const;
89 /** \name Attribute lookup.
90 * \see \ref LookupAttr and \ref ArrayAttr providing a general, more
91 * query like interface for attribute retrieval.
95 * returns the string attribute value for \ref attr
96 * or an empty string if it does not exists.
98 std::string lookupStrAttribute( const SolvAttr & attr ) const;
99 /** \overload Trying to look up a translated string attribute.
101 * Returns the translation for \c lang_r (\b no fallback locales).
103 * Passing an empty \ref Locale will return the string for the
104 * current default locale (\see \ref ZConfig::defaultTextLocale),
105 * \b considering all fallback locales.
107 * Returns an empty string if no translation is available.
109 std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
112 * returns the numeric attribute value for \ref attr
113 * or 0 if it does not exists.
115 unsigned lookupNumAttribute( const SolvAttr & attr ) const;
118 * returns the boolean attribute value for \ref attr
119 * or \c false if it does not exists.
121 bool lookupBoolAttribute( const SolvAttr & attr ) const;
124 * returns the id attribute value for \ref attr
125 * or \ref detail::noId if it does not exists.
127 detail::IdType lookupIdAttribute( const SolvAttr & attr ) const;
130 * returns the CheckSum attribute value for \ref attr
131 * or an empty CheckSum if ir does not exist.
133 CheckSum lookupCheckSumAttribute( const SolvAttr & attr ) const;
136 * returns OnMediaLocation data: This is everything we need to
137 * download e.g. an rpm (path, checksum, downloadsize, etc.).
139 OnMediaLocation lookupLocation() const;
144 * This is the solvables \ref name, \b except for packages and
145 * source packes, prefixed by it's \ref kind.
147 IdString ident() const;
149 ResKind kind() const;
150 /** Test whether a Solvable is of a certain \ref ResKind. */
151 bool isKind( const ResKind & kind_r ) const;
153 std::string name() const;
154 Edition edition() const;
157 IdString vendor() const;
161 /** \name Access to the \ref Solvable dependencies.
163 * \note Prerequires are a subset of requires.
166 Capabilities operator[]( Dep which_r ) const;
168 Capabilities provides() const;
169 Capabilities requires() const;
170 Capabilities conflicts() const;
171 Capabilities obsoletes() const;
172 Capabilities recommends() const;
173 Capabilities suggests() const;
174 Capabilities freshens() const;
175 Capabilities enhances() const;
176 Capabilities supplements() const;
177 Capabilities prerequires() const;
181 /** Returns true if the solvable is satisfied */
182 bool isSatisfied() const;
183 /** Returns true if the solvable is satisfied */
184 bool isBroken() const { return !isSatisfied(); }
187 /** \name Locale support. */
189 /** Whether this \c Solvable claims to support locales. */
190 bool supportsLocales() const;
191 /** Whether this \c Solvable supports a specific \ref Locale. */
192 bool supportsLocale( const Locale & locale_r ) const;
193 /** Whether this \c Solvable supports at least one of the specified locales. */
194 bool supportsLocale( const LocaleSet & locales_r ) const;
195 /** Whether this \c Solvable supports at least one requested locale.
196 * \see \ref Pool::setRequestedLocales
198 bool supportsRequestedLocales() const;
199 /** Return the supported locales via locales_r. */
200 void getSupportedLocales( LocaleSet & locales_r ) const;
202 LocaleSet getSupportedLocales() const
203 { LocaleSet ret; getSupportedLocales( ret ); return ret; }
207 /** Return next Solvable in \ref Pool (or \ref noSolvable). */
208 Solvable nextInPool() const;
209 /** Return next Solvable in \ref Repo (or \ref noSolvable). */
210 Solvable nextInRepo() const;
213 /** Expert backdoor. */
214 ::_Solvable * get() const;
215 /** Expert backdoor. */
216 IdType id() const { return _id; }
218 friend base::SafeBool<Solvable>::operator bool_type() const;
219 bool boolTest() const { return get(); }
223 ///////////////////////////////////////////////////////////////////
225 /** \relates Solvable Stream output */
226 std::ostream & operator<<( std::ostream & str, const Solvable & obj );
228 /** \relates Solvable More verbose stream output including dependencies */
229 std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
231 /** \relates Solvable */
232 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
233 { return lhs.get() == rhs.get(); }
235 /** \relates Solvable */
236 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
237 { return lhs.get() != rhs.get(); }
239 /** \relates Solvable */
240 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
241 { return lhs.get() < rhs.get(); }
243 ///////////////////////////////////////////////////////////////////
245 { /////////////////////////////////////////////////////////////////
246 ///////////////////////////////////////////////////////////////////
248 // CLASS NAME : SolvableIterator
251 class SolvableIterator : public boost::iterator_adaptor<
252 SolvableIterator // Derived
253 , ::_Solvable* // Base
254 , const Solvable // Value
255 , boost::forward_traversal_tag // CategoryOrTraversal
256 , const Solvable // Reference
261 : SolvableIterator::iterator_adaptor_( 0 )
264 explicit SolvableIterator( const Solvable & val_r )
265 : SolvableIterator::iterator_adaptor_( 0 )
266 { assignVal( val_r ); }
268 explicit SolvableIterator( SolvableIdType id_r )
269 : SolvableIterator::iterator_adaptor_( 0 )
270 { assignVal( Solvable( id_r ) ); }
273 friend class boost::iterator_core_access;
275 Solvable dereference() const
279 { assignVal( _val.nextInPool() ); }
282 void assignVal( const Solvable & val_r )
283 { _val = val_r; base_reference() = _val.get(); }
287 ///////////////////////////////////////////////////////////////////
288 /////////////////////////////////////////////////////////////////
289 } // namespace detail
290 ///////////////////////////////////////////////////////////////////
292 /////////////////////////////////////////////////////////////////
294 ///////////////////////////////////////////////////////////////////
296 /** \relates sat::Solvable Test whether a \ref sat::Solvable is of a certain Kind. */
298 inline bool isKind( const sat::Solvable & solvable_r )
299 { return solvable_r.isKind( ResTraits<_Res>::kind ); }
301 /////////////////////////////////////////////////////////////////
303 ///////////////////////////////////////////////////////////////////
304 #endif // ZYPP_SAT_SOLVABLE_H