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_NG_SAT_CAPABILITIES_H
13#define ZYPP_NG_SAT_CAPABILITIES_H
14
15#include <iosfwd>
16#include <iterator>
17#include <type_traits>
18
19#include <zypp-core/base/DefaultIntegral>
21
22namespace zyppng::sat
23{
33 {
34 public:
36 typedef unsigned size_type;
37
39
40 public:
43 : _begin( 0 )
44 {}
45
47 explicit
49 : _begin( base_r )
50 {}
51
56
57 public:
59 bool empty() const
60 { return ! ( _begin && *_begin ); }
61
63 size_type size() const;
64
65 public:
66 class const_iterator;
67
69 const_iterator begin() const;
70
72 const_iterator end() const;
73
74 public:
76 bool contains( const Capability & lhs ) const;
77
79 bool matches( const Capability & lhs ) const;
80
82 Capability findFirstMatch( const Capability & lhs ) const;
83
84 private:
86 };
87
98 {
99 public:
100 using iterator_category = std::forward_iterator_tag;
102 using difference_type = std::ptrdiff_t;
103 using pointer = void; // proxy iterator — no stable address
104 using reference = const Capability;
105
107 : _idx( nullptr ), _tagged( false )
108 {}
109
110 explicit const_iterator( const sat::detail::IdType * idx )
111 : _idx( idx ), _tagged( false )
112 {
113 // Skip an initial dep-marker if present, tagging subsequent entries.
115 {
116 _tagged = true;
117 ++_idx;
118 }
119 }
120
121 public:
139 bool tagged() const { return _tagged; }
140
142 { return _idx ? Capability( *_idx ) : Capability::Null; }
143
145 {
146 // Advance and jump over any libsolv internal dep-marker ids.
147 if ( sat::detail::isDepMarkerId( *(++_idx) ) )
148 {
149 _tagged = true;
150 ++_idx;
151 }
152 return *this;
153 }
154
156 {
157 const_iterator tmp( *this );
158 ++(*this);
159 return tmp;
160 }
161
162 bool operator==( const const_iterator & rhs ) const
163 {
164 // A NULL pointer is equal to a pointer pointing at Id 0 (end sentinel).
165 return ( _idx == rhs._idx )
166 || ( !rhs._idx && _idx && !*_idx )
167 || ( !_idx && rhs._idx && !*rhs._idx );
168 }
169
170 bool operator!=( const const_iterator & rhs ) const
171 { return !( *this == rhs ); }
172
173 private:
176 };
177
178
181
184
185 inline bool Capabilities::contains( const Capability & lhs ) const
186 {
187 for ( const Capability & rhs : *this )
188 if ( lhs == rhs )
189 return true;
190 return false;
191 }
192
193 inline bool Capabilities::matches( const Capability & lhs ) const
194 {
195 for ( const Capability & rhs : *this )
196 if ( lhs.matches( rhs ) == CapMatch::yes )
197 return true;
198 return false;
199 }
200
202 {
203 for ( const Capability & rhs : *this )
204 if ( lhs.matches( rhs ) == CapMatch::yes )
205 return rhs;
206 return Capability::Null;
207 }
208} // namespace zyppng::sat
209#endif // ZYPP_NG_SAT_CAPABILITIES_H
bool contains(const Capability &lhs) const
Return whether the set contains lhs (the Id).
const_iterator begin() const
Iterator pointing to the first Capability.
bool matches(const Capability &lhs) const
Return whether lhs matches at least one capability in set.
Capability findFirstMatch(const Capability &lhs) const
Return the first matching Capability in set or Capability::Null.
const_iterator end() const
Iterator pointing behind the last Capability.
Integral type with defined initial value when default constructed.
static const CapMatch yes
Definition CapMatch.h:52
bool tagged() const
Return true if the Capability is tagged.
const_iterator(const sat::detail::IdType *idx)
bool operator!=(const const_iterator &rhs) const
bool operator==(const const_iterator &rhs) const
zypp::DefaultIntegral< bool, false > _tagged
std::forward_iterator_tag iterator_category
bool empty() const
Whether the container is empty.
bool matches(const Capability &lhs) const
Return whether lhs matches at least one capability in set.
bool contains(const Capability &lhs) const
Return whether the set contains lhs (the Id).
Capabilities(const sat::detail::IdType *base_r)
Ctor from Id pointer (friend Solvable).
const_iterator begin() const
Iterator pointing to the first Capability.
const_iterator end() const
Iterator pointing behind the last Capability.
Capability findFirstMatch(const Capability &lhs) const
Return the first matching Capability in set or Capability::Null.
size_type size() const
Number of capabilities inside.
Capabilities()
Default ctor.
const sat::detail::IdType * _begin
A sat capability.
Definition capability.h:74
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition capability.h:221
static const Capability Null
No or Null Capability ( Id 0 ).
Definition capability.h:182
bool isDepMarkerId(IdType id_r)
Test for internal ids satlib includes in dependencies.
Definition PoolDefines.h:57
zypp::sat::detail::IdType IdType
This file contains private API, this might break at any time between releases.