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

libzypp 17.38.6

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
17#include <zypp-core/base/DefaultIntegral>
18#include <zypp/ng/sat/capability.h>
19
20namespace zyppng::sat
21{
30 class Capabilities
31 {
32 public:
33 typedef Capability value_type;
34 typedef unsigned size_type;
35
36 enum Mode { SKIP_TO_INTERNAL };
37
38 public:
40 Capabilities()
41 : _begin( 0 )
42 {}
43
45 explicit
46 Capabilities( const sat::detail::IdType * base_r )
47 : _begin( base_r )
48 {}
49
53 Capabilities( const sat::detail::IdType * base_r, sat::detail::IdType skip_r );
54
55 public:
57 bool empty() const
58 { return ! ( _begin && *_begin ); }
59
61 size_type size() const;
62
63 public:
64 class const_iterator;
65
67 const_iterator begin() const;
68
70 const_iterator end() const;
71
72 public:
74 bool contains( const Capability & lhs ) const;
75
77 bool matches( const Capability & lhs ) const;
78
80 Capability findFirstMatch( const Capability & lhs ) const;
81
82 private:
83 const sat::detail::IdType * _begin;
84 };
85
90 class Capabilities::const_iterator : public boost::iterator_adaptor<
91 const_iterator // Derived
92 , const sat::detail::IdType * // Base
93 , const Capability // Value
94 , boost::forward_traversal_tag // CategoryOrTraversal
95 , const Capability // Reference
96 >
97 {
98 public:
99 const_iterator()
100 : const_iterator::iterator_adaptor_( 0 )
101 {}
102
103 explicit const_iterator( const sat::detail::IdType * _idx )
104 : const_iterator::iterator_adaptor_( _idx )
105 {
106 if ( base_reference() && sat::detail::isDepMarkerId( *base_reference() ) )
107 {
108 _tagged = true;
109 ++base_reference();
110 }
111 }
112
113 public:
131 bool tagged() const { return _tagged; }
132
133 private:
134 friend class boost::iterator_core_access;
135
136 reference dereference() const
137 { return ( base() ) ? Capability( *base() ) : Capability::Null; }
138
139 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
140 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
141 { // NULL pointer is eqal pointer to Id 0
142 return ( base() == rhs.base() // includes both NULL...
143 || ( !rhs.base() && !*base() )
144 || ( !base() && !*rhs.base() ) );
145 }
146
147 void increment()
148 { // jump over libsolvs internal ids.
149 if ( sat::detail::isDepMarkerId( *(++base_reference()) ) )
150 {
151 _tagged = true;
152 ++base_reference();
153 }
154 }
155
156 private:
157 zypp::DefaultIntegral<bool,false> _tagged;
158 };
159
160
161 inline Capabilities::const_iterator Capabilities::begin() const
162 { return const_iterator( _begin ); }
163
164 inline Capabilities::const_iterator Capabilities::end() const
165 { return const_iterator( 0 ); }
166
167 inline bool Capabilities::contains( const Capability & lhs ) const
168 {
169 for ( const Capability & rhs : *this )
170 if ( lhs == rhs )
171 return true;
172 return false;
173 }
174
175 inline bool Capabilities::matches( const Capability & lhs ) const
176 {
177 for ( const Capability & rhs : *this )
178 if ( lhs.matches( rhs ) == CapMatch::yes )
179 return true;
180 return false;
181 }
182
183 inline Capability Capabilities::findFirstMatch( const Capability & lhs ) const
184 {
185 for ( const Capability & rhs : *this )
186 if ( lhs.matches( rhs ) == CapMatch::yes )
187 return rhs;
188 return Capability::Null;
189 }
190} // namespace zyppng::sat
191#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:97
zyppng::sat::Capabilities::const_iterator::tagged
bool tagged() const
Return true if the Capability is tagged.
Definition capabilities.h:131
zyppng::sat::Capabilities::const_iterator::const_iterator
const_iterator(const sat::detail::IdType *_idx)
Definition capabilities.h:103
zyppng::sat::Capabilities::const_iterator::const_iterator
const_iterator()
Definition capabilities.h:99
zyppng::sat::Capabilities::const_iterator::_tagged
zypp::DefaultIntegral< bool, false > _tagged
Definition capabilities.h:157
zyppng::sat::Capabilities::const_iterator::dereference
reference dereference() const
Definition capabilities.h:136
zyppng::sat::Capabilities::const_iterator::iterator_core_access
friend class boost::iterator_core_access
Definition capabilities.h:134
zyppng::sat::Capabilities::const_iterator::increment
void increment()
Definition capabilities.h:147
zyppng::sat::Capabilities::const_iterator::equal
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition capabilities.h:140
zyppng::sat::Capabilities::empty
bool empty() const
Whether the container is empty.
Definition capabilities.h:57
zyppng::sat::Capabilities::matches
bool matches(const Capability &lhs) const
Return whether lhs matches at least one capability in set.
Definition capabilities.h:175
zyppng::sat::Capabilities::contains
bool contains(const Capability &lhs) const
Return whether the set contains lhs (the Id).
Definition capabilities.h:167
zyppng::sat::Capabilities::Capabilities
Capabilities(const sat::detail::IdType *base_r)
Ctor from Id pointer (friend Solvable).
Definition capabilities.h:46
zyppng::sat::Capabilities::begin
const_iterator begin() const
Iterator pointing to the first Capability.
Definition capabilities.h:161
zyppng::sat::Capabilities::value_type
Capability value_type
Definition capabilities.h:33
zyppng::sat::Capabilities::Mode
Mode
Definition capabilities.h:36
zyppng::sat::Capabilities::SKIP_TO_INTERNAL
@ SKIP_TO_INTERNAL
Definition capabilities.h:36
zyppng::sat::Capabilities::end
const_iterator end() const
Iterator pointing behind the last Capability.
Definition capabilities.h:164
zyppng::sat::Capabilities::findFirstMatch
Capability findFirstMatch(const Capability &lhs) const
Return the first matching Capability in set or Capability::Null.
Definition capabilities.h:183
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:34
zyppng::sat::Capabilities::Capabilities
Capabilities()
Default ctor.
Definition capabilities.h:40
zyppng::sat::Capabilities::_begin
const sat::detail::IdType * _begin
Definition capabilities.h:83
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
zypp::base
Definition Random.cc:7
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