libzypp  13.10.6
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 extern "C"
16 {
17 struct _Dataiterator;
18 }
19 #include <iosfwd>
20 
21 #include "zypp/base/PtrTypes.h"
23 
25 #include "zypp/sat/SolvAttr.h"
26 
28 namespace zypp
29 {
30 
31  class CheckSum;
32  class Match;
33  class MatchException;
34  class StrMatcher;
35 
37  namespace sat
38  {
39 
41  //
42  // CLASS NAME : LookupAttr
43  //
112  {
113  public:
115 
116  public:
117  typedef unsigned size_type;
118 
120  enum Location {
121  SOLV_ATTR = 0,
122  REPO_ATTR = -1
123  };
124 
125  public:
127  LookupAttr();
128 
130  explicit LookupAttr( SolvAttr attr_r, Location = SOLV_ATTR );
132  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
133 
135  LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
137  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
138 
140  LookupAttr( SolvAttr attr_r, Solvable solv_r );
142  LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
143 
144  public:
148  class iterator;
149 
151  iterator begin() const;
152 
154  iterator end() const;
155 
157  bool empty() const;
158 
162  size_type size() const;
163 
165  template<class _ResultT, class _AttrT = _ResultT> class transformIterator;
167 
168  public:
172  SolvAttr attr() const;
173 
175  void setAttr( SolvAttr attr_r );
177 
189  const StrMatcher & strMatcher() const;
190 
194  void setStrMatcher( const StrMatcher & matcher_r );
195 
197  void resetStrMatcher();
199 
200  public:
204  bool pool() const;
205 
207  void setPool( Location = SOLV_ATTR );
208 
210  Repository repo() const;
211 
213  void setRepo( Repository repo_r, Location = SOLV_ATTR );
214 
216  Solvable solvable() const;
217 
219  void setSolvable( Solvable solv_r );
220 
222  SolvAttr parent() const;
223 
225  void setParent( SolvAttr attr_r );
227 
228  private:
229  class Impl;
231  };
233 
235  std::ostream & operator<<( std::ostream & str, const LookupAttr & obj );
236 
238  std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj );
239 
241  //
242  // CLASS NAME : LookupRepoAttr
243  //
260  class LookupRepoAttr : public LookupAttr
261  {
262  public:
265  {}
267  explicit LookupRepoAttr( SolvAttr attr_r )
268  : LookupAttr( attr_r, REPO_ATTR )
269  {}
271  explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
272 
273  public:
275  void setPool()
278  void setRepo( Repository repo_r );
279  private:
280  // Hide. You can't look inside and outside Solvables at the same time.
281  using LookupAttr::solvable;
283  };
285 
286  namespace detail
287  {
295  class DIWrap
296  {
297  public:
300  : _dip( 0 )
301  {}
303  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
304  const std::string & mstring_r = std::string(), int flags_r = 0 );
306  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
307  const char * mstring_r, int flags_r = 0 );
308  DIWrap( const DIWrap & rhs );
309  ~DIWrap();
310  public:
311  void swap( DIWrap & rhs )
312  {
313  if ( &rhs != this ) // prevent self assign!
314  {
315  std::swap( _dip, rhs._dip );
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  ::_Dataiterator * operator->() const { return _dip; }
334  ::_Dataiterator * get() const { return _dip; }
335  const std::string & getstr() const { return _mstring; }
336 
337  private:
338  ::_Dataiterator * _dip;
339  std::string _mstring;
340  };
342  std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
343  }
344 
346  //
347  // CLASS NAME : LookupAttr::iterator
348  //
353  class LookupAttr::iterator : public boost::iterator_adaptor<
354  iterator // Derived
355  , ::_Dataiterator * // Base
356  , detail::IdType // Value
357  , boost::forward_traversal_tag // CategoryOrTraversal
358  , detail::IdType // Reference
359  >
360  {
361  public:
365  void nextSkipSolvAttr();
366 
368  void nextSkipSolvable();
369 
371  void nextSkipRepo();
372 
375  { nextSkipSolvAttr(); increment(); }
376 
379  { nextSkipSolvable(); increment(); }
380 
382  void skipRepo()
383  { nextSkipRepo(); increment(); }
384 
386  void stayInThisSolvable();
387 
389  void stayInThisRepo();
391 
395  Repository inRepo() const;
396 
398  Solvable inSolvable() const;
399 
401  SolvAttr inSolvAttr() const;
402 
404  bool atEnd() const
405  { return !_dip; }
407 
412 
414  bool solvAttrNumeric() const;
415 
417  bool solvAttrString() const;
418 
420  bool solvAttrIdString() const;
421 
423  bool solvAttrCheckSum() const;
424 
429  bool solvAttrSubEntry() const;
431 
463  bool subEmpty() const;
464 
468  size_type subSize() const;
469 
473  iterator subBegin() const;
477  iterator subEnd() const;
482  iterator subFind( SolvAttr attr_r ) const;
490  iterator subFind( const C_Str & attrname_r ) const;
492 
496  int asInt() const;
498  unsigned asUnsigned() const;
500  bool asBool() const;
502  unsigned long long asUnsignedLL() const;
503 
505  const char * c_str() const;
510  std::string asString() const;
511 
517  IdString idStr() const;
520  { return idStr().id(); }
521 
523  CheckSum asCheckSum() const;
524 
531  template<class _Tp> _Tp asType() const { return _Tp(id()); }
533 
535  // internal stuff below
537  public:
538  iterator();
539 
540  iterator( const iterator & rhs );
541 
542  iterator & operator=( const iterator & rhs );
543 
544  ~iterator();
545 
546  public:
551  iterator( detail::DIWrap & dip_r );
552 
553  private:
555 
556  template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
557  bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
558  {
559  return ( bool(base()) == bool(rhs.base()) )
560  && ( ! base() || dip_equal( *base(), *rhs.base() ) );
561  }
562 
563  bool dip_equal( const ::_Dataiterator & lhs, const ::_Dataiterator & rhs ) const;
564 
565  detail::IdType dereference() const;
566 
567  void increment();
568 
569  public:
571  ::_Dataiterator * get() const
572  { return _dip.get(); }
573  private:
575  };
577 
579  std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj );
580 
582 
585  template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
586  template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
587  template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
588  template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
589  template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
590  template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
591  template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
592  template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
593 
594  template<class _ResultT, class _AttrT>
595  class ArrayAttr;
597 
599  } // namespace sat
602 } // namespace zypp
604 
606 std::ostream & operator<<( std::ostream & str, const ::_Dataiterator * obj );
607 
609 inline std::ostream & operator<<( std::ostream & str, const ::_Dataiterator & obj )
610 { return str << &obj; }
611 
612 #endif // ZYPP_SAT_LOOKUPATTR_H
void stayInThisRepo()
Stop after all matches in the current Repository are processed.
Definition: LookupAttr.cc:372
DIWrap()
NULL ::_Dataiterator
Definition: LookupAttr.h:299
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition: LookupAttr.h:374
int IdType
Generic Id type.
Definition: PoolMember.h:82
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
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition: LookupAttr.cc:199
std::ostream & operator<<(std::ostream &str, const LocaleSupport &obj)
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition: LookupAttr.h:404
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:111
::_Repo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:106
void resetStrMatcher()
Reset the pattern to match.
bool dip_equal(const ::_Dataiterator &lhs, const ::_Dataiterator &rhs) const
Definition: LookupAttr.cc:744
TransformIterator returning an iterator vaue of type _ResultT.
Definition: LookupAttr.h:165
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:98
void nextSkipSolvAttr()
On the next call to operator++ advance to the next SolvAttr.
Definition: LookupAttr.cc:360
bool solvAttrIdString() const
Whether this string attribute is available as IdString.
Definition: LookupAttr.cc:410
Access to the sat-pools string space.
Definition: IdString.h:39
RWCOW_pointer< Impl > _pimpl
Definition: LookupAttr.h:229
unsigned asUnsigned() const
Definition: LookupAttr.cc:560
Search for solvable attributes (default)
Definition: LookupAttr.h:121
LookupAttr::transformIterator based container to retrieve list attributes.
Definition: LookupAttr.h:595
Exceptions thrown from attribute matching.
Definition: StrMatcher.h:247
::_Dataiterator * get() const
Definition: LookupAttr.h:334
void skipRepo()
Immediately advance to the next Repository.
Definition: LookupAttr.h:382
LookupAttr()
Default ctor finds nothing.
Definition: LookupAttr.cc:168
LookupAttr implememtation.
Definition: LookupAttr.cc:55
_Tp asType() const
Templated return type.
Definition: LookupAttr.h:531
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:378
const std::string & getstr() const
Definition: LookupAttr.h:335
iterator subBegin() const
Iterator to the begin of a sub-structure.
Definition: LookupAttr.cc:471
void setRepo(Repository repo_r)
Set search in one Repository.
Definition: LookupAttr.cc:287
iterator & operator=(const iterator &rhs)
Definition: LookupAttr.cc:732
MatchException Exception
Definition: LookupAttr.h:114
DIWrap & operator=(const DIWrap &rhs)
Definition: LookupAttr.h:319
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:260
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:81
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:684
LookupRepoAttr(SolvAttr attr_r)
Definition: LookupAttr.h:267
Wrapper around sat ::_Dataiterator.
Definition: LookupAttr.h:295
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:751
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:311
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
bool solvAttrString() const
Whether this is a string attribute.
Definition: LookupAttr.cc:395
LookupRepoAttr()
Default ctor finds nothing.
Definition: LookupAttr.h:264
bool empty() const
Whether the query is empty.
Definition: LookupAttr.cc:242
std::string asString(const Patch::SeverityFlag &obj)
Definition: Patch.cc:149
Repository inRepo() const
The current Repository.
Definition: LookupAttr.cc:351
void setPool()
Set search in Pool (all repositories).
Definition: LookupAttr.h:275
detail::IdType id() const
Definition: LookupAttr.h:519
const char * c_str() const
Conversion to string types.
Definition: LookupAttr.cc:583
size_type size() const
Ammount of results.
Definition: LookupAttr.cc:245
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition: LookupAttr.h:557
::_Dataiterator * operator->() const
Definition: LookupAttr.h:333
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
unsigned long long asUnsignedLL() const
Definition: LookupAttr.cc:563
::_Dataiterator * _dip
Definition: LookupAttr.h:338
friend class boost::iterator_core_access
Definition: LookupAttr.h:554
bool solvAttrSubEntry() const
Whether this is the entry to a sub-structure (flexarray).
Definition: LookupAttr.cc:453
bool solvAttrCheckSum() const
Whether this is a CheckSum attribute.
Definition: LookupAttr.cc:423
size_type subSize() const
Ammount of attributes in the sub-structure.
Definition: LookupAttr.cc:463
bool subEmpty() const
Whether the sub-structure is empty.
Definition: LookupAttr.cc:460
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:668
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: LookupAttr.cc:613
iterator subEnd() const
Iterator behind the end of a sub-structure.
Definition: LookupAttr.cc:493
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:120
int asInt() const
Conversion to numeric types.
Definition: LookupAttr.cc:544
iterator subFind(SolvAttr attr_r) const
Iterator pointing to the first occurance of SolvAttr attr_r in sub-structure.
Definition: LookupAttr.cc:498
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:236
RW_pointer supporting &#39;copy on write&#39; functionality.
Definition: PtrTypes.h:438
Search for repository attributes.
Definition: LookupAttr.h:122