libzypp  17.8.0
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  CAP_WITH = 18,
319  CAP_ARCH = 20
320  };
321 
322  public:
324  : _kind( NOCAP ), _lhs( 0 ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
325  {}
326  explicit CapDetail( const Capability & cap_r )
327  : _kind( NOCAP ), _lhs( cap_r.id() ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
328  { _init(); }
330  : _kind( NOCAP ), _lhs( id_r ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
331  { _init(); }
332 
333  public:
334  Kind kind() const { return _kind; }
335  bool isNull() const { return _kind == NOCAP; }
336  bool isNamed() const { return _kind == NAMED; }
337  bool isVersioned() const { return _kind == VERSIONED; }
338  bool isSimple() const { return _kind & (NAMED|VERSIONED); }
339  bool isExpression() const { return _kind == EXPRESSION; }
340 
343  bool hasArch() const { return _archIfSimple; }
345  IdString name() const { return isSimple() ? IdString( _lhs ) : IdString(); }
346  Rel op() const { return isVersioned() ? Rel( _flag ) : Rel::ANY; }
347  Edition ed() const { return isVersioned() ? Edition( _rhs ) : Edition(); }
349 
353  CapRel capRel() const { return isExpression() ? CapRel(_flag) : REL_NONE; }
356 
357  private:
358  void _init();
359  private:
363  unsigned _flag;
365  };
367 
369  std::ostream & operator<<( std::ostream & str, const CapDetail & obj );
370 
372  std::ostream & operator<<( std::ostream & str, CapDetail::Kind obj );
373 
375  std::ostream & operator<<( std::ostream & str, CapDetail::CapRel obj );
376 
378 
379  inline CapDetail Capability::detail() const { return CapDetail( _id ); }
380 
382 } // namespace zypp
384 
386 
387 #endif // ZYPP_CAPABILITY_H
static CapMatch matches(const IdString &lhs, const std::string &rhs)
Definition: Capability.h:183
CapRel capRel() const
Definition: Capability.h:353
int IdType
Generic Id type.
Definition: PoolMember.h:104
bool isVersioned() const
Definition: Capability.h:337
Capability lhs() const
Definition: Capability.h:352
CapMatch matches(const Capability &rhs) const
Definition: Capability.h:196
CapMatch operator()(const Capability &lhs, const Capability &rhs) const
Definition: Capability.h:206
Edition ed() const
Definition: Capability.h:347
ZYPP_DEFINE_ID_HASHABLE(::zypp::Capability)
static CapMatch _doMatch(sat::detail::IdType lhs, sat::detail::IdType rhs)
Match two Capabilities.
Definition: Capability.cc:314
static Capability guessPackageSpec(const std::string &str_r)
Capability parser also guessing "libzypp-1.2.3-4.5.x86_64" formats.
Definition: Capability.cc:428
Helper providing more detailed information about a Capability.
Definition: Capability.h:298
static CapMatch matches(const std::string &lhs, const char *rhs)
Definition: Capability.h:189
static CapMatch matches(const Capability &lhs, const std::string &rhs)
Definition: Capability.h:178
Architecture.
Definition: Arch.h:36
static CapMatch matches(const IdString &lhs, const char *rhs)
Definition: Capability.h:184
Relational operators.
Definition: Rel.h:43
IdType id() const
Expert backdoor.
Definition: IdString.h:115
CapDetail(sat::detail::IdType id_r)
Definition: Capability.h:329
bool isNull() const
Definition: Capability.h:335
bool isNamed() const
Definition: Capability.h:336
static CapMatch matches(const Capability &lhs, const char *rhs)
Definition: Capability.h:179
static CapMatch matches(const char *lhs, const IdString &rhs)
Definition: Capability.h:192
Capability(sat::detail::IdType id_r)
Ctor from id.
Definition: Capability.h:69
String related utilities and Regular expression matching.
Access to the sat-pools string space.
Definition: IdString.h:41
Rel op() const
Definition: Capability.h:346
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
static const Rel ANY
Definition: Rel.h:56
static bool isInterestingFileSpec(const IdString &name_r)
Test for a filename that is likely being REQUIRED.
Definition: Capability.h:216
IdString arch() const
Definition: Capability.h:344
bool isExpression() const
Definition: Capability.h:339
sat::detail::IdType id() const
Expert backdoor.
Definition: Capability.h:253
ResolverNamespace
The resolvers dependency namespaces.
static bool isInterestingFileSpec(const std::string &name_r)
Definition: Capability.h:217
Backlink to the associated PoolImpl.
Definition: PoolMember.h:88
static const IdType emptyId(1)
bool operator<(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:278
static CapMatch matches(const char *lhs, const std::string &rhs)
Definition: Capability.h:193
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
Provides API related macros.
static CapMatch matches(const Capability &lhs, const IdString &rhs)
Definition: Capability.h:177
static CapMatch matches(const char *lhs, const char *rhs)
Definition: Capability.h:194
static CapMatch matches(const IdString &lhs, const Capability &rhs)
Definition: Capability.h:181
CapDetail(const Capability &cap_r)
Definition: Capability.h:326
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:444
CapMatch matches(const std::string &rhs) const
Definition: Capability.h:198
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:50
Tri state Capability match result.
Definition: CapMatch.h:37
static const Capability Null
No or Null Capability ( Id 0 ).
Definition: Capability.h:137
Kind kind() const
Definition: Capability.h:334
matches functor.
Definition: Capability.h:204
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
sat::detail::IdType _lhs
Definition: Capability.h:361
static CapMatch matches(const char *lhs, const Capability &rhs)
Definition: Capability.h:191
sat::detail::IdType _archIfSimple
Definition: Capability.h:364
A sat capability.
Definition: Capability.h:59
unsigned _flag
Definition: Capability.h:363
bool operator!=(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:274
static const IdString Null
No or Null string ( Id 0 ).
Definition: IdString.h:67
static const IdType noId(0)
static CapMatch matches(const std::string &lhs, const Capability &rhs)
Definition: Capability.h:186
CapMatch matches(const IdString &rhs) const
Definition: Capability.h:197
sat::detail::IdType _id
Definition: Capability.h:259
static const Capability Empty
Empty Capability.
Definition: Capability.h:140
Capability()
Default ctor, Empty capability.
Definition: Capability.h:66
Capability(ResolverNamespace namespace_r, const char *value_r)
Definition: Capability.h:132
static CapMatch matches(const IdString &lhs, const IdString &rhs)
Definition: Capability.h:182
sat::detail::IdType _rhs
Definition: Capability.h:362
CapRel
Enum values corresponding with libsolv defines.
Definition: Capability.h:312
Capability rhs() const
Definition: Capability.h:354
CapDetail detail() const
Helper providing more detailed information about a Capability.
Definition: Capability.h:379
bool hasArch() const
Definition: Capability.h:343
std::string asString() const
Definition: Capability.h:158
Resolvable kinds.
Definition: ResKind.h:32
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool operator==(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:270
Capability(ResolverNamespace namespace_r, const std::string &value_r)
Definition: Capability.h:133
bool empty() const
Whether the Capability is empty.
Definition: Capability.h:150
IdString name() const
Definition: Capability.h:345
bool isSimple() const
Definition: Capability.h:338
static CapMatch matches(const std::string &lhs, const IdString &rhs)
Definition: Capability.h:187
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:176
CapMatch matches(const char *rhs) const
Definition: Capability.h:199
const char * c_str() const
Conversion to const char *
Definition: Capability.cc:311
static CapMatch matches(const std::string &lhs, const std::string &rhs)
Definition: Capability.h:188