libzypp  17.36.3
LookupAttr.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_SAT_LOOKUPATTR_H
13 #define ZYPP_SAT_LOOKUPATTR_H
14 
15 #include <iosfwd>
16 #include <utility>
17 
18 #include <zypp/base/PtrTypes.h>
19 #include <zypp-core/base/DefaultIntegral>
20 #include <zypp-core/Globals.h>
21 
23 #include <zypp/sat/SolvAttr.h>
24 
26 namespace zypp
27 {
28 
29  class CheckSum;
30  class Match;
31  struct MatchException;
32  class StrMatcher;
33 
35  namespace sat
36  {
37 
39  //
40  // CLASS NAME : LookupAttr
41  //
110  {
111  public:
113 
114  public:
115  using size_type = unsigned int;
116 
118  enum Location {
119  SOLV_ATTR = 0,
120  REPO_ATTR = -1
121  };
122 
123  public:
125  LookupAttr();
126 
127  LookupAttr(const LookupAttr &) = default;
128  LookupAttr(LookupAttr &&) noexcept = default;
129  LookupAttr &operator=(const LookupAttr &) = default;
130  LookupAttr &operator=(LookupAttr &&) noexcept = default;
131 
133  explicit LookupAttr( SolvAttr attr_r, Location = SOLV_ATTR );
135  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
136 
138  LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
140  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
141 
143  LookupAttr( SolvAttr attr_r, Solvable solv_r );
145  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
146 
147  public:
151  class iterator;
152 
154  iterator begin() const;
155 
157  iterator end() const;
158 
160  bool empty() const;
161 
165  size_type size() const;
166 
168  template<class TResult, class TAttr = TResult>
171 
172  public:
176  SolvAttr attr() const;
177 
179  void setAttr( SolvAttr attr_r );
181 
193  const StrMatcher & strMatcher() const;
194 
198  void setStrMatcher( const StrMatcher & matcher_r );
199 
201  void resetStrMatcher();
203 
204  public:
208  bool pool() const;
209 
211  void setPool( Location = SOLV_ATTR );
212 
214  Repository repo() const;
215 
217  void setRepo( Repository repo_r, Location = SOLV_ATTR );
218 
220  Solvable solvable() const;
221 
223  void setSolvable( Solvable solv_r );
224 
226  SolvAttr parent() const;
227 
229  void setParent( SolvAttr attr_r );
231 
232  private:
233  class Impl;
234  RWCOW_pointer<Impl> _pimpl;
235  };
237 
239  std::ostream & operator<<( std::ostream & str, const LookupAttr & obj ) ZYPP_API;
240 
242  std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj ) ZYPP_API;
243 
245  //
246  // CLASS NAME : LookupRepoAttr
247  //
264  class LookupRepoAttr : public LookupAttr
265  {
266  public:
269  {}
271  explicit LookupRepoAttr( SolvAttr attr_r )
272  : LookupAttr( std::move(attr_r), REPO_ATTR )
273  {}
275  explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
276 
277  public:
279  void setPool()
280  { LookupAttr::setPool( REPO_ATTR ); }
282  void setRepo( Repository repo_r );
283  private:
284  // Hide. You can't look inside and outside Solvables at the same time.
285  using LookupAttr::solvable;
287  };
289 
290  namespace detail
291  {
299  class DIWrap
300  {
301  public:
304  : _dip( 0 )
305  {}
307  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
308  std::string mstring_r = std::string(), int flags_r = 0 );
310  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
311  const char * mstring_r, int flags_r = 0 );
312  DIWrap( const DIWrap & rhs );
313  ~DIWrap();
314  public:
315  void swap( DIWrap & rhs ) noexcept
316  {
317  if ( &rhs != this ) // prevent self assign!
318  {
319  std::swap( _dip, rhs._dip );
320  std::swap( _mstring, rhs._mstring );
321  }
322  }
323  DIWrap & operator=( const DIWrap & rhs )
324  {
325  if ( &rhs != this ) // prevent self assign!
326  DIWrap( rhs ).swap( *this );
327  return *this;
328  }
329  void reset()
330  { DIWrap().swap( *this ); }
331  public:
333  explicit operator bool() const
334  { return _dip; }
335 
336  public:
337  detail::CDataiterator * operator->() const { return _dip; }
338  detail::CDataiterator * get() const { return _dip; }
339  const std::string & getstr() const { return _mstring; }
340 
341  private:
343  std::string _mstring;
344  };
346  std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
347  }
348 
350  //
351  // CLASS NAME : LookupAttr::iterator
352  //
357  class LookupAttr::iterator : public boost::iterator_adaptor<
358  iterator // Derived
359  , detail::CDataiterator * // Base
360  , detail::IdType // Value
361  , boost::forward_traversal_tag // CategoryOrTraversal
362  , detail::IdType // Reference
363  >
364  {
365  public:
369  void nextSkipSolvAttr();
370 
372  void nextSkipSolvable();
373 
375  void nextSkipRepo();
376 
379  { nextSkipSolvAttr(); increment(); }
380 
383  { nextSkipSolvable(); increment(); }
384 
386  void skipRepo()
387  { nextSkipRepo(); increment(); }
388 
390  void stayInThisSolvable();
391 
393  void stayInThisRepo();
395 
399  Repository inRepo() const;
400 
402  Solvable inSolvable() const;
403 
405  SolvAttr inSolvAttr() const;
406 
408  bool atEnd() const
409  { return !_dip; }
411 
415  detail::IdType solvAttrType() const;
416 
418  bool solvAttrNumeric() const;
419 
421  bool solvAttrString() const;
422 
424  bool solvAttrIdString() const;
425 
427  bool solvAttrCheckSum() const;
428 
433  bool solvAttrSubEntry() const;
435 
467  bool subEmpty() const;
468 
472  size_type subSize() const;
473 
477  iterator subBegin() const;
481  iterator subEnd() const;
486  iterator subFind( const SolvAttr& attr_r ) const;
494  iterator subFind( const C_Str & attrname_r ) const;
496 
500  int asInt() const;
502  unsigned asUnsigned() const;
504  bool asBool() const;
506  unsigned long long asUnsignedLL() const;
507 
509  const char * c_str() const;
514  std::string asString() const;
515 
521  IdString idStr() const;
524  { return idStr().id(); }
525 
527  CheckSum asCheckSum() const;
528 
535  template<class Tp> Tp asType() const { return Tp(id()); }
537 
539  // internal stuff below
541  public:
542  iterator();
543 
544  iterator( const iterator & rhs );
545 
546  iterator & operator=( const iterator & rhs );
547 
548  ~iterator();
549 
550  public:
555  iterator( detail::DIWrap & dip_r );
556 
557  private:
558  friend class boost::iterator_core_access;
559 
560  template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
561  bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
562  {
563  return ( bool(base()) == bool(rhs.base()) )
564  && ( ! base() || dip_equal( *base(), *rhs.base() ) );
565  }
566 
567  bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
568 
569  detail::IdType dereference() const;
570 
571  void increment();
572 
573  public:
575  detail::CDataiterator * get() const
576  { return _dip.get(); }
577  private:
579  };
581 
583  std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj ) ZYPP_API;
584 
586 
589  template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
590  template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
591  template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
592  template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
593  template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
594  template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
595  template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
596  template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
597 
598  template<class TResult, class TAttr>
599  class ArrayAttr;
601 
603  } // namespace sat
606 } // namespace zypp
608 
610 std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator * obj );
611 
613 inline std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator & obj )
614 { return str << &obj; }
615 
616 #endif // ZYPP_SAT_LOOKUPATTR_H
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:122
DIWrap()
NULL detail::CDataiterator
Definition: LookupAttr.h:303
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition: LookupAttr.h:378
A Solvable object within the sat Pool.
Definition: Solvable.h:53
void setPool(Location=SOLV_ATTR)
Set search in Pool (all repositories).
Definition: LookupAttr.cc:214
Solvable solvable() const
Whether to search in one Solvable.
Definition: LookupAttr.cc:223
::s_Dataiterator CDataiterator
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:58
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition: StrMatcher.h:297
Lightweight attribute value lookup.
Definition: LookupAttr.h:109
sat::SolvAttr attr
Definition: PoolQuery.cc:312
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Definition: LookupAttr.cc:226
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition: LookupAttr.h:561
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
Definition: Arch.h:363
int IdType
Generic Id type.
Definition: PoolMember.h:104
Access to the sat-pools string space.
Definition: IdString.h:43
const std::string & getstr() const
Definition: LookupAttr.h:339
LookupAttr::TransformIterator based container to retrieve list attributes.
Definition: LookupAttr.h:599
Exceptions thrown from attribute matching.
Definition: StrMatcher.h:247
TransformIterator returning an iterator vaue of type TResult.
Definition: LookupAttr.h:169
Provides API related macros.
void skipRepo()
Immediately advance to the next Repository.
Definition: LookupAttr.h:386
unsigned int size_type
Definition: LookupAttr.h:115
LookupAttr implememtation.
Definition: LookupAttr.cc:56
void skipSolvable()
Immediately advance to the next Solvable.
Definition: LookupAttr.h:382
detail::IdType id() const
Definition: LookupAttr.h:523
DIWrap & operator=(const DIWrap &rhs)
Definition: LookupAttr.h:323
Solvable attribute keys.
Definition: SolvAttr.h:40
Tp asType() const
Templated return type.
Definition: LookupAttr.h:535
Lightweight repository attribute value lookup.
Definition: LookupAttr.h:264
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:90
LookupRepoAttr(SolvAttr attr_r)
Definition: LookupAttr.h:271
Wrapper around sat detail::CDataiterator.
Definition: LookupAttr.h:299
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
LookupRepoAttr()
Default ctor finds nothing.
Definition: LookupAttr.h:268
detail::CDataiterator * operator->() const
Definition: LookupAttr.h:337
void setPool()
Set search in Pool (all repositories).
Definition: LookupAttr.h:279
CRepo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:133
detail::CDataiterator * _dip
Definition: LookupAttr.h:342
unsigned int SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition: LookupAttr.h:408
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
SolvableIdType size_type
Definition: PoolMember.h:126
StrMatcher strMatcher
Definition: PoolQuery.cc:313
Location
Specify the where to look for the attribule.
Definition: LookupAttr.h:118
RW_pointer supporting &#39;copy on write&#39; functionality.
Definition: PtrTypes.h:468
void swap(DIWrap &rhs) noexcept
Definition: LookupAttr.h:315