libzypp 17.38.7
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 //
35 {
36 public:
38 typedef unsigned size_type;
39
41
42 public:
45 : _begin( 0 )
46 {}
47
49 explicit
51 : _begin( base_r )
52 {}
53
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:
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:
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:
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
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:
168 };
169
170
173
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
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
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 PoolDefines.h:42
bool isDepMarkerId(IdType id_r)
Test for internal ids satlib includes in dependencies.
Definition PoolDefines.h:57
Easy-to use interface to the ZYPP dependency resolver.
bool contains(const Container &c, const Elem &elem)
Definition Algorithm.h:70
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output