libzypp  17.32.4
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 
22 #include <zypp/sat/SolvAttr.h>
23 
25 namespace zypp
26 {
27 
28  class CheckSum;
29  class Match;
30  struct MatchException;
31  class StrMatcher;
32 
34  namespace sat
35  {
36 
38  //
39  // CLASS NAME : LookupAttr
40  //
109  {
110  public:
112 
113  public:
114  using size_type = unsigned int;
115 
117  enum Location {
118  SOLV_ATTR = 0,
119  REPO_ATTR = -1
120  };
121 
122  public:
124  LookupAttr();
125 
126  LookupAttr(const LookupAttr &) = default;
127  LookupAttr(LookupAttr &&) noexcept = default;
128  LookupAttr &operator=(const LookupAttr &) = default;
129  LookupAttr &operator=(LookupAttr &&) noexcept = default;
130 
132  explicit LookupAttr( SolvAttr attr_r, Location = SOLV_ATTR );
134  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
135 
137  LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
139  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
140 
142  LookupAttr( SolvAttr attr_r, Solvable solv_r );
144  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
145 
146  public:
150  class iterator;
151 
153  iterator begin() const;
154 
156  iterator end() const;
157 
159  bool empty() const;
160 
164  size_type size() const;
165 
167  template<class TResult, class TAttr = TResult>
170 
171  public:
175  SolvAttr attr() const;
176 
178  void setAttr( SolvAttr attr_r );
180 
192  const StrMatcher & strMatcher() const;
193 
197  void setStrMatcher( const StrMatcher & matcher_r );
198 
200  void resetStrMatcher();
202 
203  public:
207  bool pool() const;
208 
210  void setPool( Location = SOLV_ATTR );
211 
213  Repository repo() const;
214 
216  void setRepo( Repository repo_r, Location = SOLV_ATTR );
217 
219  Solvable solvable() const;
220 
222  void setSolvable( Solvable solv_r );
223 
225  SolvAttr parent() const;
226 
228  void setParent( SolvAttr attr_r );
230 
231  private:
232  class Impl;
234  };
236 
238  std::ostream & operator<<( std::ostream & str, const LookupAttr & obj );
239 
241  std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj );
242 
244  //
245  // CLASS NAME : LookupRepoAttr
246  //
263  class LookupRepoAttr : public LookupAttr
264  {
265  public:
268  {}
270  explicit LookupRepoAttr( SolvAttr attr_r )
271  : LookupAttr( std::move(attr_r), REPO_ATTR )
272  {}
274  explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
275 
276  public:
278  void setPool()
281  void setRepo( Repository repo_r );
282  private:
283  // Hide. You can't look inside and outside Solvables at the same time.
284  using LookupAttr::solvable;
286  };
288 
289  namespace detail
290  {
298  class DIWrap
299  {
300  public:
303  : _dip( 0 )
304  {}
306  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
307  std::string mstring_r = std::string(), int flags_r = 0 );
309  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
310  const char * mstring_r, int flags_r = 0 );
311  DIWrap( const DIWrap & rhs );
312  ~DIWrap();
313  public:
314  void swap( DIWrap & rhs ) noexcept
315  {
316  if ( &rhs != this ) // prevent self assign!
317  {
318  std::swap( _dip, rhs._dip );
319  std::swap( _mstring, rhs._mstring );
320  }
321  }
322  DIWrap & operator=( const DIWrap & rhs )
323  {
324  if ( &rhs != this ) // prevent self assign!
325  DIWrap( rhs ).swap( *this );
326  return *this;
327  }
328  void reset()
329  { DIWrap().swap( *this ); }
330  public:
332  explicit operator bool() const
333  { return _dip; }
334 
335  public:
336  detail::CDataiterator * operator->() const { return _dip; }
337  detail::CDataiterator * get() const { return _dip; }
338  const std::string & getstr() const { return _mstring; }
339 
340  private:
342  std::string _mstring;
343  };
345  std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
346  }
347 
349  //
350  // CLASS NAME : LookupAttr::iterator
351  //
356  class LookupAttr::iterator : public boost::iterator_adaptor<
357  iterator // Derived
358  , detail::CDataiterator * // Base
359  , detail::IdType // Value
360  , boost::forward_traversal_tag // CategoryOrTraversal
361  , detail::IdType // Reference
362  >
363  {
364  public:
368  void nextSkipSolvAttr();
369 
371  void nextSkipSolvable();
372 
374  void nextSkipRepo();
375 
378  { nextSkipSolvAttr(); increment(); }
379 
382  { nextSkipSolvable(); increment(); }
383 
385  void skipRepo()
386  { nextSkipRepo(); increment(); }
387 
389  void stayInThisSolvable();
390 
392  void stayInThisRepo();
394 
398  Repository inRepo() const;
399 
401  Solvable inSolvable() const;
402 
404  SolvAttr inSolvAttr() const;
405 
407  bool atEnd() const
408  { return !_dip; }
410 
414  detail::IdType solvAttrType() const;
415 
417  bool solvAttrNumeric() const;
418 
420  bool solvAttrString() const;
421 
423  bool solvAttrIdString() const;
424 
426  bool solvAttrCheckSum() const;
427 
432  bool solvAttrSubEntry() const;
434 
466  bool subEmpty() const;
467 
471  size_type subSize() const;
472 
476  iterator subBegin() const;
480  iterator subEnd() const;
485  iterator subFind( const SolvAttr& attr_r ) const;
493  iterator subFind( const C_Str & attrname_r ) const;
495 
499  int asInt() const;
501  unsigned asUnsigned() const;
503  bool asBool() const;
505  unsigned long long asUnsignedLL() const;
506 
508  const char * c_str() const;
513  std::string asString() const;
514 
520  IdString idStr() const;
523  { return idStr().id(); }
524 
526  CheckSum asCheckSum() const;
527 
534  template<class Tp> Tp asType() const { return Tp(id()); }
536 
538  // internal stuff below
540  public:
541  iterator();
542 
543  iterator( const iterator & rhs );
544 
545  iterator & operator=( const iterator & rhs );
546 
547  ~iterator();
548 
549  public:
554  iterator( detail::DIWrap & dip_r );
555 
556  private:
557  friend class boost::iterator_core_access;
558 
559  template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
560  bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
561  {
562  return ( bool(base()) == bool(rhs.base()) )
563  && ( ! base() || dip_equal( *base(), *rhs.base() ) );
564  }
565 
566  bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
567 
568  detail::IdType dereference() const;
569 
570  void increment();
571 
572  public:
574  detail::CDataiterator * get() const
575  { return _dip.get(); }
576  private:
578  };
580 
582  std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj );
583 
585 
588  template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
589  template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
590  template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
591  template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
592  template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
593  template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
594  template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
595  template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
596 
597  template<class TResult, class TAttr>
598  class ArrayAttr;
600 
602  } // namespace sat
605 } // namespace zypp
607 
609 std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator * obj );
610 
612 inline std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator & obj )
613 { return str << &obj; }
614 
615 #endif // ZYPP_SAT_LOOKUPATTR_H
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:122
DIWrap()
NULL detail::CDataiterator
Definition: LookupAttr.h:302
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not)
Definition: LookupAttr.cc:229
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition: LookupAttr.h:377
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
LookupAttr & operator=(const LookupAttr &)=default
Solvable solvable() const
Whether to search in one Solvable.
Definition: LookupAttr.cc:223
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition: LookupAttr.cc:200
::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
const StrMatcher & strMatcher() const
The pattern to match.
Definition: LookupAttr.cc:203
Lightweight attribute value lookup.
Definition: LookupAttr.h:108
void resetStrMatcher()
Reset the pattern to match.
void setParent(SolvAttr attr_r)
Set search within a sub-structure (SolvAttr::noAttr for none)
Definition: LookupAttr.cc:232
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:560
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:42
RWCOW_pointer< Impl > _pimpl
Definition: LookupAttr.h:232
Search for solvable attributes (default)
Definition: LookupAttr.h:118
const std::string & getstr() const
Definition: LookupAttr.h:338
LookupAttr::TransformIterator based container to retrieve list attributes.
Definition: LookupAttr.h:598
Exceptions thrown from attribute matching.
Definition: StrMatcher.h:247
TransformIterator returning an iterator vaue of type TResult.
Definition: LookupAttr.h:168
void skipRepo()
Immediately advance to the next Repository.
Definition: LookupAttr.h:385
unsigned int size_type
Definition: LookupAttr.h:114
LookupAttr()
Default ctor finds nothing.
Definition: LookupAttr.cc:169
LookupAttr implememtation.
Definition: LookupAttr.cc:56
void skipSolvable()
Immediately advance to the next Solvable.
Definition: LookupAttr.h:381
iterator end() const
Iterator behind the end of query results.
Definition: LookupAttr.cc:240
detail::IdType id() const
Definition: LookupAttr.h:522
DIWrap & operator=(const DIWrap &rhs)
Definition: LookupAttr.h:322
Solvable attribute keys.
Definition: SolvAttr.h:40
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition: LookupAttr.cc:220
Tp asType() const
Templated return type.
Definition: LookupAttr.h:534
Lightweight repository attribute value lookup.
Definition: LookupAttr.h:263
std::ostream & dumpOn(std::ostream &str, const LookupAttr &obj)
Definition: LookupAttr.cc:273
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:270
Wrapper around sat detail::CDataiterator.
Definition: LookupAttr.h:298
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition: LookupAttr.cc:206
LookupRepoAttr()
Default ctor finds nothing.
Definition: LookupAttr.h:267
bool pool() const
Whether to search in Pool.
Definition: LookupAttr.cc:211
SolvAttr attr() const
The SolvAttr to search.
Definition: LookupAttr.cc:197
Repository repo() const
Whether to search in one Repository.
Definition: LookupAttr.cc:217
detail::CDataiterator * operator->() const
Definition: LookupAttr.h:336
void setPool()
Set search in Pool (all repositories).
Definition: LookupAttr.h:278
CRepo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:133
std::ostream & operator<<(std::ostream &str, const LookupAttr &obj)
Definition: LookupAttr.cc:256
detail::CDataiterator * _dip
Definition: LookupAttr.h:341
unsigned int SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
size_type size() const
Ammount of results.
Definition: LookupAttr.cc:246
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition: LookupAttr.h:407
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
Location
Specify the where to look for the attribule.
Definition: LookupAttr.h:117
bool empty() const
Whether the query is empty.
Definition: LookupAttr.cc:243
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:237
RW_pointer supporting &#39;copy on write&#39; functionality.
Definition: PtrTypes.h:467
Search for repository attributes.
Definition: LookupAttr.h:119
void swap(DIWrap &rhs) noexcept
Definition: LookupAttr.h:314