1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Solvable.h
12 #ifndef ZYPP_SAT_SOLVABLE_H
13 #define ZYPP_SAT_SOLVABLE_H
17 #include "zypp/sat/detail/PoolMember.h"
18 #include "zypp/sat/SolvAttr.h"
19 #include "zypp/ResTraits.h"
20 #include "zypp/IdString.h"
21 #include "zypp/Edition.h"
22 #include "zypp/Arch.h"
24 #include "zypp/Capabilities.h"
25 #include "zypp/Capability.h"
26 #include "zypp/Locale.h"
28 ///////////////////////////////////////////////////////////////////
35 class OnMediaLocation;
36 ///////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////
41 /// \brief A \ref Solvable object within the sat \ref Pool.
43 /// \note Unfortunately libsolv combines the objects kind and
44 /// name in a single identifier \c "pattern:kde_multimedia",
45 /// \b except for packages and source packes. They are not prefixed
46 /// by any kind string. Instead the architecture is abused to store
47 /// \c "src" and \c "nosrc" values.
49 /// \ref Solvable will hide this inconsistency by treating source
50 /// packages as an own kind of solvable and map their arch to
52 ///////////////////////////////////////////////////////////////////
53 class Solvable : protected detail::PoolMember
56 typedef sat::detail::SolvableIdType IdType;
59 /** Default ctor creates \ref noSolvable.*/
61 : _id( detail::noSolvableId )
64 /** \ref PoolImpl ctor. */
65 explicit Solvable( IdType id_r )
70 /** Represents no \ref Solvable. */
71 static const Solvable noSolvable;
73 /** Evaluate \ref Solvable in a boolean context (\c != \c noSolvable). */
74 explicit operator bool() const
79 * This is the solvables \ref name, \b except for packages and
80 * source packes, prefixed by it's \ref kind.
82 IdString ident()const;
84 /** The Solvables ResKind. */
87 /** Test whether a Solvable is of a certain \ref ResKind.
88 * The test is far cheaper than actually retrieving and
89 * comparing the \ref kind.
91 bool isKind( const ResKind & kind_r ) const;
95 { return isKind( resKind<TRes>() ); }
96 /** \overload Extend the test to a range of \ref ResKind. */
97 template<class TIterator>
98 bool isKind( TIterator begin, TIterator end ) const
99 { for_( it, begin, end ) if ( isKind( *it ) ) return true; return false; }
101 /** The name (without any ResKind prefix). */
102 std::string name() const;
104 /** The edition (version-release). */
105 Edition edition() const;
107 /** The architecture. */
111 IdString vendor() const;
113 /** The \ref Repository this \ref Solvable belongs to. */
114 Repository repository() const;
115 /** The repositories \ref RepoInfo. */
116 RepoInfo repoInfo() const;
118 /** Return whether this \ref Solvable belongs to the system repo.
119 * \note This includes the otherwise hidden systemSolvable.
121 bool isSystem() const;
123 /** Whether this is known to be installed on behalf of a user request.
124 * \note Returns \c false for non-system (uninstalled) solvables.
126 bool onSystemByUser() const;
128 /** Whether this is known to be automatically installed (as dependency of a user request package).
129 * \note Returns \c false for non-system (uninstalled) solvables.
131 bool onSystemByAuto() const;
133 /** Whether an installed solvable with the same \ref ident is flagged as AutoInstalled. */
134 bool identIsAutoInstalled() const
135 { return identIsAutoInstalled( ident() ); }
136 /** \overload static version */
137 static bool identIsAutoInstalled( const IdString & ident_r );
139 /** Whether different versions of this package can be installed at the same time.
140 * Per default \c false. \see also \ref ZConfig::multiversion.
142 bool multiversionInstall() const;
144 /** The items build time. */
145 Date buildtime() const;
147 /** The items install time (\c false if not installed). */
148 Date installtime() const;
151 /** String representation <tt>"ident-edition.arch"</tt> or \c "noSolvable"
153 * product:openSUSE-11.1.x86_64
154 * autoyast2-2.16.19-0.1.src
158 std::string asString() const;
160 /** String representation <tt>"ident-edition.arch(repo)"</tt> or \c "noSolvable" */
161 std::string asUserString() const;
163 /** Test whether two Solvables have the same content.
164 * Basically the same name, edition, arch, vendor and buildtime.
166 bool identical( const Solvable & rhs ) const;
168 /** Test for same name-version-release.arch */
169 bool sameNVRA( const Solvable & rhs ) const
170 { return( get() == rhs.get() || ( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ) ); }
173 /** \name Access to the \ref Solvable dependencies.
175 * \note Prerequires are a subset of requires.
178 Capabilities provides() const;
179 Capabilities requires() const;
180 Capabilities conflicts() const;
181 Capabilities obsoletes() const;
182 Capabilities recommends() const;
183 Capabilities suggests() const;
184 Capabilities enhances() const;
185 Capabilities supplements() const;
186 Capabilities prerequires() const;
188 /** Return \ref Capabilities selected by \ref Dep constant. */
189 Capabilities dep( Dep which_r ) const
191 switch( which_r.inSwitch() )
193 case Dep::PROVIDES_e: return provides(); break;
194 case Dep::REQUIRES_e: return requires(); break;
195 case Dep::CONFLICTS_e: return conflicts(); break;
196 case Dep::OBSOLETES_e: return obsoletes(); break;
197 case Dep::RECOMMENDS_e: return recommends(); break;
198 case Dep::SUGGESTS_e: return suggests(); break;
199 case Dep::ENHANCES_e: return enhances(); break;
200 case Dep::SUPPLEMENTS_e: return supplements(); break;
201 case Dep::PREREQUIRES_e: return prerequires(); break;
203 return Capabilities();
205 /** \overload operator[] */
206 Capabilities operator[]( Dep which_r ) const
207 { return dep( which_r ); }
210 /** Return the namespaced provides <tt>'namespace([value])[ op edition]'</tt> of this Solvable. */
211 CapabilitySet providesNamespace( const std::string & namespace_r ) const;
213 /** Return <tt>'value[ op edition]'</tt> for namespaced provides <tt>'namespace(value)[ op edition]'</tt>.
214 * Similar to \ref providesNamespace, but the namespace is stripped from the
215 * dependencies. This is convenient if the namespace denotes packages that
216 * should be looked up. E.g. the \c weakremover namespace used in a products
217 * release package denotes the packages that were dropped from the distribution.
218 * \see \ref Product::droplist
220 CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
224 /** \name Locale support. */
226 /** Whether this \c Solvable claims to support locales. */
227 bool supportsLocales() const;
228 /** Whether this \c Solvable supports a specific \ref Locale. */
229 bool supportsLocale( const Locale & locale_r ) const;
230 /** Whether this \c Solvable supports at least one of the specified locales. */
231 bool supportsLocale( const LocaleSet & locales_r ) const;
232 /** Whether this \c Solvable supports at least one requested locale.
233 * \see \ref Pool::setRequestedLocales
235 bool supportsRequestedLocales() const;
236 /** Return the supported locales. */
237 LocaleSet getSupportedLocales() const;
238 /** \overload Legacy return via arg \a locales_r */
239 void getSupportedLocales( LocaleSet & locales_r ) const
240 { locales_r = getSupportedLocales(); }
244 /** The solvables CpeId if available. */
247 /** Media number the solvable is located on (\c 0 if no media access required). */
248 unsigned mediaNr() const;
250 /** Installed (unpacked) size.
251 * This is just a total number. Many objects provide even more detailed
252 * disk usage data. You can use \ref DiskUsageCounter to find out
253 * how objects data are distributed across partitions/directories.
255 * // Load directory set into ducounter
256 * DiskUsageCounter ducounter( { "/", "/usr", "/var" } );
258 * // see how noch space the packages use
259 * for ( const PoolItem & pi : pool )
261 * cout << pi << ducounter.disk_usage( pi ) << endl;
262 * // I__s_(7)GeoIP-1.4.8-3.1.2.x86_64(@System) {
263 * // dir:[/] [ bs: 0 B ts: 0 B us: 0 B (+-: 1.0 KiB)]
264 * // dir:[/usr] [ bs: 0 B ts: 0 B us: 0 B (+-: 133.0 KiB)]
265 * // dir:[/var] [ bs: 0 B ts: 0 B us: 0 B (+-: 1.1 MiB)]
269 * \see \ref DiskUsageCounter
271 ByteCount installSize() const;
273 /** Download size. */
274 ByteCount downloadSize() const;
276 /** The distribution string. */
277 std::string distribution() const;
279 /** Short (singleline) text describing the solvable (opt. translated). */
280 std::string summary( const Locale & lang_r = Locale() ) const;
282 /** Long (multiline) text describing the solvable (opt. translated). */
283 std::string description( const Locale & lang_r = Locale() ) const;
285 /** UI hint text when selecting the solvable for install (opt. translated). */
286 std::string insnotify( const Locale & lang_r = Locale() ) const;
287 /** UI hint text when selecting the solvable for uninstall (opt. translated).*/
288 std::string delnotify( const Locale & lang_r = Locale() ) const;
290 /** License or agreement to accept before installing the solvable (opt. translated). */
291 std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
292 /** \c True except for well known exceptions (i.e show license but no need to accept it). */
293 bool needToAcceptLicense() const;
296 /** Helper that splits an identifier into kind and name or vice versa.
297 * \note In case \c name_r is preceded by a well known kind spec, the
298 * \c kind_r argument is ignored, and kind is derived from name.
305 SplitIdent( IdString ident_r );
306 SplitIdent( const char * ident_r );
307 SplitIdent( const std::string & ident_r );
308 SplitIdent( ResKind kind_r, IdString name_r );
309 SplitIdent( ResKind kind_r, const C_Str & name_r );
311 IdString ident() const { return _ident; }
312 ResKind kind() const { return _kind; }
313 IdString name() const { return _name; }
322 /** \name Attribute lookup.
323 * \see \ref LookupAttr and \ref ArrayAttr providing a general, more
324 * query like interface for attribute retrieval.
328 * returns the string attribute value for \ref attr
329 * or an empty string if it does not exists.
331 std::string lookupStrAttribute( const SolvAttr & attr ) const;
332 /** \overload Trying to look up a translated string attribute.
334 * Returns the translation for \c lang_r.
336 * Passing an empty \ref Locale will return the string for the
337 * current default locale (\see \ref ZConfig::TextLocale),
338 * \b considering all fallback locales.
340 * Returns an empty string if no translation is available.
342 std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
345 * returns the numeric attribute value for \ref attr
346 * or 0 if it does not exists.
348 unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
349 /** \overload returning custom notfound_r value */
350 unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const;
353 * returns the boolean attribute value for \ref attr
354 * or \c false if it does not exists.
356 bool lookupBoolAttribute( const SolvAttr & attr ) const;
359 * returns the id attribute value for \ref attr
360 * or \ref detail::noId if it does not exists.
362 detail::IdType lookupIdAttribute( const SolvAttr & attr ) const;
365 * returns the CheckSum attribute value for \ref attr
366 * or an empty CheckSum if ir does not exist.
368 CheckSum lookupCheckSumAttribute( const SolvAttr & attr ) const;
371 * returns OnMediaLocation data: This is everything we need to
372 * download e.g. an rpm (path, checksum, downloadsize, etc.).
374 OnMediaLocation lookupLocation() const;
378 /** Return next Solvable in \ref Pool (or \ref noSolvable). */
379 Solvable nextInPool() const;
380 /** Return next Solvable in \ref Repo (or \ref noSolvable). */
381 Solvable nextInRepo() const;
382 /** Expert backdoor. */
383 detail::CSolvable * get() const;
384 /** Expert backdoor. */
385 IdType id() const { return _id; }
390 ///////////////////////////////////////////////////////////////////
392 /** \relates Solvable Stream output */
393 std::ostream & operator<<( std::ostream & str, const Solvable & obj );
395 /** \relates Solvable More verbose stream output including dependencies */
396 std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
398 /** \relates Solvable XML output */
399 std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj );
401 /** \relates Solvable */
402 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
403 { return lhs.get() == rhs.get(); }
405 /** \relates Solvable */
406 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
407 { return lhs.get() != rhs.get(); }
409 /** \relates Solvable */
410 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
411 { return lhs.get() < rhs.get(); }
413 /** \relates Solvable Test whether a \ref Solvable is of a certain Kind. */
415 inline bool isKind( const Solvable & solvable_r )
416 { return solvable_r.isKind( ResTraits<TRes>::kind ); }
418 /** \relates Solvable Test for same content. */
419 inline bool identical( const Solvable & lhs, const Solvable & rhs )
420 { return lhs.identical( rhs ); }
422 /** \relates Solvable Test for same name version release and arch. */
423 inline bool sameNVRA( const Solvable & lhs, const Solvable & rhs )
424 { return lhs.sameNVRA( rhs ); }
427 /** \relates Solvable Compare according to \a kind and \a name. */
428 inline int compareByN( const Solvable & lhs, const Solvable & rhs )
433 if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
434 res = lhs.name().compare( rhs.name() );
439 /** \relates Solvable Compare according to \a kind, \a name and \a edition. */
440 inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
442 int res = compareByN( lhs, rhs );
444 res = lhs.edition().compare( rhs.edition() );
448 /** \relates Solvable Compare according to \a kind, \a name, \a edition and \a arch. */
449 inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
451 int res = compareByNVR( lhs, rhs );
453 res = lhs.arch().compare( rhs.arch() );
457 ///////////////////////////////////////////////////////////////////
460 ///////////////////////////////////////////////////////////////////
462 // CLASS NAME : SolvableIterator
465 class SolvableIterator : public boost::iterator_adaptor<
466 SolvableIterator // Derived
468 , const Solvable // Value
469 , boost::forward_traversal_tag // CategoryOrTraversal
470 , const Solvable // Reference
475 : SolvableIterator::iterator_adaptor_( 0 )
478 explicit SolvableIterator( const Solvable & val_r )
479 : SolvableIterator::iterator_adaptor_( 0 )
480 { assignVal( val_r ); }
482 explicit SolvableIterator( SolvableIdType id_r )
483 : SolvableIterator::iterator_adaptor_( 0 )
484 { assignVal( Solvable( id_r ) ); }
487 friend class boost::iterator_core_access;
489 Solvable dereference() const
493 { assignVal( _val.nextInPool() ); }
496 void assignVal( const Solvable & val_r )
497 { _val = val_r; base_reference() = _val.get(); }
501 } // namespace detail
502 ///////////////////////////////////////////////////////////////////
504 ///////////////////////////////////////////////////////////////////
507 ///////////////////////////////////////////////////////////////////
510 /** To Solvable transform functor.
512 * \relates sat::SolvIterMixin
516 typedef Solvable result_type;
518 Solvable operator()( const Solvable & solv_r ) const
521 Solvable operator()( const PoolItem & pi_r ) const;
523 Solvable operator()( const ResObject_constPtr & res_r ) const;
526 ///////////////////////////////////////////////////////////////////
528 ///////////////////////////////////////////////////////////////////
530 ZYPP_DEFINE_ID_HASHABLE( ::zypp::sat::Solvable );
532 #endif // ZYPP_SAT_SOLVABLE_H