libzypp 17.31.23
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/APIConfig.h>
19
20#include <zypp/IdString.h>
21#include <zypp/Edition.h>
22#include <zypp/Rel.h>
23#include <zypp/ResTraits.h>
25#include <zypp/CapMatch.h>
26
28namespace zypp
29{
30
31 class Capability;
32 class CapDetail;
33 class Arch;
34
35 typedef std::unordered_set<Capability> CapabilitySet;
36
38 //
39 // CLASS NAME : Capability
40 //
63 {
64 public:
66
67 public:
69 Capability() : _id( sat::detail::emptyId ) {}
70
72 explicit Capability( sat::detail::IdType id_r ) : _id( id_r ) {}
73
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
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
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:
264 { return _id; }
265 private:
268 private:
270 };
272
274 std::ostream & operator<<( std::ostream & str, const Capability & obj );
275
277 std::ostream & dumpOn( std::ostream & str, const Capability & obj );
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 //
310 {
311 public:
312 enum Kind
313 {
314 NOCAP = 0x00,
315 NAMED = 0x01,
316 VERSIONED = 0x02,
317 EXPRESSION = 0x04
318 };
319
324 {
326 CAP_AND = 16,
327 CAP_OR = 17,
328
329 CAP_COND = 22,
331 CAP_ELSE = 26,
332
333 CAP_WITH = 18,
335
337 CAP_ARCH = 20,
338 };
339
340 public:
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(); }
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; }
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
371 CapRel capRel() const { return isExpression() ? CapRel(_flag) : REL_NONE; }
374
375 private:
376 void _init();
377 private:
381 unsigned _flag;
383 };
385
387 std::ostream & operator<<( std::ostream & str, const CapDetail & obj );
388
390 std::ostream & operator<<( std::ostream & str, CapDetail::Kind obj );
391
393 std::ostream & operator<<( std::ostream & str, CapDetail::CapRel obj );
394
396
397 inline CapDetail Capability::detail() const { return CapDetail( _id ); }
398
400} // namespace zypp
402
404
405#endif // ZYPP_CAPABILITY_H
Provides API related macros.
Architecture.
Definition: Arch.h:37
Helper providing more detailed information about a Capability.
Definition: Capability.h:310
CapDetail(const Capability &cap_r)
Definition: Capability.h:344
bool isNamed() const
Definition: Capability.h:354
bool isSimple() const
Definition: Capability.h:356
IdString name() const
Definition: Capability.h:363
bool isNull() const
Definition: Capability.h:353
bool hasArch() const
Definition: Capability.h:361
CapDetail(sat::detail::IdType id_r)
Definition: Capability.h:347
IdString arch() const
Definition: Capability.h:362
Capability rhs() const
Definition: Capability.h:372
Edition ed() const
Definition: Capability.h:365
Rel op() const
Definition: Capability.h:364
sat::detail::IdType _archIfSimple
Definition: Capability.h:382
Capability lhs() const
Definition: Capability.h:370
Kind kind() const
Definition: Capability.h:352
sat::detail::IdType _rhs
Definition: Capability.h:380
CapRel capRel() const
Definition: Capability.h:371
sat::detail::IdType _lhs
Definition: Capability.h:379
unsigned _flag
Definition: Capability.h:381
CapRel
Enum values corresponding with libsolv defines.
Definition: Capability.h:324
@ REL_NONE
Not an expression.
Definition: Capability.h:325
@ CAP_WITHOUT
without
Definition: Capability.h:334
@ CAP_ARCH
Used internally.
Definition: Capability.h:337
@ CAP_UNLESS
unless
Definition: Capability.h:330
bool isVersioned() const
Definition: Capability.h:355
bool isExpression() const
Definition: Capability.h:357
Tri state Capability match result.
Definition: CapMatch.h:38
A sat capability.
Definition: Capability.h:63
static CapMatch matches(const char *lhs, const char *rhs)
Definition: Capability.h:204
static CapMatch matches(const IdString &lhs, const std::string &rhs)
Definition: Capability.h:193
Capability(ResolverNamespace namespace_r, const char *value_r)
Definition: Capability.h:142
sat::detail::IdType id() const
Expert backdoor.
Definition: Capability.h:263
CapMatch matches(const char *rhs) const
Definition: Capability.h:209
static CapMatch matches(const char *lhs, const IdString &rhs)
Definition: Capability.h:202
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: Capability.h:168
CapMatch matches(const IdString &rhs) const
Definition: Capability.h:207
static CapMatch matches(const std::string &lhs, const Capability &rhs)
Definition: Capability.h:196
static CapMatch matches(const Capability &lhs, const std::string &rhs)
Definition: Capability.h:188
CapMatch matches(const std::string &rhs) const
Definition: Capability.h:208
static CapMatch matches(const IdString &lhs, const Capability &rhs)
Definition: Capability.h:191
static const Capability Null
No or Null Capability ( Id 0 ).
Definition: Capability.h:147
static CapMatch matches(const IdString &lhs, const char *rhs)
Definition: Capability.h:194
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:186
CapMatch matches(const Capability &rhs) const
Definition: Capability.h:206
sat::detail::IdType _id
Definition: Capability.h:269
Capability()
Default ctor, Empty capability.
Definition: Capability.h:69
bool empty() const
Whether the Capability is empty.
Definition: Capability.h:160
CapDetail detail() const
Helper providing more detailed information about a Capability.
Definition: Capability.h:397
static CapMatch matches(const Capability &lhs, const char *rhs)
Definition: Capability.h:189
bool operator!=(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:284
static CapMatch matches(const std::string &lhs, const IdString &rhs)
Definition: Capability.h:197
const char * c_str() const
Conversion to const char *
Definition: Capability.cc:438
bool operator==(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:280
static CapMatch _doMatch(sat::detail::IdType lhs, sat::detail::IdType rhs)
Match two Capabilities.
Definition: Capability.cc:450
static bool isInterestingFileSpec(const IdString &name_r)
Test for a filename that is likely being REQUIRED.
Definition: Capability.h:226
bool operator<(const Capability &lhs, const Capability &rhs)
Arbitrary order.
Definition: Capability.h:288
static CapMatch matches(const Capability &lhs, const IdString &rhs)
Definition: Capability.h:187
Capability(ResolverNamespace namespace_r, const std::string &value_r)
Definition: Capability.h:143
static const Capability Empty
Empty Capability.
Definition: Capability.h:150
static bool isInterestingFileSpec(const std::string &name_r)
Definition: Capability.h:227
static Capability guessPackageSpec(const std::string &str_r)
Capability parser also guessing "libzypp-1.2.3-4.5.x86_64" formats.
Definition: Capability.cc:564
Capability(sat::detail::IdType id_r)
Ctor from id.
Definition: Capability.h:72
static CapMatch matches(const IdString &lhs, const IdString &rhs)
Definition: Capability.h:192
static CapMatch matches(const char *lhs, const Capability &rhs)
Definition: Capability.h:201
static CapMatch matches(const char *lhs, const std::string &rhs)
Definition: Capability.h:203
static CapMatch matches(const std::string &lhs, const char *rhs)
Definition: Capability.h:199
static CapMatch matches(const std::string &lhs, const std::string &rhs)
Definition: Capability.h:198
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
Access to the sat-pools string space.
Definition: IdString.h:43
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:50
IdType id() const
Expert backdoor.
Definition: IdString.h:122
static const IdString Null
No or Null string ( Id 0 ).
Definition: IdString.h:74
Resolvable kinds.
Definition: ResKind.h:33
String related utilities and Regular expression matching.
static const IdType emptyId(1)
static const IdType noId(0)
int IdType
Generic Id type.
Definition: PoolMember.h:104
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:35
ResolverNamespace
The resolver's dependency namespaces.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:580
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
matches functor.
Definition: Capability.h:215
CapMatch operator()(const Capability &lhs, const Capability &rhs) const
Definition: Capability.h:216
Relational operators.
Definition: Rel.h:44
static const Rel NONE
Definition: Rel.h:57
static const Rel ANY
Definition: Rel.h:56
Backlink to the associated PoolImpl.
Definition: PoolMember.h:89
#define ZYPP_DEFINE_ID_HASHABLE(C)
Define hash function for id based classes.
Definition: Hash.h:26