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 #ifndef SWIG // Swig treats it as syntax error
77 /** Evaluate \ref Solvable in a boolean context (\c != \c noSolvable). */
78 using base::SafeBool<Solvable>::operator bool_type;
81 /** Return whether this \ref Solvable belongs to the system repo.
82 * \note This includes the otherwise hidden systemSolvable.
84 bool isSystem() const;
86 /** The \ref Repository this \ref Solvable belongs to. */
87 Repository repository() const;
91 /** \name Attribute lookup.
92 * \see \ref LookupAttr and \ref ArrayAttr providing a general, more
93 * query like interface for attribute retrieval.
97 * returns the string attribute value for \ref attr
98 * or an empty string if it does not exists.
100 std::string lookupStrAttribute( const SolvAttr & attr ) const;
101 /** \overload Trying to look up a translated string attribute.
103 * Returns the translation for \c lang_r (\b no fallback locales).
105 * Passing an empty \ref Locale will return the string for the
106 * current default locale (\see \ref ZConfig::defaultTextLocale),
107 * \b considering all fallback locales.
109 * Returns an empty string if no translation is available.
111 std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
114 * returns the numeric attribute value for \ref attr
115 * or 0 if it does not exists.
117 unsigned lookupNumAttribute( const SolvAttr & attr ) const;
120 * returns the boolean attribute value for \ref attr
121 * or \c false if it does not exists.
123 bool lookupBoolAttribute( const SolvAttr & attr ) const;
126 * returns the id attribute value for \ref attr
127 * or \ref detail::noId if it does not exists.
129 detail::IdType lookupIdAttribute( const SolvAttr & attr ) const;
132 * returns the CheckSum attribute value for \ref attr
133 * or an empty CheckSum if ir does not exist.
135 CheckSum lookupCheckSumAttribute( const SolvAttr & attr ) const;
138 * returns OnMediaLocation data: This is everything we need to
139 * download e.g. an rpm (path, checksum, downloadsize, etc.).
141 OnMediaLocation lookupLocation() const;
146 * This is the solvables \ref name, \b except for packages and
147 * source packes, prefixed by it's \ref kind.
149 IdString ident() const;
151 ResKind kind() const;
152 /** Test whether a Solvable is of a certain \ref ResKind. */
153 bool isKind( const ResKind & kind_r ) const;
155 std::string name() const;
156 Edition edition() const;
159 IdString vendor() const;
161 bool installOnly() const;
165 /** \name Access to the \ref Solvable dependencies.
167 * \note Prerequires are a subset of requires.
170 Capabilities operator[]( Dep which_r ) const;
172 Capabilities provides() const;
173 Capabilities requires() const;
174 Capabilities conflicts() const;
175 Capabilities obsoletes() const;
176 Capabilities recommends() const;
177 Capabilities suggests() const;
178 Capabilities enhances() const;
179 Capabilities supplements() const;
180 Capabilities prerequires() const;
184 /** \name Locale support. */
186 /** Whether this \c Solvable claims to support locales. */
187 bool supportsLocales() const;
188 /** Whether this \c Solvable supports a specific \ref Locale. */
189 bool supportsLocale( const Locale & locale_r ) const;
190 /** Whether this \c Solvable supports at least one of the specified locales. */
191 bool supportsLocale( const LocaleSet & locales_r ) const;
192 /** Whether this \c Solvable supports at least one requested locale.
193 * \see \ref Pool::setRequestedLocales
195 bool supportsRequestedLocales() const;
196 /** Return the supported locales via locales_r. */
197 void getSupportedLocales( LocaleSet & locales_r ) const;
199 LocaleSet getSupportedLocales() const
200 { LocaleSet ret; getSupportedLocales( ret ); return ret; }
204 /** Return next Solvable in \ref Pool (or \ref noSolvable). */
205 Solvable nextInPool() const;
206 /** Return next Solvable in \ref Repo (or \ref noSolvable). */
207 Solvable nextInRepo() const;
209 /** Helper that splits an identifier into kind and name or vice versa.
216 SplitIdent( IdString ident_r );
217 SplitIdent( ResKind kind_r, IdString name_r );
218 SplitIdent( ResKind kind_r, const C_Str & name_r );
220 IdString ident() const { return _ident; }
221 ResKind kind() const { return _kind; }
222 IdString name() const { return _name; }
230 /** Expert backdoor. */
231 ::_Solvable * get() const;
232 /** Expert backdoor. */
233 IdType id() const { return _id; }
235 #ifndef SWIG // Swig treats it as syntax error
236 friend base::SafeBool<Solvable>::operator bool_type() const;
238 bool boolTest() const { return get(); }
242 ///////////////////////////////////////////////////////////////////
244 /** \relates Solvable Stream output */
245 std::ostream & operator<<( std::ostream & str, const Solvable & obj );
247 /** \relates Solvable More verbose stream output including dependencies */
248 std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
250 /** \relates Solvable */
251 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
252 { return lhs.get() == rhs.get(); }
254 /** \relates Solvable */
255 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
256 { return lhs.get() != rhs.get(); }
258 /** \relates Solvable */
259 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
260 { return lhs.get() < rhs.get(); }
262 ///////////////////////////////////////////////////////////////////
264 { /////////////////////////////////////////////////////////////////
265 ///////////////////////////////////////////////////////////////////
267 // CLASS NAME : SolvableIterator
270 class SolvableIterator : public boost::iterator_adaptor<
271 SolvableIterator // Derived
272 , ::_Solvable* // Base
273 , const Solvable // Value
274 , boost::forward_traversal_tag // CategoryOrTraversal
275 , const Solvable // Reference
280 : SolvableIterator::iterator_adaptor_( 0 )
283 explicit SolvableIterator( const Solvable & val_r )
284 : SolvableIterator::iterator_adaptor_( 0 )
285 { assignVal( val_r ); }
287 explicit SolvableIterator( SolvableIdType id_r )
288 : SolvableIterator::iterator_adaptor_( 0 )
289 { assignVal( Solvable( id_r ) ); }
292 friend class boost::iterator_core_access;
294 Solvable dereference() const
298 { assignVal( _val.nextInPool() ); }
301 void assignVal( const Solvable & val_r )
302 { _val = val_r; base_reference() = _val.get(); }
306 ///////////////////////////////////////////////////////////////////
307 /////////////////////////////////////////////////////////////////
308 } // namespace detail
309 ///////////////////////////////////////////////////////////////////
311 /////////////////////////////////////////////////////////////////
313 ///////////////////////////////////////////////////////////////////
315 /** \relates sat::Solvable Test whether a \ref sat::Solvable is of a certain Kind. */
317 inline bool isKind( const sat::Solvable & solvable_r )
318 { return solvable_r.isKind( ResTraits<_Res>::kind ); }
320 /////////////////////////////////////////////////////////////////
322 ///////////////////////////////////////////////////////////////////
324 ZYPP_DEFINE_ID_HASHABLE( ::zypp::sat::Solvable );
326 #endif // ZYPP_SAT_SOLVABLE_H