libzypp  17.38.7
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  {
54  {
55  public:
57 
58  static const IdString patternToken;
59  static const IdString productToken;
60 
61  static const IdString retractedToken;
62  static const IdString ptfMasterToken;
63  static const IdString ptfPackageToken;
64 
65  public:
68  : _id( detail::noSolvableId )
69  {}
70 
71  Solvable(const Solvable &) = default;
72  Solvable(Solvable &&) noexcept = default;
73  Solvable &operator=(const Solvable &) = default;
74  Solvable &operator=(Solvable &&) noexcept = default;
75 
77  explicit Solvable( IdType id_r )
78  : _id( id_r )
79  {}
80 
81  public:
83  static const Solvable noSolvable;
84 
86  explicit operator bool() const
87  { return get(); }
88 
89  public:
94  IdString ident()const;
95 
97  ResKind kind()const;
98 
103  bool isKind( const ResKind & kind_r ) const;
105  template<class TRes>
106  bool isKind() const
107  { return isKind( resKind<TRes>() ); }
109  template<class TIterator>
110  bool isKind( TIterator begin, TIterator end ) const
111  { for_( it, begin, end ) if ( isKind( *it ) ) return true; return false; }
112 
114  std::string name() const;
115 
117  Edition edition() const;
118 
120  Arch arch() const;
121 
123  IdString vendor() const;
124 
126  Repository repository() const;
128  RepoInfo repoInfo() const;
129 
133  bool isSystem() const;
134 
138  bool onSystemByUser() const;
139 
143  bool onSystemByAuto() const;
144 
146  bool identIsAutoInstalled() const
147  { return identIsAutoInstalled( ident() ); }
149  static bool identIsAutoInstalled( const IdString & ident_r );
150 
154  bool multiversionInstall() const;
155 
157  bool isNeedreboot() const;
158 
161  { return dep_provides().findFirstMatch( Capability(patternToken.id()) ); }
162 
164  bool isPatternPackage() const
165  { return bool(patternProvides()); }
166 
169  { return dep_provides().findFirstMatch( Capability(productToken.id()) ); }
170 
172  bool isProductPackage() const
173  { return bool(productProvides()); }
174 
194  bool isBlacklisted() const;
195 
197  bool isRetracted() const;
198 
200  bool isPtf() const;
201 
203  bool isPtfMaster() const;
204 
206  bool isPtfPackage() const;
208 
210  Date buildtime() const;
211 
213  Date installtime() const;
214 
215  public:
223  std::string asString() const;
224 
226  std::string asUserString() const;
227 
231  bool identical( const Solvable & rhs ) const;
232 
234  bool sameNVRA( const Solvable & rhs ) const
235  { return( get() == rhs.get() || ( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ) ); }
236 
237  public:
243  Capabilities dep_provides() const;
244  Capabilities dep_requires() const;
245  Capabilities dep_conflicts() const;
246  Capabilities dep_obsoletes() const;
247  Capabilities dep_recommends() const;
248  Capabilities dep_suggests() const;
249  Capabilities dep_enhances() const;
250  Capabilities dep_supplements() const;
251  Capabilities dep_prerequires() const;
252 
253 #if __cplusplus < 202002L
254  Capabilities provides() const ZYPP_DEPRECATED; // use dep_ prefixed version instead
255  Capabilities requires() const ZYPP_DEPRECATED; // use dep_ prefixed version instead
256  Capabilities conflicts() const ZYPP_DEPRECATED; // use dep_ prefixed version instead
257  Capabilities obsoletes() const ZYPP_DEPRECATED; // use dep_ prefixed version instead
258  Capabilities recommends() const ZYPP_DEPRECATED; // use dep_ prefixed version instead
259  Capabilities suggests() const ZYPP_DEPRECATED; // use dep_ prefixed version instead
260  Capabilities enhances() const ZYPP_DEPRECATED; // use dep_ prefixed version instead
261  Capabilities supplements() const ZYPP_DEPRECATED; // use dep_ prefixed version instead
262  Capabilities prerequires() const ZYPP_DEPRECATED; // use dep_ prefixed version instead
263 #endif
264 
266  Capabilities dep( Dep which_r ) const
267  {
268  switch( which_r.inSwitch() )
269  {
270  case Dep::PROVIDES_e: return dep_provides(); break;
271  case Dep::REQUIRES_e: return dep_requires(); break;
272  case Dep::CONFLICTS_e: return dep_conflicts(); break;
273  case Dep::OBSOLETES_e: return dep_obsoletes(); break;
274  case Dep::RECOMMENDS_e: return dep_recommends(); break;
275  case Dep::SUGGESTS_e: return dep_suggests(); break;
276  case Dep::ENHANCES_e: return dep_enhances(); break;
277  case Dep::SUPPLEMENTS_e: return dep_supplements(); break;
278  case Dep::PREREQUIRES_e: return dep_prerequires(); break;
279  }
280  return Capabilities();
281  }
283  Capabilities operator[]( Dep which_r ) const
284  { return dep( which_r ); }
285 
286 
288  CapabilitySet providesNamespace( const std::string & namespace_r ) const;
289 
297  CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
299 
300  std::pair<bool, CapabilitySet> matchesSolvable ( const SolvAttr &attr, const sat::Solvable &solv ) const;
301 
302  public:
306  bool supportsLocales() const;
308  bool supportsLocale( const Locale & locale_r ) const;
310  bool supportsLocale( const LocaleSet & locales_r ) const;
314  bool supportsRequestedLocales() const;
316  LocaleSet getSupportedLocales() const;
318  void getSupportedLocales( LocaleSet & locales_r ) const
319  { locales_r = getSupportedLocales(); }
321 
322  public:
324  CpeId cpeId() const;
325 
327  unsigned mediaNr() const;
328 
350  ByteCount installSize() const;
351 
353  ByteCount downloadSize() const;
354 
356  std::string distribution() const;
357 
359  std::string summary( const Locale & lang_r = Locale() ) const;
360 
362  std::string description( const Locale & lang_r = Locale() ) const;
363 
365  std::string insnotify( const Locale & lang_r = Locale() ) const;
367  std::string delnotify( const Locale & lang_r = Locale() ) const;
368 
370  std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
372  bool needToAcceptLicense() const;
373 
374  public:
381  {
382  public:
384  SplitIdent( IdString ident_r );
385  SplitIdent( const char * ident_r );
386  SplitIdent( const std::string & ident_r );
387  SplitIdent( ResKind kind_r, IdString name_r );
388  SplitIdent( ResKind kind_r, const C_Str & name_r );
389 
390  IdString ident() const { return _ident; }
391  ResKind kind() const { return _kind; }
392  IdString name() const { return _name; }
393 
394  private:
398  };
399 
400  public:
410  std::string lookupStrAttribute( const SolvAttr & attr ) const;
421  std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
422 
427  unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
429  unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const;
430 
435  bool lookupBoolAttribute( const SolvAttr & attr ) const;
436 
441  detail::IdType lookupIdAttribute( const SolvAttr & attr ) const;
442 
447  CheckSum lookupCheckSumAttribute( const SolvAttr & attr ) const;
448 
453  OnMediaLocation lookupLocation() const;
455 
456  public:
458  Solvable nextInPool() const;
460  Solvable nextInRepo() const;
462  detail::CSolvable * get() const;
464  IdType id() const { return _id; }
465 
466  private:
468  };
470 
472  std::ostream & operator<<( std::ostream & str, const Solvable & obj ) ZYPP_API;
473 
475  std::ostream & dumpOn( std::ostream & str, const Solvable & obj ) ZYPP_API;
476 
478  std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj ) ZYPP_API;
479 
481  inline bool operator==( const Solvable & lhs, const Solvable & rhs )
482  { return lhs.get() == rhs.get(); }
483 
485  inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
486  { return lhs.get() != rhs.get(); }
487 
489  inline bool operator<( const Solvable & lhs, const Solvable & rhs )
490  { return lhs.get() < rhs.get(); }
491 
493  template<class TRes>
494  inline bool isKind( const Solvable & solvable_r )
495  { return solvable_r.isKind( ResTraits<TRes>::kind ); }
496 
498  inline bool identical( const Solvable & lhs, const Solvable & rhs )
499  { return lhs.identical( rhs ); }
500 
502  inline bool sameNVRA( const Solvable & lhs, const Solvable & rhs )
503  { return lhs.sameNVRA( rhs ); }
504 
505 
507  inline int compareByN( const Solvable & lhs, const Solvable & rhs )
508  {
509  int res = 0;
510  if ( lhs != rhs )
511  {
512  if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
513  res = lhs.name().compare( rhs.name() );
514  }
515  return res;
516  }
517 
519  inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
520  {
521  int res = compareByN( lhs, rhs );
522  if ( res == 0 )
523  res = lhs.edition().compare( rhs.edition() );
524  return res;
525  }
526 
528  inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
529  {
530  int res = compareByNVR( lhs, rhs );
531  if ( res == 0 )
532  res = lhs.arch().compare( rhs.arch() );
533  return res;
534  }
535 
537  namespace detail
538  {
545  class SolvableIterator : public boost::iterator_adaptor<
546  SolvableIterator // Derived
547  , CSolvable* // Base
548  , const Solvable // Value
549  , boost::forward_traversal_tag // CategoryOrTraversal
550  , const Solvable // Reference
551  >
552  {
553  public:
555  : SolvableIterator::iterator_adaptor_( nullptr )
556  {}
557 
558  explicit SolvableIterator( const Solvable & val_r )
559  : SolvableIterator::iterator_adaptor_( nullptr )
560  { initialAssignVal( val_r ); }
561 
563  : SolvableIterator::iterator_adaptor_( nullptr )
564  { initialAssignVal( Solvable(id_r) ); }
565 
566  private:
568 
570  { return _val; }
571 
572  void increment()
573  { assignVal( _val.nextInPool() ); }
574 
575  private:
576  void initialAssignVal( const Solvable & val_r )
577  { assignVal( val_r ? val_r : val_r.nextInPool() ); }
578 
579  void assignVal( const Solvable & val_r )
580  { _val = val_r; base_reference() = _val.get(); }
581 
583  };
584  } // namespace detail
586  } // namespace sat
588 
589  class PoolItem;
591  namespace sat
592  {
598  {
600 
601  Solvable operator()( const Solvable & solv_r ) const
602  { return solv_r; }
603 
604  Solvable operator()( const PoolItem & pi_r ) const;
605 
606  Solvable operator()( const ResObject_constPtr & res_r ) const;
607  };
608  } // namespace sat
610 } // namespace zypp
612 
614 
615 #endif // ZYPP_SAT_SOLVABLE_H
static const SolvableIdType noSolvableId(0)
Id to denote Solvable::noSolvable.
std::ostream & dumpAsXmlOn(std::ostream &str, const FileConflicts &obj)
relates: FileConflicts XML output
bool sameNVRA(const Solvable &rhs) const
Test for same name-version-release.arch.
Definition: Solvable.h:234
std::string name() const
The name (without any ResKind prefix).
Definition: Solvable.cc:333
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
relates: FileConflicts Stream output
bool operator<(const LocaleSupport &lhs, const LocaleSupport &rhs)
relates: LocaleSupport
static const IdString ptfMasterToken
Indicator provides ptf()
Definition: Solvable.h:62
A Solvable object within the sat Pool.
Definition: Solvable.h:53
IdType id() const
Expert backdoor.
Definition: Solvable.h:464
ResKind kind() const
The Solvables ResKind.
Definition: Solvable.cc:279
Container of Capability (currently read only).
Definition: Capabilities.h:34
Describes a resource file located on a medium.
SolvableIterator(const Solvable &val_r)
Definition: Solvable.h:558
Enumeration class of dependency types.
Definition: Dep.h:30
#define ZYPP_DEPRECATED
The ZYPP_DEPRECATED macro can be used to trigger compile-time warnings with gcc >= 3...
Definition: Globals.h:112
bool isKind(TIterator begin, TIterator end) const
Definition: Solvable.h:110
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition: Patch.cc:122
Architecture.
Definition: Arch.h:36
static const IdString patternToken
Indicator provides pattern()
Definition: Solvable.h:58
Store and operate with byte count.
Definition: ByteCount.h:31
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:29
IdType id() const
Expert backdoor.
Definition: IdString.h:144
sat::SolvAttr attr
Definition: PoolQuery.cc:312
ZYPP_DEFINE_ID_HASHABLE(::zypp::sat::Solvable)
String related utilities and Regular expression matching.
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:306
bool operator==(const FileConflicts &lhs, const FileConflicts &rhs)
relates: FileConflicts
Definition: FileConflicts.h:85
int IdType
Generic Id type.
Definition: PoolDefines.h:42
What is known about a repository.
Definition: RepoInfo.h:71
Access to the sat-pools string space.
Definition: IdString.h:51
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition: CpeId.h:32
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
Edition represents [epoch:]version[-release]
Definition: Edition.h:59
ResTraits.
Definition: ResTraits.h:79
Iterate over valid Solvables in the pool.
Definition: Solvable.h:545
int compare(const Arch &rhs) const
Arch comparison.
Definition: Arch.cc:785
bool identical(const Solvable &rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:471
std::string asUserString(VendorSupportOption opt)
converts the support option to a name intended to be printed to the user.
Capability productProvides() const
Return the provided productToken or Capability::Null.
Definition: Solvable.h:168
static const Solvable noSolvable
Represents no Solvable.
Definition: Solvable.h:83
bool isKind(const Solvable &solvable_r)
relates: Solvable Test whether a Solvable is of a certain Kind.
Definition: Solvable.h:494
static const IdString productToken
Indicator provides product()
Definition: Solvable.h:59
int compareByNVRA(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Compare according to kind, name, edition and arch.
Definition: Solvable.h:528
static int compare(const Derived &lhs, const Derived &rhs)
Definition: IdStringType.h:142
static const IdString ptfPackageToken
Indicator provides ptf-package()
Definition: Solvable.h:63
::s_Solvable CSolvable
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolDefines.h:37
bool isKind() const
Definition: Solvable.h:106
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:146
Solvable attribute keys.
Definition: SolvAttr.h:40
Backlink to the associated PoolImpl.
Definition: PoolMember.h:52
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Dep.h:90
Edition edition() const
The edition (version-release).
Definition: Solvable.cc:341
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition: Arch.h:173
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:91
Capability patternProvides() const
Return the provided patternToken or Capability::Null.
Definition: Solvable.h:160
bool sameNVRA(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Test for same name version release and arch.
Definition: Solvable.h:502
bool isProductPackage() const
Whether this solvable provides the productToken.
Definition: Solvable.h:172
int compareByN(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Compare according to kind and name.
Definition: Solvable.h:507
Arch arch() const
The architecture.
Definition: Solvable.cc:347
void getSupportedLocales(LocaleSet &locales_r) const
Definition: Solvable.h:318
Capabilities operator[](Dep which_r) const
Definition: Solvable.h:283
void initialAssignVal(const Solvable &val_r)
Definition: Solvable.h:576
void assignVal(const Solvable &val_r)
Definition: Solvable.h:579
bool isPatternPackage() const
Whether this solvable provides the patternToken.
Definition: Solvable.h:164
Solvable nextInPool() const
Return next Solvable in Pool (or noSolvable).
Definition: Solvable.cc:117
&#39;Language[_Country]&#39; codes.
Definition: Locale.h:50
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:35
detail::CSolvable * get() const
Expert backdoor.
Definition: Solvable.cc:110
int compareByNVR(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Compare according to kind, name and edition.
Definition: Solvable.h:519
friend class boost::iterator_core_access
Definition: Solvable.h:567
bool identical(const Solvable &lhs, const Solvable &rhs)
relates: Solvable Test for same content.
Definition: Solvable.h:498
Solvable()
Default ctor creates noSolvable.
Definition: Solvable.h:67
SolvableIterator(SolvableIdType id_r)
Definition: Solvable.h:562
sat::detail::SolvableIdType IdType
Definition: Solvable.h:56
A sat capability.
Definition: Capability.h:62
Helper that splits an identifier into kind and name or vice versa.
Definition: Solvable.h:380
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
relates: LocaleSupport More verbose stream output including dependencies
Capabilities dep(Dep which_r) const
Return Capabilities selected by Dep constant.
Definition: Solvable.h:266
bool operator!=(const FileConflicts &lhs, const FileConflicts &rhs)
relates: FileConflicts
Definition: FileConflicts.h:89
unsigned int SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolDefines.h:63
Solvable operator()(const Solvable &solv_r) const
Definition: Solvable.h:601
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
static const IdString retractedToken
Indicator provides retracted-patch-package()
Definition: Solvable.h:61
Resolvable kinds.
Definition: ResKind.h:32
To Solvable transform functor.
Definition: Solvable.h:597
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
IdString ident() const
The identifier.
Definition: Solvable.cc:273