libzypp  17.30.2
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>
24 #include <zypp/ResolverNamespace.h>
25 #include <zypp/CapMatch.h>
26 
28 namespace 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  //
60  {
61  public:
63 
64  public:
66  Capability() : _id( sat::detail::emptyId ) {}
67 
69  explicit Capability( sat::detail::IdType id_r ) : _id( id_r ) {}
70 
79  explicit Capability( const char * str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
81  explicit Capability( const std::string & str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
83  Capability( const Arch & arch_r, const char * str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
85  Capability( const Arch & arch_r, const std::string & str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
86 
88  Capability( const char * str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
90  Capability( const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
92  Capability( const Arch & arch_r, const char * str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
94  Capability( const Arch & arch_r, const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
96 
97 
102  Capability( const std::string & name_r, const std::string & op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
104  Capability( const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
106  Capability( const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
108 
113  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() );
115  Capability( const std::string & arch_r, const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
117  Capability( const std::string & arch_r, const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
119  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() );
121  Capability( const Arch & arch_r, const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r = ResKind() );
123  Capability( const Arch & arch_r, const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
125 
131  Capability( ResolverNamespace namespace_r, IdString value_r = IdString::Null );
132  Capability( ResolverNamespace namespace_r, const char * value_r ) : Capability( namespace_r, IdString(value_r) ) {}
133  Capability( ResolverNamespace namespace_r, const std::string & value_r ) : Capability( namespace_r, IdString(value_r) ) {}
135  public:
137  static const Capability Null;
138 
140  static const Capability Empty;
141 
142  public:
144  explicit operator bool() const
145  { return ! empty(); }
146 
150  bool empty() const
151  { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
152 
153  public:
155  const char * c_str() const;
156 
158  std::string asString() const
159  { return c_str(); }
160 
161  public:
163  CapDetail detail() const;
164 
165  public:
176  static CapMatch matches( const Capability & lhs, const Capability & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
177  static CapMatch matches( const Capability & lhs, const IdString & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
178  static CapMatch matches( const Capability & lhs, const std::string & rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
179  static CapMatch matches( const Capability & lhs, const char * rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() );}
180 
181  static CapMatch matches( const IdString & lhs, const Capability & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
182  static CapMatch matches( const IdString & lhs, const IdString & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
183  static CapMatch matches( const IdString & lhs, const std::string & rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
184  static CapMatch matches( const IdString & lhs, const char * rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
185 
186  static CapMatch matches( const std::string & lhs, const Capability & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() );}
187  static CapMatch matches( const std::string & lhs, const IdString & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() ); }
188  static CapMatch matches( const std::string & lhs, const std::string & rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
189  static CapMatch matches( const std::string & lhs, const char * rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
190 
191  static CapMatch matches( const char * lhs, const Capability & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() );}
192  static CapMatch matches( const char * lhs, const IdString & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() ); }
193  static CapMatch matches( const char * lhs, const std::string & rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
194  static CapMatch matches( const char * lhs, const char * rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
195 
196  CapMatch matches( const Capability & rhs ) const { return _doMatch( id(), rhs.id() ); }
197  CapMatch matches( const IdString & rhs ) const { return _doMatch( id(), rhs.id() ); }
198  CapMatch matches( const std::string & rhs ) const { return _doMatch( id(), Capability(rhs).id() ); }
199  CapMatch matches( const char * rhs ) const { return _doMatch( id(), Capability(rhs).id() ); }
201 
204  struct Matches: public std::binary_function<Capability,Capability,CapMatch>
205  {
206  CapMatch operator()( const Capability & lhs, const Capability & rhs ) const
207  { return Capability::matches( lhs, rhs ); }
208  };
209 
210  public:
216  static bool isInterestingFileSpec( const IdString & name_r ) { return isInterestingFileSpec( name_r.c_str() ); }
217  static bool isInterestingFileSpec( const std::string & name_r ) { return isInterestingFileSpec( name_r.c_str() ); }
218  static bool isInterestingFileSpec( const char * name_r );
219 
244  static Capability guessPackageSpec( const std::string & str_r );
249  static Capability guessPackageSpec( const std::string & str_r, bool & rewrote_r );
250 
251  public:
254  { return _id; }
255  private:
258  private:
260  };
262 
264  std::ostream & operator<<( std::ostream & str, const Capability & obj );
265 
267  std::ostream & dumpOn( std::ostream & str, const Capability & obj );
268 
270  inline bool operator==( const Capability & lhs, const Capability & rhs )
271  { return lhs.id() == rhs.id(); }
272 
274  inline bool operator!=( const Capability & lhs, const Capability & rhs )
275  { return lhs.id() != rhs.id(); }
276 
278  inline bool operator<( const Capability & lhs, const Capability & rhs )
279  { return lhs.id() < rhs.id(); }
280 
282  //
283  // CLASS NAME : CapDetail
284  //
299  {
300  public:
301  enum Kind
302  {
303  NOCAP = 0x00,
304  NAMED = 0x01,
305  VERSIONED = 0x02,
306  EXPRESSION = 0x04
307  };
308 
312  enum CapRel
313  {
314  REL_NONE = 0,
315  CAP_AND = 16,
316  CAP_OR = 17,
317 
318  CAP_COND = 22,
319  CAP_UNLESS = 29,
320  CAP_ELSE = 26,
321 
322  CAP_WITH = 18,
323  CAP_WITHOUT = 28,
324 
326  CAP_ARCH = 20,
327  };
328 
329  public:
331  : _kind( NOCAP ), _lhs( 0 ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
332  {}
333  explicit CapDetail( const Capability & cap_r )
334  : _kind( NOCAP ), _lhs( cap_r.id() ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
335  { _init(); }
337  : _kind( NOCAP ), _lhs( id_r ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
338  { _init(); }
339 
340  public:
341  Kind kind() const { return _kind; }
342  bool isNull() const { return _kind == NOCAP; }
343  bool isNamed() const { return _kind == NAMED; }
344  bool isVersioned() const { return _kind == VERSIONED; }
345  bool isSimple() const { return _kind & (NAMED|VERSIONED); }
346  bool isExpression() const { return _kind == EXPRESSION; }
347 
350  bool hasArch() const { return _archIfSimple; }
352  IdString name() const { return isSimple() ? IdString( _lhs ) : IdString(); }
353  Rel op() const { return isVersioned() ? Rel( _flag ) : Rel::ANY; }
354  Edition ed() const { return isVersioned() ? Edition( _rhs ) : Edition(); }
356 
360  CapRel capRel() const { return isExpression() ? CapRel(_flag) : REL_NONE; }
363 
364  private:
365  void _init();
366  private:
370  unsigned _flag;
372  };
374 
376  std::ostream & operator<<( std::ostream & str, const CapDetail & obj );
377 
379  std::ostream & operator<<( std::ostream & str, CapDetail::Kind obj );
380 
382  std::ostream & operator<<( std::ostream & str, CapDetail::CapRel obj );
383 
385 
386  inline CapDetail Capability::detail() const { return CapDetail( _id ); }
387 
389 } // namespace zypp
391 
393 
394 #endif // ZYPP_CAPABILITY_H
ZYPP_DEFINE_ID_HASHABLE(::zypp::Capability)
Architecture.
Definition: Arch.h:37
Helper providing more detailed information about a Capability.
Definition: Capability.h:299
CapDetail(const Capability &cap_r)
Definition: Capability.h:333
bool isNamed() const
Definition: Capability.h:343
bool isSimple() const
Definition: Capability.h:345
IdString name() const
Definition: Capability.h:352
bool isNull() const
Definition: Capability.h:342
bool hasArch() const
Definition: Capability.h:350
CapDetail(sat::detail::IdType id_r)
Definition: Capability.h:336
IdString arch() const
Definition: Capability.h:351
Capability rhs() const
Definition: Capability.h:361
Edition ed() const
Definition: Capability.h:354
Rel op() const
Definition: Capability.h:353
sat::detail::IdType _archIfSimple
Definition: Capability.h:371
Capability lhs() const
Definition: Capability.h:359
Kind kind() const
Definition: Capability.h:341
sat::detail::IdType _rhs
Definition: Capability.h:369
CapRel capRel() const
Definition: Capability.h:360
sat::detail::IdType _lhs
Definition: Capability.h:368
unsigned _flag
Definition: Capability.h:370
CapRel
Enum values corresponding with libsolv defines.
Definition: Capability.h:313
@ REL_NONE
Not an expression.
Definition: Capability.h:314
@ CAP_WITHOUT
without
Definition: Capability.h:323
@ CAP_ARCH
Used internally.
Definition: Capability.h:326
@ CAP_UNLESS
unless
Definition: Capability.h:319
bool isVersioned() const
Definition: Capability.h:344
bool isExpression() const
Definition: Capability.h:346
Tri state Capability match result.
Definition: CapMatch.h:38
A sat capability.
Definition: Capability.h:60
static CapMatch matches(const char *lhs, const char *rhs)
Definition: Capability.h:194
static CapMatch matches(const IdString &lhs, const std::string &rhs)
Definition: Capability.h:183
Capability(ResolverNamespace namespace_r, const char *value_r)
Definition: Capability.h:132
sat::detail::IdType id() const
Expert backdoor.
Definition: Capability.h:253
CapMatch matches(const char *rhs) const
Definition: Capability.h:199
static CapMatch matches(const char *lhs, const IdString &rhs)
Definition: Capability.h:192
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: Capability.h:158
CapMatch matches(const IdString &rhs) const
Definition: Capability.h:197
static CapMatch matches(const std::string &lhs, const Capability &rhs)
Definition: Capability.h:186
static CapMatch matches(const Capability &lhs, const std::string &rhs)
Definition: Capability.h:178
CapMatch matches(const std::string &rhs) const
Definition: Capability.h:198
static CapMatch matches(const IdString &lhs, const Capability &rhs)
Definition: Capability.h:181
static const Capability Null
No or Null Capability ( Id 0 ).
Definition: Capability.h:137
static CapMatch matches(const IdString &lhs, const char *rhs)
Definition: Capability.h:184
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:176
CapMatch matches(const Capability &rhs) const
Definition: Capability.h:196
sat::detail::IdType _id
Definition: Capability.h:259
Capability()
Default ctor, Empty capability.
Definition: Capability.h:66
bool empty() const
Whether the Capability is empty.
Definition: Capability.h:150
CapDetail detail() const
Helper providing more detailed information about a Capability.
Definition: Capability.h:386
static CapMatch matches(const Capability &lhs, const char *rhs)
Definition: Capability.h:179
bool operator!=(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:274
static CapMatch matches(const std::string &lhs, const IdString &rhs)
Definition: Capability.h:187
const char * c_str() const
Conversion to const char *
Definition: Capability.cc:425
bool operator==(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:270
static CapMatch _doMatch(sat::detail::IdType lhs, sat::detail::IdType rhs)
Match two Capabilities.
Definition: Capability.cc:437
static bool isInterestingFileSpec(const IdString &name_r)
Test for a filename that is likely being REQUIRED.
Definition: Capability.h:216
bool operator<(const Capability &lhs, const Capability &rhs)
Arbitrary order.
Definition: Capability.h:278
static CapMatch matches(const Capability &lhs, const IdString &rhs)
Definition: Capability.h:177
Capability(ResolverNamespace namespace_r, const std::string &value_r)
Definition: Capability.h:133
static const Capability Empty
Empty Capability.
Definition: Capability.h:140
static bool isInterestingFileSpec(const std::string &name_r)
Definition: Capability.h:217
static Capability guessPackageSpec(const std::string &str_r)
Capability parser also guessing "libzypp-1.2.3-4.5.x86_64" formats.
Definition: Capability.cc:551
Capability(sat::detail::IdType id_r)
Ctor from id.
Definition: Capability.h:69
static CapMatch matches(const IdString &lhs, const IdString &rhs)
Definition: Capability.h:182
static CapMatch matches(const char *lhs, const Capability &rhs)
Definition: Capability.h:191
static CapMatch matches(const char *lhs, const std::string &rhs)
Definition: Capability.h:193
static CapMatch matches(const std::string &lhs, const char *rhs)
Definition: Capability.h:189
static CapMatch matches(const std::string &lhs, const std::string &rhs)
Definition: Capability.h:188
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:33
ResolverNamespace
The resolver's dependency namespaces.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:567
matches functor.
Definition: Capability.h:205
CapMatch operator()(const Capability &lhs, const Capability &rhs) const
Definition: Capability.h:206
Relational operators.
Definition: Rel.h:44
static const Rel ANY
Definition: Rel.h:56
Backlink to the associated PoolImpl.
Definition: PoolMember.h:89