libzypp  15.28.6
WhatProvides.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_SAT_WHATPROVIDES_H
13 #define ZYPP_SAT_WHATPROVIDES_H
14 
15 #include <iosfwd>
16 #include <vector>
17 
18 #include "zypp/base/PtrTypes.h"
20 #include "zypp/sat/Solvable.h"
21 #include "zypp/sat/SolvIterMixin.h"
22 
24 namespace zypp
25 {
26  namespace sat
28  {
29 
30  namespace detail
31  {
32  class WhatProvidesIterator;
33  }
34 
36  //
37  // CLASS NAME : WhatProvides
38  //
87  class WhatProvides : public SolvIterMixin<WhatProvides,detail::WhatProvidesIterator>,
88  protected detail::PoolMember
89  {
90  public:
92  typedef unsigned size_type;
93 
94  public:
96  WhatProvides();
97 
99  explicit
100  WhatProvides( Capability cap_r );
101 
103  explicit
104  WhatProvides( Capabilities caps_r );
105 
107  explicit
108  WhatProvides( const CapabilitySet & caps_r );
109 
110  public:
112  bool empty() const;
113 
115  size_type size() const;
116 
117  public:
119 
121  const_iterator begin() const;
122 
124  const_iterator end() const;
125 
126  private:
127  struct Impl;
129  };
131 
133  std::ostream & operator<<( std::ostream & str, const WhatProvides & obj );
134 
135  namespace detail
136  {
138  //
139  // CLASS NAME : WhatProvides::const_iterator
140  //
146  class WhatProvidesIterator : public boost::iterator_adaptor<
147  WhatProvidesIterator // Derived
148  , const detail::IdType * // Base
149  , const Solvable // Value
150  , boost::forward_traversal_tag // CategoryOrTraversal
151  , const Solvable // Reference
152  >
153  {
154  friend std::ostream & operator<<( std::ostream & str, const WhatProvidesIterator & obj );
155  public:
157  : iterator_adaptor_( 0 ), _baseRef( 0 ), _offset( 0 )
158  {}
159 
163  explicit WhatProvidesIterator( const detail::IdType *const base_r, unsigned offset_r = 0 )
164  : iterator_adaptor_( base_r ), _baseRef( base_r ? &base_reference() : 0 ), _offset( offset_r )
165  {}
166 
170  explicit WhatProvidesIterator( const detail::IdType *const* baseRef_r, unsigned offset_r )
171  : iterator_adaptor_( 0 ), _baseRef( baseRef_r ), _offset( offset_r )
172  {}
173 
176  : iterator_adaptor_( rhs.base_reference() )
177  , _baseRef( base_reference() ? &base_reference() : rhs._baseRef )
178  , _offset( rhs._offset )
179  {}
180 
183  {
184  if ( this != &rhs ) // no self assign
185  {
186  base_reference() = rhs.base_reference();
187  _baseRef = ( base_reference() ? &base_reference() : rhs._baseRef );
188  _offset = rhs._offset;
189  }
190  return *this;
191  }
192 
193  private:
195 
196  reference dereference() const
197  { return Solvable( getId() ); }
198 #if 0
199  template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
200  bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
201 #endif
202  bool equal( const WhatProvidesIterator & rhs ) const
203  {
204  if ( ! ( getId() || rhs.getId() ) )
205  return true; // both @end
206  if ( _offset != rhs._offset )
207  return false;
208  if ( base_reference() )
209  return( base_reference() == rhs.base_reference() );
210  return( _baseRef == rhs._baseRef );
211  }
212 
213  void increment()
214  { ++_offset; }
215 
217  { return _baseRef ? (*_baseRef)[_offset] : detail::noId; }
218 
219  private:
220  const detail::IdType *const* _baseRef;
221  unsigned _offset;
222  };
224  }
225 
227  { return const_iterator(); }
228 
230  } // namespace sat
233 } // namespace zypp
235 #endif // ZYPP_SAT_WHATPROVIDES_H
const detail::IdType *const * _baseRef
Definition: WhatProvides.h:220
int IdType
Generic Id type.
Definition: PoolMember.h:130
A Solvable object within the sat Pool.
Definition: Solvable.h:53
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:87
Container of Capability (currently read only).
Definition: Capabilities.h:35
friend std::ostream & operator<<(std::ostream &str, const WhatProvidesIterator &obj)
detail::WhatProvidesIterator const_iterator
Definition: WhatProvides.h:118
bool empty() const
Whether the container is empty.
WhatProvidesIterator & operator=(const WhatProvidesIterator &rhs)
Assignment operator required to keep _baseRef adjusted.
Definition: WhatProvides.h:182
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
WhatProvidesIterator(const detail::IdType *const *baseRef_r, unsigned offset_r)
Ctor with pointer to pointer to 1st elemment of an array.
Definition: WhatProvides.h:170
Base class providing common iterator types based on a Solvable iterator.
Backlink to the associated PoolImpl.
Definition: PoolMember.h:114
const_iterator begin() const
Iterator pointing to the first Solvable.
WhatProvidesIterator(const detail::IdType *const base_r, unsigned offset_r=0)
Ctor with pointer to 1st elemment of an array.
Definition: WhatProvides.h:163
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: WhatProvides.h:226
WhatProvidesIterator(const WhatProvidesIterator &rhs)
Copy-ctor required to keep _baseRef adjusted.
Definition: WhatProvides.h:175
WhatProvides implementation date.
Definition: WhatProvides.cc:41
WhatProvides()
Default ctor.
Definition: WhatProvides.cc:94
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
size_type size() const
Number of solvables inside.
A sat capability.
Definition: Capability.h:59
static const IdType noId(0)
bool equal(const WhatProvidesIterator &rhs) const
Definition: WhatProvides.h:202
RW_pointer< Impl > _pimpl
Definition: WhatProvides.h:127