libzypp 17.38.8
solvable.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_SAT_SOLVABLE_H
13#define ZYPP_SAT_SOLVABLE_H
14
15#include <iosfwd>
16
19#include <zypp-core/ByteCount.h>
20#include <zypp-core/Date.h>
21#include <zypp-core/CheckSum.h>
22
26#include <zypp/ng/restraits.h>
27#include <zypp/ng/idstring.h>
28#include <zypp/ng/edition.h>
29#include <zypp/ng/arch.h>
30#include <zypp/ng/cpeid.h>
31#include <zypp/ng/dep.h>
34#include <zypp/ng/reskind.h>
35#include <zypp/ng/locale.h>
36
37
38
39namespace zyppng
40{
42 namespace sat
43 {
44 class Solvable;
45
46 namespace detail {
47 template<> Pool & poolFromType( Solvable & );
48 template<> const Pool & poolFromType( const Solvable & );
49 }
50
65 class Solvable : public PoolMember<Solvable>
66 {
67 public:
69
70 static const IdString patternToken;
71 static const IdString productToken;
72
73 static const IdString retractedToken;
74 static const IdString ptfMasterToken;
76
77 public:
80 : _id( detail::noSolvableId )
81 {}
82
83 Solvable(const Solvable &) = default;
84 Solvable(Solvable &&) noexcept = default;
85 Solvable &operator=(const Solvable &) = default;
86 Solvable &operator=(Solvable &&) noexcept = default;
87
89 explicit Solvable( IdType id_r )
90 : _id( id_r )
91 {}
92
93 public:
95 static const Solvable noSolvable;
96
98 explicit operator bool() const
99 { return get(); }
100
101 public:
106 IdString ident()const;
107
109 ResKind kind()const;
110
115 bool isKind( const ResKind & kind_r ) const;
117 template<class TRes>
118 bool isKind() const
119 { return isKind( resKind<TRes>() ); }
120
121 template<class TIterator>
122 bool isKind( TIterator begin, TIterator end ) const
123 { return ranges::any_of( begin, end, [this]( const ResKind & k ){ return isKind(k); } ); }
124
125 bool isKind( std::initializer_list<ResKind> range ) const
126 { return isKind( range.begin(), range.end() ); }
127
129 std::string name() const;
130
132 Edition edition() const;
133
135 Arch arch() const;
136
138 IdString vendor() const;
139
142
146 bool isSystem() const;
147
149 zypp::Date buildtime() const;
150
152 zypp::Date installtime() const;
153
157 bool identical( const Solvable & rhs ) const;
158
160 bool sameNVRA( const Solvable & rhs ) const
161 { return( get() == rhs.get() || ( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ) ); }
162
163 public:
178
180 Capabilities dep( Dep which_r ) const
181 {
182 switch( which_r.inSwitch() )
183 {
184 case Dep::PROVIDES_e: return dep_provides(); break;
185 case Dep::REQUIRES_e: return dep_requires(); break;
186 case Dep::CONFLICTS_e: return dep_conflicts(); break;
187 case Dep::OBSOLETES_e: return dep_obsoletes(); break;
188 case Dep::RECOMMENDS_e: return dep_recommends(); break;
189 case Dep::SUGGESTS_e: return dep_suggests(); break;
190 case Dep::ENHANCES_e: return dep_enhances(); break;
191 case Dep::SUPPLEMENTS_e: return dep_supplements(); break;
192 case Dep::PREREQUIRES_e: return dep_prerequires(); break;
193 }
194 return Capabilities();
195 }
196
197 Capabilities operator[]( Dep which_r ) const
198 { return dep( which_r ); }
199
200
202 CapabilitySet providesNamespace( const std::string & namespace_r ) const;
203
211 CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
213
214 std::pair<bool, CapabilitySet> matchesSolvable ( const SolvAttr &attr, const Solvable &solv ) const;
215
216 public:
219
220 bool supportsLocales() const;
222 bool supportsLocale( const Locale & locale_r ) const;
224 bool supportsLocale( const LocaleSet & locales_r ) const;
229 void getSupportedLocales( LocaleSet & locales_r ) const
230 { locales_r = getSupportedLocales(); }
231
232
233 public:
235 CpeId cpeId() const;
236
238 unsigned mediaNr() const;
239
262
265
267 std::string distribution() const;
268
270 std::string summary( const Locale & lang_r = Locale() ) const;
271
273 std::string description( const Locale & lang_r = Locale() ) const;
274
276 std::string insnotify( const Locale & lang_r = Locale() ) const;
278 std::string delnotify( const Locale & lang_r = Locale() ) const;
279
281 std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
284
285 public:
291
295 std::string lookupStrAttribute( const SolvAttr & attr ) const;
306 std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
307
312 unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
314 unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const;
315
320 bool lookupBoolAttribute( const SolvAttr & attr ) const;
321
326 detail::IdType lookupIdAttribute( const SolvAttr & attr ) const;
327
332 zypp::CheckSum lookupCheckSumAttribute( const SolvAttr & attr ) const;
333
334 public:
336 Solvable nextInPool() const;
338 Solvable nextInRepo() const;
340 detail::CSolvable * get() const;
342 IdType id() const { return _id; }
343
344 private:
346 };
347
348
350 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
351 { return lhs.get() == rhs.get(); }
352
354 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
355 { return lhs.get() != rhs.get(); }
356
358 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
359 { return lhs.get() < rhs.get(); }
360
362 template<class TRes>
363 inline bool isKind( const Solvable & solvable_r )
364 { return solvable_r.isKind( ResTraits<TRes>::kind ); }
365
367 inline bool identical( const Solvable & lhs, const Solvable & rhs )
368 { return lhs.identical( rhs ); }
369
371 inline bool sameNVRA( const Solvable & lhs, const Solvable & rhs )
372 { return lhs.sameNVRA( rhs ); }
373
374
376 inline int compareByN( const Solvable & lhs, const Solvable & rhs )
377 {
378 int res = 0;
379 if ( lhs != rhs )
380 {
381 if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
382 res = lhs.name().compare( rhs.name() );
383 }
384 return res;
385 }
386
388 inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
389 {
390 int res = compareByN( lhs, rhs );
391 if ( res == 0 )
392 res = lhs.edition().compare( rhs.edition() );
393 return res;
394 }
395
397 inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
398 {
399 int res = compareByNVR( lhs, rhs );
400 if ( res == 0 )
401 res = lhs.arch().compare( rhs.arch() );
402 return res;
403 }
404
406 namespace detail
407 {
415 {
416 public:
417 using iterator_category = std::forward_iterator_tag;
418 using value_type = Solvable; // non-cv-qualified per [iterator.traits]; constness lives on reference
419 using difference_type = std::ptrdiff_t;
420 using pointer = void; // proxy-by-value: no stable address exists for a temporary
421 using reference = const Solvable; // operator* returns by value – read-only proxy
422
424 : _base( nullptr )
425 {}
426
427 explicit SolvableIterator( const Solvable & val_r )
428 : _base( nullptr )
429 { initialAssignVal( val_r ); }
430
432 : _base( nullptr )
433 { initialAssignVal( Solvable(id_r) ); }
434
436 { return _val; }
437
439 { increment(); return *this; }
440
442 { SolvableIterator tmp = *this; increment(); return tmp; }
443
444 bool operator==( const SolvableIterator & rhs ) const
445 { return _base == rhs._base; }
446
447 bool operator!=( const SolvableIterator & rhs ) const
448 { return !(*this == rhs); }
449
450 CSolvable * const & base() const
451 { return _base; }
452
453 private:
455 { assignVal( _val.nextInPool() ); }
456
457 void initialAssignVal( const Solvable & val_r )
458 { assignVal( val_r ? val_r : val_r.nextInPool() ); }
459
460 void assignVal( const Solvable & val_r )
461 { _val = val_r; _base = _val.get(); }
462
465 };
466 } // namespace detail
467
468 namespace detail {
469
470 template <typename T>
471 using satSolvable_t = decltype(std::declval<T>().satSolvable());
472
473 template <typename T>
475
476 template <typename T, typename = void >
478 // static_assert to force specialization/implementation
479 static_assert( always_false_v<T>, "Type must have .satSolvable() or a specialization of detail::convert_to_solvable" );
480 };
481
482 template <typename T>
483 struct convert_to_solvable<T, std::void_t<satSolvable_t<T>>> {
484 template <typename SType = T>
485 static Solvable asSolvable( SType && obj ) {
486 return std::forward<SType>(obj).satSolvable();
487 }
488 };
489 }
490
496 {
498
499 Solvable operator()( const Solvable & solv_r ) const
500 { return solv_r; }
501
502 template <typename T>
503 Solvable operator()( T&& obj )const {
504 return detail::convert_to_solvable<T>::asSolvable( std::forward<T>(obj));
505 }
506 };
507
508 } // namespace sat
509} // namespace zypp
510
512
513#endif // ZYPP_SAT_SOLVABLE_H
#define ZYPP_DEFINE_ID_HASHABLE(C)
Define hash function for id based classes.
Definition Hash.h:26
Architecture.
Definition Arch.h:37
int compare(const Arch &rhs) const
Arch comparison.
Definition Arch.cc:785
Store and operate with byte count.
Definition ByteCount.h:32
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition CpeId.h:33
Store and operate on date (time_t).
Definition Date.h:33
Edition represents [epoch:]version[-release].
Definition Edition.h:60
Access to the sat-pools string space.
Definition IdString.h:55
'Language[_Country]' codes.
Definition Locale.h:51
Resolvable kinds.
Definition ResKind.h:33
Solvable attribute keys.
Definition SolvAttr.h:41
static int compare(const Derived &lhs, const Derived &rhs)
Container of Capability (currently read only).
A Solvable object within the sat Pool.
Definition solvable.h:66
std::string lookupStrAttribute(const SolvAttr &attr) const
returns the string attribute value for attr or an empty string if it does not exists.
Definition solvable.cc:108
Capabilities dep(Dep which_r) const
Return Capabilities selected by Dep constant.
Definition solvable.h:180
static const IdString ptfPackageToken
Indicator provides ptf-package().
Definition solvable.h:75
detail::CSolvable * get() const
Expert backdoor.
Definition solvable.cc:77
bool lookupBoolAttribute(const SolvAttr &attr) const
returns the boolean attribute value for attr or false if it does not exists.
Definition solvable.cc:148
Capabilities dep_conflicts() const
Definition solvable.cc:345
std::string summary(const Locale &lang_r=Locale()) const
Short (singleline) text describing the solvable (opt.
Definition solvable.cc:575
bool identical(const Solvable &rhs) const
Test whether two Solvables have the same content.
Definition solvable.cc:318
Solvable()
Default ctor creates noSolvable.
Definition solvable.h:79
std::string name() const
The name (without any ResKind prefix).
Definition solvable.cc:239
bool needToAcceptLicense() const
True except for well known exceptions (i.e show license but no need to accept it).
Capabilities operator[](Dep which_r) const
Definition solvable.h:197
bool isKind(TIterator begin, TIterator end) const
Definition solvable.h:122
CapabilitySet valuesOfNamespace(const std::string &namespace_r) const
Return 'value[ op edition]' for namespaced provides 'namespace(value)[ op edition]'.
Definition solvable.cc:400
Solvable(const Solvable &)=default
static const IdString productToken
Indicator provides product().
Definition solvable.h:71
bool isKind(std::initializer_list< ResKind > range) const
Definition solvable.h:125
ResKind kind() const
The Solvables ResKind.
Definition solvable.cc:185
CpeId cpeId() const
The solvables CpeId if available.
Definition solvable.cc:538
zypp::ByteCount installSize() const
Installed (unpacked) size.
Definition solvable.cc:557
bool isKind() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition solvable.h:118
static const IdString retractedToken
Indicator provides retracted-patch-package().
Definition solvable.h:73
Capabilities dep_prerequires() const
Definition solvable.cc:375
Solvable nextInPool() const
Return next Solvable in Pool (or noSolvable).
Definition solvable.cc:88
static const IdString patternToken
Indicator provides pattern().
Definition solvable.h:70
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition solvable.cc:279
bool sameNVRA(const Solvable &rhs) const
Test for same name-version-release.arch.
Definition solvable.h:160
std::string delnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for uninstall (opt.
Definition solvable.cc:593
Capabilities dep_enhances() const
Definition solvable.cc:365
std::string licenseToConfirm(const Locale &lang_r=Locale()) const
License or agreement to accept before installing the solvable (opt.
Edition edition() const
The edition (version-release).
Definition solvable.cc:247
bool supportsLocale(const Locale &locale_r) const
Whether this Solvable supports a specific Locale.
Definition solvable.cc:514
std::string description(const Locale &lang_r=Locale()) const
Long (multiline) text describing the solvable (opt.
Definition solvable.cc:581
LocaleSet getSupportedLocales() const
Return the supported locales.
Definition solvable.cc:528
Capabilities dep_requires() const
Definition solvable.cc:340
Capabilities dep_supplements() const
Definition solvable.cc:370
detail::IdType lookupIdAttribute(const SolvAttr &attr) const
returns the id attribute value for attr or detail::noId if it does not exists.
Definition solvable.cc:154
IdString ident() const
The identifier.
Definition solvable.cc:179
zypp::Date installtime() const
The items install time (false if not installed).
Definition solvable.cc:291
Capabilities dep_obsoletes() const
Definition solvable.cc:350
unsigned long long lookupNumAttribute(const SolvAttr &attr) const
returns the numeric attribute value for attr or 0 if it does not exists.
Definition solvable.cc:136
Capabilities dep_suggests() const
Definition solvable.cc:360
detail::SolvableIdType IdType
Definition solvable.h:68
IdType id() const
Expert backdoor.
Definition solvable.h:342
std::string insnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for install (opt.
Definition solvable.cc:587
zypp::CheckSum lookupCheckSumAttribute(const SolvAttr &attr) const
returns the CheckSum attribute value for attr or an empty CheckSum if ir does not exist.
Definition solvable.cc:160
Capabilities dep_recommends() const
Definition solvable.cc:355
Capabilities dep_provides() const
Definition solvable.cc:335
CapabilitySet providesNamespace(const std::string &namespace_r) const
Return the namespaced provides 'namespace([value])[ op edition]' of this Solvable.
Definition solvable.cc:384
std::string distribution() const
The distribution string.
Definition solvable.cc:569
static const Solvable noSolvable
Represents no Solvable.
Definition solvable.h:95
Arch arch() const
The architecture.
Definition solvable.cc:253
zypp::ByteCount downloadSize() const
Download size.
Definition solvable.cc:563
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition solvable.cc:212
IdString vendor() const
The vendor.
Definition solvable.cc:267
Solvable nextInRepo() const
Return next Solvable in Repo (or noSolvable).
Definition solvable.cc:94
detail::RepoIdType repository() const
The repo id this Solvable belongs to.
Definition solvable.cc:273
zypp::Date buildtime() const
The items build time.
Definition solvable.cc:285
Solvable(Solvable &&) noexcept=default
unsigned mediaNr() const
Media number the solvable is located on (0 if no media access required).
Definition solvable.cc:544
std::pair< bool, CapabilitySet > matchesSolvable(const SolvAttr &attr, const Solvable &solv) const
Definition solvable.cc:421
static const IdString ptfMasterToken
Indicator provides ptf().
Definition solvable.h:74
bool supportsLocales() const
Whether this Solvable claims to support locales.
Definition solvable.cc:508
CSolvable *const & base() const
Definition solvable.h:450
bool operator==(const SolvableIterator &rhs) const
Definition solvable.h:444
SolvableIterator(const Solvable &val_r)
Definition solvable.h:427
void initialAssignVal(const Solvable &val_r)
Definition solvable.h:457
SolvableIterator & operator++()
Definition solvable.h:438
bool operator!=(const SolvableIterator &rhs) const
Definition solvable.h:447
SolvableIterator(SolvableIdType id_r)
Definition solvable.h:431
void assignVal(const Solvable &val_r)
Definition solvable.h:460
std::forward_iterator_tag iterator_category
Definition solvable.h:417
SolvableIterator operator++(int)
Definition solvable.h:441
Definition ansi.h:855
constexpr bool is_detected_v
Definition type_traits.h:57
int compareByN(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Compare according to kind and name.
Definition Solvable.h:507
bool identical(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Test for same content.
Definition Solvable.h:498
bool operator!=(const FileConflicts &lhs, const FileConflicts &rhs)
relates: FileConflicts
bool isKind(const Solvable &solvable_r)
relates: Solvable Test whether a Solvable is of a certain Kind.
Definition Solvable.h:494
bool operator<(const LocaleSupport &lhs, const LocaleSupport &rhs)
relates: LocaleSupport
bool operator==(const FileConflicts &lhs, const FileConflicts &rhs)
relates: FileConflicts
bool sameNVRA(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Test for same name version release and arch.
Definition Solvable.h:502
int compareByNVRA(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Compare according to kind, name, edition and arch.
Definition Solvable.h:528
int compareByNVR(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Compare according to kind, name and edition.
Definition Solvable.h:519
std::unordered_set< Locale > LocaleSet
Definition Locale.h:29
constexpr bool always_false_v
Definition LogControl.cc:60
ResKind resKind()
Convenient access to well known ResKinds.
Definition ResTraits.h:129
CLASS NAME : detail::DIWrap.
Definition cap2str.cc:14
zypp::sat::detail::CSolvable CSolvable
zypp::sat::detail::RepoIdType RepoIdType
Pool & poolFromType(T &)
zypp::sat::detail::SolvableIdType SolvableIdType
decltype(std::declval< T >().satSolvable()) satSolvable_t
Definition solvable.h:471
zypp::sat::detail::IdType IdType
constexpr bool has_satSolvable_v
Definition solvable.h:474
This file contains private API, this might break at any time between releases.
std::unordered_set< Capability > CapabilitySet
Definition capability.h:35
Namespace routing for C++20 ranges and C++23 ranges::to<T>() backport.
Enumeration class of dependency types.
Definition Dep.h:31
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition Dep.h:90
ResTraits.
Definition ResTraits.h:80
@ SUGGESTS_e
Definition Dep.h:64
@ REQUIRES_e
Definition Dep.h:60
@ PREREQUIRES_e
Definition Dep.h:59
@ RECOMMENDS_e
Definition Dep.h:63
@ SUPPLEMENTS_e
Definition Dep.h:66
@ PROVIDES_e
Definition Dep.h:58
@ CONFLICTS_e
Definition Dep.h:61
@ ENHANCES_e
Definition Dep.h:65
@ OBSOLETES_e
Definition Dep.h:62
To Solvable transform functor.
Definition solvable.h:496
Solvable operator()(T &&obj) const
Definition solvable.h:503
Solvable operator()(const Solvable &solv_r) const
Definition solvable.h:499