libzypp  11.13.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 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 : private base::SafeBool<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:
328 #ifndef SWIG // Swig treats it as syntax error
329 
331 #endif
332  public:
333  ::_Dataiterator * operator->() const { return _dip; }
334  ::_Dataiterator * get() const { return _dip; }
335  const std::string & getstr() const { return _mstring; }
336  private:
338  bool boolTest() const
339  { return _dip; }
340  private:
341  ::_Dataiterator * _dip;
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  , ::_Dataiterator * // 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 
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( 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:
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 ::_Dataiterator & lhs, const ::_Dataiterator & rhs ) const;
567 
568  detail::IdType dereference() const;
569 
570  void increment();
571 
572  public:
574  ::_Dataiterator * 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 _ResultT, class _AttrT>
598  class ArrayAttr;
600 
602  } // namespace sat
605 } // namespace zypp
607 
609 std::ostream & operator<<( std::ostream & str, const ::_Dataiterator * obj );
610 
612 inline std::ostream & operator<<( std::ostream & str, const ::_Dataiterator & obj )
613 { return str << &obj; }
614 
615 #endif // ZYPP_SAT_LOOKUPATTR_H