libzypp  14.48.5
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 
17 #include "zypp/base/PtrTypes.h"
19 
21 #include "zypp/sat/SolvAttr.h"
22 
24 namespace zypp
25 {
26 
27  class CheckSum;
28  class Match;
29  class MatchException;
30  class StrMatcher;
31 
33  namespace sat
34  {
35 
37  //
38  // CLASS NAME : LookupAttr
39  //
108  {
109  public:
111 
112  public:
113  typedef unsigned size_type;
114 
116  enum Location {
117  SOLV_ATTR = 0,
118  REPO_ATTR = -1
119  };
120 
121  public:
123  LookupAttr();
124 
126  explicit LookupAttr( SolvAttr attr_r, Location = SOLV_ATTR );
128  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
129 
131  LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
133  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
134 
136  LookupAttr( SolvAttr attr_r, Solvable solv_r );
138  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
139 
140  public:
144  class iterator;
145 
147  iterator begin() const;
148 
150  iterator end() const;
151 
153  bool empty() const;
154 
158  size_type size() const;
159 
161  template<class _ResultT, class _AttrT = _ResultT> class transformIterator;
163 
164  public:
168  SolvAttr attr() const;
169 
171  void setAttr( SolvAttr attr_r );
173 
185  const StrMatcher & strMatcher() const;
186 
190  void setStrMatcher( const StrMatcher & matcher_r );
191 
193  void resetStrMatcher();
195 
196  public:
200  bool pool() const;
201 
203  void setPool( Location = SOLV_ATTR );
204 
206  Repository repo() const;
207 
209  void setRepo( Repository repo_r, Location = SOLV_ATTR );
210 
212  Solvable solvable() const;
213 
215  void setSolvable( Solvable solv_r );
216 
218  SolvAttr parent() const;
219 
221  void setParent( SolvAttr attr_r );
223 
224  private:
225  class Impl;
227  };
229 
231  std::ostream & operator<<( std::ostream & str, const LookupAttr & obj );
232 
234  std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj );
235 
237  //
238  // CLASS NAME : LookupRepoAttr
239  //
256  class LookupRepoAttr : public LookupAttr
257  {
258  public:
261  {}
263  explicit LookupRepoAttr( SolvAttr attr_r )
264  : LookupAttr( attr_r, REPO_ATTR )
265  {}
267  explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
268 
269  public:
271  void setPool()
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  };
281 
282  namespace detail
283  {
291  class DIWrap
292  {
293  public:
296  : _dip( 0 )
297  {}
299  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
300  const std::string & mstring_r = std::string(), int flags_r = 0 );
302  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
303  const char * mstring_r, int flags_r = 0 );
304  DIWrap( const DIWrap & rhs );
305  ~DIWrap();
306  public:
307  void swap( DIWrap & rhs )
308  {
309  if ( &rhs != this ) // prevent self assign!
310  {
311  std::swap( _dip, rhs._dip );
312  std::swap( _mstring, rhs._mstring );
313  }
314  }
315  DIWrap & operator=( const DIWrap & rhs )
316  {
317  if ( &rhs != this ) // prevent self assign!
318  DIWrap( rhs ).swap( *this );
319  return *this;
320  }
321  void reset()
322  { DIWrap().swap( *this ); }
323  public:
325  explicit operator bool() const
326  { return _dip; }
327 
328  public:
329  detail::CDataiterator * operator->() const { return _dip; }
330  detail::CDataiterator * get() const { return _dip; }
331  const std::string & getstr() const { return _mstring; }
332 
333  private:
335  std::string _mstring;
336  };
338  std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
339  }
340 
342  //
343  // CLASS NAME : LookupAttr::iterator
344  //
349  class LookupAttr::iterator : public boost::iterator_adaptor<
350  iterator // Derived
351  , detail::CDataiterator * // Base
352  , detail::IdType // Value
353  , boost::forward_traversal_tag // CategoryOrTraversal
354  , detail::IdType // Reference
355  >
356  {
357  public:
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 
391  Repository inRepo() const;
392 
394  Solvable inSolvable() const;
395 
397  SolvAttr inSolvAttr() const;
398 
400  bool atEnd() const
401  { return !_dip; }
403 
408 
410  bool solvAttrNumeric() const;
411 
413  bool solvAttrString() const;
414 
416  bool solvAttrIdString() const;
417 
419  bool solvAttrCheckSum() const;
420 
425  bool solvAttrSubEntry() const;
427 
459  bool subEmpty() const;
460 
464  size_type subSize() const;
465 
469  iterator subBegin() const;
473  iterator subEnd() const;
478  iterator subFind( SolvAttr attr_r ) const;
486  iterator subFind( const C_Str & attrname_r ) const;
488 
492  int asInt() const;
494  unsigned asUnsigned() const;
496  bool asBool() const;
498  unsigned long long asUnsignedLL() const;
499 
501  const char * c_str() const;
506  std::string asString() const;
507 
513  IdString idStr() const;
516  { return idStr().id(); }
517 
519  CheckSum asCheckSum() const;
520 
527  template<class _Tp> _Tp asType() const { return _Tp(id()); }
529 
531  // internal stuff below
533  public:
534  iterator();
535 
536  iterator( const iterator & rhs );
537 
538  iterator & operator=( const iterator & rhs );
539 
540  ~iterator();
541 
542  public:
547  iterator( detail::DIWrap & dip_r );
548 
549  private:
551 
552  template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
553  bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
554  {
555  return ( bool(base()) == bool(rhs.base()) )
556  && ( ! base() || dip_equal( *base(), *rhs.base() ) );
557  }
558 
559  bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
560 
561  detail::IdType dereference() const;
562 
563  void increment();
564 
565  public:
567  detail::CDataiterator * get() const
568  { return _dip.get(); }
569  private:
571  };
573 
575  std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj );
576 
578 
581  template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
582  template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
583  template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
584  template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
585  template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
586  template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
587  template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
588  template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
589 
590  template<class _ResultT, class _AttrT>
591  class ArrayAttr;
593 
595  } // namespace sat
598 } // namespace zypp
600 
602 std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator * obj );
603 
605 inline std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator & obj )
606 { return str << &obj; }
607 
608 #endif // ZYPP_SAT_LOOKUPATTR_H
void stayInThisRepo()
Stop after all matches in the current Repository are processed.
Definition: LookupAttr.cc:372
DIWrap()
NULL detail::CDataiterator
Definition: LookupAttr.h:295
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition: LookupAttr.h:370
int IdType
Generic Id type.
Definition: PoolMember.h:130
A Solvable object within the sat Pool.
Definition: Solvable.h:55
void setPool(Location=SOLV_ATTR)
Set search in Pool (all repositories).
Definition: LookupAttr.cc:213
::_Dataiterator CDataiterator
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:83
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition: LookupAttr.cc:199
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition: LookupAttr.h:400
IdType id() const
Expert backdoor.
Definition: IdString.h:103
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition: StrMatcher.h:297
Lightweight attribute value lookup.
Definition: LookupAttr.h:107
void resetStrMatcher()
Reset the pattern to match.
TransformIterator returning an iterator vaue of type _ResultT.
Definition: LookupAttr.h:161
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
void setParent(SolvAttr attr_r)
Set search within a sub-structure (SolvAttr::noAttr for none)
Definition: LookupAttr.cc:231
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Definition: LookupAttr.cc:225
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:146
void nextSkipSolvAttr()
On the next call to operator++ advance to the next SolvAttr.
Definition: LookupAttr.cc:360
CRepo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:154
bool solvAttrIdString() const
Whether this string attribute is available as IdString.
Definition: LookupAttr.cc:409
Access to the sat-pools string space.
Definition: IdString.h:39
RWCOW_pointer< Impl > _pimpl
Definition: LookupAttr.h:225
unsigned asUnsigned() const
Definition: LookupAttr.cc:558
Search for solvable attributes (default)
Definition: LookupAttr.h:117
LookupAttr::transformIterator based container to retrieve list attributes.
Definition: LookupAttr.h:591
Exceptions thrown from attribute matching.
Definition: StrMatcher.h:247
void skipRepo()
Immediately advance to the next Repository.
Definition: LookupAttr.h:378
LookupAttr()
Default ctor finds nothing.
Definition: LookupAttr.cc:168
LookupAttr implememtation.
Definition: LookupAttr.cc:55
_Tp asType() const
Templated return type.
Definition: LookupAttr.h:527
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not)
Definition: LookupAttr.cc:228
void skipSolvable()
Immediately advance to the next Solvable.
Definition: LookupAttr.h:374
const std::string & getstr() const
Definition: LookupAttr.h:331
bool dip_equal(const detail::CDataiterator &lhs, const detail::CDataiterator &rhs) const
Definition: LookupAttr.cc:752
iterator subBegin() const
Iterator to the begin of a sub-structure.
Definition: LookupAttr.cc:470
void setRepo(Repository repo_r)
Set search in one Repository.
Definition: LookupAttr.cc:287
iterator & operator=(const iterator &rhs)
Definition: LookupAttr.cc:740
MatchException Exception
Definition: LookupAttr.h:110
DIWrap & operator=(const DIWrap &rhs)
Definition: LookupAttr.h:315
bool pool() const
Whether to search in Pool.
Definition: LookupAttr.cc:210
Solvable attribute keys.
Definition: SolvAttr.h:40
iterator end() const
Iterator behind the end of query results.
Definition: LookupAttr.cc:239
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition: LookupAttr.cc:219
Lightweight repository attribute value lookup.
Definition: LookupAttr.h:256
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:97
SolvAttr attr() const
The SolvAttr to search.
Definition: LookupAttr.cc:196
Solvable inSolvable() const
The current Solvable.
Definition: LookupAttr.cc:354
std::ostream & operator<<(std::ostream &str, const Arch::CompatEntry &obj)
Definition: Arch.cc:110
CheckSum asCheckSum() const
As CheckSum.
Definition: LookupAttr.cc:680
LookupRepoAttr(SolvAttr attr_r)
Definition: LookupAttr.h:263
Wrapper around sat detail::CDataiterator.
Definition: LookupAttr.h:291
SolvAttr inSolvAttr() const
The current SolvAttr.
Definition: LookupAttr.cc:357
void stayInThisSolvable()
Stop after all matches in the current Solvable are processed.
Definition: LookupAttr.cc:369
detail::IdType dereference() const
Definition: LookupAttr.cc:759
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition: LookupAttr.cc:205
void nextSkipSolvable()
On the next call to operator++ advance to the next Solvable.
Definition: LookupAttr.cc:363
std::ostream & operator<<(std::ostream &str, const DIWrap &obj)
Definition: LookupAttr.cc:337
const StrMatcher & strMatcher() const
The pattern to match.
Definition: LookupAttr.cc:202
void swap(DIWrap &rhs)
Definition: LookupAttr.h:307
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
detail::CDataiterator * operator->() const
Definition: LookupAttr.h:329
bool solvAttrString() const
Whether this is a string attribute.
Definition: LookupAttr.cc:394
LookupRepoAttr()
Default ctor finds nothing.
Definition: LookupAttr.h:260
bool empty() const
Whether the query is empty.
Definition: LookupAttr.cc:242
std::string asString(const Patch::SeverityFlag &obj)
Definition: Patch.cc:166
Repository inRepo() const
The current Repository.
Definition: LookupAttr.cc:351
void setPool()
Set search in Pool (all repositories).
Definition: LookupAttr.h:271
detail::IdType id() const
Definition: LookupAttr.h:515
const char * c_str() const
Conversion to string types.
Definition: LookupAttr.cc:580
size_type size() const
Ammount of results.
Definition: LookupAttr.cc:245
detail::CDataiterator * get() const
Definition: LookupAttr.h:330
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition: LookupAttr.h:553
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
Definition: LookupAttr.cc:366
Solvable solvable() const
Whether to search in one Solvable.
Definition: LookupAttr.cc:222
detail::CDataiterator * _dip
Definition: LookupAttr.h:334
unsigned long long asUnsignedLL() const
Definition: LookupAttr.cc:561
friend class boost::iterator_core_access
Definition: LookupAttr.h:550
bool solvAttrSubEntry() const
Whether this is the entry to a sub-structure (flexarray).
Definition: LookupAttr.cc:452
bool solvAttrCheckSum() const
Whether this is a CheckSum attribute.
Definition: LookupAttr.cc:422
size_type subSize() const
Ammount of attributes in the sub-structure.
Definition: LookupAttr.cc:462
bool subEmpty() const
Whether the sub-structure is empty.
Definition: LookupAttr.cc:459
bool solvAttrNumeric() const
Whether this is a numeric attribute (incl.
Definition: LookupAttr.cc:382
detail::IdType solvAttrType() const
The current SolvAttr type.
Definition: LookupAttr.cc:379
IdString idStr() const
As IdStr.
Definition: LookupAttr.cc:664
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: LookupAttr.cc:610
iterator subEnd() const
Iterator behind the end of a sub-structure.
Definition: LookupAttr.cc:492
Repository repo() const
Whether to search in one Repository.
Definition: LookupAttr.cc:216
Location
Specify the where to look for the attribule.
Definition: LookupAttr.h:116
int asInt() const
Conversion to numeric types.
Definition: LookupAttr.cc:543
iterator subFind(SolvAttr attr_r) const
Iterator pointing to the first occurance of SolvAttr attr_r in sub-structure.
Definition: LookupAttr.cc:497
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:236
Search for repository attributes.
Definition: LookupAttr.h:118