libzypp  17.31.0
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 
29 namespace 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;
60  static const IdString ptfPackageToken;
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 
138  bool identIsAutoInstalled() const
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;
226  Capabilities supplements() const;
227  Capabilities prerequires() 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 
536  void increment()
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  {
561  struct asSolvable
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
static const SolvableIdType noSolvableId(0)
Id to denote Solvable::noSolvable.
bool sameNVRA(const Solvable &rhs) const
Test for same name-version-release.arch.
Definition: Solvable.h:210
std::string description(const Locale &lang_r=Locale()) const
Long (multiline) text describing the solvable (opt.
Definition: Solvable.cc:727
std::string name() const
The name (without any ResKind prefix).
Definition: Solvable.cc:329
int IdType
Generic Id type.
Definition: PoolMember.h:104
static const IdString ptfMasterToken
Indicator provides ptf()
Definition: Solvable.h:59
A Solvable object within the sat Pool.
Definition: Solvable.h:53
IdString vendor() const
The vendor.
Definition: Solvable.cc:357
IdType id() const
Expert backdoor.
Definition: Solvable.h:428
Capabilities provides() const
Definition: Solvable.cc:484
RepoInfo repoInfo() const
The repositories RepoInfo.
Definition: Solvable.cc:369
ResKind kind() const
The Solvables ResKind.
Definition: Solvable.cc:275
Container of Capability (currently read only).
Definition: Capabilities.h:35
Describes a resource file located on a medium.
SolvableIterator(const Solvable &val_r)
Definition: Solvable.h:522
Enumeration class of dependency types.
Definition: Dep.h:29
bool isKind(TIterator begin, TIterator end) const
Definition: Solvable.h:102
OnMediaLocation lookupLocation() const
returns OnMediaLocation data: This is everything we need to download e.g.
Definition: Solvable.cc:224
bool isKind(const Solvable &solvable_r)
Definition: Solvable.h:458
Architecture.
Definition: Arch.h:36
LocaleSet getSupportedLocales() const
Return the supported locales.
Definition: Solvable.cc:677
Capabilities recommends() const
Definition: Solvable.cc:504
Store and operate with byte count.
Definition: ByteCount.h:30
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
sat::SolvAttr attr
Definition: PoolQuery.cc:311
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
bool operator==(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:445
bool isBlacklisted() const
Whether this solvable is blacklisted (retracted,ptf,...).
Definition: Solvable.cc:401
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
ZYPP_DEFINE_ID_HASHABLE(::zypp::sat::Solvable)
String related utilities and Regular expression matching.
Capabilities supplements() const
Definition: Solvable.cc:519
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:302
What is known about a repository.
Definition: RepoInfo.h:71
std::string delnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for uninstall (opt.
Definition: Solvable.cc:739
Access to the sat-pools string space.
Definition: IdString.h:42
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition: CpeId.h:31
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
ResTraits.
Definition: ResTraits.h:79
ByteCount downloadSize() const
Download size.
Definition: Solvable.cc:709
Iterate over valid Solvables in the pool.
Definition: Solvable.h:509
int compare(const Arch &rhs) const
Arch comparison.
Definition: Arch.cc:550
bool identical(const Solvable &rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:467
bool compareByN(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:246
bool isPtfPackage() const
Subset of isPtf (provides ptfPackageToken).
Definition: Solvable.cc:423
static const Solvable noSolvable
Represents no Solvable.
Definition: Solvable.h:75
int compareByNVRA(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:492
bool identical(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:462
CapabilitySet valuesOfNamespace(const std::string &namespace_r) const
Return &#39;value[ op edition]&#39; for namespaced provides &#39;namespace(value)[ op edition]&#39;.
Definition: Solvable.cc:547
Solvable nextInRepo() const
Return next Solvable in Repo (or noSolvable).
Definition: Solvable.cc:116
std::string asUserString() const
String representation "ident-edition.arch(repo)" or "noSolvable".
Definition: Solvable.cc:457
bool sameNVRA(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:466
static int compare(const Derived &lhs, const Derived &rhs)
Definition: IdStringType.h:127
std::string distribution() const
The distribution string.
Definition: Solvable.cc:715
static const IdString ptfPackageToken
Indicator provides ptf-package()
Definition: Solvable.h:60
Repository repository() const
The Repository this Solvable belongs to.
Definition: Solvable.cc:363
bool onSystemByAuto() const
Whether this is known to be automatically installed (as dependency of a user request package)...
Definition: Solvable.cc:384
bool isKind() const
Definition: Solvable.h:98
Store and operate on date (time_t).
Definition: Date.h:32
bool identIsAutoInstalled() const
Whether an installed solvable with the same ident is flagged as AutoInstalled.
Definition: Solvable.h:138
Solvable attribute keys.
Definition: SolvAttr.h:40
Backlink to the associated PoolImpl.
Definition: PoolMember.h:88
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Dep.h:89
Capabilities enhances() const
Definition: Solvable.cc:514
Edition edition() const
The edition (version-release).
Definition: Solvable.cc:337
CapabilitySet providesNamespace(const std::string &namespace_r) const
Return the namespaced provides &#39;namespace([value])[ op edition]&#39; of this Solvable.
Definition: Solvable.cc:533
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:90
ByteCount installSize() const
Installed (unpacked) size.
Definition: Solvable.cc:703
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
int compareByNVR(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:483
#define nullptr
Definition: Easy.h:55
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
Arch arch() const
The architecture.
Definition: Solvable.cc:343
void getSupportedLocales(LocaleSet &locales_r) const
Definition: Solvable.h:282
Capabilities operator[](Dep which_r) const
Definition: Solvable.h:247
unsigned mediaNr() const
Media number the solvable is located on (0 if no media access required).
Definition: Solvable.cc:690
std::string asString() const
String representation "ident-edition.arch" or "noSolvable".
Definition: Solvable.cc:448
Solvable(IdType id_r)
PoolImpl ctor.
Definition: Solvable.h:69
void initialAssignVal(const Solvable &val_r)
Definition: Solvable.h:540
CpeId cpeId() const
The solvables CpeId if available.
Definition: Solvable.cc:684
bool multiversionInstall() const
Whether different versions of this package can be installed at the same time.
Definition: Solvable.cc:430
void assignVal(const Solvable &val_r)
Definition: Solvable.h:543
Capabilities requires() const
Definition: Solvable.cc:489
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
::s_Solvable CSolvable
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:64
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
&#39;Language[_Country]&#39; codes.
Definition: Locale.h:49
bool supportsLocale(const Locale &locale_r) const
Whether this Solvable supports a specific Locale.
Definition: Solvable.cc:660
detail::CSolvable * get() const
Expert backdoor.
Definition: Solvable.cc:106
friend class boost::iterator_core_access
Definition: Solvable.h:531
bool compareByNVR(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:260
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
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
Solvable()
Default ctor creates noSolvable.
Definition: Solvable.h:64
bool supportsRequestedLocales() const
Whether this Solvable supports at least one requested locale.
Definition: Solvable.cc:674
bool isNeedreboot() const
Whether this solvable triggers the reboot-needed hint if installed/updated.
Definition: Solvable.cc:394
std::string insnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for install (opt.
Definition: Solvable.cc:733
std::string summary(const Locale &lang_r=Locale()) const
Short (singleline) text describing the solvable (opt.
Definition: Solvable.cc:721
Capabilities conflicts() const
Definition: Solvable.cc:494
SolvableIterator(SolvableIdType id_r)
Definition: Solvable.h:526
bool onSystemByUser() const
Whether this is known to be installed on behalf of a user request.
Definition: Solvable.cc:379
bool isPtfMaster() const
Subset of isPtf (provides ptfMasterToken).
Definition: Solvable.cc:417
Helper that splits an identifier into kind and name or vice versa.
Definition: Solvable.h:344
Capabilities prerequires() const
Definition: Solvable.cc:524
Capabilities dep(Dep which_r) const
Return Capabilities selected by Dep constant.
Definition: Solvable.h:230
Solvable result_type
Definition: Solvable.h:563
bool needToAcceptLicense() const
True except for well known exceptions (i.e show license but no need to accept it).
Definition: Solvable.cc:762
int compareByN(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:471
bool operator<(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:453
std::pair< bool, CapabilitySet > matchesSolvable(const SolvAttr &attr, const sat::Solvable &solv) const
Definition: Solvable.cc:565
Solvable operator()(const Solvable &solv_r) const
Definition: Solvable.h:565
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
Capabilities obsoletes() const
Definition: Solvable.cc:499
static const IdString retractedToken
Indicator provides retracted-patch-package()
Definition: Solvable.h:58
std::ostream & dumpAsXmlOn(std::ostream &str, const FileConflicts &obj)
sat::detail::SolvableIdType IdType
Definition: Solvable.h:56
Resolvable kinds.
Definition: ResKind.h:32
To Solvable transform functor.
Definition: Solvable.h:561
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool supportsLocales() const
Whether this Solvable claims to support locales.
Definition: Solvable.cc:654
Date buildtime() const
The items build time.
Definition: Solvable.cc:436
std::string licenseToConfirm(const Locale &lang_r=Locale()) const
License or agreement to accept before installing the solvable (opt.
Definition: Solvable.cc:745
bool isPtf() const
Whether this solvable belongs to a PTF (provides ptfMasterToken or ptfPackageToken).
Definition: Solvable.cc:414
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
Capabilities suggests() const
Definition: Solvable.cc:509
IdString ident() const
The identifier.
Definition: Solvable.cc:269
Date installtime() const
The items install time (false if not installed).
Definition: Solvable.cc:442
bool operator!=(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:449
bool lookupBoolAttribute(const SolvAttr &attr) const
returns the boolean attribute value for attr or false if it does not exists.
Definition: Solvable.cc:170
bool isRetracted() const
Whether this solvable is retracted (provides retractedToken).
Definition: Solvable.cc:404