libzypp  17.1.1
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 TResult, class TAttr = TResult>
164 
165  public:
169  SolvAttr attr() const;
170 
172  void setAttr( SolvAttr attr_r );
174 
186  const StrMatcher & strMatcher() const;
187 
191  void setStrMatcher( const StrMatcher & matcher_r );
192 
194  void resetStrMatcher();
196 
197  public:
201  bool pool() const;
202 
204  void setPool( Location = SOLV_ATTR );
205 
207  Repository repo() const;
208 
210  void setRepo( Repository repo_r, Location = SOLV_ATTR );
211 
213  Solvable solvable() const;
214 
216  void setSolvable( Solvable solv_r );
217 
219  SolvAttr parent() const;
220 
222  void setParent( SolvAttr attr_r );
224 
225  private:
226  class Impl;
228  };
230 
232  std::ostream & operator<<( std::ostream & str, const LookupAttr & obj );
233 
235  std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj );
236 
238  //
239  // CLASS NAME : LookupRepoAttr
240  //
257  class LookupRepoAttr : public LookupAttr
258  {
259  public:
262  {}
264  explicit LookupRepoAttr( SolvAttr attr_r )
265  : LookupAttr( attr_r, REPO_ATTR )
266  {}
268  explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
269 
270  public:
272  void setPool()
275  void setRepo( Repository repo_r );
276  private:
277  // Hide. You can't look inside and outside Solvables at the same time.
278  using LookupAttr::solvable;
280  };
282 
283  namespace detail
284  {
292  class DIWrap
293  {
294  public:
297  : _dip( 0 )
298  {}
300  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
301  const std::string & mstring_r = std::string(), int flags_r = 0 );
303  DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
304  const char * mstring_r, int flags_r = 0 );
305  DIWrap( const DIWrap & rhs );
306  ~DIWrap();
307  public:
308  void swap( DIWrap & rhs )
309  {
310  if ( &rhs != this ) // prevent self assign!
311  {
312  std::swap( _dip, rhs._dip );
313  std::swap( _mstring, rhs._mstring );
314  }
315  }
316  DIWrap & operator=( const DIWrap & rhs )
317  {
318  if ( &rhs != this ) // prevent self assign!
319  DIWrap( rhs ).swap( *this );
320  return *this;
321  }
322  void reset()
323  { DIWrap().swap( *this ); }
324  public:
326  explicit operator bool() const
327  { return _dip; }
328 
329  public:
330  detail::CDataiterator * operator->() const { return _dip; }
331  detail::CDataiterator * get() const { return _dip; }
332  const std::string & getstr() const { return _mstring; }
333 
334  private:
336  std::string _mstring;
337  };
339  std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
340  }
341 
343  //
344  // CLASS NAME : LookupAttr::iterator
345  //
350  class LookupAttr::iterator : public boost::iterator_adaptor<
351  iterator // Derived
352  , detail::CDataiterator * // Base
353  , detail::IdType // Value
354  , boost::forward_traversal_tag // CategoryOrTraversal
355  , detail::IdType // Reference
356  >
357  {
358  public:
362  void nextSkipSolvAttr();
363 
365  void nextSkipSolvable();
366 
368  void nextSkipRepo();
369 
372  { nextSkipSolvAttr(); increment(); }
373 
376  { nextSkipSolvable(); increment(); }
377 
379  void skipRepo()
380  { nextSkipRepo(); increment(); }
381 
383  void stayInThisSolvable();
384 
386  void stayInThisRepo();
388 
392  Repository inRepo() const;
393 
395  Solvable inSolvable() const;
396 
398  SolvAttr inSolvAttr() const;
399 
401  bool atEnd() const
402  { return !_dip; }
404 
408  detail::IdType solvAttrType() const;
409 
411  bool solvAttrNumeric() const;
412 
414  bool solvAttrString() const;
415 
417  bool solvAttrIdString() const;
418 
420  bool solvAttrCheckSum() const;
421 
426  bool solvAttrSubEntry() const;
428 
460  bool subEmpty() const;
461 
465  size_type subSize() const;
466 
470  iterator subBegin() const;
474  iterator subEnd() const;
479  iterator subFind( SolvAttr attr_r ) const;
487  iterator subFind( const C_Str & attrname_r ) const;
489 
493  int asInt() const;
495  unsigned asUnsigned() const;
497  bool asBool() const;
499  unsigned long long asUnsignedLL() const;
500 
502  const char * c_str() const;
507  std::string asString() const;
508 
514  IdString idStr() const;
517  { return idStr().id(); }
518 
520  CheckSum asCheckSum() const;
521 
528  template<class Tp> Tp asType() const { return Tp(id()); }
530 
532  // internal stuff below
534  public:
535  iterator();
536 
537  iterator( const iterator & rhs );
538 
539  iterator & operator=( const iterator & rhs );
540 
541  ~iterator();
542 
543  public:
548  iterator( detail::DIWrap & dip_r );
549 
550  private:
551  friend class boost::iterator_core_access;
552 
553  template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
554  bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
555  {
556  return ( bool(base()) == bool(rhs.base()) )
557  && ( ! base() || dip_equal( *base(), *rhs.base() ) );
558  }
559 
560  bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
561 
562  detail::IdType dereference() const;
563 
564  void increment();
565 
566  public:
568  detail::CDataiterator * get() const
569  { return _dip.get(); }
570  private:
572  };
574 
576  std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj );
577 
579 
582  template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
583  template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
584  template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
585  template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
586  template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
587  template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
588  template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
589  template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
590 
591  template<class TResult, class TAttr>
592  class ArrayAttr;
594 
596  } // namespace sat
599 } // namespace zypp
601 
603 std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator * obj );
604 
606 inline std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator & obj )
607 { return str << &obj; }
608 
609 #endif // ZYPP_SAT_LOOKUPATTR_H
DIWrap()
NULL detail::CDataiterator
Definition: LookupAttr.h:296
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not)
Definition: LookupAttr.cc:228
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition: LookupAttr.h:371
int IdType
Generic Id type.
Definition: PoolMember.h:104
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:213
Solvable solvable() const
Whether to search in one Solvable.
Definition: LookupAttr.cc:222
::_Dataiterator CDataiterator
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:58
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition: LookupAttr.cc:199
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition: StrMatcher.h:297
const StrMatcher & strMatcher() const
The pattern to match.
Definition: LookupAttr.cc:202
Lightweight attribute value lookup.
Definition: LookupAttr.h:107
::_Repo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:133
void resetStrMatcher()
Reset the pattern to match.
IdType id() const
Expert backdoor.
Definition: IdString.h:115
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
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition: LookupAttr.h:554
String related utilities and Regular expression matching.
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
Access to the sat-pools string space.
Definition: IdString.h:41
RWCOW_pointer< Impl > _pimpl
Definition: LookupAttr.h:226
Search for solvable attributes (default)
Definition: LookupAttr.h:117
const std::string & getstr() const
Definition: LookupAttr.h:332
LookupAttr::TransformIterator based container to retrieve list attributes.
Definition: LookupAttr.h:592
Exceptions thrown from attribute matching.
Definition: StrMatcher.h:247
TransformIterator returning an iterator vaue of type TResult.
Definition: LookupAttr.h:162
void skipRepo()
Immediately advance to the next Repository.
Definition: LookupAttr.h:379
LookupAttr()
Default ctor finds nothing.
Definition: LookupAttr.cc:168
LookupAttr implememtation.
Definition: LookupAttr.cc:55
void skipSolvable()
Immediately advance to the next Solvable.
Definition: LookupAttr.h:375
iterator end() const
Iterator behind the end of query results.
Definition: LookupAttr.cc:239
detail::IdType id() const
Definition: LookupAttr.h:516
MatchException Exception
Definition: LookupAttr.h:110
DIWrap & operator=(const DIWrap &rhs)
Definition: LookupAttr.h:316
Solvable attribute keys.
Definition: SolvAttr.h:40
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition: LookupAttr.cc:219
Tp asType() const
Templated return type.
Definition: LookupAttr.h:528
Lightweight repository attribute value lookup.
Definition: LookupAttr.h:257
std::ostream & dumpOn(std::ostream &str, const LookupAttr &obj)
Definition: LookupAttr.cc:272
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:264
Wrapper around sat detail::CDataiterator.
Definition: LookupAttr.h:292
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition: LookupAttr.cc:205
void swap(DIWrap &rhs)
Definition: LookupAttr.h:308
LookupRepoAttr()
Default ctor finds nothing.
Definition: LookupAttr.h:261
bool pool() const
Whether to search in Pool.
Definition: LookupAttr.cc:210
SolvAttr attr() const
The SolvAttr to search.
Definition: LookupAttr.cc:196
Repository repo() const
Whether to search in one Repository.
Definition: LookupAttr.cc:216
detail::CDataiterator * operator->() const
Definition: LookupAttr.h:330
void setPool()
Set search in Pool (all repositories).
Definition: LookupAttr.h:272
std::ostream & operator<<(std::ostream &str, const LookupAttr &obj)
Definition: LookupAttr.cc:255
detail::CDataiterator * _dip
Definition: LookupAttr.h:335
size_type size() const
Ammount of results.
Definition: LookupAttr.cc:245
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition: LookupAttr.h:401
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Location
Specify the where to look for the attribule.
Definition: LookupAttr.h:116
bool empty() const
Whether the query is empty.
Definition: LookupAttr.cc:242
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:236
Search for repository attributes.
Definition: LookupAttr.h:118