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>
19
20namespace zyppng::sat
21{
31 {
32 public:
34 typedef unsigned size_type;
35
37
38 public:
41 : _begin( 0 )
42 {}
43
45 explicit
47 : _begin( base_r )
48 {}
49
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:
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:
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:
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
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:
158 };
159
160
163
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
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
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)
zypp::DefaultIntegral< bool, false > _tagged
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
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.