libzypp  16.22.5
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 
167  bool isBlacklisted() const;
168 
170  bool isRetracted() const;
171 
173  bool isPtf() const;
174 
176  bool isPtfMaster() const;
177 
179  bool isPtfPackage() const;
181 
183  Date buildtime() const;
184 
186  Date installtime() const;
187 
188  public:
196  std::string asString() const;
197 
199  std::string asUserString() const;
200 
204  bool identical( const Solvable & rhs ) const;
205 
207  bool sameNVRA( const Solvable & rhs ) const
208  { return( get() == rhs.get() || ( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ) ); }
209 
210  public:
216  Capabilities provides() const;
217  Capabilities requires() const;
218  Capabilities conflicts() const;
219  Capabilities obsoletes() const;
220  Capabilities recommends() const;
221  Capabilities suggests() const;
222  Capabilities enhances() const;
223  Capabilities supplements() const;
224  Capabilities prerequires() const;
225 
227  Capabilities dep( Dep which_r ) const
228  {
229  switch( which_r.inSwitch() )
230  {
231  case Dep::PROVIDES_e: return provides(); break;
232  case Dep::REQUIRES_e: return requires(); break;
233  case Dep::CONFLICTS_e: return conflicts(); break;
234  case Dep::OBSOLETES_e: return obsoletes(); break;
235  case Dep::RECOMMENDS_e: return recommends(); break;
236  case Dep::SUGGESTS_e: return suggests(); break;
237  case Dep::ENHANCES_e: return enhances(); break;
238  case Dep::SUPPLEMENTS_e: return supplements(); break;
239  case Dep::PREREQUIRES_e: return prerequires(); break;
240  }
241  return Capabilities();
242  }
244  Capabilities operator[]( Dep which_r ) const
245  { return dep( which_r ); }
246 
247 
249  CapabilitySet providesNamespace( const std::string & namespace_r ) const;
250 
258  CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
260 
261  public:
265  bool supportsLocales() const;
267  bool supportsLocale( const Locale & locale_r ) const;
269  bool supportsLocale( const LocaleSet & locales_r ) const;
273  bool supportsRequestedLocales() const;
277  void getSupportedLocales( LocaleSet & locales_r ) const
278  { locales_r = getSupportedLocales(); }
280 
281  public:
283  CpeId cpeId() const;
284 
286  unsigned mediaNr() const;
287 
309  ByteCount installSize() const;
310 
312  ByteCount downloadSize() const;
313 
315  std::string distribution() const;
316 
318  std::string summary( const Locale & lang_r = Locale() ) const;
319 
321  std::string description( const Locale & lang_r = Locale() ) const;
322 
324  std::string insnotify( const Locale & lang_r = Locale() ) const;
326  std::string delnotify( const Locale & lang_r = Locale() ) const;
327 
329  std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
331  bool needToAcceptLicense() const;
332 
333  public:
340  {
341  public:
343  SplitIdent( IdString ident_r );
344  SplitIdent( const char * ident_r );
345  SplitIdent( const std::string & ident_r );
346  SplitIdent( ResKind kind_r, IdString name_r );
347  SplitIdent( ResKind kind_r, const C_Str & name_r );
348 
349  IdString ident() const { return _ident; }
350  ResKind kind() const { return _kind; }
351  IdString name() const { return _name; }
352 
353  private:
357  };
358 
359  public:
369  std::string lookupStrAttribute( const SolvAttr & attr ) const;
380  std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
381 
386  unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
388  unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const;
389 
394  bool lookupBoolAttribute( const SolvAttr & attr ) const;
395 
401 
407 
414 
415  public:
417  Solvable nextInPool() const;
419  Solvable nextInRepo() const;
421  detail::CSolvable * get() const;
423  IdType id() const { return _id; }
424 
425  private:
427  };
429 
431  std::ostream & operator<<( std::ostream & str, const Solvable & obj );
432 
434  std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
435 
437  std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj );
438 
440  inline bool operator==( const Solvable & lhs, const Solvable & rhs )
441  { return lhs.get() == rhs.get(); }
442 
444  inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
445  { return lhs.get() != rhs.get(); }
446 
448  inline bool operator<( const Solvable & lhs, const Solvable & rhs )
449  { return lhs.get() < rhs.get(); }
450 
452  template<class TRes>
453  inline bool isKind( const Solvable & solvable_r )
454  { return solvable_r.isKind( ResTraits<TRes>::kind ); }
455 
457  inline bool identical( const Solvable & lhs, const Solvable & rhs )
458  { return lhs.identical( rhs ); }
459 
461  inline bool sameNVRA( const Solvable & lhs, const Solvable & rhs )
462  { return lhs.sameNVRA( rhs ); }
463 
464 
466  inline int compareByN( const Solvable & lhs, const Solvable & rhs )
467  {
468  int res = 0;
469  if ( lhs != rhs )
470  {
471  if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
472  res = lhs.name().compare( rhs.name() );
473  }
474  return res;
475  }
476 
478  inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
479  {
480  int res = compareByN( lhs, rhs );
481  if ( res == 0 )
482  res = lhs.edition().compare( rhs.edition() );
483  return res;
484  }
485 
487  inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
488  {
489  int res = compareByNVR( lhs, rhs );
490  if ( res == 0 )
491  res = lhs.arch().compare( rhs.arch() );
492  return res;
493  }
494 
496  namespace detail
497  {
499  //
500  // CLASS NAME : SolvableIterator
501  //
503  class SolvableIterator : public boost::iterator_adaptor<
504  SolvableIterator // Derived
505  , CSolvable* // Base
506  , const Solvable // Value
507  , boost::forward_traversal_tag // CategoryOrTraversal
508  , const Solvable // Reference
509  >
510  {
511  public:
513  : SolvableIterator::iterator_adaptor_( 0 )
514  {}
515 
516  explicit SolvableIterator( const Solvable & val_r )
517  : SolvableIterator::iterator_adaptor_( 0 )
518  { assignVal( val_r ); }
519 
521  : SolvableIterator::iterator_adaptor_( 0 )
522  { assignVal( Solvable( id_r ) ); }
523 
524  private:
526 
528  { return _val; }
529 
530  void increment()
531  { assignVal( _val.nextInPool() ); }
532 
533  private:
534  void assignVal( const Solvable & val_r )
535  { _val = val_r; base_reference() = _val.get(); }
536 
538  };
539  } // namespace detail
541  } // namespace sat
543 
544  class PoolItem;
546  namespace sat
547  {
552  struct asSolvable
553  {
555 
556  Solvable operator()( const Solvable & solv_r ) const
557  { return solv_r; }
558 
559  Solvable operator()( const PoolItem & pi_r ) const;
560 
561  Solvable operator()( const ResObject_constPtr & res_r ) const;
562  };
563  } // namespace sat
565 } // namespace zypp
567 
569 
570 #endif // ZYPP_SAT_SOLVABLE_H
static const SolvableIdType noSolvableId(0)
Id to denote Solvable::noSolvable.
Repository repository() const
The Repository this Solvable belongs to.
Definition: Solvable.cc:363
bool needToAcceptLicense() const
True except for well known exceptions (i.e show license but no need to accept it).
Definition: Solvable.cc:735
bool isPtfPackage() const
Subset of isPtf (provides ptfPackageToken).
Definition: Solvable.cc:416
bool isPtf() const
Whether this solvable belongs to a PTF (provides ptfMasterToken or ptfPackageToken).
Definition: Solvable.cc:407
int IdType
Generic Id type.
Definition: PoolMember.h:130
static const IdString ptfMasterToken
Indicator provides ptf()
Definition: Solvable.h:59
A Solvable object within the sat Pool.
Definition: Solvable.h:53
Arch arch() const
The architecture.
Definition: Solvable.cc:343
Capabilities recommends() const
Definition: Solvable.cc:496
detail::CSolvable * get() const
Expert backdoor.
Definition: Solvable.cc:106
CapabilitySet providesNamespace(const std::string &namespace_r) const
Return the namespaced provides 'namespace([value])[ op edition]' of this Solvable.
Definition: Solvable.cc:525
Container of Capability (currently read only).
Definition: Capabilities.h:35
Date buildtime() const
The items build time.
Definition: Solvable.cc:428
IdString ident() const
The identifier.
Definition: Solvable.cc:269
Describes a path on a certain media amongs as the information required to download it...
SolvableIterator(const Solvable &val_r)
Definition: Solvable.h:516
Enumeration class of dependency types.
Definition: Dep.h:29
bool isKind(const Solvable &solvable_r)
Definition: Solvable.h:453
Architecture.
Definition: Arch.h:36
bool supportsLocale(const Locale &locale_r) const
Whether this Solvable supports a specific Locale.
Definition: Solvable.cc:640
Store and operate with byte count.
Definition: ByteCount.h:30
sat::SolvAttr attr
Definition: PoolQuery.cc:314
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
bool operator==(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:440
bool supportsLocales() const
Whether this Solvable claims to support locales.
Definition: Solvable.cc:634
Capabilities supplements() const
Definition: Solvable.cc:511
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
ZYPP_DEFINE_ID_HASHABLE(::zypp::sat::Solvable)
std::string asString() const
String representation "ident-edition.arch" or "noSolvable".
Definition: Solvable.cc:440
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition: Solvable.cc:373
bool isKind() const
Definition: Solvable.h:98
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:151
bool isKind(TIterator begin, TIterator end) const
Definition: Solvable.h:102
Capabilities suggests() const
Definition: Solvable.cc:501
ByteCount downloadSize() const
Download size.
Definition: Solvable.cc:682
Solvable operator()(const Solvable &solv_r) const
Definition: Solvable.h:556
What is known about a repository.
Definition: RepoInfo.h:71
std::string insnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for install (opt.
Definition: Solvable.cc:706
Access to the sat-pools string space.
Definition: IdString.h:41
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition: CpeId.h:31
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
::_Solvable CSolvable
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:89
ResTraits.
Definition: ResTraits.h:79
CapabilitySet valuesOfNamespace(const std::string &namespace_r) const
Return 'value[ op edition]' for namespaced provides 'namespace(value)[ op edition]'.
Definition: Solvable.cc:539
bool identIsAutoInstalled() const
Whether an installed solvable with the same ident is flagged as AutoInstalled.
Definition: Solvable.h:138
bool compareByN(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:247
std::string asUserString() const
String representation "ident-edition.arch(repo)" or "noSolvable".
Definition: Solvable.cc:449
std::string licenseToConfirm(const Locale &lang_r=Locale()) const
License or agreement to accept before installing the solvable (opt.
Definition: Solvable.cc:718
Capabilities provides() const
Definition: Solvable.cc:476
static const Solvable noSolvable
Represents no Solvable.
Definition: Solvable.h:75
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
int compareByNVRA(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:487
bool identical(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:457
int compare(const Arch &rhs) const
Arch comparison.
Definition: Arch.cc:542
bool sameNVRA(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:461
static int compare(const Derived &lhs, const Derived &rhs)
Definition: IdStringType.h:127
std::string name() const
The name (without any ResKind prefix).
Definition: Solvable.cc:329
static const IdString ptfPackageToken
Indicator provides ptf-package()
Definition: Solvable.h:60
Store and operate on date (time_t).
Definition: Date.h:32
Solvable attribute keys.
Definition: SolvAttr.h:40
RepoInfo repoInfo() const
The repositories RepoInfo.
Definition: Solvable.cc:369
Backlink to the associated PoolImpl.
Definition: PoolMember.h:114
OnMediaLocation lookupLocation() const
returns OnMediaLocation data: This is everything we need to download e.g.
Definition: Solvable.cc:224
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
bool sameNVRA(const Solvable &rhs) const
Test for same name-version-release.arch.
Definition: Solvable.h:207
unsigned mediaNr() const
Media number the solvable is located on (0 if no media access required).
Definition: Solvable.cc:670
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:90
std::string description(const Locale &lang_r=Locale()) const
Long (multiline) text describing the solvable (opt.
Definition: Solvable.cc:700
IdString ident() const
Definition: Solvable.h:349
bool supportsRequestedLocales() const
Whether this Solvable supports at least one requested locale.
Definition: Solvable.cc:654
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)
Definition: Solvable.h:478
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:410
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
LocaleSet getSupportedLocales() const
Return the supported locales.
Definition: Solvable.cc:657
Date installtime() const
The items install time (false if not installed).
Definition: Solvable.cc:434
bool identical(const Solvable &rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:459
bool isBlacklisted() const
Whether this solvable is blacklisted (retracted,ptf,...).
Definition: Solvable.cc:394
Solvable(IdType id_r)
PoolImpl ctor.
Definition: Solvable.h:69
Capabilities dep(Dep which_r) const
Return Capabilities selected by Dep constant.
Definition: Solvable.h:227
void assignVal(const Solvable &val_r)
Definition: Solvable.h:534
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
Solvable nextInRepo() const
Return next Solvable in Repo (or noSolvable).
Definition: Solvable.cc:116
Capabilities enhances() const
Definition: Solvable.cc:506
'Language[_Country]' codes.
Definition: Locale.h:49
friend class boost::iterator_core_access
Definition: Solvable.h:525
bool compareByNVR(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:261
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
IdString vendor() const
The vendor.
Definition: Solvable.cc:357
ResKind kind() const
The Solvables ResKind.
Definition: Solvable.cc:275
Solvable nextInPool() const
Return next Solvable in Pool (or noSolvable).
Definition: Solvable.cc:113
Solvable()
Default ctor creates noSolvable.
Definition: Solvable.h:64
void getSupportedLocales(LocaleSet &locales_r) const
Definition: Solvable.h:277
Capabilities conflicts() const
Definition: Solvable.cc:486
bool multiversionInstall() const
Whether different versions of this package can be installed at the same time.
Definition: Solvable.cc:422
bool isRetracted() const
Whether this solvable is retracted (provides retractedToken).
Definition: Solvable.cc:397
SolvableIterator(SolvableIdType id_r)
Definition: Solvable.h:520
Capabilities prerequires() const
Definition: Solvable.cc:516
std::string summary(const Locale &lang_r=Locale()) const
Short (singleline) text describing the solvable (opt.
Definition: Solvable.cc:694
std::string delnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for uninstall (opt.
Definition: Solvable.cc:712
Helper that splits an identifier into kind and name or vice versa.
Definition: Solvable.h:339
Solvable result_type
Definition: Solvable.h:554
ByteCount installSize() const
Installed (unpacked) size.
Definition: Solvable.cc:676
int compareByN(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:466
Capabilities operator[](Dep which_r) const
Definition: Solvable.h:244
Capabilities requires() const
Definition: Solvable.cc:481
bool operator<(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:448
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Dep.h:89
CpeId cpeId() const
The solvables CpeId if available.
Definition: Solvable.cc:664
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
IdType id() const
Expert backdoor.
Definition: Solvable.h:423
static const IdString retractedToken
Indicator provides retracted-patch-package()
Definition: Solvable.h:58
std::ostream & dumpAsXmlOn(std::ostream &str, const FileConflicts &obj)
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:302
sat::detail::SolvableIdType IdType
Definition: Solvable.h:56
Resolvable kinds.
Definition: ResKind.h:32
To Solvable transform functor.
Definition: Solvable.h:552
IdString name() const
Definition: Solvable.h:351
std::string distribution() const
The distribution string.
Definition: Solvable.cc:688
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
Edition edition() const
The edition (version-release).
Definition: Solvable.cc:337
bool onSystemByAuto() const
Whether this is known to be automatically installed (as dependency of a user request package)...
Definition: Solvable.cc:384
Capabilities obsoletes() const
Definition: Solvable.cc:491
bool operator!=(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:444