libzypp: zypp/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_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
21namespace zypp
22{
23
25 //
26 // CLASS NAME : Capabilities
27 //
34 class ZYPP_API Capabilities
35 {
36 public:
37 typedef Capability value_type;
38 typedef unsigned size_type;
39
40 enum Mode { SKIP_TO_INTERNAL };
41
42 public:
44 Capabilities()
45 : _begin( 0 )
46 {}
47
49 explicit
50 Capabilities( const sat::detail::IdType * base_r )
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:
87 const sat::detail::IdType * _begin;
88 };
89
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:
109 const_iterator()
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:
144 friend class boost::iterator_core_access;
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:
167 DefaultIntegral<bool,false> _tagged;
168 };
169
170
171 inline Capabilities::const_iterator Capabilities::begin() const
172 { return const_iterator( _begin ); }
173
174 inline Capabilities::const_iterator Capabilities::end() const
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
193 inline Capability Capabilities::findFirstMatch( const Capability & lhs ) const
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
Capability.h
zypp::CapMatch::yes
static const CapMatch yes
Definition CapMatch.h:52
zypp::Capabilities::const_iterator
Capabilities iterator.
Definition Capabilities.h:107
zypp::Capabilities::const_iterator::_tagged
DefaultIntegral< bool, false > _tagged
Definition Capabilities.h:167
zypp::Capabilities::const_iterator::increment
void increment()
Definition Capabilities.h:157
zypp::Capabilities::const_iterator::const_iterator
const_iterator()
Definition Capabilities.h:109
zypp::Capabilities::const_iterator::equal
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition Capabilities.h:150
zypp::Capabilities::const_iterator::dereference
reference dereference() const
Definition Capabilities.h:146
zypp::Capabilities::const_iterator::const_iterator
const_iterator(const sat::detail::IdType *_idx)
Definition Capabilities.h:113
zypp::Capabilities::const_iterator::iterator_core_access
friend class boost::iterator_core_access
Definition Capabilities.h:144
zypp::Capabilities::const_iterator::tagged
bool tagged() const
Return true if the Capability is tagged.
Definition Capabilities.h:141
zypp::Capabilities
Container of Capability (currently read only).
Definition Capabilities.h:35
zypp::Capabilities::value_type
Capability value_type
Definition Capabilities.h:37
zypp::Capabilities::Capabilities
Capabilities(const sat::detail::IdType *base_r)
Ctor from Id pointer (friend Solvable).
Definition Capabilities.h:50
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::Capabilities::size_type
unsigned size_type
Definition Capabilities.h:38
zypp::Capabilities::_begin
const sat::detail::IdType * _begin
Definition Capabilities.h:87
zypp::Capabilities::empty
bool empty() const
Whether the container is empty.
Definition Capabilities.h:61
zypp::Capabilities::Mode
Mode
Definition Capabilities.h:40
zypp::Capabilities::SKIP_TO_INTERNAL
@ SKIP_TO_INTERNAL
Definition Capabilities.h:40
zypp::Capabilities::Capabilities
Capabilities()
Default ctor.
Definition Capabilities.h:44
zypp::Capability
A sat capability.
Definition Capability.h:63
zypp::Capability::Null
static const Capability Null
No or Null Capability ( Id 0 ).
Definition Capability.h:172
zypp::Capability::matches
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition Capability.h:211
zypp::DefaultIntegral
Integral type with defined initial value when default constructed.
Definition defaultintegral.h:42
str
String related utilities and Regular expression matching.
zypp::base
Definition Random.cc:7
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition PoolDefines.h:42
zypp::sat::detail::isDepMarkerId
bool isDepMarkerId(IdType id_r)
Test for internal ids satlib includes in dependencies.
Definition PoolDefines.h:57
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::contains
bool contains(const Container &c, const Elem &elem)
Definition Algorithm.h:70
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65