libzypp: zypp/ng/sat/capabilities.h Source File

libzypp 17.38.14

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>
20#include <zypp/ng/sat/capability.h>
21
22namespace zyppng::sat
23{
32 class Capabilities
33 {
34 public:
35 typedef Capability value_type;
36 typedef unsigned size_type;
37
38 enum Mode { SKIP_TO_INTERNAL };
39
40 public:
42 Capabilities()
43 : _begin( 0 )
44 {}
45
47 explicit
48 Capabilities( const sat::detail::IdType * base_r )
49 : _begin( base_r )
50 {}
51
55 Capabilities( const sat::detail::IdType * base_r, sat::detail::IdType skip_r );
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:
85 const sat::detail::IdType * _begin;
86 };
87
97 class Capabilities::const_iterator
98 {
99 public:
100 using iterator_category = std::forward_iterator_tag;
101 using value_type = Capability;
102 using difference_type = std::ptrdiff_t;
103 using pointer = void; // proxy iterator — no stable address
104 using reference = const Capability;
105
106 const_iterator()
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.
114 if ( _idx && sat::detail::isDepMarkerId( *_idx ) )
115 {
116 _tagged = true;
117 ++_idx;
118 }
119 }
120
121 public:
139 bool tagged() const { return _tagged; }
140
141 reference operator*() const
142 { return _idx ? Capability( *_idx ) : Capability::Null; }
143
144 const_iterator & operator++()
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
155 const_iterator operator++(int)
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:
174 const sat::detail::IdType * _idx;
175 zypp::DefaultIntegral<bool,false> _tagged;
176 };
177
178
179 inline Capabilities::const_iterator Capabilities::begin() const
180 { return const_iterator( _begin ); }
181
182 inline Capabilities::const_iterator Capabilities::end() const
183 { return const_iterator( 0 ); }
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
201 inline Capability Capabilities::findFirstMatch( const Capability & lhs ) const
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
zypp::Capabilities::contains
bool contains(const Capability &lhs) const
Return whether the set contains lhs (the Id).
Definition Capabilities.h:177
zypp::Capabilities::begin
const_iterator begin() const
Iterator pointing to the first Capability.
Definition Capabilities.h:171
zypp::Capabilities::matches
bool matches(const Capability &lhs) const
Return whether lhs matches at least one capability in set.
Definition Capabilities.h:185
zypp::Capabilities::findFirstMatch
Capability findFirstMatch(const Capability &lhs) const
Return the first matching Capability in set or Capability::Null.
Definition Capabilities.h:193
zypp::Capabilities::end
const_iterator end() const
Iterator pointing behind the last Capability.
Definition Capabilities.h:174
zypp::DefaultIntegral
Integral type with defined initial value when default constructed.
Definition defaultintegral.h:42
zyppng::CapMatch::yes
static const CapMatch yes
Definition CapMatch.h:52
zyppng::sat::Capabilities::const_iterator
Capabilities iterator.
Definition capabilities.h:98
zyppng::sat::Capabilities::const_iterator::difference_type
std::ptrdiff_t difference_type
Definition capabilities.h:102
zyppng::sat::Capabilities::const_iterator::tagged
bool tagged() const
Return true if the Capability is tagged.
Definition capabilities.h:139
zyppng::sat::Capabilities::const_iterator::operator++
const_iterator & operator++()
Definition capabilities.h:144
zyppng::sat::Capabilities::const_iterator::const_iterator
const_iterator(const sat::detail::IdType *idx)
Definition capabilities.h:110
zyppng::sat::Capabilities::const_iterator::operator!=
bool operator!=(const const_iterator &rhs) const
Definition capabilities.h:170
zyppng::sat::Capabilities::const_iterator::pointer
void pointer
Definition capabilities.h:103
zyppng::sat::Capabilities::const_iterator::const_iterator
const_iterator()
Definition capabilities.h:106
zyppng::sat::Capabilities::const_iterator::value_type
Capability value_type
Definition capabilities.h:101
zyppng::sat::Capabilities::const_iterator::operator++
const_iterator operator++(int)
Definition capabilities.h:155
zyppng::sat::Capabilities::const_iterator::operator==
bool operator==(const const_iterator &rhs) const
Definition capabilities.h:162
zyppng::sat::Capabilities::const_iterator::reference
const Capability reference
Definition capabilities.h:104
zyppng::sat::Capabilities::const_iterator::_tagged
zypp::DefaultIntegral< bool, false > _tagged
Definition capabilities.h:175
zyppng::sat::Capabilities::const_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition capabilities.h:100
zyppng::sat::Capabilities::const_iterator::_idx
const sat::detail::IdType * _idx
Definition capabilities.h:174
zyppng::sat::Capabilities::const_iterator::operator*
reference operator*() const
Definition capabilities.h:141
zyppng::sat::Capabilities::empty
bool empty() const
Whether the container is empty.
Definition capabilities.h:59
zyppng::sat::Capabilities::matches
bool matches(const Capability &lhs) const
Return whether lhs matches at least one capability in set.
Definition capabilities.h:193
zyppng::sat::Capabilities::Capabilities
Capabilities(const sat::detail::IdType *base_r)
Ctor from Id pointer (friend Solvable).
Definition capabilities.h:48
zyppng::sat::Capabilities::begin
const_iterator begin() const
Iterator pointing to the first Capability.
Definition capabilities.h:179
zyppng::sat::Capabilities::value_type
Capability value_type
Definition capabilities.h:35
zyppng::sat::Capabilities::Mode
Mode
Definition capabilities.h:38
zyppng::sat::Capabilities::SKIP_TO_INTERNAL
@ SKIP_TO_INTERNAL
Definition capabilities.h:38
zyppng::sat::Capabilities::end
const_iterator end() const
Iterator pointing behind the last Capability.
Definition capabilities.h:182
zyppng::sat::Capabilities::findFirstMatch
Capability findFirstMatch(const Capability &lhs) const
Return the first matching Capability in set or Capability::Null.
Definition capabilities.h:201
zyppng::sat::Capabilities::size
size_type size() const
Number of capabilities inside.
Definition capabilities.cc:44
zyppng::sat::Capabilities::size_type
unsigned size_type
Definition capabilities.h:36
zyppng::sat::Capabilities::Capabilities
Capabilities()
Default ctor.
Definition capabilities.h:42
zyppng::sat::Capabilities::_begin
const sat::detail::IdType * _begin
Definition capabilities.h:85
zyppng::sat::Capability
A sat capability.
Definition capability.h:74
zyppng::sat::Capability::matches
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition capability.h:221
zyppng::sat::Capability::Null
static const Capability Null
No or Null Capability ( Id 0 ).
Definition capability.h:182
zyppng::sat::Capability::Capability
Capability()
Default ctor, Empty capability.
Definition capability.h:80
zypp::contains
bool contains(const Container &c, const Elem &elem)
Definition Algorithm.h:70
zyppng::sat::detail::isDepMarkerId
bool isDepMarkerId(IdType id_r)
Test for internal ids satlib includes in dependencies.
Definition PoolDefines.h:57
zyppng::sat::detail::IdType
zypp::sat::detail::IdType IdType
Definition poolconstants.h:43
zyppng::sat
This file contains private API, this might break at any time between releases.
Definition capabilities.h:22
capability.h