libzypp  16.2.1
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 
128  bool onSystemByUser() const;
129 
133  bool multiversionInstall() const;
134 
136  Date buildtime() const;
137 
139  Date installtime() const;
140 
141  public:
149  std::string asString() const;
150 
152  std::string asUserString() const;
153 
157  bool identical( const Solvable & rhs ) const;
158 
160  bool sameNVRA( const Solvable & rhs ) const
161  { return( get() == rhs.get() || ( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ) ); }
162 
163  public:
169  Capabilities provides() const;
170  Capabilities requires() const;
171  Capabilities conflicts() const;
172  Capabilities obsoletes() const;
173  Capabilities recommends() const;
174  Capabilities suggests() const;
175  Capabilities enhances() const;
176  Capabilities supplements() const;
177  Capabilities prerequires() const;
178 
180  Capabilities dep( Dep which_r ) const
181  {
182  switch( which_r.inSwitch() )
183  {
184  case Dep::PROVIDES_e: return provides(); break;
185  case Dep::REQUIRES_e: return requires(); break;
186  case Dep::CONFLICTS_e: return conflicts(); break;
187  case Dep::OBSOLETES_e: return obsoletes(); break;
188  case Dep::RECOMMENDS_e: return recommends(); break;
189  case Dep::SUGGESTS_e: return suggests(); break;
190  case Dep::ENHANCES_e: return enhances(); break;
191  case Dep::SUPPLEMENTS_e: return supplements(); break;
192  case Dep::PREREQUIRES_e: return prerequires(); break;
193  }
194  return Capabilities();
195  }
197  Capabilities operator[]( Dep which_r ) const
198  { return dep( which_r ); }
199 
200 
202  CapabilitySet providesNamespace( const std::string & namespace_r ) const;
203 
211  CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
213 
214  public:
218  bool supportsLocales() const;
220  bool supportsLocale( const Locale & locale_r ) const;
222  bool supportsLocale( const LocaleSet & locales_r ) const;
226  bool supportsRequestedLocales() const;
230  void getSupportedLocales( LocaleSet & locales_r ) const
231  { locales_r = getSupportedLocales(); }
233 
234  public:
236  CpeId cpeId() const;
237 
239  unsigned mediaNr() const;
240 
262  ByteCount installSize() const;
263 
265  ByteCount downloadSize() const;
266 
268  std::string distribution() const;
269 
271  std::string summary( const Locale & lang_r = Locale() ) const;
272 
274  std::string description( const Locale & lang_r = Locale() ) const;
275 
277  std::string insnotify( const Locale & lang_r = Locale() ) const;
279  std::string delnotify( const Locale & lang_r = Locale() ) const;
280 
282  std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
284  bool needToAcceptLicense() const;
285 
286  public:
293  {
294  public:
296  SplitIdent( IdString ident_r );
297  SplitIdent( const char * ident_r );
298  SplitIdent( const std::string & ident_r );
299  SplitIdent( ResKind kind_r, IdString name_r );
300  SplitIdent( ResKind kind_r, const C_Str & name_r );
301 
302  IdString ident() const { return _ident; }
303  ResKind kind() const { return _kind; }
304  IdString name() const { return _name; }
305 
306  private:
310  };
311 
312  public:
322  std::string lookupStrAttribute( const SolvAttr & attr ) const;
333  std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
334 
339  unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
341  unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const;
342 
347  bool lookupBoolAttribute( const SolvAttr & attr ) const;
348 
354 
360 
367 
368  public:
370  Solvable nextInPool() const;
372  Solvable nextInRepo() const;
374  detail::CSolvable * get() const;
376  IdType id() const { return _id; }
377 
378  private:
379  IdType _id;
380  };
382 
384  std::ostream & operator<<( std::ostream & str, const Solvable & obj );
385 
387  std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
388 
390  std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj );
391 
393  inline bool operator==( const Solvable & lhs, const Solvable & rhs )
394  { return lhs.get() == rhs.get(); }
395 
397  inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
398  { return lhs.get() != rhs.get(); }
399 
401  inline bool operator<( const Solvable & lhs, const Solvable & rhs )
402  { return lhs.get() < rhs.get(); }
403 
405  template<class TRes>
406  inline bool isKind( const Solvable & solvable_r )
407  { return solvable_r.isKind( ResTraits<TRes>::kind ); }
408 
410  inline bool identical( const Solvable & lhs, const Solvable & rhs )
411  { return lhs.identical( rhs ); }
412 
414  inline bool sameNVRA( const Solvable & lhs, const Solvable & rhs )
415  { return lhs.sameNVRA( rhs ); }
416 
417 
419  inline int compareByN( const Solvable & lhs, const Solvable & rhs )
420  {
421  int res = 0;
422  if ( lhs != rhs )
423  {
424  if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
425  res = lhs.name().compare( rhs.name() );
426  }
427  return res;
428  }
429 
431  inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
432  {
433  int res = compareByN( lhs, rhs );
434  if ( res == 0 )
435  res = lhs.edition().compare( rhs.edition() );
436  return res;
437  }
438 
440  inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
441  {
442  int res = compareByNVR( lhs, rhs );
443  if ( res == 0 )
444  res = lhs.arch().compare( rhs.arch() );
445  return res;
446  }
447 
449  namespace detail
450  {
452  //
453  // CLASS NAME : SolvableIterator
454  //
456  class SolvableIterator : public boost::iterator_adaptor<
457  SolvableIterator // Derived
458  , CSolvable* // Base
459  , const Solvable // Value
460  , boost::forward_traversal_tag // CategoryOrTraversal
461  , const Solvable // Reference
462  >
463  {
464  public:
466  : SolvableIterator::iterator_adaptor_( 0 )
467  {}
468 
469  explicit SolvableIterator( const Solvable & val_r )
470  : SolvableIterator::iterator_adaptor_( 0 )
471  { assignVal( val_r ); }
472 
474  : SolvableIterator::iterator_adaptor_( 0 )
475  { assignVal( Solvable( id_r ) ); }
476 
477  private:
478  friend class boost::iterator_core_access;
479 
481  { return _val; }
482 
483  void increment()
484  { assignVal( _val.nextInPool() ); }
485 
486  private:
487  void assignVal( const Solvable & val_r )
488  { _val = val_r; base_reference() = _val.get(); }
489 
491  };
492  } // namespace detail
494  } // namespace sat
496 
497  class PoolItem;
499  namespace sat
500  {
505  struct asSolvable
506  {
508 
509  Solvable operator()( const Solvable & solv_r ) const
510  { return solv_r; }
511 
512  Solvable operator()( const PoolItem & pi_r ) const;
513 
514  Solvable operator()( const ResObject_constPtr & res_r ) const;
515  };
516  } // namespace sat
518 } // namespace zypp
520 
522 
523 #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:357
bool needToAcceptLicense() const
True except for well known exceptions (i.e show license but no need to accept it).
Definition: Solvable.cc:687
int IdType
Generic Id type.
Definition: PoolMember.h:104
A Solvable object within the sat Pool.
Definition: Solvable.h:53
Arch arch() const
The architecture.
Definition: Solvable.cc:337
Capabilities recommends() const
Definition: Solvable.cc:452
detail::CSolvable * get() const
Expert backdoor.
Definition: Solvable.cc:102
CapabilitySet providesNamespace(const std::string &namespace_r) const
Return the namespaced provides &#39;namespace([value])[ op edition]&#39; of this Solvable.
Definition: Solvable.cc:481
Container of Capability (currently read only).
Definition: Capabilities.h:35
Date buildtime() const
The items build time.
Definition: Solvable.cc:384
IdString ident() const
The identifier.
Definition: Solvable.cc:263
Describes a path on a certain media amongs as the information required to download it...
SolvableIterator(const Solvable &val_r)
Definition: Solvable.h:469
Enumeration class of dependency types.
Definition: Dep.h:29
bool isKind(const Solvable &solvable_r)
Definition: Solvable.h:406
Architecture.
Definition: Arch.h:36
bool supportsLocale(const Locale &locale_r) const
Whether this Solvable supports a specific Locale.
Definition: Solvable.cc:596
Store and operate with byte count.
Definition: ByteCount.h:30
sat::SolvAttr attr
Definition: PoolQuery.cc:303
bool operator==(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:393
bool supportsLocales() const
Whether this Solvable claims to support locales.
Definition: Solvable.cc:590
Capabilities supplements() const
Definition: Solvable.cc:467
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
ZYPP_DEFINE_ID_HASHABLE(::zypp::sat::Solvable)
std::string asString() const
String representation "ident-edition.arch" or "noSolvable".
Definition: Solvable.cc:396
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition: Solvable.cc:367
std::ostream & operator<<(std::ostream &str, const Solvable &obj)
Definition: Solvable.cc:694
String related utilities and Regular expression matching.
bool isKind() const
Definition: Solvable.h:94
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
bool isKind(TIterator begin, TIterator end) const
Definition: Solvable.h:98
Capabilities suggests() const
Definition: Solvable.cc:457
ByteCount downloadSize() const
Download size.
Definition: Solvable.cc:638
Solvable operator()(const Solvable &solv_r) const
Definition: Solvable.h:509
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:662
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:64
ResTraits.
Definition: ResTraits.h:79
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:495
std::string asUserString() const
String representation "ident-edition.arch(repo)" or "noSolvable".
Definition: Solvable.cc:405
std::string licenseToConfirm(const Locale &lang_r=Locale()) const
License or agreement to accept before installing the solvable (opt.
Definition: Solvable.cc:674
Capabilities provides() const
Definition: Solvable.cc:432
static const Solvable noSolvable
Represents no Solvable.
Definition: Solvable.h:71
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:170
int compareByNVRA(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:440
bool identical(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:410
int compare(const Arch &rhs) const
Arch comparison.
Definition: Arch.cc:532
bool sameNVRA(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:414
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:323
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:363
Backlink to the associated PoolImpl.
Definition: PoolMember.h:88
OnMediaLocation lookupLocation() const
returns OnMediaLocation data: This is everything we need to download e.g.
Definition: Solvable.cc:218
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:176
bool sameNVRA(const Solvable &rhs) const
Test for same name-version-release.arch.
Definition: Solvable.h:160
unsigned mediaNr() const
Media number the solvable is located on (0 if no media access required).
Definition: Solvable.cc:626
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:656
IdString ident() const
Definition: Solvable.h:302
bool supportsRequestedLocales() const
Whether this Solvable supports at least one requested locale.
Definition: Solvable.cc:610
bool lookupBoolAttribute(const SolvAttr &attr) const
returns the boolean attribute value for attr or false if it does not exists.
Definition: Solvable.cc:164
int compareByNVR(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:431
bool onSystemByUser() const
Whether this is known to be installed on behalf of a user request.
Definition: Solvable.cc:373
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:152
LocaleSet getSupportedLocales() const
Return the supported locales.
Definition: Solvable.cc:613
Date installtime() const
The items install time (false if not installed).
Definition: Solvable.cc:390
bool identical(const Solvable &rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:415
std::ostream & dumpOn(std::ostream &str, const Solvable &obj)
Definition: Solvable.cc:705
Solvable(IdType id_r)
PoolImpl ctor.
Definition: Solvable.h:65
Capabilities dep(Dep which_r) const
Return Capabilities selected by Dep constant.
Definition: Solvable.h:180
void assignVal(const Solvable &val_r)
Definition: Solvable.h:487
Solvable nextInRepo() const
Return next Solvable in Repo (or noSolvable).
Definition: Solvable.cc:112
Capabilities enhances() const
Definition: Solvable.cc:462
&#39;Language[_Country]&#39; codes.
Definition: Locale.h:49
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
IdString vendor() const
The vendor.
Definition: Solvable.cc:351
ResKind kind() const
The Solvables ResKind.
Definition: Solvable.cc:269
Solvable nextInPool() const
Return next Solvable in Pool (or noSolvable).
Definition: Solvable.cc:109
Solvable()
Default ctor creates noSolvable.
Definition: Solvable.h:60
void getSupportedLocales(LocaleSet &locales_r) const
Definition: Solvable.h:230
Capabilities conflicts() const
Definition: Solvable.cc:442
bool multiversionInstall() const
Whether different versions of this package can be installed at the same time.
Definition: Solvable.cc:378
std::ostream & dumpAsXmlOn(std::ostream &str, const Solvable &obj)
Definition: Solvable.cc:725
SolvableIterator(SolvableIdType id_r)
Definition: Solvable.h:473
Capabilities prerequires() const
Definition: Solvable.cc:472
std::string summary(const Locale &lang_r=Locale()) const
Short (singleline) text describing the solvable (opt.
Definition: Solvable.cc:650
std::string delnotify(const Locale &lang_r=Locale()) const
UI hint text when selecting the solvable for uninstall (opt.
Definition: Solvable.cc:668
Helper that splits an identifier into kind and name or vice versa.
Definition: Solvable.h:292
Solvable result_type
Definition: Solvable.h:507
ByteCount installSize() const
Installed (unpacked) size.
Definition: Solvable.cc:632
int compareByN(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:419
Capabilities operator[](Dep which_r) const
Definition: Solvable.h:197
Capabilities requires() const
Definition: Solvable.cc:437
bool operator<(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:401
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:620
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
IdType id() const
Expert backdoor.
Definition: Solvable.h:376
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:296
sat::detail::SolvableIdType IdType
Definition: Solvable.h:56
Resolvable kinds.
Definition: ResKind.h:32
To Solvable transform functor.
Definition: Solvable.h:505
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
IdString name() const
Definition: Solvable.h:304
std::string distribution() const
The distribution string.
Definition: Solvable.cc:644
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
Edition edition() const
The edition (version-release).
Definition: Solvable.cc:331
Capabilities obsoletes() const
Definition: Solvable.cc:447
bool operator!=(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:397