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;
58 static const IdString retractedToken; ///< Indicator provides `retracted-patch-package()`
59 static const IdString ptfToken; ///< Indicator provides `ptf()`
62 /** Default ctor creates \ref noSolvable.*/
64 : _id( detail::noSolvableId )
67 /** \ref PoolImpl ctor. */
68 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 explicit operator bool() const
82 * This is the solvables \ref name, \b except for packages and
83 * source packes, prefixed by it's \ref kind.
85 IdString ident()const;
87 /** The Solvables ResKind. */
90 /** Test whether a Solvable is of a certain \ref ResKind.
91 * The test is far cheaper than actually retrieving and
92 * comparing the \ref kind.
94 bool isKind( const ResKind & kind_r ) const;
98 { return isKind( resKind<TRes>() ); }
99 /** \overload Extend the test to a range of \ref ResKind. */
100 template<class TIterator>
101 bool isKind( TIterator begin, TIterator end ) const
102 { for_( it, begin, end ) if ( isKind( *it ) ) return true; return false; }
104 /** The name (without any ResKind prefix). */
105 std::string name() const;
107 /** The edition (version-release). */
108 Edition edition() const;
110 /** The architecture. */
114 IdString vendor() const;
116 /** The \ref Repository this \ref Solvable belongs to. */
117 Repository repository() const;
118 /** The repositories \ref RepoInfo. */
119 RepoInfo repoInfo() const;
121 /** Return whether this \ref Solvable belongs to the system repo.
122 * \note This includes the otherwise hidden systemSolvable.
124 bool isSystem() const;
126 /** Whether this is known to be installed on behalf of a user request.
127 * \note Returns \c false for non-system (uninstalled) solvables.
129 bool onSystemByUser() const;
131 /** Whether this is known to be automatically installed (as dependency of a user request package).
132 * \note Returns \c false for non-system (uninstalled) solvables.
134 bool onSystemByAuto() const;
136 /** Whether an installed solvable with the same \ref ident is flagged as AutoInstalled. */
137 bool identIsAutoInstalled() const
138 { return identIsAutoInstalled( ident() ); }
139 /** \overload static version */
140 static bool identIsAutoInstalled( const IdString & ident_r );
142 /** Whether different versions of this package can be installed at the same time.
143 * Per default \c false. \see also \ref ZConfig::multiversion.
145 bool multiversionInstall() const;
147 /** Whether this solvable triggers the reboot-needed hint if installed/updated. */
148 bool isNeedreboot() const;
150 /** Whether this solvable is retracted (provides \ref retractedToken). */
151 bool isRetracted() const;
153 /** Whether this solvable is a PTF (provides \ref ptfToken). */
156 /** The items build time. */
157 Date buildtime() const;
159 /** The items install time (\c false if not installed). */
160 Date installtime() const;
163 /** String representation <tt>"ident-edition.arch"</tt> or \c "noSolvable"
165 * product:openSUSE-11.1.x86_64
166 * autoyast2-2.16.19-0.1.src
170 std::string asString() const;
172 /** String representation <tt>"ident-edition.arch(repo)"</tt> or \c "noSolvable" */
173 std::string asUserString() const;
175 /** Test whether two Solvables have the same content.
176 * Basically the same name, edition, arch, vendor and buildtime.
178 bool identical( const Solvable & rhs ) const;
180 /** Test for same name-version-release.arch */
181 bool sameNVRA( const Solvable & rhs ) const
182 { return( get() == rhs.get() || ( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ) ); }
185 /** \name Access to the \ref Solvable dependencies.
187 * \note Prerequires are a subset of requires.
190 Capabilities provides() const;
191 Capabilities requires() const;
192 Capabilities conflicts() const;
193 Capabilities obsoletes() const;
194 Capabilities recommends() const;
195 Capabilities suggests() const;
196 Capabilities enhances() const;
197 Capabilities supplements() const;
198 Capabilities prerequires() const;
200 /** Return \ref Capabilities selected by \ref Dep constant. */
201 Capabilities dep( Dep which_r ) const
203 switch( which_r.inSwitch() )
205 case Dep::PROVIDES_e: return provides(); break;
206 case Dep::REQUIRES_e: return requires(); break;
207 case Dep::CONFLICTS_e: return conflicts(); break;
208 case Dep::OBSOLETES_e: return obsoletes(); break;
209 case Dep::RECOMMENDS_e: return recommends(); break;
210 case Dep::SUGGESTS_e: return suggests(); break;
211 case Dep::ENHANCES_e: return enhances(); break;
212 case Dep::SUPPLEMENTS_e: return supplements(); break;
213 case Dep::PREREQUIRES_e: return prerequires(); break;
215 return Capabilities();
217 /** \overload operator[] */
218 Capabilities operator[]( Dep which_r ) const
219 { return dep( which_r ); }
222 /** Return the namespaced provides <tt>'namespace([value])[ op edition]'</tt> of this Solvable. */
223 CapabilitySet providesNamespace( const std::string & namespace_r ) const;
225 /** Return <tt>'value[ op edition]'</tt> for namespaced provides <tt>'namespace(value)[ op edition]'</tt>.
226 * Similar to \ref providesNamespace, but the namespace is stripped from the
227 * dependencies. This is convenient if the namespace denotes packages that
228 * should be looked up. E.g. the \c weakremover namespace used in a products
229 * release package denotes the packages that were dropped from the distribution.
230 * \see \ref Product::droplist
232 CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
235 std::pair<bool, CapabilitySet> matchesSolvable ( const SolvAttr &attr, const sat::Solvable &solv ) const;
238 /** \name Locale support. */
240 /** Whether this \c Solvable claims to support locales. */
241 bool supportsLocales() const;
242 /** Whether this \c Solvable supports a specific \ref Locale. */
243 bool supportsLocale( const Locale & locale_r ) const;
244 /** Whether this \c Solvable supports at least one of the specified locales. */
245 bool supportsLocale( const LocaleSet & locales_r ) const;
246 /** Whether this \c Solvable supports at least one requested locale.
247 * \see \ref Pool::setRequestedLocales
249 bool supportsRequestedLocales() const;
250 /** Return the supported locales. */
251 LocaleSet getSupportedLocales() const;
252 /** \overload Legacy return via arg \a locales_r */
253 void getSupportedLocales( LocaleSet & locales_r ) const
254 { locales_r = getSupportedLocales(); }
258 /** The solvables CpeId if available. */
261 /** Media number the solvable is located on (\c 0 if no media access required). */
262 unsigned mediaNr() const;
264 /** Installed (unpacked) size.
265 * This is just a total number. Many objects provide even more detailed
266 * disk usage data. You can use \ref DiskUsageCounter to find out
267 * how objects data are distributed across partitions/directories.
269 * // Load directory set into ducounter
270 * DiskUsageCounter ducounter( { "/", "/usr", "/var" } );
272 * // see how noch space the packages use
273 * for ( const PoolItem & pi : pool )
275 * cout << pi << ducounter.disk_usage( pi ) << endl;
276 * // I__s_(7)GeoIP-1.4.8-3.1.2.x86_64(@System) {
277 * // dir:[/] [ bs: 0 B ts: 0 B us: 0 B (+-: 1.0 KiB)]
278 * // dir:[/usr] [ bs: 0 B ts: 0 B us: 0 B (+-: 133.0 KiB)]
279 * // dir:[/var] [ bs: 0 B ts: 0 B us: 0 B (+-: 1.1 MiB)]
283 * \see \ref DiskUsageCounter
285 ByteCount installSize() const;
287 /** Download size. */
288 ByteCount downloadSize() const;
290 /** The distribution string. */
291 std::string distribution() const;
293 /** Short (singleline) text describing the solvable (opt. translated). */
294 std::string summary( const Locale & lang_r = Locale() ) const;
296 /** Long (multiline) text describing the solvable (opt. translated). */
297 std::string description( const Locale & lang_r = Locale() ) const;
299 /** UI hint text when selecting the solvable for install (opt. translated). */
300 std::string insnotify( const Locale & lang_r = Locale() ) const;
301 /** UI hint text when selecting the solvable for uninstall (opt. translated).*/
302 std::string delnotify( const Locale & lang_r = Locale() ) const;
304 /** License or agreement to accept before installing the solvable (opt. translated). */
305 std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
306 /** \c True except for well known exceptions (i.e show license but no need to accept it). */
307 bool needToAcceptLicense() const;
310 /** Helper that splits an identifier into kind and name or vice versa.
311 * \note In case \c name_r is preceded by a well known kind spec, the
312 * \c kind_r argument is ignored, and kind is derived from name.
319 SplitIdent( IdString ident_r );
320 SplitIdent( const char * ident_r );
321 SplitIdent( const std::string & ident_r );
322 SplitIdent( ResKind kind_r, IdString name_r );
323 SplitIdent( ResKind kind_r, const C_Str & name_r );
325 IdString ident() const { return _ident; }
326 ResKind kind() const { return _kind; }
327 IdString name() const { return _name; }
336 /** \name Attribute lookup.
337 * \see \ref LookupAttr and \ref ArrayAttr providing a general, more
338 * query like interface for attribute retrieval.
342 * returns the string attribute value for \ref attr
343 * or an empty string if it does not exists.
345 std::string lookupStrAttribute( const SolvAttr & attr ) const;
346 /** \overload Trying to look up a translated string attribute.
348 * Returns the translation for \c lang_r.
350 * Passing an empty \ref Locale will return the string for the
351 * current default locale (\see \ref ZConfig::TextLocale),
352 * \b considering all fallback locales.
354 * Returns an empty string if no translation is available.
356 std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
359 * returns the numeric attribute value for \ref attr
360 * or 0 if it does not exists.
362 unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
363 /** \overload returning custom notfound_r value */
364 unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const;
367 * returns the boolean attribute value for \ref attr
368 * or \c false if it does not exists.
370 bool lookupBoolAttribute( const SolvAttr & attr ) const;
373 * returns the id attribute value for \ref attr
374 * or \ref detail::noId if it does not exists.
376 detail::IdType lookupIdAttribute( const SolvAttr & attr ) const;
379 * returns the CheckSum attribute value for \ref attr
380 * or an empty CheckSum if ir does not exist.
382 CheckSum lookupCheckSumAttribute( const SolvAttr & attr ) const;
385 * returns OnMediaLocation data: This is everything we need to
386 * download e.g. an rpm (path, checksum, downloadsize, etc.).
388 OnMediaLocation lookupLocation() const;
392 /** Return next Solvable in \ref Pool (or \ref noSolvable). */
393 Solvable nextInPool() const;
394 /** Return next Solvable in \ref Repo (or \ref noSolvable). */
395 Solvable nextInRepo() const;
396 /** Expert backdoor. */
397 detail::CSolvable * get() const;
398 /** Expert backdoor. */
399 IdType id() const { return _id; }
404 ///////////////////////////////////////////////////////////////////
406 /** \relates Solvable Stream output */
407 std::ostream & operator<<( std::ostream & str, const Solvable & obj );
409 /** \relates Solvable More verbose stream output including dependencies */
410 std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
412 /** \relates Solvable XML output */
413 std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj );
415 /** \relates Solvable */
416 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
417 { return lhs.get() == rhs.get(); }
419 /** \relates Solvable */
420 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
421 { return lhs.get() != rhs.get(); }
423 /** \relates Solvable */
424 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
425 { return lhs.get() < rhs.get(); }
427 /** \relates Solvable Test whether a \ref Solvable is of a certain Kind. */
429 inline bool isKind( const Solvable & solvable_r )
430 { return solvable_r.isKind( ResTraits<TRes>::kind ); }
432 /** \relates Solvable Test for same content. */
433 inline bool identical( const Solvable & lhs, const Solvable & rhs )
434 { return lhs.identical( rhs ); }
436 /** \relates Solvable Test for same name version release and arch. */
437 inline bool sameNVRA( const Solvable & lhs, const Solvable & rhs )
438 { return lhs.sameNVRA( rhs ); }
441 /** \relates Solvable Compare according to \a kind and \a name. */
442 inline int compareByN( const Solvable & lhs, const Solvable & rhs )
447 if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
448 res = lhs.name().compare( rhs.name() );
453 /** \relates Solvable Compare according to \a kind, \a name and \a edition. */
454 inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
456 int res = compareByN( lhs, rhs );
458 res = lhs.edition().compare( rhs.edition() );
462 /** \relates Solvable Compare according to \a kind, \a name, \a edition and \a arch. */
463 inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
465 int res = compareByNVR( lhs, rhs );
467 res = lhs.arch().compare( rhs.arch() );
471 ///////////////////////////////////////////////////////////////////
474 ///////////////////////////////////////////////////////////////////
476 // CLASS NAME : SolvableIterator
479 class SolvableIterator : public boost::iterator_adaptor<
480 SolvableIterator // Derived
482 , const Solvable // Value
483 , boost::forward_traversal_tag // CategoryOrTraversal
484 , const Solvable // Reference
489 : SolvableIterator::iterator_adaptor_( 0 )
492 explicit SolvableIterator( const Solvable & val_r )
493 : SolvableIterator::iterator_adaptor_( 0 )
494 { assignVal( val_r ); }
496 explicit SolvableIterator( SolvableIdType id_r )
497 : SolvableIterator::iterator_adaptor_( 0 )
498 { assignVal( Solvable( id_r ) ); }
501 friend class boost::iterator_core_access;
503 Solvable dereference() const
507 { assignVal( _val.nextInPool() ); }
510 void assignVal( const Solvable & val_r )
511 { _val = val_r; base_reference() = _val.get(); }
515 } // namespace detail
516 ///////////////////////////////////////////////////////////////////
518 ///////////////////////////////////////////////////////////////////
521 ///////////////////////////////////////////////////////////////////
524 /** To Solvable transform functor.
526 * \relates sat::SolvIterMixin
530 typedef Solvable result_type;
532 Solvable operator()( const Solvable & solv_r ) const
535 Solvable operator()( const PoolItem & pi_r ) const;
537 Solvable operator()( const ResObject_constPtr & res_r ) const;
540 ///////////////////////////////////////////////////////////////////
542 ///////////////////////////////////////////////////////////////////
544 ZYPP_DEFINE_ID_HASHABLE( ::zypp::sat::Solvable );
546 #endif // ZYPP_SAT_SOLVABLE_H