libzypp  14.48.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 
32  class CheckSum;
33  class OnMediaLocation;
34 
36  namespace sat
37  {
38 
40  //
41  // CLASS NAME : Solvable
42  //
55  class Solvable : protected detail::PoolMember
56  {
57  public:
59 
60  public:
63  : _id( detail::noSolvableId ) {}
64 
66  explicit Solvable( IdType id_r )
67  : _id( id_r ) {}
68 
69  public:
71  static const Solvable noSolvable;
72 
74  explicit operator bool() const
75  { return get(); }
76 
80  bool isSystem() const;
81 
87  bool onSystemByUser() const;
88 
90  Repository repository() const;
91 
92  public:
93 
103  std::string lookupStrAttribute( const SolvAttr & attr ) const;
114  std::string lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const;
115 
120  unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
121 
126  bool lookupBoolAttribute( const SolvAttr & attr ) const;
127 
133 
139 
145 
147  public:
152  IdString ident() const;
153 
154  ResKind kind() const;
159  bool isKind( const ResKind & kind_r ) const;
161  template<class _Res>
162  bool isKind() const
163  { return isKind( resKind<_Res>() ); }
165  template<class _Iterator>
166  bool isKind( _Iterator begin, _Iterator end )
167  { for_( it, begin, end ) if ( isKind( *it ) ) return true; return false; }
168 
169  std::string name() const;
170  Edition edition() const;
171  Arch arch() const;
172 
173  IdString vendor() const;
174 
178  bool multiversionInstall() const;
179 
187  std::string asString() const;
188 
190  std::string asUserString() const;
191 
195  bool identical( Solvable rhs ) const;
196 
198  bool sameNVRA( Solvable rhs ) const
199  { return( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ); }
200 
201  public:
202 
208  Capabilities operator[]( Dep which_r ) const;
209 
210  Capabilities provides() const;
211  Capabilities requires() const;
212  Capabilities conflicts() const;
213  Capabilities obsoletes() const;
214  Capabilities recommends() const;
215  Capabilities suggests() const;
216  Capabilities enhances() const;
217  Capabilities supplements() const;
218  Capabilities prerequires() const;
219 
221  CapabilitySet providesNamespace( const std::string & namespace_r ) const;
222 
230  CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
232 
233  public:
237  bool supportsLocales() const;
239  bool supportsLocale( const Locale & locale_r ) const;
241  bool supportsLocale( const LocaleSet & locales_r ) const;
245  bool supportsRequestedLocales() const;
247  void getSupportedLocales( LocaleSet & locales_r ) const;
250  { LocaleSet ret; getSupportedLocales( ret ); return ret; }
252 
253  public:
255  Solvable nextInPool() const;
257  Solvable nextInRepo() const;
258 
265  {
266  public:
268  SplitIdent( IdString ident_r );
269  SplitIdent( const char * ident_r );
270  SplitIdent( const std::string & ident_r );
271  SplitIdent( ResKind kind_r, IdString name_r );
272  SplitIdent( ResKind kind_r, const C_Str & name_r );
273 
274  IdString ident() const { return _ident; }
275  ResKind kind() const { return _kind; }
276  IdString name() const { return _name; }
277 
278  private:
282  };
283 
284  public:
286  detail::CSolvable * get() const;
288  IdType id() const { return _id; }
289 
290  private:
292  };
294 
296  std::ostream & operator<<( std::ostream & str, const Solvable & obj );
297 
299  std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
300 
302  std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj );
303 
305  inline bool operator==( const Solvable & lhs, const Solvable & rhs )
306  { return lhs.get() == rhs.get(); }
307 
309  inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
310  { return lhs.get() != rhs.get(); }
311 
313  inline bool operator<( const Solvable & lhs, const Solvable & rhs )
314  { return lhs.get() < rhs.get(); }
315 
317  inline bool identical( Solvable lhs, Solvable rhs )
318  { return lhs.identical( rhs ); }
319 
321  inline bool sameNVRA( Solvable lhs, Solvable rhs )
322  { return lhs.sameNVRA( rhs ); }
323 
324 
326  inline int compareByN( const Solvable & lhs, const Solvable & rhs )
327  {
328  int res = 0;
329  if ( lhs != rhs )
330  {
331  if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
332  res = lhs.name().compare( rhs.name() );
333  }
334  return res;
335  }
336 
338  inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
339  {
340  int res = compareByN( lhs, rhs );
341  if ( res == 0 )
342  res = lhs.edition().compare( rhs.edition() );
343  return res;
344  }
345 
347  inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
348  {
349  int res = compareByNVR( lhs, rhs );
350  if ( res == 0 )
351  res = lhs.arch().compare( rhs.arch() );
352  return res;
353  }
354 
356  namespace detail
357  {
358  //
360  // CLASS NAME : SolvableIterator
361  //
363  class SolvableIterator : public boost::iterator_adaptor<
364  SolvableIterator // Derived
365  , detail::CSolvable* // Base
366  , const Solvable // Value
367  , boost::forward_traversal_tag // CategoryOrTraversal
368  , const Solvable // Reference
369  >
370  {
371  public:
373  : SolvableIterator::iterator_adaptor_( 0 )
374  {}
375 
376  explicit SolvableIterator( const Solvable & val_r )
377  : SolvableIterator::iterator_adaptor_( 0 )
378  { assignVal( val_r ); }
379 
381  : SolvableIterator::iterator_adaptor_( 0 )
382  { assignVal( Solvable( id_r ) ); }
383 
384  private:
386 
388  { return _val; }
389 
390  void increment()
391  { assignVal( _val.nextInPool() ); }
392 
393  private:
394  void assignVal( const Solvable & val_r )
395  { _val = val_r; base_reference() = _val.get(); }
396 
398  };
401  } // namespace detail
403 
405  } // namespace sat
407 
409  template<class _Res>
410  inline bool isKind( const sat::Solvable & solvable_r )
411  { return solvable_r.isKind( ResTraits<_Res>::kind ); }
412 
413  class PoolItem;
415  namespace sat
416  {
417 
421  struct asSolvable
422  {
424 
425  Solvable operator()( Solvable solv_r ) const
426  { return solv_r; }
427 
428  Solvable operator()( const PoolItem & pi_r ) const;
429 
430  Solvable operator()( const ResObject_constPtr & res_r ) const;
431  };
433  } // namespace sat
435 
437 } // namespace zypp
439 
441 
442 #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:121
int IdType
Generic Id type.
Definition: PoolMember.h:130
A Solvable object within the sat Pool.
Definition: Solvable.h:55
Arch arch() const
Definition: Solvable.cc:342
Capabilities recommends() const
Definition: Solvable.cc:408
detail::CSolvable * get() const
Expert backdoor.
Definition: Solvable.cc:97
CapabilitySet providesNamespace(const std::string &namespace_r) const
Return the namespaced provides 'namespace([value])[ op edition]' of this Solvable.
Definition: Solvable.cc:437
Container of Capability (currently read only).
Definition: Capabilities.h:35
IdString ident() const
The identifier.
Definition: Solvable.cc:138
Describes a path on a certain media amongs as the information required to download it...
SolvableIterator(const Solvable &val_r)
Definition: Solvable.h:376
Enumeration class of dependency types.
Definition: Dep.h:29
Architecture.
Definition: Arch.h:36
bool supportsLocale(const Locale &locale_r) const
Whether this Solvable supports a specific Locale.
Definition: Solvable.cc:579
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:305
bool supportsLocales() const
Whether this Solvable claims to support locales.
Definition: Solvable.cc:573
Capabilities supplements() const
Definition: Solvable.cc:423
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:144
ZYPP_DEFINE_ID_HASHABLE(::zypp::sat::Solvable)
std::string asString() const
String representation "ident-edition.arch" or "noSolvable".
Definition: Solvable.cc:470
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition: Solvable.cc:127
bool isKind() const
Definition: Solvable.h:162
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:146
Capabilities suggests() const
Definition: Solvable.cc:413
Access to the sat-pools string space.
Definition: IdString.h:39
#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
bool identical(Solvable lhs, Solvable rhs)
Definition: Solvable.h:317
CapabilitySet valuesOfNamespace(const std::string &namespace_r) const
Return 'value[ op edition]' for namespaced provides 'namespace(value)[ op edition]'.
Definition: Solvable.cc:451
std::string asUserString() const
String representation "ident-edition.arch(repo)" or "noSolvable".
Definition: Solvable.cc:479
std::tr1::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
Capabilities provides() const
Definition: Solvable.cc:388
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:182
int compareByNVRA(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:347
int compare(const Arch &rhs) const
Arch comparison.
Definition: Arch.cc:532
static int compare(const Derived &lhs, const Derived &rhs)
Definition: IdStringType.h:119
std::string name() const
Definition: Solvable.cc:328
Solvable attribute keys.
Definition: SolvAttr.h:40
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:230
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:188
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:97
IdString ident() const
Definition: Solvable.h:274
bool supportsRequestedLocales() const
Whether this Solvable supports at least one requested locale.
Definition: Solvable.cc:593
bool lookupBoolAttribute(const SolvAttr &attr) const
returns the boolean attribute value for attr or false if it does not exists.
Definition: Solvable.cc:176
int compareByNVR(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:338
bool onSystemByUser() const
Whether this is known to be installed on behalf of a user request.
Definition: Solvable.cc:133
Solvable operator()(Solvable solv_r) const
Definition: Solvable.h:425
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:170
LocaleSet getSupportedLocales() const
Definition: Solvable.h:249
std::tr1::unordered_set< Locale > LocaleSet
Definition: Locale.h:28
Solvable(IdType id_r)
PoolImpl ctor.
Definition: Solvable.h:66
void assignVal(const Solvable &val_r)
Definition: Solvable.h:394
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
Solvable nextInRepo() const
Return next Solvable in Repo (or noSolvable).
Definition: Solvable.cc:107
Capabilities enhances() const
Definition: Solvable.cc:418
friend class boost::iterator_core_access
Definition: Solvable.h:385
IdString vendor() const
Definition: Solvable.cc:361
ResKind kind() const
Definition: Solvable.cc:274
Solvable nextInPool() const
Return next Solvable in Pool (or noSolvable).
Definition: Solvable.cc:104
Solvable()
Default ctor creates noSolvable.
Definition: Solvable.h:62
Capabilities conflicts() const
Definition: Solvable.cc:398
bool multiversionInstall() const
Whether different versions of this package can be installed at the same time.
Definition: Solvable.cc:356
SolvableIterator(SolvableIdType id_r)
Definition: Solvable.h:380
Capabilities prerequires() const
Definition: Solvable.cc:428
Helper that splits an identifier into kind and name or vice versa.
Definition: Solvable.h:264
Solvable result_type
Definition: Solvable.h:423
int compareByN(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:326
Capabilities operator[](Dep which_r) const
Definition: Solvable.cc:367
Capabilities requires() const
Definition: Solvable.cc:393
bool operator<(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:313
bool sameNVRA(Solvable rhs) const
Test for same name-version-release.arch.
Definition: Solvable.h:198
Reference to a PoolItem connecting ResObject and ResStatus.
Definition: PoolItem.h:50
IdType id() const
Expert backdoor.
Definition: Solvable.h:288
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:301
sat::detail::SolvableIdType IdType
Definition: Solvable.h:58
Resolvable kinds.
Definition: ResKind.h:32
To Solvable transform functor.
Definition: Solvable.h:421
IdString name() const
Definition: Solvable.h:276
bool isKind(const sat::Solvable &solvable_r)
Definition: Solvable.h:410
bool isKind(_Iterator begin, _Iterator end)
Definition: Solvable.h:166
Edition edition() const
Definition: Solvable.cc:336
bool sameNVRA(Solvable lhs, Solvable rhs)
Definition: Solvable.h:321
Capabilities obsoletes() const
Definition: Solvable.cc:403
bool operator!=(const Solvable &lhs, const Solvable &rhs)
Definition: Solvable.h:309
bool identical(Solvable rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:489