libzypp  17.28.4
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  {
504  //
505  // CLASS NAME : SolvableIterator
506  //
508  class SolvableIterator : public boost::iterator_adaptor<
509  SolvableIterator // Derived
510  , CSolvable* // Base
511  , const Solvable // Value
512  , boost::forward_traversal_tag // CategoryOrTraversal
513  , const Solvable // Reference
514  >
515  {
516  public:
518  : SolvableIterator::iterator_adaptor_( 0 )
519  {}
520 
521  explicit SolvableIterator( const Solvable & val_r )
522  : SolvableIterator::iterator_adaptor_( 0 )
523  { assignVal( val_r ); }
524 
526  : SolvableIterator::iterator_adaptor_( 0 )
527  { assignVal( Solvable( id_r ) ); }
528 
529  private:
531 
533  { return _val; }
534 
535  void increment()
536  { assignVal( _val.nextInPool() ); }
537 
538  private:
539  void assignVal( const Solvable & val_r )
540  { _val = val_r; base_reference() = _val.get(); }
541 
543  };
544  } // namespace detail
546  } // namespace sat
548 
549  class PoolItem;
551  namespace sat
552  {
557  struct asSolvable
558  {
560 
561  Solvable operator()( const Solvable & solv_r ) const
562  { return solv_r; }
563 
564  Solvable operator()( const PoolItem & pi_r ) const;
565 
566  Solvable operator()( const ResObject_constPtr & res_r ) const;
567  };
568  } // namespace sat
570 } // namespace zypp
572 
574 
575 #endif // ZYPP_SAT_SOLVABLE_H
sat::SolvAttr attr
Definition: PoolQuery.cc:311
ZYPP_DEFINE_ID_HASHABLE(::zypp::sat::Solvable)
Architecture.
Definition: Arch.h:37
int compare(const Arch &rhs) const
Arch comparison.
Definition: Arch.cc:546
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:703
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:762
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:715
unsigned mediaNr() const
Media number the solvable is located on (0 if no media access required).
Definition: Solvable.cc:690
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:684
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:677
bool supportsRequestedLocales() const
Whether this Solvable supports at least one requested locale.
Definition: Solvable.cc:674
Solvable(IdType id_r)
PoolImpl ctor.
Definition: Solvable.h:69
bool operator==(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:445
Capabilities requires() const
Definition: Solvable.cc:489
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:745
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:654
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:721
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:660
Capabilities supplements() const
Definition: Solvable.cc:519
ByteCount downloadSize() const
Download size.
Definition: Solvable.cc:709
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:739
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:727
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:733
bool identical(const Solvable &rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:467
SolvableIterator(SolvableIdType id_r)
Definition: Solvable.h:525
void assignVal(const Solvable &val_r)
Definition: Solvable.h:539
SolvableIterator(const Solvable &val_r)
Definition: Solvable.h:521
friend class boost::iterator_core_access
Definition: Solvable.h:530
String related utilities and Regular expression matching.
static const SolvableIdType noSolvableId(0)
Id to denote Solvable::noSolvable.
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
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
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 & 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
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
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:558
Solvable operator()(const Solvable &solv_r) const
Definition: Solvable.h:561
Solvable result_type
Definition: Solvable.h:559
Backlink to the associated PoolImpl.
Definition: PoolMember.h:89
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28