libzypp  17.38.7
lookupattr.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPPNG_SAT_LOOKUPATTR_H
13 #define ZYPPNG_SAT_LOOKUPATTR_H
14 
15 #include <iosfwd>
16 #include <utility>
17 
20 #include <zypp-core/Globals.h>
21 
22 #include <zypp/ng/sat/solvattr.h>
23 #include <zypp/ng/sat/solvable.h>
24 #include <zypp/ng/sat/repository.h>
25 #include <zypp/ng/idstring.h>
26 
27 namespace zypp
28 {
29  class CheckSum;
30  class Match;
31  struct MatchException;
32  class StrMatcher;
33 }
34 
35 namespace zyppng::sat
36 {
37  class Pool;
38 
40  using zypp::StrMatcher;
41  using zypp::CheckSum;
42 
112  {
113  public:
115 
116  public:
117  using size_type = unsigned int;
118 
120  enum Location {
121  SOLV_ATTR = 0,
122  REPO_ATTR = -1
123  };
124 
125  public:
127  LookupAttr();
128 
129  LookupAttr(const LookupAttr &) = default;
130  LookupAttr(LookupAttr &&) noexcept = default;
131  LookupAttr &operator=(const LookupAttr &) = default;
132  LookupAttr &operator=(LookupAttr &&) noexcept = default;
133 
135  explicit LookupAttr( Pool & pool, SolvAttr attr_r, Location = SOLV_ATTR );
137  LookupAttr( Pool & pool, SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
138 
140  LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
142  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
143 
145  LookupAttr( SolvAttr attr_r, Solvable solv_r );
147  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
148 
149  public:
153  class iterator;
154 
156  iterator begin() const;
157 
159  iterator end() const;
160 
162  bool empty() const;
163 
167  size_type size() const;
168 
170  template<class TResult, class TAttr = TResult>
173 
174  public:
178  SolvAttr attr() const;
179 
181  void setAttr( SolvAttr attr_r );
183 
195  const StrMatcher & strMatcher() const;
196 
200  void setStrMatcher( const StrMatcher & matcher_r );
201 
203  void resetStrMatcher();
205 
206  public:
210  bool pool() const;
211 
213  void setPool(Location = SOLV_ATTR );
214 
216  Repository repo() const;
217 
219  void setRepo( Repository repo_r, Location = SOLV_ATTR );
220 
222  Solvable solvable() const;
223 
225  void setSolvable( Solvable solv_r );
226 
228  SolvAttr parent() const;
229 
231  void setParent( SolvAttr attr_r );
233 
234  private:
235  class Impl;
236  zypp::RWCOW_pointer<Impl> _pimpl;
237  };
238 
256  class LookupRepoAttr : public LookupAttr
257  {
258  public:
261  {}
263  explicit LookupRepoAttr( Pool & pool, SolvAttr attr_r )
264  : LookupAttr( pool, std::move(attr_r), REPO_ATTR )
265  {}
267  explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
268 
269  public:
271  void setPool( )
272  { LookupAttr::setPool( REPO_ATTR ); }
274  void setRepo( Repository repo_r );
275  private:
276  // Hide. You can't look inside and outside Solvables at the same time.
277  using LookupAttr::solvable;
279  };
280 
281  namespace detail
282  {
291  class DIWrap
292  {
293  public:
296  : _dip( 0 )
297  , _pool( 0 )
298  {}
300  DIWrap( detail::CPool * pool, RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
301  std::string mstring_r = std::string(), int flags_r = 0 );
303  DIWrap( detail::CPool * pool, RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
304  const char * mstring_r, int flags_r = 0 );
305  DIWrap( const DIWrap & rhs );
306  ~DIWrap();
307  public:
308  void swap( DIWrap & rhs ) noexcept
309  {
310  if ( &rhs != this ) // prevent self assign!
311  {
312  std::swap( _dip, rhs._dip );
313  std::swap( _pool, rhs._pool );
314  std::swap( _mstring, rhs._mstring );
315  }
316  }
317  DIWrap & operator=( const DIWrap & rhs )
318  {
319  if ( &rhs != this ) // prevent self assign!
320  DIWrap( rhs ).swap( *this );
321  return *this;
322  }
323  void reset()
324  { DIWrap().swap( *this ); }
325  public:
327  explicit operator bool() const
328  { return _dip; }
329 
330  public:
331  detail::CDataiterator * operator->() const { return _dip; }
332  detail::CDataiterator * get() const { return _dip; }
333  detail::CPool * pool() const { return _pool; }
334  const std::string & getstr() const { return _mstring; }
335 
336  private:
339  std::string _mstring;
340  };
341  }
342 
348  {
349  public:
350  using iterator_category = std::forward_iterator_tag;
352  using difference_type = std::ptrdiff_t;
353  using pointer = void;
355 
359  void nextSkipSolvAttr();
360 
362  void nextSkipSolvable();
363 
365  void nextSkipRepo();
366 
369  { nextSkipSolvAttr(); increment(); }
370 
373  { nextSkipSolvable(); increment(); }
374 
376  void skipRepo()
377  { nextSkipRepo(); increment(); }
378 
380  void stayInThisSolvable();
381 
383  void stayInThisRepo();
385 
389  Repository inRepo() const;
390 
392  Solvable inSolvable() const;
393 
395  SolvAttr inSolvAttr() const;
396 
398  bool atEnd() const
399  { return !_dip; }
401 
405  detail::IdType solvAttrType() const;
406 
408  bool solvAttrNumeric() const;
409 
411  bool solvAttrString() const;
412 
414  bool solvAttrIdString() const;
415 
417  bool solvAttrCheckSum() const;
418 
423  bool solvAttrSubEntry() const;
425 
458  bool subEmpty() const;
459 
463  size_type subSize() const;
464 
468  iterator subBegin() const;
472  iterator subEnd() const;
477  iterator subFind( const SolvAttr& attr_r ) const;
485  iterator subFind( const zypp::C_Str & attrname_r ) const;
487 
491  int asInt() const;
493  unsigned asUnsigned() const;
495  bool asBool() const;
497  unsigned long long asUnsignedLL() const;
498 
500  const char * c_str() const;
505  std::string asString() const;
506 
512  IdString idStr() const;
515  { return idStr().id(); }
516 
518  CheckSum asCheckSum() const;
519 
526  template<class Tp> Tp asType() const { return Tp(id()); }
528 
529  public:
530  iterator();
531 
532  iterator( const iterator & rhs );
533 
534  iterator & operator=( const iterator & rhs );
535 
536  ~iterator();
537 
538  public:
543  iterator( detail::DIWrap & dip_r );
544 
545  reference operator*() const;
546  iterator& operator++();
547  iterator operator++(int);
548 
549  bool operator==( const iterator & rhs ) const;
550  bool operator!=( const iterator & rhs ) const
551  { return !(*this == rhs); }
552 
553  private:
554  bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
555  void increment();
556 
557  public:
559  detail::CDataiterator * get() const
560  { return _dip.get(); }
561  private:
563  };
564 
567  template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
568  template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
569  template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
570  template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
571  template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
572  template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
573  template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
574  template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
575 
576  template<class TResult, class TAttr>
577  class ArrayAttr;
579 
580 } // namespace zyppng::sat
581 
582 #endif // ZYPPNG_SAT_LOOKUPATTR_H
A Solvable object within the sat Pool.
Definition: solvable.h:64
void setPool()
Set search in Pool (all repositories).
Definition: lookupattr.h:271
TransformIterator returning an iterator vaue of type TResult.
Definition: lookupattr.h:171
bool operator!=(const iterator &rhs) const
Definition: lookupattr.h:550
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition: capability.h:311
Lightweight repository attribute value lookup.
Definition: lookupattr.h:256
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition: Patch.cc:122
DIWrap()
NULL detail::CDataiterator
Definition: lookupattr.h:295
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition: StrMatcher.h:297
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Definition: lookupattr.cc:231
sat::SolvAttr attr
Definition: PoolQuery.cc:312
detail::CDataiterator * operator->() const
Definition: lookupattr.h:331
Lightweight attribute value lookup.
Definition: lookupattr.h:111
void swap(DIWrap &rhs) noexcept
Definition: lookupattr.h:308
Definition: ansi.h:854
Access to the sat-pools string space.
Definition: IdString.h:51
Orchestrator for a libsolv pool instance.
Definition: pool.h:36
Exceptions thrown from attribute matching.
Definition: StrMatcher.h:247
void setPool(Location=SOLV_ATTR)
Set search in Pool (all repositories).
Definition: lookupattr.cc:219
zypp::sat::detail::CPool CPool
Definition: poolconstants.h:36
zypp::sat::detail::SolvableIdType SolvableIdType
Definition: poolconstants.h:44
unsigned int size_type
Definition: lookupattr.h:117
void skipSolvable()
Immediately advance to the next Solvable.
Definition: lookupattr.h:372
void skipRepo()
Immediately advance to the next Repository.
Definition: lookupattr.h:376
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition: lookupattr.h:398
LookupRepoAttr(Pool &pool, SolvAttr attr_r)
Definition: lookupattr.h:263
detail::IdType id() const
Definition: lookupattr.h:514
std::forward_iterator_tag iterator_category
Definition: lookupattr.h:350
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:91
This file contains private API, this might break at any time between releases.
Definition: capabilities.h:22
Tp asType() const
Templated return type.
Definition: lookupattr.h:526
Provides API related macros.
LookupAttr implementation.
Definition: lookupattr.cc:46
#define ZYPP_API
Definition: Globals.h:69
DIWrap & operator=(const DIWrap &rhs)
Definition: lookupattr.h:317
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition: lookupattr.h:368
detail::CDataiterator * _dip
Definition: lookupattr.h:337
Location
Specify the where to look for the attribule.
Definition: lookupattr.h:120
SolvableIdType size_type
Definition: poolconstants.h:59
zypp::sat::detail::IdType IdType
Definition: poolconstants.h:43
detail::CPool * pool() const
Definition: lookupattr.h:333
zypp::sat::detail::CDataiterator CDataiterator
Definition: poolconstants.h:33
const std::string & getstr() const
Definition: lookupattr.h:334
Wrapper around sat detail::CDataiterator.
Definition: lookupattr.h:291
Solvable solvable() const
Whether to search in one Solvable.
Definition: lookupattr.cc:228
LookupRepoAttr()
Default ctor finds nothing.
Definition: lookupattr.h:260
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
StrMatcher strMatcher
Definition: PoolQuery.cc:313
zypp::sat::detail::RepoIdType RepoIdType
Definition: poolconstants.h:45
RW_pointer supporting &#39;copy on write&#39; functionality.
Definition: PtrTypes.h:468