libzypp  17.38.8
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>
22 
23 #include <zypp/ng/sat/solvattr.h>
24 #include <zypp/ng/sat/solvable.h>
25 #include <zypp/ng/sat/repository.h>
26 #include <zypp/ng/idstring.h>
27 
28 namespace zypp
29 {
30  class CheckSum;
31  class Match;
32  struct MatchException;
33  class StrMatcher;
34 }
35 
36 namespace zyppng::sat
37 {
38  class Pool;
39  class LookupAttrValue;
40 
42  using zypp::StrMatcher;
43  using zypp::CheckSum;
44 
114  {
115  public:
117 
118  public:
119  using size_type = unsigned int;
120 
122  enum Location {
123  SOLV_ATTR = 0,
124  REPO_ATTR = -1
125  };
126 
127  public:
129  LookupAttr();
130 
131  LookupAttr(const LookupAttr &) = default;
132  LookupAttr(LookupAttr &&) noexcept = default;
133  LookupAttr &operator=(const LookupAttr &) = default;
134  LookupAttr &operator=(LookupAttr &&) noexcept = default;
135 
137  explicit LookupAttr( Pool & pool, SolvAttr attr_r, Location = SOLV_ATTR );
139  LookupAttr( Pool & pool, SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
140 
142  LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
144  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
145 
147  LookupAttr( SolvAttr attr_r, Solvable solv_r );
149  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
150 
151  public:
155  class iterator;
156 
158  iterator begin() const;
159 
161  iterator end() const;
162 
164  bool empty() const;
165 
169  size_type size() const;
170 
172  template<class TResult, class TAttr = TResult>
175 
176  public:
180  SolvAttr attr() const;
181 
183  void setAttr( SolvAttr attr_r );
185 
197  const StrMatcher & strMatcher() const;
198 
202  void setStrMatcher( const StrMatcher & matcher_r );
203 
205  void resetStrMatcher();
207 
208  public:
212  bool pool() const;
213 
215  void setPool(Location = SOLV_ATTR );
216 
218  Repository repo() const;
219 
221  void setRepo( Repository repo_r, Location = SOLV_ATTR );
222 
224  Solvable solvable() const;
225 
227  void setSolvable( Solvable solv_r );
228 
230  SolvAttr parent() const;
231 
233  void setParent( SolvAttr attr_r );
235 
236  private:
237  class Impl;
239  };
240 
258  class LookupRepoAttr : public LookupAttr
259  {
260  public:
263  {}
265  explicit LookupRepoAttr( Pool & pool, SolvAttr attr_r )
266  : LookupAttr( pool, std::move(attr_r), REPO_ATTR )
267  {}
269  explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
270 
271  public:
273  void setPool( )
276  void setRepo( Repository repo_r );
277  private:
278  // Hide. You can't look inside and outside Solvables at the same time.
279  using LookupAttr::solvable;
281  };
282 
283  namespace detail
284  {
293  class DIWrap
294  {
295  public:
298  : _dip( 0 )
299  , _pool( 0 )
300  {}
302  DIWrap( detail::CPool * pool, RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
303  std::string mstring_r = std::string(), int flags_r = 0 );
305  DIWrap( detail::CPool * pool, RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
306  const char * mstring_r, int flags_r = 0 );
307  DIWrap( const DIWrap & rhs );
308  ~DIWrap();
309  public:
310  void swap( DIWrap & rhs ) noexcept
311  {
312  if ( &rhs != this ) // prevent self assign!
313  {
314  std::swap( _dip, rhs._dip );
315  std::swap( _pool, rhs._pool );
316  std::swap( _mstring, rhs._mstring );
317  }
318  }
319  DIWrap & operator=( const DIWrap & rhs )
320  {
321  if ( &rhs != this ) // prevent self assign!
322  DIWrap( rhs ).swap( *this );
323  return *this;
324  }
325  void reset()
326  { DIWrap().swap( *this ); }
327  public:
329  explicit operator bool() const
330  { return _dip; }
331 
332  public:
333  detail::CDataiterator * operator->() const { return _dip; }
334  detail::CDataiterator * get() const { return _dip; }
335  detail::CPool * pool() const { return _pool; }
336  const std::string & getstr() const { return _mstring; }
337 
338  private:
341  std::string _mstring;
342  };
343  }
344 
350  {
351  public:
352  using iterator_category = std::forward_iterator_tag;
354  using difference_type = std::ptrdiff_t;
355  using pointer = void;
357 
361  void nextSkipSolvAttr();
362 
364  void nextSkipSolvable();
365 
367  void nextSkipRepo();
368 
371  { nextSkipSolvAttr(); increment(); }
372 
375  { nextSkipSolvable(); increment(); }
376 
378  void skipRepo()
379  { nextSkipRepo(); increment(); }
380 
382  void stayInThisSolvable();
383 
385  void stayInThisRepo();
387 
389  bool atEnd() const
390  { return !_dip; }
391 
392  public:
393  iterator();
394 
395  iterator( const iterator & rhs );
396 
397  iterator & operator=( const iterator & rhs );
398 
399  ~iterator();
400 
401  public:
406  iterator( detail::DIWrap & dip_r );
407 
408  reference operator*() const;
409  iterator& operator++();
410  iterator operator++(int);
411 
412  bool operator==( const iterator & rhs ) const;
413  bool operator!=( const iterator & rhs ) const
414  { return !(*this == rhs); }
415 
416  private:
417  bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
418  void increment();
419 
420  public:
422  detail::CDataiterator * get() const
423  { return _dip.get(); }
424  private:
426  };
427 
430  template<class TResult, class TAttr>
431  class ArrayAttr;
433 
434  template<class TResult, class TAttr>
435  class ArrayAttr;
437 
438  // -----------------------------------------------------------------------
439 
454  {
455  public:
457 
460  : _dip( dip ), _pool( pool )
461  {}
462 
463  public:
467  Repository inRepo() const;
468 
470  Solvable inSolvable() const;
471 
473  SolvAttr inSolvAttr() const;
475 
479  detail::IdType solvAttrType() const;
480 
482  bool solvAttrNumeric() const;
483 
485  bool solvAttrString() const;
486 
488  bool solvAttrIdString() const;
489 
491  bool solvAttrCheckSum() const;
492 
497  bool solvAttrSubEntry() const;
499 
514  bool subEmpty() const;
515 
519  size_type subSize() const;
520 
524  LookupAttr::iterator subBegin() const;
525 
529  LookupAttr::iterator subEnd() const;
530 
536  LookupAttr::iterator subFind( const SolvAttr & attr_r ) const;
537 
545  LookupAttr::iterator subFind( const zypp::C_Str & attrname_r ) const;
547 
551  int asInt() const;
553  unsigned asUnsigned() const;
555  bool asBool() const;
557  unsigned long long asUnsignedLL() const;
558 
560  const char * c_str() const;
565  std::string asString() const;
566 
572  IdString idStr() const;
573 
576  { return idStr().id(); }
577 
579  CheckSum asCheckSum() const;
580 
587  template<class Tp> Tp asType() const { return Tp( id() ); }
589 
590  private:
593  };
594 
595  // asType<> specialisations for LookupAttrValue (mirrors those on iterator)
596  template<> inline int LookupAttrValue::asType<int>() const { return asInt(); }
597  template<> inline unsigned LookupAttrValue::asType<unsigned>() const { return asUnsigned(); }
598  template<> inline unsigned long long LookupAttrValue::asType<unsigned long long>()const { return asUnsignedLL(); }
599  template<> inline bool LookupAttrValue::asType<bool>() const { return asBool(); }
600  template<> inline const char * LookupAttrValue::asType<const char *>() const { return c_str(); }
601  template<> inline std::string LookupAttrValue::asType<std::string>() const { return asString(); }
602  template<> inline IdString LookupAttrValue::asType<IdString>() const { return idStr(); }
603  template<> CheckSum LookupAttrValue::asType<CheckSum>() const;
604 
605 } // namespace zyppng::sat
606 
607 #endif // ZYPPNG_SAT_LOOKUPATTR_H
const StrMatcher & strMatcher() const
The pattern to match.
Definition: lookupattr.cc:210
LookupAttrValue(detail::CDataiterator *dip, detail::CPool *pool)
Definition: lookupattr.h:459
A Solvable object within the sat Pool.
Definition: solvable.h:65
void setPool()
Set search in Pool (all repositories).
Definition: lookupattr.h:273
TransformIterator returning an iterator vaue of type TResult.
Definition: lookupattr.h:173
bool operator!=(const iterator &rhs) const
Definition: lookupattr.h:413
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition: capability.h:311
Lightweight repository attribute value lookup.
Definition: lookupattr.h:258
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition: Patch.cc:122
DIWrap()
NULL detail::CDataiterator
Definition: lookupattr.h:297
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition: StrMatcher.h:297
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Definition: lookupattr.cc:231
detail::IdType id() const
Definition: lookupattr.h:575
detail::CDataiterator * operator->() const
Definition: lookupattr.h:333
Search for solvable attributes (default)
Definition: lookupattr.h:123
Lightweight attribute value lookup.
Definition: lookupattr.h:113
void swap(DIWrap &rhs) noexcept
Definition: lookupattr.h:310
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition: lookupattr.cc:207
Value proxy returned by LookupAttr::iterator::operator*().
Definition: lookupattr.h:453
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
void setParent(SolvAttr attr_r)
Set search within a sub-structure (SolvAttr::noAttr for none)
Definition: lookupattr.cc:237
LookupAttr()
Default ctor finds nothing.
Definition: lookupattr.cc:165
zypp::sat::detail::SolvableIdType SolvableIdType
Definition: poolconstants.h:44
bool empty() const
Whether the query is empty.
Definition: lookupattr.cc:246
unsigned int size_type
Definition: lookupattr.h:119
void skipSolvable()
Immediately advance to the next Solvable.
Definition: lookupattr.h:374
void skipRepo()
Immediately advance to the next Repository.
Definition: lookupattr.h:378
bool atEnd() const
Whether this points to the end of a query (iterator is invalid).
Definition: lookupattr.h:389
LookupRepoAttr(Pool &pool, SolvAttr attr_r)
Definition: lookupattr.h:265
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition: lookupattr.cc:225
Repository repo() const
Whether to search in one Repository.
Definition: lookupattr.cc:222
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition: lookupattr.cc:213
std::forward_iterator_tag iterator_category
Definition: lookupattr.h:352
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
Provides API related macros.
LookupAttr implementation.
Definition: lookupattr.cc:46
DIWrap & operator=(const DIWrap &rhs)
Definition: lookupattr.h:319
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition: lookupattr.h:370
size_type size() const
Ammount of results.
Definition: lookupattr.cc:249
detail::CDataiterator * _dip
Definition: lookupattr.h:339
Location
Specify the where to look for the attribule.
Definition: lookupattr.h:122
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not)
Definition: lookupattr.cc:234
LookupAttr::size_type size_type
Definition: lookupattr.h:456
zypp::sat::detail::IdType IdType
Definition: poolconstants.h:43
iterator begin() const
Iterator to the begin of query results.
Definition: lookupattr.cc:240
Namespace routing for C++20 ranges and C++23 ranges::to<T>() backport.
zypp::RWCOW_pointer< Impl > _pimpl
Definition: lookupattr.h:237
detail::CPool * pool() const
Definition: lookupattr.h:335
Search for repository attributes.
Definition: lookupattr.h:124
detail::CPool * _pool
non-owning — needed for sub-structure DIWrap construction
Definition: lookupattr.h:592
zypp::sat::detail::CDataiterator CDataiterator
Definition: poolconstants.h:33
const std::string & getstr() const
Definition: lookupattr.h:336
void pointer
proxy type — no stable address
Definition: lookupattr.h:355
detail::CDataiterator * _dip
non-owning — current iterator position
Definition: lookupattr.h:591
Wrapper around sat detail::CDataiterator.
Definition: lookupattr.h:293
LookupAttr & operator=(const LookupAttr &)=default
iterator end() const
Iterator behind the end of query results.
Definition: lookupattr.cc:243
Tp asType() const
Templated return type.
Definition: lookupattr.h:587
Solvable solvable() const
Whether to search in one Solvable.
Definition: lookupattr.cc:228
LookupRepoAttr()
Default ctor finds nothing.
Definition: lookupattr.h:262
void resetStrMatcher()
Reset the pattern to match.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::sat::detail::RepoIdType RepoIdType
Definition: poolconstants.h:45
SolvAttr attr() const
The SolvAttr to search.
Definition: lookupattr.cc:204
RW_pointer supporting &#39;copy on write&#39; functionality.
Definition: PtrTypes.h:468
bool pool() const
Whether to search in Pool.
Definition: lookupattr.cc:216