libzypp  17.38.7
Capabilities.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_SAT_CAPABILITIES_H
13 #define ZYPP_SAT_CAPABILITIES_H
14 
15 #include <iosfwd>
16 
17 #include <zypp-core/base/DefaultIntegral>
18 #include <zypp/Capability.h>
19 
21 namespace zypp
22 {
23 
25  //
26  // CLASS NAME : Capabilities
27  //
35  {
36  public:
38  typedef unsigned size_type;
39 
40  enum Mode { SKIP_TO_INTERNAL };
41 
42  public:
45  : _begin( 0 )
46  {}
47 
49  explicit
51  : _begin( base_r )
52  {}
53 
57  Capabilities( const sat::detail::IdType * base_r, sat::detail::IdType skip_r );
58 
59  public:
61  bool empty() const
62  { return ! ( _begin && *_begin ); }
63 
65  size_type size() const;
66 
67  public:
68  class const_iterator;
69 
71  const_iterator begin() const;
72 
74  const_iterator end() const;
75 
76  public:
78  bool contains( const Capability & lhs ) const;
79 
81  bool matches( const Capability & lhs ) const;
82 
84  Capability findFirstMatch( const Capability & lhs ) const;
85 
86  private:
88  };
90 
92  std::ostream & operator<<( std::ostream & str, const Capabilities & obj );
93 
95  //
96  // CLASS NAME : Capabilities::const_iterator
97  //
100  class Capabilities::const_iterator : public boost::iterator_adaptor<
101  const_iterator // Derived
102  , const sat::detail::IdType * // Base
103  , const Capability // Value
104  , boost::forward_traversal_tag // CategoryOrTraversal
105  , const Capability // Reference
106  >
107  {
108  public:
110  : const_iterator::iterator_adaptor_( 0 )
111  {}
112 
113  explicit const_iterator( const sat::detail::IdType * _idx )
114  : const_iterator::iterator_adaptor_( _idx )
115  {
116  if ( base_reference() && sat::detail::isDepMarkerId( *base_reference() ) )
117  {
118  _tagged = true;
119  ++base_reference();
120  }
121  }
122 
123  public:
141  bool tagged() const { return _tagged; }
142 
143  private:
145 
146  reference dereference() const
147  { return ( base() ) ? Capability( *base() ) : Capability::Null; }
148 
149  template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
150  bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
151  { // NULL pointer is eqal pointer to Id 0
152  return ( base() == rhs.base() // includes both NULL...
153  || ( !rhs.base() && !*base() )
154  || ( !base() && !*rhs.base() ) );
155  }
156 
157  void increment()
158  { // jump over libsolvs internal ids.
159  if ( sat::detail::isDepMarkerId( *(++base_reference()) ) )
160  {
161  _tagged = true;
162  ++base_reference();
163  }
164  }
165 
166  private:
168  };
170 
172  { return const_iterator( _begin ); }
173 
175  { return const_iterator( 0 ); }
176 
177  inline bool Capabilities::contains( const Capability & lhs ) const
178  {
179  for ( const Capability & rhs : *this )
180  if ( lhs == rhs )
181  return true;
182  return false;
183  }
184 
185  inline bool Capabilities::matches( const Capability & lhs ) const
186  {
187  for ( const Capability & rhs : *this )
188  if ( lhs.matches( rhs ) == CapMatch::yes )
189  return true;
190  return false;
191  }
192 
194  {
195  for ( const Capability & rhs : *this )
196  if ( lhs.matches( rhs ) == CapMatch::yes )
197  return rhs;
198  return Capability::Null;
199  }
200 
202 } // namespace zypp
204 #endif // ZYPP_SAT_CAPABILITIES_H
Capabilities(const sat::detail::IdType *base_r)
Ctor from Id pointer (friend Solvable).
Definition: Capabilities.h:50
Container of Capability (currently read only).
Definition: Capabilities.h:34
const_iterator end() const
Iterator pointing behind the last Capability.
Definition: Capabilities.h:174
bool contains(const Capability &lhs) const
Return whether the set contains lhs (the Id)
Definition: Capabilities.h:177
String related utilities and Regular expression matching.
int IdType
Generic Id type.
Definition: PoolDefines.h:42
const_iterator(const sat::detail::IdType *_idx)
Definition: Capabilities.h:113
bool contains(const Container &c, const Elem &elem)
Definition: Algorithm.h:70
const_iterator begin() const
Iterator pointing to the first Capability.
Definition: Capabilities.h:171
Capability value_type
Definition: Capabilities.h:37
Capabilities()
Default ctor.
Definition: Capabilities.h:44
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition: Arch.h:173
static const Capability Null
No or Null Capability ( Id 0 ).
Definition: Capability.h:172
SolvableIdType size_type
Definition: poolconstants.h:59
bool isDepMarkerId(IdType id_r)
Test for internal ids satlib includes in dependencies.
Definition: PoolDefines.h:57
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition: Capabilities.h:150
bool tagged() const
Return true if the Capability is tagged.
Definition: Capabilities.h:141
const sat::detail::IdType * _begin
Definition: Capabilities.h:87
A sat capability.
Definition: Capability.h:62
Capabilities iterator.
Definition: Capabilities.h:100
Capability findFirstMatch(const Capability &lhs) const
Return the first matching Capability in set or Capability::Null.
Definition: Capabilities.h:193
friend class boost::iterator_core_access
Definition: Capabilities.h:144
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition: Capabilities.cc:65
static const CapMatch yes
Definition: CapMatch.h:52
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool matches(const Capability &lhs) const
Return whether lhs matches at least one capability in set.
Definition: Capabilities.h:185
bool empty() const
Whether the container is empty.
Definition: Capabilities.h:61
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:211
DefaultIntegral< bool, false > _tagged
Definition: Capabilities.h:167