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

libzypp 17.38.9

capability.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_CAPABILITY_H
13#define ZYPP_CAPABILITY_H
14
15#include <iosfwd>
16
17#include <zypp-core/Globals.h>
18#include <zypp/ng/sat/poolconstants.h>
19#include <zypp/ng/sat/poolmember.h>
20
21#include <zypp/ng/arch.h>
22#include <zypp/ng/idstring.h>
23#include <zypp/ng/edition.h>
24#include <zypp/ng/rel.h>
25#include <zypp/ng/restraits.h>
26#include <zypp/ng/resolvernamespace.h>
27#include <zypp/ng/capmatch.h>
28#include <zypp/ng/reskind.h>
29
30namespace zyppng::sat
31{
32 class Capability;
33 class CapDetail;
34
35 using CapabilitySet = std::unordered_set<Capability>;
36
73 class Capability
74 {
75 public:
76 enum CtorFlag { PARSED, UNPARSED };
77
78 public:
80 Capability() : _id( sat::detail::emptyId ) {}
81
83 explicit Capability( sat::detail::IdType id_r ) : _id( id_r ) {}
84
88
100 explicit Capability( const char * str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
102 explicit Capability( const std::string & str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
104 Capability( const Arch & arch_r, const char * str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
106 Capability( const Arch & arch_r, const std::string & str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
107
109 Capability( const char * str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
111 Capability( const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
113 Capability( const Arch & arch_r, const char * str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
115 Capability( const Arch & arch_r, const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
117
118
122
123 Capability( const std::string & name_r, const std::string & op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
125 Capability( const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
127 Capability( const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
129
133
134 Capability( const std::string & arch_r, const std::string & name_r, const std::string & op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
136 Capability( const std::string & arch_r, const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
138 Capability( const std::string & arch_r, const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
140 Capability( const Arch & arch_r, const std::string & name_r, const std::string & op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
142 Capability( const Arch & arch_r, const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
144 Capability( const Arch & arch_r, const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
146
152 Capability( ResolverNamespace namespace_r, IdString value_r = IdString::Null );
153 Capability( ResolverNamespace namespace_r, const char * value_r ) : Capability( namespace_r, IdString(value_r) ) {}
154 Capability( ResolverNamespace namespace_r, const std::string & value_r ) : Capability( namespace_r, IdString(value_r) ) {}
156
158
161 enum CapRel
162 {
163 CAP_AND = 16,
164 CAP_OR = 17,
165
166 CAP_COND = 22,
167 CAP_UNLESS = 29,
168 CAP_ELSE = 26,
169
170 CAP_WITH = 18,
171 CAP_WITHOUT = 28,
172
173 CAP_NAMESPACE = 19,
174 CAP_ARCH = 20,
175 };
176
177 Capability( CapRel rel_r, const Capability & lhs_r, const Capability & rhs_r );
179
180 public:
182 static const Capability Null;
183
185 static const Capability Empty;
186
187 public:
189 explicit operator bool() const
190 { return ! empty(); }
191
195 bool empty() const
196 { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
197
198 public:
200 const char * c_str() const;
201
203 std::string asString() const
204 { return c_str(); }
205
206 public:
208 CapDetail detail() const;
209
210 public:
221 static CapMatch matches( const Capability & lhs, const Capability & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
222 static CapMatch matches( const Capability & lhs, const IdString & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
223 static CapMatch matches( const Capability & lhs, const std::string & rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
224 static CapMatch matches( const Capability & lhs, const char * rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() );}
225
226 static CapMatch matches( const IdString & lhs, const Capability & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
227 static CapMatch matches( const IdString & lhs, const IdString & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
228 static CapMatch matches( const IdString & lhs, const std::string & rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
229 static CapMatch matches( const IdString & lhs, const char * rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
230
231 static CapMatch matches( const std::string & lhs, const Capability & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() );}
232 static CapMatch matches( const std::string & lhs, const IdString & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() ); }
233 static CapMatch matches( const std::string & lhs, const std::string & rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
234 static CapMatch matches( const std::string & lhs, const char * rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
235
236 static CapMatch matches( const char * lhs, const Capability & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() );}
237 static CapMatch matches( const char * lhs, const IdString & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() ); }
238 static CapMatch matches( const char * lhs, const std::string & rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
239 static CapMatch matches( const char * lhs, const char * rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
240
241 CapMatch matches( const Capability & rhs ) const { return _doMatch( id(), rhs.id() ); }
242 CapMatch matches( const IdString & rhs ) const { return _doMatch( id(), rhs.id() ); }
243 CapMatch matches( const std::string & rhs ) const { return _doMatch( id(), Capability(rhs).id() ); }
244 CapMatch matches( const char * rhs ) const { return _doMatch( id(), Capability(rhs).id() ); }
246
249 struct Matches
250 {
251 CapMatch operator()( const Capability & lhs, const Capability & rhs ) const
252 { return Capability::matches( lhs, rhs ); }
253 };
254
255 public:
261 static bool isInterestingFileSpec( const IdString & name_r ) { return isInterestingFileSpec( name_r.c_str() ); }
262 static bool isInterestingFileSpec( const std::string & name_r ) { return isInterestingFileSpec( name_r.c_str() ); }
263 static bool isInterestingFileSpec( const char * name_r );
264
265#if MOVE_CODE_FROM_LEGACY
266
291 static Capability guessPackageSpec( const std::string & str_r );
296 static Capability guessPackageSpec( const std::string & str_r, bool & rewrote_r );
297#endif
298
299 public:
301 sat::detail::IdType id() const
302 { return _id; }
303 private:
305 static CapMatch _doMatch( sat::detail::IdType lhs, sat::detail::IdType rhs );
306 private:
307 sat::detail::IdType _id;
308 };
309
311 inline bool operator==( const Capability & lhs, const Capability & rhs )
312 { return lhs.id() == rhs.id(); }
313
315 inline bool operator!=( const Capability & lhs, const Capability & rhs )
316 { return lhs.id() != rhs.id(); }
317
319 inline bool operator<( const Capability & lhs, const Capability & rhs )
320 { return lhs.id() < rhs.id(); }
321
338 class CapDetail
339 {
340 public:
341 enum Kind
342 {
343 NOCAP = 0x00,
344 NAMED = 0x01,
345 VERSIONED = 0x02,
346 EXPRESSION = 0x04
347 };
348
352 enum CapRel
353 {
354 REL_NONE = 0,
355 CAP_AND = Capability::CAP_AND,
356 CAP_OR = Capability::CAP_OR,
357
358 CAP_COND = Capability::CAP_COND,
359 CAP_UNLESS = Capability::CAP_UNLESS,
360 CAP_ELSE = Capability::CAP_ELSE,
361
362 CAP_WITH = Capability::CAP_WITH,
363 CAP_WITHOUT = Capability::CAP_WITHOUT,
364
365 CAP_NAMESPACE = Capability::CAP_NAMESPACE,
366 CAP_ARCH = Capability::CAP_ARCH,
367 };
368
369 public:
370 CapDetail()
371 : _kind( NOCAP ), _lhs( 0 ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
372 {}
373 explicit CapDetail( const Capability & cap_r )
374 : _kind( NOCAP ), _lhs( cap_r.id() ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
375 { _init(); }
376 explicit CapDetail( sat::detail::IdType id_r )
377 : _kind( NOCAP ), _lhs( id_r ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
378 { _init(); }
379
380 public:
381 Kind kind() const { return _kind; }
382 bool isNull() const { return _kind == NOCAP; }
383 bool isNamed() const { return _kind == NAMED; }
384 bool isVersioned() const { return _kind == VERSIONED; }
385 bool isSimple() const { return _kind & (NAMED|VERSIONED); }
386 bool isExpression() const { return _kind == EXPRESSION; }
387
390 bool hasArch() const { return _archIfSimple; }
391 IdString arch() const { return _archIfSimple ? IdString( _archIfSimple ) : IdString(); }
392 IdString name() const { return isSimple() ? IdString( _lhs ) : IdString(); }
393 Rel op() const { return isVersioned() ? Rel( _flag ) : isSimple() ? Rel::ANY : Rel::NONE; }
394 Edition ed() const { return isVersioned() ? Edition( _rhs ) : Edition(); }
396
399 Capability lhs() const { return isExpression() ? Capability( _lhs ) : Capability::Null; }
400 CapRel capRel() const { return isExpression() ? CapRel(_flag) : REL_NONE; }
401 Capability rhs() const { return isExpression() ? Capability( _rhs ) : Capability::Null; }
403
404 private:
405 void _init();
406 private:
407 Kind _kind;
408 sat::detail::IdType _lhs;
409 sat::detail::IdType _rhs;
410 unsigned _flag;
411 sat::detail::IdType _archIfSimple;
412 };
413
414 inline CapDetail Capability::detail() const { return CapDetail( _id ); }
415} // namespace zyppng::sat
416
417 ZYPP_DEFINE_ID_HASHABLE( ::zyppng::sat::Capability );
418
419#endif // ZYPP_CAPABILITY_H
Globals.h
Provides API related macros.
ZYPP_DEFINE_ID_HASHABLE
#define ZYPP_DEFINE_ID_HASHABLE(C)
Define hash function for id based classes.
Definition Hash.h:26
arch.h
capmatch.h
bool
zypp::Arch
Architecture.
Definition Arch.h:37
zypp::CapMatch
Tri state Capability match result.
Definition CapMatch.h:39
zypp::Capability::detail
CapDetail detail() const
Helper providing more detailed information about a Capability.
Definition Capability.h:453
zypp::Edition
Edition represents [epoch:]version[-release].
Definition Edition.h:60
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *.
Definition IdString.cc:51
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition IdString.h:144
zypp::IdString::Null
static const IdString Null
No or Null string ( Id 0 ).
Definition IdString.h:86
zypp::ResKind
Resolvable kinds.
Definition ResKind.h:33
zyppng::sat::CapDetail
Helper providing more detailed information about a Capability.
Definition capability.h:339
zyppng::sat::CapDetail::Kind
Kind
Definition capability.h:342
zyppng::sat::CapDetail::NOCAP
@ NOCAP
Definition capability.h:343
zyppng::sat::CapDetail::NAMED
@ NAMED
Definition capability.h:344
zyppng::sat::CapDetail::EXPRESSION
@ EXPRESSION
Definition capability.h:346
zyppng::sat::CapDetail::VERSIONED
@ VERSIONED
Definition capability.h:345
zyppng::sat::CapDetail::isExpression
bool isExpression() const
Definition capability.h:386
zyppng::sat::CapDetail::CapDetail
CapDetail()
Definition capability.h:370
zyppng::sat::CapDetail::_lhs
sat::detail::IdType _lhs
Definition capability.h:408
zyppng::sat::CapDetail::ed
Edition ed() const
Definition capability.h:394
zyppng::sat::CapDetail::_flag
unsigned _flag
Definition capability.h:410
zyppng::sat::CapDetail::lhs
Capability lhs() const
Definition capability.h:399
zyppng::sat::CapDetail::isSimple
bool isSimple() const
Definition capability.h:385
zyppng::sat::CapDetail::_init
void _init()
Definition capability.cc:475
zyppng::sat::CapDetail::name
IdString name() const
Definition capability.h:392
zyppng::sat::CapDetail::capRel
CapRel capRel() const
Definition capability.h:400
zyppng::sat::CapDetail::isNamed
bool isNamed() const
Definition capability.h:383
zyppng::sat::CapDetail::CapRel
CapRel
Enum values corresponding with libsolv defines.
Definition capability.h:353
zyppng::sat::CapDetail::CAP_ELSE
@ CAP_ELSE
else
Definition capability.h:360
zyppng::sat::CapDetail::CAP_OR
@ CAP_OR
or
Definition capability.h:356
zyppng::sat::CapDetail::CAP_WITH
@ CAP_WITH
with
Definition capability.h:362
zyppng::sat::CapDetail::REL_NONE
@ REL_NONE
Not an expression.
Definition capability.h:354
zyppng::sat::CapDetail::CAP_UNLESS
@ CAP_UNLESS
unless
Definition capability.h:359
zyppng::sat::CapDetail::CAP_ARCH
@ CAP_ARCH
Used internally.
Definition capability.h:366
zyppng::sat::CapDetail::CAP_NAMESPACE
@ CAP_NAMESPACE
Definition capability.h:365
zyppng::sat::CapDetail::CAP_COND
@ CAP_COND
if
Definition capability.h:358
zyppng::sat::CapDetail::CAP_WITHOUT
@ CAP_WITHOUT
without
Definition capability.h:363
zyppng::sat::CapDetail::CAP_AND
@ CAP_AND
and
Definition capability.h:355
zyppng::sat::CapDetail::_rhs
sat::detail::IdType _rhs
Definition capability.h:409
zyppng::sat::CapDetail::CapDetail
CapDetail(const Capability &cap_r)
Definition capability.h:373
zyppng::sat::CapDetail::_kind
Kind _kind
Definition capability.h:407
zyppng::sat::CapDetail::rhs
Capability rhs() const
Definition capability.h:401
zyppng::sat::CapDetail::hasArch
bool hasArch() const
Definition capability.h:390
zyppng::sat::CapDetail::isNull
bool isNull() const
Definition capability.h:382
zyppng::sat::CapDetail::isVersioned
bool isVersioned() const
Definition capability.h:384
zyppng::sat::CapDetail::CapDetail
CapDetail(sat::detail::IdType id_r)
Definition capability.h:376
zyppng::sat::CapDetail::op
Rel op() const
Definition capability.h:393
zyppng::sat::CapDetail::_archIfSimple
sat::detail::IdType _archIfSimple
Definition capability.h:411
zyppng::sat::CapDetail::arch
IdString arch() const
Definition capability.h:391
zyppng::sat::CapDetail::kind
Kind kind() const
Definition capability.h:381
zyppng::sat::Capability
A sat capability.
Definition capability.h:74
zyppng::sat::Capability::isInterestingFileSpec
static bool isInterestingFileSpec(const std::string &name_r)
Definition capability.h:262
zyppng::sat::Capability::matches
static CapMatch matches(const char *lhs, const char *rhs)
Definition capability.h:239
zyppng::sat::Capability::matches
static CapMatch matches(const std::string &lhs, const IdString &rhs)
Definition capability.h:232
zyppng::sat::Capability::CapRel
CapRel
Enum values correspond with libsolv defines.
Definition capability.h:162
zyppng::sat::Capability::CAP_COND
@ CAP_COND
if
Definition capability.h:166
zyppng::sat::Capability::CAP_AND
@ CAP_AND
and
Definition capability.h:163
zyppng::sat::Capability::CAP_NAMESPACE
@ CAP_NAMESPACE
Definition capability.h:173
zyppng::sat::Capability::CAP_WITHOUT
@ CAP_WITHOUT
without
Definition capability.h:171
zyppng::sat::Capability::CAP_ELSE
@ CAP_ELSE
else
Definition capability.h:168
zyppng::sat::Capability::CAP_ARCH
@ CAP_ARCH
Used internally.
Definition capability.h:174
zyppng::sat::Capability::CAP_WITH
@ CAP_WITH
with
Definition capability.h:170
zyppng::sat::Capability::CAP_UNLESS
@ CAP_UNLESS
unless
Definition capability.h:167
zyppng::sat::Capability::CAP_OR
@ CAP_OR
or
Definition capability.h:164
zyppng::sat::Capability::isInterestingFileSpec
static bool isInterestingFileSpec(const IdString &name_r)
Test for a filename that is likely being REQUIRED.
Definition capability.h:261
zyppng::sat::Capability::matches
static CapMatch matches(const IdString &lhs, const std::string &rhs)
Definition capability.h:228
zyppng::sat::Capability::matches
static CapMatch matches(const char *lhs, const Capability &rhs)
Definition capability.h:236
zyppng::sat::Capability::matches
static CapMatch matches(const IdString &lhs, const char *rhs)
Definition capability.h:229
zyppng::sat::Capability::asString
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition capability.h:203
zyppng::sat::Capability::matches
CapMatch matches(const char *rhs) const
Definition capability.h:244
zyppng::sat::Capability::matches
static CapMatch matches(const std::string &lhs, const std::string &rhs)
Definition capability.h:233
zyppng::sat::Capability::CtorFlag
CtorFlag
Definition capability.h:76
zyppng::sat::Capability::UNPARSED
@ UNPARSED
Definition capability.h:76
zyppng::sat::Capability::PARSED
@ PARSED
Definition capability.h:76
zyppng::sat::Capability::matches
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition capability.h:221
zyppng::sat::Capability::matches
static CapMatch matches(const IdString &lhs, const Capability &rhs)
Definition capability.h:226
zyppng::sat::Capability::_id
sat::detail::IdType _id
Definition capability.h:307
zyppng::sat::Capability::matches
static CapMatch matches(const std::string &lhs, const Capability &rhs)
Definition capability.h:231
zyppng::sat::Capability::_doMatch
static CapMatch _doMatch(sat::detail::IdType lhs, sat::detail::IdType rhs)
Match two Capabilities.
Definition capability.cc:347
zyppng::sat::Capability::matches
CapMatch matches(const Capability &rhs) const
Definition capability.h:241
zyppng::sat::Capability::detail
CapDetail detail() const
Helper providing more detailed information about a Capability.
Definition capability.h:414
zyppng::sat::Capability::Capability
Capability(ResolverNamespace namespace_r, const std::string &value_r)
Definition capability.h:154
zyppng::sat::Capability::Null
static const Capability Null
No or Null Capability ( Id 0 ).
Definition capability.h:182
zyppng::sat::Capability::matches
static CapMatch matches(const char *lhs, const std::string &rhs)
Definition capability.h:238
zyppng::sat::Capability::id
sat::detail::IdType id() const
Expert backdoor.
Definition capability.h:301
zyppng::sat::Capability::matches
static CapMatch matches(const Capability &lhs, const std::string &rhs)
Definition capability.h:223
zyppng::sat::Capability::matches
static CapMatch matches(const char *lhs, const IdString &rhs)
Definition capability.h:237
zyppng::sat::Capability::c_str
const char * c_str() const
Conversion to const char *.
Definition capability.cc:342
zyppng::sat::Capability::matches
static CapMatch matches(const Capability &lhs, const char *rhs)
Definition capability.h:224
zyppng::sat::Capability::matches
CapMatch matches(const std::string &rhs) const
Definition capability.h:243
zyppng::sat::Capability::Empty
static const Capability Empty
Empty Capability.
Definition capability.h:185
zyppng::sat::Capability::matches
CapMatch matches(const IdString &rhs) const
Definition capability.h:242
zyppng::sat::Capability::Capability
Capability()
Default ctor, Empty capability.
Definition capability.h:80
zyppng::sat::Capability::empty
bool empty() const
Whether the Capability is empty.
Definition capability.h:195
zyppng::sat::Capability::Capability
Capability(ResolverNamespace namespace_r, const char *value_r)
Definition capability.h:153
zyppng::sat::Capability::Capability
Capability(sat::detail::IdType id_r)
Ctor from id.
Definition capability.h:83
zyppng::sat::Capability::matches
static CapMatch matches(const std::string &lhs, const char *rhs)
Definition capability.h:234
zyppng::sat::Capability::matches
static CapMatch matches(const IdString &lhs, const IdString &rhs)
Definition capability.h:227
zyppng::sat::Capability::matches
static CapMatch matches(const Capability &lhs, const IdString &rhs)
Definition capability.h:222
edition.h
zypp::sat
Libsolv interface
zypp::sat::operator!=
bool operator!=(const FileConflicts &lhs, const FileConflicts &rhs)
relates: FileConflicts
Definition FileConflicts.h:89
zypp::sat::operator<
bool operator<(const LocaleSupport &lhs, const LocaleSupport &rhs)
relates: LocaleSupport
Definition LocaleSupport.h:120
zypp::sat::operator==
bool operator==(const FileConflicts &lhs, const FileConflicts &rhs)
relates: FileConflicts
Definition FileConflicts.h:85
zypp::ResolverNamespace
ResolverNamespace
The resolver's dependency namespaces.
Definition ResolverNamespace.h:25
zyppng::sat::detail::emptyId
static const IdType emptyId(1)
zyppng::sat::detail::noId
static const IdType noId(0)
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
zyppng::sat::CapabilitySet
std::unordered_set< Capability > CapabilitySet
Definition capability.h:35
zyppng::IdString
zypp::IdString IdString
Definition idstring.h:16
poolconstants.h
poolmember.h
rel.h
reskind.h
resolvernamespace.h
restraits.h
zypp::Rel
Relational operators.
Definition Rel.h:46
zyppng::Rel::NONE
static const Rel NONE
Definition Rel.h:59
zyppng::Rel::ANY
static const Rel ANY
Definition Rel.h:58
zyppng::sat::Capability::Matches
matches functor.
Definition capability.h:250
zyppng::sat::Capability::Matches::operator()
CapMatch operator()(const Capability &lhs, const Capability &rhs) const
Definition capability.h:251
idstring.h