libzypp  17.9.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  public:
61  : _id( detail::noSolvableId )
62  {}
63 
65  explicit Solvable( IdType id_r )
66  : _id( id_r )
67  {}
68 
69  public:
71  static const Solvable noSolvable;
72 
74  explicit operator bool() const
75  { return get(); }
76 
77  public:
82  IdString ident()const;
83 
85  ResKind kind()const;
86 
91  bool isKind( const ResKind & kind_r ) const;
93  template<class TRes>
94  bool isKind() const
95  { return isKind( resKind<TRes>() ); }
97  template<class TIterator>
98  bool isKind( TIterator begin, TIterator end ) const
99  { for_( it, begin, end ) if ( isKind( *it ) ) return true; return false; }
100 
102  std::string name() const;
103 
105  Edition edition() const;
106 
108  Arch arch() const;
109 
111  IdString vendor() const;
112 
114  Repository repository() const;
116  RepoInfo repoInfo() const;
117 
121  bool isSystem() const;
122 
126  bool onSystemByUser() const;
127 
131  bool onSystemByAuto() const;
132 
134  bool identIsAutoInstalled() const
135  { return identIsAutoInstalled( ident() ); }
137  static bool identIsAutoInstalled( const IdString & ident_r );
138 
141  { return identTriggersRebootNeededHint( ident() ); }
142  static bool identTriggersRebootNeededHint ( const IdString &ident_r );
143 
147  bool multiversionInstall() const;
148 
150  Date buildtime() const;
151 
153  Date installtime() const;
154 
155  public:
163  std::string asString() const;
164 
166  std::string asUserString() const;
167 
171  bool identical( const Solvable & rhs ) const;
172 
174  bool sameNVRA( const Solvable & rhs ) const
175  { return( get() == rhs.get() || ( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ) ); }
176 
177  public:
183  Capabilities provides() const;
184  Capabilities requires() const;
185  Capabilities conflicts() const;
186  Capabilities obsoletes() const;
187  Capabilities recommends() const;
188  Capabilities suggests() const;
189  Capabilities enhances() const;
190  Capabilities supplements() const;
191  Capabilities prerequires() const;
192 
194  Capabilities dep( Dep which_r ) const
195  {
196  switch( which_r.inSwitch() )
197  {
198  case Dep::PROVIDES_e: return provides(); break;
199  case Dep::REQUIRES_e: return requires(); break;
200  case Dep::CONFLICTS_e: return conflicts(); break;
201  case Dep::OBSOLETES_e: return obsoletes(); break;
202  case Dep::RECOMMENDS_e: return recommends(); break;
203  case Dep::SUGGESTS_e: return suggests(); break;
204  case Dep::ENHANCES_e: return enhances(); break;
205  case Dep::SUPPLEMENTS_e: return supplements(); break;
206  case Dep::PREREQUIRES_e: return prerequires(); break;
207  }
208  return Capabilities();
209  }
211  Capabilities operator[]( Dep which_r ) const
212  { return dep( which_r ); }
213 
214 
216  CapabilitySet providesNamespace( const std::string & namespace_r ) const;
217 
225  CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
227 
228  public:
232  bool supportsLocales() const;
234  bool supportsLocale( const Locale & locale_r ) const;
236  bool supportsLocale( const LocaleSet & locales_r ) const;
240  bool supportsRequestedLocales() const;
244  void getSupportedLocales( LocaleSet & locales_r ) const
245  { locales_r = getSupportedLocales(); }
247 
248  public:
250  CpeId cpeId() const;
251 
253  unsigned mediaNr() const;
254 
276  ByteCount installSize() const;
277 
279  ByteCount downloadSize() const;
280 
282  std::string distribution() const;
283 
285  std::string summary( const Locale & lang_r = Locale() ) const;
286 
288  std::string description( const Locale & lang_r = Locale() ) const;
289 
291  std::string insnotify( const Locale & lang_r = Locale() ) const;
293  std::string delnotify( const Locale & lang_r = Locale() ) const;
294 
296  std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
298  bool needToAcceptLicense() const;
299 
300  public:
307  {
308  public:
310  SplitIdent( IdString ident_r );
311  SplitIdent( const char * ident_r );
312  SplitIdent( const std::string & ident_r );
313  SplitIdent( ResKind kind_r, IdString name_r );
314  SplitIdent( ResKind kind_r, const C_Str & name_r );
315 
316  IdString ident() const { return _ident; }
317  ResKind kind() const { return _kind; }
318  IdString name() const { return _name; }
319 
320  private:
324  };
325 
326  public:
336  std::string lookupStrAttribute( const SolvAttr & attr ) const;
347  std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
348 
353  unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
355  unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const;
356 
361  bool lookupBoolAttribute( const SolvAttr & attr ) const;
362 
368 
374 
381 
382  public:
384  Solvable nextInPool() const;
386  Solvable nextInRepo() const;
388  detail::CSolvable * get() const;
390  IdType id() const { return _id; }
391 
392  private:
394  };
396 
398  std::ostream & operator<<( std::ostream & str, const Solvable & obj );
399 
401  std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
402 
404  std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj );
405 
407  inline bool operator==( const Solvable & lhs, const Solvable & rhs )
408  { return lhs.get() == rhs.get(); }
409 
411  inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
412  { return lhs.get() != rhs.get(); }
413 
415  inline bool operator<( const Solvable & lhs, const Solvable & rhs )
416  { return lhs.get() < rhs.get(); }
417 
419  template<class TRes>
420  inline bool isKind( const Solvable & solvable_r )
421  { return solvable_r.isKind( ResTraits<TRes>::kind ); }
422 
424  inline bool identical( const Solvable & lhs, const Solvable & rhs )
425  { return lhs.identical( rhs ); }
426 
428  inline bool sameNVRA( const Solvable & lhs, const Solvable & rhs )
429  { return lhs.sameNVRA( rhs ); }
430 
431 
433  inline int compareByN( const Solvable & lhs, const Solvable & rhs )
434  {
435  int res = 0;
436  if ( lhs != rhs )
437  {
438  if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
439  res = lhs.name().compare( rhs.name() );
440  }
441  return res;
442  }
443 
445  inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
446  {
447  int res = compareByN( lhs, rhs );
448  if ( res == 0 )
449  res = lhs.edition().compare( rhs.edition() );
450  return res;
451  }
452 
454  inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
455  {
456  int res = compareByNVR( lhs, rhs );
457  if ( res == 0 )
458  res = lhs.arch().compare( rhs.arch() );
459  return res;
460  }
461 
463  namespace detail
464  {
466  //
467  // CLASS NAME : SolvableIterator
468  //
470  class SolvableIterator : public boost::iterator_adaptor<
471  SolvableIterator // Derived
472  , CSolvable* // Base
473  , const Solvable // Value
474  , boost::forward_traversal_tag // CategoryOrTraversal
475  , const Solvable // Reference
476  >
477  {
478  public:
480  : SolvableIterator::iterator_adaptor_( 0 )
481  {}
482 
483  explicit SolvableIterator( const Solvable & val_r )
484  : SolvableIterator::iterator_adaptor_( 0 )
485  { assignVal( val_r ); }
486 
488  : SolvableIterator::iterator_adaptor_( 0 )
489  { assignVal( Solvable( id_r ) ); }
490 
491  private:
493 
495  { return _val; }
496 
497  void increment()
498  { assignVal( _val.nextInPool() ); }
499 
500  private:
501  void assignVal( const Solvable & val_r )
502  { _val = val_r; base_reference() = _val.get(); }
503 
505  };
506  } // namespace detail
508  } // namespace sat
510 
511  class PoolItem;
513  namespace sat
514  {
519  struct asSolvable
520  {
522 
523  Solvable operator()( const Solvable & solv_r ) const
524  { return solv_r; }
525 
526  Solvable operator()( const PoolItem & pi_r ) const;
527 
528  Solvable operator()( const ResObject_constPtr & res_r ) const;
529  };
530  } // namespace sat
532 } // namespace zypp
534 
536 
537 #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:174
std::string description(const Locale &lang_r=Locale()) const
Long (multiline) text describing the solvable (opt.
Definition: Solvable.cc:680
std::string name() const
The name (without any ResKind prefix).
Definition: Solvable.cc:325
int IdType
Generic Id type.
Definition: PoolMember.h:130
A Solvable object within the sat Pool.
Definition: Solvable.h:53
IdString vendor() const
The vendor.
Definition: Solvable.cc:353
IdType id() const
Expert backdoor.
Definition: Solvable.h:390
Capabilities provides() const
Definition: Solvable.cc:449
RepoInfo repoInfo() const
The repositories RepoInfo.
Definition: Solvable.cc:365
ResKind kind() const
The Solvables ResKind.
Definition: Solvable.cc:271
Container of Capability (currently read only).
Definition: Capabilities.h:35
Describes a path on a certain media amongs as the information required to download it,...
SolvableIterator(const Solvable &val_r)
Definition: Solvable.h:483
Enumeration class of dependency types.
Definition: Dep.h:29
bool isKind(TIterator begin, TIterator end) const
Definition: Solvable.h:98
OnMediaLocation lookupLocation() const
returns OnMediaLocation data: This is everything we need to download e.g.
Definition: Solvable.cc:220
bool isKind(const Solvable &solvable_r)
Definition: Solvable.h:420
Architecture.
Definition: Arch.h:36
LocaleSet getSupportedLocales() const
Return the supported locales.
Definition: Solvable.cc:630
Capabilities recommends() const
Definition: Solvable.cc:469
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:172
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:407
ZYPP_DEFINE_ID_HASHABLE(::zypp::sat::Solvable)
String related utilities and Regular expression matching.
Capabilities supplements() const
Definition: Solvable.cc:484
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:151
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:298
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:692
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
ByteCount downloadSize() const
Download size.
Definition: Solvable.cc:662
int compare(const Arch &rhs) const
Arch comparison.
Definition: Arch.cc:542
bool identical(const Solvable &rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:432
bool compareByN(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:242
static const Solvable noSolvable
Represents no Solvable.
Definition: Solvable.h:71
int compareByNVRA(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:454
bool identical(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:424
CapabilitySet valuesOfNamespace(const std::string &namespace_r) const
Return 'value[ op edition]' for namespaced provides 'namespace(value)[ op edition]'.
Definition: Solvable.cc:512
bool identTriggersRebootNeededHint() const
Whether installing or upgrading a solvable with the same ident will trigger the reboot needed hint.
Definition: Solvable.h:140
Solvable nextInRepo() const
Return next Solvable in Repo (or noSolvable).
Definition: Solvable.cc:112
std::string asUserString() const
String representation "ident-edition.arch(repo)" or "noSolvable".
Definition: Solvable.cc:422
bool sameNVRA(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:428
static int compare(const Derived &lhs, const Derived &rhs)
Definition: IdStringType.h:127
std::string distribution() const
The distribution string.
Definition: Solvable.cc:668
Repository repository() const
The Repository this Solvable belongs to.
Definition: Solvable.cc:359
bool onSystemByAuto() const
Whether this is known to be automatically installed (as dependency of a user request package).
Definition: Solvable.cc:380
bool isKind() const
Definition: Solvable.h:94
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:134
Solvable attribute keys.
Definition: SolvAttr.h:40
Backlink to the associated PoolImpl.
Definition: PoolMember.h:114
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Dep.h:89
Capabilities enhances() const
Definition: Solvable.cc:479
Edition edition() const
The edition (version-release).
Definition: Solvable.cc:333
CapabilitySet providesNamespace(const std::string &namespace_r) const
Return the namespaced provides 'namespace([value])[ op edition]' of this Solvable.
Definition: Solvable.cc:498
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:656
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:154
int compareByNVR(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:445
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:178
Arch arch() const
The architecture.
Definition: Solvable.cc:339
void getSupportedLocales(LocaleSet &locales_r) const
Definition: Solvable.h:244
Capabilities operator[](Dep which_r) const
Definition: Solvable.h:211
unsigned mediaNr() const
Media number the solvable is located on (0 if no media access required).
Definition: Solvable.cc:643
std::string asString() const
String representation "ident-edition.arch" or "noSolvable".
Definition: Solvable.cc:413
Solvable(IdType id_r)
PoolImpl ctor.
Definition: Solvable.h:65
CpeId cpeId() const
The solvables CpeId if available.
Definition: Solvable.cc:637
bool multiversionInstall() const
Whether different versions of this package can be installed at the same time.
Definition: Solvable.cc:395
void assignVal(const Solvable &val_r)
Definition: Solvable.h:501
Capabilities requires() const
Definition: Solvable.cc:454
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition: Solvable.cc:369
Solvable nextInPool() const
Return next Solvable in Pool (or noSolvable).
Definition: Solvable.cc:109
'Language[_Country]' codes.
Definition: Locale.h:49
bool supportsLocale(const Locale &locale_r) const
Whether this Solvable supports a specific Locale.
Definition: Solvable.cc:613
detail::CSolvable * get() const
Expert backdoor.
Definition: Solvable.cc:102
friend class boost::iterator_core_access
Definition: Solvable.h:492
bool compareByNVR(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:256
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:126
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
Solvable()
Default ctor creates noSolvable.
Definition: Solvable.h:60
bool supportsRequestedLocales() const
Whether this Solvable supports at least one requested locale.
Definition: Solvable.cc:627
std::string insnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for install (opt.
Definition: Solvable.cc:686
std::string summary(const Locale &lang_r=Locale()) const
Short (singleline) text describing the solvable (opt.
Definition: Solvable.cc:674
Capabilities conflicts() const
Definition: Solvable.cc:459
SolvableIterator(SolvableIdType id_r)
Definition: Solvable.h:487
bool onSystemByUser() const
Whether this is known to be installed on behalf of a user request.
Definition: Solvable.cc:375
Helper that splits an identifier into kind and name or vice versa.
Definition: Solvable.h:306
Capabilities prerequires() const
Definition: Solvable.cc:489
Capabilities dep(Dep which_r) const
Return Capabilities selected by Dep constant.
Definition: Solvable.h:194
Solvable result_type
Definition: Solvable.h:521
bool needToAcceptLicense() const
True except for well known exceptions (i.e show license but no need to accept it).
Definition: Solvable.cc:715
int compareByN(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:433
bool operator<(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:415
Solvable operator()(const Solvable &solv_r) const
Definition: Solvable.h:523
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
Capabilities obsoletes() const
Definition: Solvable.cc:464
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:519
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:607
Date buildtime() const
The items build time.
Definition: Solvable.cc:401
std::string licenseToConfirm(const Locale &lang_r=Locale()) const
License or agreement to accept before installing the solvable (opt.
Definition: Solvable.cc:698
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
Capabilities suggests() const
Definition: Solvable.cc:474
IdString ident() const
The identifier.
Definition: Solvable.cc:265
Date installtime() const
The items install time (false if not installed).
Definition: Solvable.cc:407
bool operator!=(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:411
bool lookupBoolAttribute(const SolvAttr &attr) const
returns the boolean attribute value for attr or false if it does not exists.
Definition: Solvable.cc:166