libzypp 17.31.23
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
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>
23#include <zypp/Dep.h>
24#include <zypp/Capabilities.h>
25#include <zypp/Capability.h>
26#include <zypp/Locale.h>
27
29namespace zypp
30{
31 class ByteCount;
32 class CheckSum;
33 class CpeId;
34 class Date;
35 class OnMediaLocation;
37 namespace sat
38 {
53 class Solvable : protected detail::PoolMember
54 {
55 public:
57
58 static const IdString retractedToken;
59 static const IdString ptfMasterToken;
61
62 public:
65 : _id( detail::noSolvableId )
66 {}
67
69 explicit Solvable( IdType id_r )
70 : _id( id_r )
71 {}
72
73 public:
75 static const Solvable noSolvable;
76
78 explicit operator bool() const
79 { return get(); }
80
81 public:
86 IdString ident()const;
87
89 ResKind kind()const;
90
95 bool isKind( const ResKind & kind_r ) const;
97 template<class TRes>
98 bool isKind() const
99 { return isKind( resKind<TRes>() ); }
101 template<class TIterator>
102 bool isKind( TIterator begin, TIterator end ) const
103 { for_( it, begin, end ) if ( isKind( *it ) ) return true; return false; }
104
106 std::string name() const;
107
109 Edition edition() const;
110
112 Arch arch() const;
113
115 IdString vendor() const;
116
118 Repository repository() const;
120 RepoInfo repoInfo() const;
121
125 bool isSystem() const;
126
130 bool onSystemByUser() const;
131
135 bool onSystemByAuto() const;
136
139 { return identIsAutoInstalled( ident() ); }
141 static bool identIsAutoInstalled( const IdString & ident_r );
142
146 bool multiversionInstall() const;
147
149 bool isNeedreboot() const;
150
170 bool isBlacklisted() const;
171
173 bool isRetracted() const;
174
176 bool isPtf() const;
177
179 bool isPtfMaster() const;
180
182 bool isPtfPackage() const;
184
186 Date buildtime() const;
187
189 Date installtime() const;
190
191 public:
199 std::string asString() const;
200
202 std::string asUserString() const;
203
207 bool identical( const Solvable & rhs ) const;
208
210 bool sameNVRA( const Solvable & rhs ) const
211 { return( get() == rhs.get() || ( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ) ); }
212
213 public:
219 Capabilities provides() const;
220 Capabilities requires() const;
221 Capabilities conflicts() const;
222 Capabilities obsoletes() const;
223 Capabilities recommends() const;
224 Capabilities suggests() const;
225 Capabilities enhances() const;
228
230 Capabilities dep( Dep which_r ) const
231 {
232 switch( which_r.inSwitch() )
233 {
234 case Dep::PROVIDES_e: return provides(); break;
235 case Dep::REQUIRES_e: return requires(); break;
236 case Dep::CONFLICTS_e: return conflicts(); break;
237 case Dep::OBSOLETES_e: return obsoletes(); break;
238 case Dep::RECOMMENDS_e: return recommends(); break;
239 case Dep::SUGGESTS_e: return suggests(); break;
240 case Dep::ENHANCES_e: return enhances(); break;
241 case Dep::SUPPLEMENTS_e: return supplements(); break;
242 case Dep::PREREQUIRES_e: return prerequires(); break;
243 }
244 return Capabilities();
245 }
247 Capabilities operator[]( Dep which_r ) const
248 { return dep( which_r ); }
249
250
252 CapabilitySet providesNamespace( const std::string & namespace_r ) const;
253
261 CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
263
264 std::pair<bool, CapabilitySet> matchesSolvable ( const SolvAttr &attr, const sat::Solvable &solv ) const;
265
266 public:
270 bool supportsLocales() const;
272 bool supportsLocale( const Locale & locale_r ) const;
274 bool supportsLocale( const LocaleSet & locales_r ) const;
278 bool supportsRequestedLocales() const;
282 void getSupportedLocales( LocaleSet & locales_r ) const
283 { locales_r = getSupportedLocales(); }
285
286 public:
288 CpeId cpeId() const;
289
291 unsigned mediaNr() const;
292
314 ByteCount installSize() const;
315
317 ByteCount downloadSize() const;
318
320 std::string distribution() const;
321
323 std::string summary( const Locale & lang_r = Locale() ) const;
324
326 std::string description( const Locale & lang_r = Locale() ) const;
327
329 std::string insnotify( const Locale & lang_r = Locale() ) const;
331 std::string delnotify( const Locale & lang_r = Locale() ) const;
332
334 std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
336 bool needToAcceptLicense() const;
337
338 public:
345 {
346 public:
348 SplitIdent( IdString ident_r );
349 SplitIdent( const char * ident_r );
350 SplitIdent( const std::string & ident_r );
351 SplitIdent( ResKind kind_r, IdString name_r );
352 SplitIdent( ResKind kind_r, const C_Str & name_r );
353
354 IdString ident() const { return _ident; }
355 ResKind kind() const { return _kind; }
356 IdString name() const { return _name; }
357
358 private:
362 };
363
364 public:
374 std::string lookupStrAttribute( const SolvAttr & attr ) const;
385 std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
386
391 unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
393 unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const;
394
399 bool lookupBoolAttribute( const SolvAttr & attr ) const;
400
406
412
419
420 public:
422 Solvable nextInPool() const;
424 Solvable nextInRepo() const;
426 detail::CSolvable * get() const;
428 IdType id() const { return _id; }
429
430 private:
432 };
434
436 std::ostream & operator<<( std::ostream & str, const Solvable & obj );
437
439 std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
440
442 std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj );
443
445 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
446 { return lhs.get() == rhs.get(); }
447
449 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
450 { return lhs.get() != rhs.get(); }
451
453 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
454 { return lhs.get() < rhs.get(); }
455
457 template<class TRes>
458 inline bool isKind( const Solvable & solvable_r )
459 { return solvable_r.isKind( ResTraits<TRes>::kind ); }
460
462 inline bool identical( const Solvable & lhs, const Solvable & rhs )
463 { return lhs.identical( rhs ); }
464
466 inline bool sameNVRA( const Solvable & lhs, const Solvable & rhs )
467 { return lhs.sameNVRA( rhs ); }
468
469
471 inline int compareByN( const Solvable & lhs, const Solvable & rhs )
472 {
473 int res = 0;
474 if ( lhs != rhs )
475 {
476 if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
477 res = lhs.name().compare( rhs.name() );
478 }
479 return res;
480 }
481
483 inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
484 {
485 int res = compareByN( lhs, rhs );
486 if ( res == 0 )
487 res = lhs.edition().compare( rhs.edition() );
488 return res;
489 }
490
492 inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
493 {
494 int res = compareByNVR( lhs, rhs );
495 if ( res == 0 )
496 res = lhs.arch().compare( rhs.arch() );
497 return res;
498 }
499
501 namespace detail
502 {
509 class SolvableIterator : public boost::iterator_adaptor<
510 SolvableIterator // Derived
511 , CSolvable* // Base
512 , const Solvable // Value
513 , boost::forward_traversal_tag // CategoryOrTraversal
514 , const Solvable // Reference
515 >
516 {
517 public:
519 : SolvableIterator::iterator_adaptor_( nullptr )
520 {}
521
522 explicit SolvableIterator( const Solvable & val_r )
523 : SolvableIterator::iterator_adaptor_( nullptr )
524 { initialAssignVal( val_r ); }
525
527 : SolvableIterator::iterator_adaptor_( nullptr )
528 { initialAssignVal( Solvable(id_r) ); }
529
530 private:
532
534 { return _val; }
535
537 { assignVal( _val.nextInPool() ); }
538
539 private:
540 void initialAssignVal( const Solvable & val_r )
541 { assignVal( val_r ? val_r : val_r.nextInPool() ); }
542
543 void assignVal( const Solvable & val_r )
544 { _val = val_r; base_reference() = _val.get(); }
545
547 };
548 } // namespace detail
550 } // namespace sat
552
553 class PoolItem;
555 namespace sat
556 {
562 {
564
565 Solvable operator()( const Solvable & solv_r ) const
566 { return solv_r; }
567
568 Solvable operator()( const PoolItem & pi_r ) const;
569
570 Solvable operator()( const ResObject_constPtr & res_r ) const;
571 };
572 } // namespace sat
574} // namespace zypp
576
578
579#endif // ZYPP_SAT_SOLVABLE_H
sat::SolvAttr attr
Definition: PoolQuery.cc:311
Architecture.
Definition: Arch.h:37
int compare(const Arch &rhs) const
Arch comparison.
Definition: Arch.cc:556
Store and operate with byte count.
Definition: ByteCount.h:31
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition: String.h:91
Container of Capability (currently read only).
Definition: Capabilities.h:36
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition: CpeId.h:32
Store and operate on date (time_t).
Definition: Date.h:33
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
static int compare(const Derived &lhs, const Derived &rhs)
Definition: IdStringType.h:127
Access to the sat-pools string space.
Definition: IdString.h:43
'Language[_Country]' codes.
Definition: Locale.h:50
Describes a resource file located on a medium.
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:51
What is known about a repository.
Definition: RepoInfo.h:72
Resolvable kinds.
Definition: ResKind.h:33
Solvable attribute keys.
Definition: SolvAttr.h:41
Helper that splits an identifier into kind and name or vice versa.
Definition: Solvable.h:345
A Solvable object within the sat Pool.
Definition: Solvable.h:54
Capabilities suggests() const
Definition: Solvable.cc:509
IdType id() const
Expert backdoor.
Definition: Solvable.h:428
bool isKind(const Solvable &solvable_r)
Test whether a Solvable is of a certain Kind.
Definition: Solvable.h:458
bool isPtfPackage() const
Subset of isPtf (provides ptfPackageToken).
Definition: Solvable.cc:423
bool isNeedreboot() const
Whether this solvable triggers the reboot-needed hint if installed/updated.
Definition: Solvable.cc:394
bool identIsAutoInstalled() const
Whether an installed solvable with the same ident is flagged as AutoInstalled.
Definition: Solvable.h:138
OnMediaLocation lookupLocation() const
returns OnMediaLocation data: This is everything we need to download e.g.
Definition: Solvable.cc:224
bool isKind(TIterator begin, TIterator end) const
Definition: Solvable.h:102
Capabilities dep(Dep which_r) const
Return Capabilities selected by Dep constant.
Definition: Solvable.h:230
bool identical(const Solvable &lhs, const Solvable &rhs)
Test for same content.
Definition: Solvable.h:462
bool lookupBoolAttribute(const SolvAttr &attr) const
returns the boolean attribute value for attr or false if it does not exists.
Definition: Solvable.cc:170
int compareByNVR(const Solvable &lhs, const Solvable &rhs)
Compare according to kind, name and edition.
Definition: Solvable.h:483
IdString vendor() const
The vendor.
Definition: Solvable.cc:357
void getSupportedLocales(LocaleSet &locales_r) const
Definition: Solvable.h:282
ByteCount installSize() const
Installed (unpacked) size.
Definition: Solvable.cc:701
Date buildtime() const
The items build time.
Definition: Solvable.cc:436
bool needToAcceptLicense() const
True except for well known exceptions (i.e show license but no need to accept it).
Definition: Solvable.cc:760
ResKind kind() const
The Solvables ResKind.
Definition: Solvable.cc:275
CapabilitySet providesNamespace(const std::string &namespace_r) const
Return the namespaced provides 'namespace([value])[ op edition]' of this Solvable.
Definition: Solvable.cc:533
static const Solvable noSolvable
Represents no Solvable.
Definition: Solvable.h:75
std::string asString() const
String representation "ident-edition.arch" or "noSolvable".
Definition: Solvable.cc:448
std::string distribution() const
The distribution string.
Definition: Solvable.cc:713
unsigned mediaNr() const
Media number the solvable is located on (0 if no media access required).
Definition: Solvable.cc:688
bool isBlacklisted() const
Whether this solvable is blacklisted (retracted,ptf,...).
Definition: Solvable.cc:401
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:158
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:130
bool multiversionInstall() const
Whether different versions of this package can be installed at the same time.
Definition: Solvable.cc:430
int compareByN(const Solvable &lhs, const Solvable &rhs)
Compare according to kind and name.
Definition: Solvable.h:471
CpeId cpeId() const
The solvables CpeId if available.
Definition: Solvable.cc:682
Solvable nextInRepo() const
Return next Solvable in Repo (or noSolvable).
Definition: Solvable.cc:116
Capabilities operator[](Dep which_r) const
Definition: Solvable.h:247
Date installtime() const
The items install time (false if not installed).
Definition: Solvable.cc:442
Edition edition() const
The edition (version-release).
Definition: Solvable.cc:337
bool sameNVRA(const Solvable &rhs) const
Test for same name-version-release.arch.
Definition: Solvable.h:210
static const IdString ptfMasterToken
Indicator provides ptf()
Definition: Solvable.h:59
Capabilities prerequires() const
Definition: Solvable.cc:524
bool isPtfMaster() const
Subset of isPtf (provides ptfMasterToken).
Definition: Solvable.cc:417
Solvable()
Default ctor creates noSolvable.
Definition: Solvable.h:64
Capabilities enhances() const
Definition: Solvable.cc:514
LocaleSet getSupportedLocales() const
Return the supported locales.
Definition: Solvable.cc:675
bool supportsRequestedLocales() const
Whether this Solvable supports at least one requested locale.
Definition: Solvable.cc:672
Solvable(IdType id_r)
PoolImpl ctor.
Definition: Solvable.h:69
bool operator==(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:445
detail::CSolvable * get() const
Expert backdoor.
Definition: Solvable.cc:106
Arch arch() const
The architecture.
Definition: Solvable.cc:343
static const IdString ptfPackageToken
Indicator provides ptf-package()
Definition: Solvable.h:60
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition: Solvable.cc:373
Solvable nextInPool() const
Return next Solvable in Pool (or noSolvable).
Definition: Solvable.cc:113
std::string licenseToConfirm(const Locale &lang_r=Locale()) const
License or agreement to accept before installing the solvable (opt.
Definition: Solvable.cc:743
bool operator!=(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:449
bool supportsLocales() const
Whether this Solvable claims to support locales.
Definition: Solvable.cc:652
Capabilities provides() const
Definition: Solvable.cc:484
std::string asUserString() const
String representation "ident-edition.arch(repo)" or "noSolvable".
Definition: Solvable.cc:457
static const IdString retractedToken
Indicator provides retracted-patch-package()
Definition: Solvable.h:58
bool sameNVRA(const Solvable &lhs, const Solvable &rhs)
Test for same name version release and arch.
Definition: Solvable.h:466
std::string summary(const Locale &lang_r=Locale()) const
Short (singleline) text describing the solvable (opt.
Definition: Solvable.cc:719
Capabilities conflicts() const
Definition: Solvable.cc:494
Capabilities obsoletes() const
Definition: Solvable.cc:499
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:176
std::pair< bool, CapabilitySet > matchesSolvable(const SolvAttr &attr, const sat::Solvable &solv) const
Definition: Solvable.cc:565
std::string name() const
The name (without any ResKind prefix).
Definition: Solvable.cc:329
sat::detail::SolvableIdType IdType
Definition: Solvable.h:56
bool supportsLocale(const Locale &locale_r) const
Whether this Solvable supports a specific Locale.
Definition: Solvable.cc:658
Capabilities supplements() const
Definition: Solvable.cc:519
ByteCount downloadSize() const
Download size.
Definition: Solvable.cc:707
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:302
bool operator<(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:453
bool onSystemByAuto() const
Whether this is known to be automatically installed (as dependency of a user request package).
Definition: Solvable.cc:384
std::string delnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for uninstall (opt.
Definition: Solvable.cc:737
CapabilitySet valuesOfNamespace(const std::string &namespace_r) const
Return 'value[ op edition]' for namespaced provides 'namespace(value)[ op edition]'.
Definition: Solvable.cc:547
IdString ident() const
The identifier.
Definition: Solvable.cc:269
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:182
std::string description(const Locale &lang_r=Locale()) const
Long (multiline) text describing the solvable (opt.
Definition: Solvable.cc:725
bool onSystemByUser() const
Whether this is known to be installed on behalf of a user request.
Definition: Solvable.cc:379
Capabilities recommends() const
Definition: Solvable.cc:504
int compareByNVRA(const Solvable &lhs, const Solvable &rhs)
Compare according to kind, name, edition and arch.
Definition: Solvable.h:492
RepoInfo repoInfo() const
The repositories RepoInfo.
Definition: Solvable.cc:369
Repository repository() const
The Repository this Solvable belongs to.
Definition: Solvable.cc:363
bool isPtf() const
Whether this solvable belongs to a PTF (provides ptfMasterToken or ptfPackageToken).
Definition: Solvable.cc:414
bool isRetracted() const
Whether this solvable is retracted (provides retractedToken).
Definition: Solvable.cc:404
bool isKind() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: Solvable.h:98
std::string insnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for install (opt.
Definition: Solvable.cc:731
bool identical(const Solvable &rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:467
Iterate over valid Solvables in the pool.
Definition: Solvable.h:516
void initialAssignVal(const Solvable &val_r)
Definition: Solvable.h:540
SolvableIterator(SolvableIdType id_r)
Definition: Solvable.h:526
void assignVal(const Solvable &val_r)
Definition: Solvable.h:543
SolvableIterator(const Solvable &val_r)
Definition: Solvable.h:522
friend class boost::iterator_core_access
Definition: Solvable.h:531
String related utilities and Regular expression matching.
int IdType
Generic Id type.
Definition: PoolMember.h:104
::s_Solvable CSolvable
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:64
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
bool compareByNVR(const SolvableType< Derived > &lhs, const Solvable &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SolvableType.h:260
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
std::ostream & dumpAsXmlOn(std::ostream &str, const FileConflicts &obj)
bool compareByN(const SolvableType< Derived > &lhs, const Solvable &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SolvableType.h:246
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:35
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:28
Enumeration class of dependency types.
Definition: Dep.h:30
@ SUGGESTS_e
Definition: Dep.h:63
@ REQUIRES_e
Definition: Dep.h:59
@ PREREQUIRES_e
Definition: Dep.h:58
@ RECOMMENDS_e
Definition: Dep.h:62
@ SUPPLEMENTS_e
Definition: Dep.h:65
@ PROVIDES_e
Definition: Dep.h:57
@ CONFLICTS_e
Definition: Dep.h:60
@ ENHANCES_e
Definition: Dep.h:64
@ OBSOLETES_e
Definition: Dep.h:61
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Dep.h:89
ResTraits.
Definition: ResTraits.h:80
To Solvable transform functor.
Definition: Solvable.h:562
Solvable operator()(const Solvable &solv_r) const
Definition: Solvable.h:565
Solvable result_type
Definition: Solvable.h:563
Backlink to the associated PoolImpl.
Definition: PoolMember.h:89
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
#define nullptr
Definition: Easy.h:55
#define ZYPP_DEFINE_ID_HASHABLE(C)
Define hash function for id based classes.
Definition: Hash.h:26