libzypp: zypp/Capability.h Source File

libzypp 17.36.6

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/sat/detail/PoolMember.h>
19
20#include <zypp/IdString.h>
21#include <zypp/Edition.h>
22#include <zypp/Rel.h>
23#include <zypp/ResTraits.h>
24#include <zypp/ResolverNamespace.h>
25#include <zypp/CapMatch.h>
26
28namespace zypp
29{
30
31 class Capability;
32 class CapDetail;
33 class Arch;
34
35 using CapabilitySet = std::unordered_set<Capability>;
36
38 //
39 // CLASS NAME : Capability
40 //
62 class ZYPP_API Capability: protected sat::detail::PoolMember
63 {
64 public:
65 enum CtorFlag { PARSED, UNPARSED };
66
67 public:
69 Capability() : _id( sat::detail::emptyId ) {}
70
72 explicit Capability( sat::detail::IdType id_r ) : _id( id_r ) {}
73
77
89 explicit Capability( const char * str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
91 explicit Capability( const std::string & str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
93 Capability( const Arch & arch_r, const char * str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
95 Capability( const Arch & arch_r, const std::string & str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
96
98 Capability( const char * str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
100 Capability( const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
102 Capability( const Arch & arch_r, const char * str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
104 Capability( const Arch & arch_r, const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
106
107
111
112 Capability( const std::string & name_r, const std::string & op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
114 Capability( const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
116 Capability( const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
118
122
123 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() );
125 Capability( const std::string & arch_r, const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
127 Capability( const std::string & arch_r, const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
129 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() );
131 Capability( const Arch & arch_r, const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
133 Capability( const Arch & arch_r, const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
135
141 Capability( ResolverNamespace namespace_r, IdString value_r = IdString::Null );
142 Capability( ResolverNamespace namespace_r, const char * value_r ) : Capability( namespace_r, IdString(value_r) ) {}
143 Capability( ResolverNamespace namespace_r, const std::string & value_r ) : Capability( namespace_r, IdString(value_r) ) {}
145 public:
147 static const Capability Null;
148
150 static const Capability Empty;
151
152 public:
154 explicit operator bool() const
155 { return ! empty(); }
156
160 bool empty() const
161 { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
162
163 public:
165 const char * c_str() const;
166
168 std::string asString() const
169 { return c_str(); }
170
171 public:
173 CapDetail detail() const;
174
175 public:
186 static CapMatch matches( const Capability & lhs, const Capability & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
187 static CapMatch matches( const Capability & lhs, const IdString & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
188 static CapMatch matches( const Capability & lhs, const std::string & rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
189 static CapMatch matches( const Capability & lhs, const char * rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() );}
190
191 static CapMatch matches( const IdString & lhs, const Capability & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
192 static CapMatch matches( const IdString & lhs, const IdString & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
193 static CapMatch matches( const IdString & lhs, const std::string & rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
194 static CapMatch matches( const IdString & lhs, const char * rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
195
196 static CapMatch matches( const std::string & lhs, const Capability & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() );}
197 static CapMatch matches( const std::string & lhs, const IdString & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() ); }
198 static CapMatch matches( const std::string & lhs, const std::string & rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
199 static CapMatch matches( const std::string & lhs, const char * rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
200
201 static CapMatch matches( const char * lhs, const Capability & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() );}
202 static CapMatch matches( const char * lhs, const IdString & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() ); }
203 static CapMatch matches( const char * lhs, const std::string & rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
204 static CapMatch matches( const char * lhs, const char * rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
205
206 CapMatch matches( const Capability & rhs ) const { return _doMatch( id(), rhs.id() ); }
207 CapMatch matches( const IdString & rhs ) const { return _doMatch( id(), rhs.id() ); }
208 CapMatch matches( const std::string & rhs ) const { return _doMatch( id(), Capability(rhs).id() ); }
209 CapMatch matches( const char * rhs ) const { return _doMatch( id(), Capability(rhs).id() ); }
211
214 struct Matches
215 {
216 CapMatch operator()( const Capability & lhs, const Capability & rhs ) const
217 { return Capability::matches( lhs, rhs ); }
218 };
219
220 public:
226 static bool isInterestingFileSpec( const IdString & name_r ) { return isInterestingFileSpec( name_r.c_str() ); }
227 static bool isInterestingFileSpec( const std::string & name_r ) { return isInterestingFileSpec( name_r.c_str() ); }
228 static bool isInterestingFileSpec( const char * name_r );
229
254 static Capability guessPackageSpec( const std::string & str_r );
259 static Capability guessPackageSpec( const std::string & str_r, bool & rewrote_r );
260
261 public:
263 sat::detail::IdType id() const
264 { return _id; }
265 private:
267 static CapMatch _doMatch( sat::detail::IdType lhs, sat::detail::IdType rhs );
268 private:
269 sat::detail::IdType _id;
270 };
271
272
274 std::ostream & operator<<( std::ostream & str, const Capability & obj ) ZYPP_API;
275
277 std::ostream & dumpOn( std::ostream & str, const Capability & obj ) ZYPP_API;
278
280 inline bool operator==( const Capability & lhs, const Capability & rhs )
281 { return lhs.id() == rhs.id(); }
282
284 inline bool operator!=( const Capability & lhs, const Capability & rhs )
285 { return lhs.id() != rhs.id(); }
286
288 inline bool operator<( const Capability & lhs, const Capability & rhs )
289 { return lhs.id() < rhs.id(); }
290
292 //
293 // CLASS NAME : CapDetail
294 //
309 class ZYPP_API CapDetail: protected sat::detail::PoolMember
310 {
311 public:
312 enum Kind
313 {
314 NOCAP = 0x00,
315 NAMED = 0x01,
316 VERSIONED = 0x02,
317 EXPRESSION = 0x04
318 };
319
323 enum CapRel
324 {
325 REL_NONE = 0,
326 CAP_AND = 16,
327 CAP_OR = 17,
328
329 CAP_COND = 22,
330 CAP_UNLESS = 29,
331 CAP_ELSE = 26,
332
333 CAP_WITH = 18,
334 CAP_WITHOUT = 28,
335
336 CAP_NAMESPACE = 19,
337 CAP_ARCH = 20,
338 };
339
340 public:
341 CapDetail()
342 : _kind( NOCAP ), _lhs( 0 ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
343 {}
344 explicit CapDetail( const Capability & cap_r )
345 : _kind( NOCAP ), _lhs( cap_r.id() ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
346 { _init(); }
347 explicit CapDetail( sat::detail::IdType id_r )
348 : _kind( NOCAP ), _lhs( id_r ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
349 { _init(); }
350
351 public:
352 Kind kind() const { return _kind; }
353 bool isNull() const { return _kind == NOCAP; }
354 bool isNamed() const { return _kind == NAMED; }
355 bool isVersioned() const { return _kind == VERSIONED; }
356 bool isSimple() const { return _kind & (NAMED|VERSIONED); }
357 bool isExpression() const { return _kind == EXPRESSION; }
358
361 bool hasArch() const { return _archIfSimple; }
362 IdString arch() const { return _archIfSimple ? IdString( _archIfSimple ) : IdString(); }
363 IdString name() const { return isSimple() ? IdString( _lhs ) : IdString(); }
364 Rel op() const { return isVersioned() ? Rel( _flag ) : isSimple() ? Rel::ANY : Rel::NONE; }
365 Edition ed() const { return isVersioned() ? Edition( _rhs ) : Edition(); }
367
370 Capability lhs() const { return isExpression() ? Capability( _lhs ) : Capability::Null; }
371 CapRel capRel() const { return isExpression() ? CapRel(_flag) : REL_NONE; }
372 Capability rhs() const { return isExpression() ? Capability( _rhs ) : Capability::Null; }
374
375 private:
376 void _init();
377 private:
378 Kind _kind;
379 sat::detail::IdType _lhs;
380 sat::detail::IdType _rhs;
381 unsigned _flag;
382 sat::detail::IdType _archIfSimple;
383 };
384
385
387 std::ostream & operator<<( std::ostream & str, const CapDetail & obj ) ZYPP_API;
388
390 std::ostream & operator<<( std::ostream & str, CapDetail::Kind obj ) ZYPP_API;
391
393 std::ostream & operator<<( std::ostream & str, CapDetail::CapRel obj ) ZYPP_API;
394
396
397 inline CapDetail Capability::detail() const { return CapDetail( _id ); }
398
400} // namespace zypp
402
403 ZYPP_DEFINE_ID_HASHABLE( ::zypp::Capability );
404
405#endif // ZYPP_CAPABILITY_H
CapMatch.h
Edition.h
IdString.h
PoolMember.h
Rel.h
ResTraits.h
ResolverNamespace.h
bool
zypp::Arch
Architecture.
Definition Arch.h:37
zypp::CapDetail
Helper providing more detailed information about a Capability.
Definition Capability.h:310
zypp::CapDetail::CapDetail
CapDetail(const Capability &cap_r)
Definition Capability.h:344
zypp::CapDetail::CapDetail
CapDetail()
Definition Capability.h:341
zypp::CapDetail::isNamed
bool isNamed() const
Definition Capability.h:354
zypp::CapDetail::Kind
Kind
Definition Capability.h:313
zypp::CapDetail::NAMED
@ NAMED
Definition Capability.h:315
zypp::CapDetail::NOCAP
@ NOCAP
Definition Capability.h:314
zypp::CapDetail::EXPRESSION
@ EXPRESSION
Definition Capability.h:317
zypp::CapDetail::VERSIONED
@ VERSIONED
Definition Capability.h:316
zypp::CapDetail::isSimple
bool isSimple() const
Definition Capability.h:356
zypp::CapDetail::name
IdString name() const
Definition Capability.h:363
zypp::CapDetail::isNull
bool isNull() const
Definition Capability.h:353
zypp::CapDetail::hasArch
bool hasArch() const
Definition Capability.h:361
zypp::CapDetail::CapDetail
CapDetail(sat::detail::IdType id_r)
Definition Capability.h:347
zypp::CapDetail::arch
IdString arch() const
Definition Capability.h:362
zypp::CapDetail::rhs
Capability rhs() const
Definition Capability.h:372
zypp::CapDetail::ed
Edition ed() const
Definition Capability.h:365
zypp::CapDetail::op
Rel op() const
Definition Capability.h:364
zypp::CapDetail::_archIfSimple
sat::detail::IdType _archIfSimple
Definition Capability.h:382
zypp::CapDetail::lhs
Capability lhs() const
Definition Capability.h:370
zypp::CapDetail::kind
Kind kind() const
Definition Capability.h:352
zypp::CapDetail::_init
void _init()
Definition Capability.cc:591
zypp::CapDetail::_kind
Kind _kind
Definition Capability.h:378
zypp::CapDetail::_rhs
sat::detail::IdType _rhs
Definition Capability.h:380
zypp::CapDetail::capRel
CapRel capRel() const
Definition Capability.h:371
zypp::CapDetail::_lhs
sat::detail::IdType _lhs
Definition Capability.h:379
zypp::CapDetail::_flag
unsigned _flag
Definition Capability.h:381
zypp::CapDetail::CapRel
CapRel
Enum values corresponding with libsolv defines.
Definition Capability.h:324
zypp::CapDetail::CAP_OR
@ CAP_OR
or
Definition Capability.h:327
zypp::CapDetail::REL_NONE
@ REL_NONE
Not an expression.
Definition Capability.h:325
zypp::CapDetail::CAP_AND
@ CAP_AND
and
Definition Capability.h:326
zypp::CapDetail::CAP_WITHOUT
@ CAP_WITHOUT
without
Definition Capability.h:334
zypp::CapDetail::CAP_ARCH
@ CAP_ARCH
Used internally.
Definition Capability.h:337
zypp::CapDetail::CAP_ELSE
@ CAP_ELSE
else
Definition Capability.h:331
zypp::CapDetail::CAP_UNLESS
@ CAP_UNLESS
unless
Definition Capability.h:330
zypp::CapDetail::CAP_NAMESPACE
@ CAP_NAMESPACE
Definition Capability.h:336
zypp::CapDetail::CAP_WITH
@ CAP_WITH
with
Definition Capability.h:333
zypp::CapDetail::CAP_COND
@ CAP_COND
if
Definition Capability.h:329
zypp::CapDetail::isVersioned
bool isVersioned() const
Definition Capability.h:355
zypp::CapDetail::isExpression
bool isExpression() const
Definition Capability.h:357
zypp::CapMatch
Tri state Capability match result.
Definition CapMatch.h:39
zypp::Capability
A sat capability.
Definition Capability.h:63
zypp::Capability::matches
static CapMatch matches(const char *lhs, const char *rhs)
Definition Capability.h:204
zypp::Capability::matches
static CapMatch matches(const IdString &lhs, const std::string &rhs)
Definition Capability.h:193
zypp::Capability::Capability
Capability(ResolverNamespace namespace_r, const char *value_r)
Definition Capability.h:142
zypp::Capability::id
sat::detail::IdType id() const
Expert backdoor.
Definition Capability.h:263
zypp::Capability::matches
CapMatch matches(const char *rhs) const
Definition Capability.h:209
zypp::Capability::matches
static CapMatch matches(const char *lhs, const IdString &rhs)
Definition Capability.h:202
zypp::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:168
zypp::Capability::matches
CapMatch matches(const IdString &rhs) const
Definition Capability.h:207
zypp::Capability::matches
static CapMatch matches(const std::string &lhs, const Capability &rhs)
Definition Capability.h:196
zypp::Capability::matches
static CapMatch matches(const Capability &lhs, const std::string &rhs)
Definition Capability.h:188
zypp::Capability::matches
CapMatch matches(const std::string &rhs) const
Definition Capability.h:208
zypp::Capability::matches
static CapMatch matches(const IdString &lhs, const Capability &rhs)
Definition Capability.h:191
zypp::Capability::Null
static const Capability Null
No or Null Capability ( Id 0 ).
Definition Capability.h:147
zypp::Capability::matches
static CapMatch matches(const IdString &lhs, const char *rhs)
Definition Capability.h:194
zypp::Capability::matches
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition Capability.h:186
zypp::Capability::matches
CapMatch matches(const Capability &rhs) const
Definition Capability.h:206
zypp::Capability::_id
sat::detail::IdType _id
Definition Capability.h:269
zypp::Capability::Capability
Capability()
Default ctor, Empty capability.
Definition Capability.h:69
zypp::Capability::empty
bool empty() const
Whether the Capability is empty.
Definition Capability.h:160
zypp::Capability::detail
CapDetail detail() const
Helper providing more detailed information about a Capability.
Definition Capability.h:397
zypp::Capability::matches
static CapMatch matches(const Capability &lhs, const char *rhs)
Definition Capability.h:189
zypp::Capability::operator!=
bool operator!=(const Capability &lhs, const Capability &rhs)
Definition Capability.h:284
zypp::Capability::matches
static CapMatch matches(const std::string &lhs, const IdString &rhs)
Definition Capability.h:197
zypp::Capability::c_str
const char * c_str() const
Conversion to const char *
Definition Capability.cc:438
zypp::Capability::operator==
bool operator==(const Capability &lhs, const Capability &rhs)
Definition Capability.h:280
zypp::Capability::_doMatch
static CapMatch _doMatch(sat::detail::IdType lhs, sat::detail::IdType rhs)
Match two Capabilities.
Definition Capability.cc:450
zypp::Capability::isInterestingFileSpec
static bool isInterestingFileSpec(const IdString &name_r)
Test for a filename that is likely being REQUIRED.
Definition Capability.h:226
zypp::Capability::operator<
bool operator<(const Capability &lhs, const Capability &rhs)
Arbitrary order.
Definition Capability.h:288
zypp::Capability::matches
static CapMatch matches(const Capability &lhs, const IdString &rhs)
Definition Capability.h:187
zypp::Capability::Capability
Capability(ResolverNamespace namespace_r, const std::string &value_r)
Definition Capability.h:143
zypp::Capability::CtorFlag
CtorFlag
Definition Capability.h:65
zypp::Capability::PARSED
@ PARSED
Definition Capability.h:65
zypp::Capability::UNPARSED
@ UNPARSED
Definition Capability.h:65
zypp::Capability::Empty
static const Capability Empty
Empty Capability.
Definition Capability.h:150
zypp::Capability::isInterestingFileSpec
static bool isInterestingFileSpec(const std::string &name_r)
Definition Capability.h:227
zypp::Capability::Capability
Capability(sat::detail::IdType id_r)
Ctor from id.
Definition Capability.h:72
zypp::Capability::matches
static CapMatch matches(const IdString &lhs, const IdString &rhs)
Definition Capability.h:192
zypp::Capability::matches
static CapMatch matches(const char *lhs, const Capability &rhs)
Definition Capability.h:201
zypp::Capability::matches
static CapMatch matches(const char *lhs, const std::string &rhs)
Definition Capability.h:203
zypp::Capability::matches
static CapMatch matches(const std::string &lhs, const char *rhs)
Definition Capability.h:199
zypp::Capability::matches
static CapMatch matches(const std::string &lhs, const std::string &rhs)
Definition Capability.h:198
zypp::Edition
Edition represents [epoch:]version[-release]
Definition Edition.h:61
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:44
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *
Definition IdString.cc:50
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition IdString.h:133
zypp::IdString::Null
static const IdString Null
No or Null string ( Id 0 ).
Definition IdString.h:75
zypp::ResKind
Resolvable kinds.
Definition ResKind.h:33
str
String related utilities and Regular expression matching.
zypp::sat::detail::emptyId
static const IdType emptyId(1)
zypp::sat::detail::noId
static const IdType noId(0)
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition PoolMember.h:104
zypp::sat
Definition Resolver.h:28
zypp::solver::detail
Definition PoolImpl.h:110
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::ResolverNamespace
ResolverNamespace
The resolver's dependency namespaces.
Definition ResolverNamespace.h:25
zypp::dumpOn
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition Capability.cc:580
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
zypp::CapabilitySet
std::unordered_set< Capability > CapabilitySet
Definition Capability.h:35
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
zypp::Capability::Matches
matches functor.
Definition Capability.h:215
zypp::Capability::Matches::operator()
CapMatch operator()(const Capability &lhs, const Capability &rhs) const
Definition Capability.h:216
zypp::Rel
Relational operators.
Definition Rel.h:46
zypp::Rel::NONE
static const Rel NONE
Definition Rel.h:59
zypp::Rel::ANY
static const Rel ANY
Definition Rel.h:58
zypp::sat::detail::PoolMember
Backlink to the associated PoolImpl.
Definition PoolMember.h:89
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