libzypp 17.38.3
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>
19#include <zypp/Capability.h>
20
22namespace zypp
23{
24
26 //
27 // CLASS NAME : Capabilities
28 //
36 {
37 public:
39 typedef unsigned size_type;
40
42
43 public:
46 : _begin( 0 )
47 {}
48
50 explicit
52 : _begin( base_r )
53 {}
54
59
60 public:
62 bool empty() const
63 { return ! ( _begin && *_begin ); }
64
66 size_type size() const;
67
68 public:
69 class const_iterator;
70
72 const_iterator begin() const;
73
75 const_iterator end() const;
76
77 public:
79 bool contains( const Capability & lhs ) const;
80
82 bool matches( const Capability & lhs ) const;
83
85 Capability findFirstMatch( const Capability & lhs ) const;
86
87 private:
89 };
90
91
93 std::ostream & operator<<( std::ostream & str, const Capabilities & obj );
94
96 //
97 // CLASS NAME : Capabilities::const_iterator
98 //
101 class Capabilities::const_iterator : public boost::iterator_adaptor<
102 const_iterator // Derived
103 , const sat::detail::IdType * // Base
104 , const Capability // Value
105 , boost::forward_traversal_tag // CategoryOrTraversal
106 , const Capability // Reference
107 >
108 {
109 public:
111 : const_iterator::iterator_adaptor_( 0 )
112 {}
113
114 explicit const_iterator( const sat::detail::IdType * _idx )
115 : const_iterator::iterator_adaptor_( _idx )
116 {
117 if ( base_reference() && sat::detail::isDepMarkerId( *base_reference() ) )
118 {
119 _tagged = true;
120 ++base_reference();
121 }
122 }
123
124 public:
142 bool tagged() const { return _tagged; }
143
144 private:
146
147 reference dereference() const
148 { return ( base() ) ? Capability( *base() ) : Capability::Null; }
149
150 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
151 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
152 { // NULL pointer is eqal pointer to Id 0
153 return ( base() == rhs.base() // includes both NULL...
154 || ( !rhs.base() && !*base() )
155 || ( !base() && !*rhs.base() ) );
156 }
157
159 { // jump over libsolvs internal ids.
160 if ( sat::detail::isDepMarkerId( *(++base_reference()) ) )
161 {
162 _tagged = true;
163 ++base_reference();
164 }
165 }
166
167 private:
169 };
170
171
174
177
178 inline bool Capabilities::contains( const Capability & lhs ) const
179 {
180 for ( const Capability & rhs : *this )
181 if ( lhs == rhs )
182 return true;
183 return false;
184 }
185
186 inline bool Capabilities::matches( const Capability & lhs ) const
187 {
188 for ( const Capability & rhs : *this )
189 if ( lhs.matches( rhs ) == CapMatch::yes )
190 return true;
191 return false;
192 }
193
195 {
196 for ( const Capability & rhs : *this )
197 if ( lhs.matches( rhs ) == CapMatch::yes )
198 return rhs;
199 return Capability::Null;
200 }
201
203} // namespace zypp
205#endif // ZYPP_SAT_CAPABILITIES_H
static const CapMatch yes
Definition CapMatch.h:52
DefaultIntegral< bool, false > _tagged
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
const_iterator(const sat::detail::IdType *_idx)
friend class boost::iterator_core_access
bool tagged() const
Return true if the Capability is tagged.
Container of Capability (currently read only).
Capability value_type
Capabilities(const sat::detail::IdType *base_r)
Ctor from Id pointer (friend Solvable).
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.
const sat::detail::IdType * _begin
bool empty() const
Whether the container is empty.
Capabilities()
Default ctor.
A sat capability.
Definition Capability.h:63
static const Capability Null
No or Null Capability ( Id 0 ).
Definition Capability.h:172
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition Capability.h:211
Integral type with defined initial value when default constructed.
String related utilities and Regular expression matching.
int IdType
Generic Id type.
Definition PoolMember.h:104
bool isDepMarkerId(IdType id_r)
Test for internal ids satlib includes in dependencies.
Definition PoolMember.h:119
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
bool contains(const Container &c, const Elem &elem)
Definition Algorithm.h:70
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247