libzypp  17.23.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/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
zypp::CapDetail::lhs
Capability lhs() const
Definition: Capability.h:352
zypp::Capability::id
sat::detail::IdType id() const
Expert backdoor.
Definition: Capability.h:253
zypp::Capability::matches
static CapMatch matches(const IdString &lhs, const std::string &rhs)
Definition: Capability.h:183
Edition.h
zypp::CapDetail::_init
void _init()
Definition: Capability.cc:454
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:158
zypp::Capability::matches
static CapMatch matches(const Capability &lhs, const char *rhs)
Definition: Capability.h:179
zypp::CapDetail::isVersioned
bool isVersioned() const
Definition: Capability.h:337
zypp::CapDetail::capRel
CapRel capRel() const
Definition: Capability.h:353
zypp::Capability::operator!=
bool operator!=(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:274
zypp::Capability::matches
static CapMatch matches(const Capability &lhs, const std::string &rhs)
Definition: Capability.h:178
zypp::CapDetail::REL_NONE
Definition: Capability.h:314
zypp::CapDetail::ed
Edition ed() const
Definition: Capability.h:347
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:50
zypp::sat::detail::noId
static const IdType noId(0)
zypp::Capability::Capability
Capability(sat::detail::IdType id_r)
Ctor from id.
Definition: Capability.h:69
zypp::CapDetail::isNull
bool isNull() const
Definition: Capability.h:335
zypp::Capability::matches
CapMatch matches(const Capability &rhs) const
Definition: Capability.h:196
zypp::Capability::Matches
matches functor.
Definition: Capability.h:204
zypp::CapDetail::VERSIONED
Definition: Capability.h:305
zypp::Rel
Relational operators.
Definition: Rel.h:43
zypp::Capability::matches
CapMatch matches(const std::string &rhs) const
Definition: Capability.h:198
zypp::Capability::matches
static CapMatch matches(const char *lhs, const IdString &rhs)
Definition: Capability.h:192
zypp::Edition
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
ResolverNamespace.h
zypp::IdString::Null
static const IdString Null
No or Null string ( Id 0 ).
Definition: IdString.h:67
CapMatch.h
zypp::CapDetail::_kind
Kind _kind
Definition: Capability.h:360
zypp::CapDetail::CapDetail
CapDetail(sat::detail::IdType id_r)
Definition: Capability.h:329
zypp::Capability::matches
static CapMatch matches(const char *lhs, const Capability &rhs)
Definition: Capability.h:191
zypp::CapDetail::isNamed
bool isNamed() const
Definition: Capability.h:336
ResTraits.h
zypp::CapDetail::NOCAP
Definition: Capability.h:303
PoolMember.h
zypp::CapDetail::op
Rel op() const
Definition: Capability.h:346
zypp::Capability::matches
CapMatch matches(const char *rhs) const
Definition: Capability.h:199
zypp::Capability::matches
static CapMatch matches(const std::string &lhs, const IdString &rhs)
Definition: Capability.h:187
zypp::CapDetail::CapDetail
CapDetail()
Definition: Capability.h:323
zypp::Arch
Architecture.
Definition: Arch.h:36
zypp::CapDetail::arch
IdString arch() const
Definition: Capability.h:344
bool
zypp::CapDetail::CAP_WITH
Definition: Capability.h:317
zypp::Capability::matches
static CapMatch matches(const char *lhs, const std::string &rhs)
Definition: Capability.h:193
zypp::CapDetail::isExpression
bool isExpression() const
Definition: Capability.h:339
Rel.h
zypp::Capability::matches
static CapMatch matches(const IdString &lhs, const IdString &rhs)
Definition: Capability.h:182
zypp::sat::detail::emptyId
static const IdType emptyId(1)
zypp::CapDetail::CAP_OR
Definition: Capability.h:316
zypp::IdString
Access to the sat-pools string space.
Definition: IdString.h:41
zypp::CapabilitySet
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
zypp::Capability::matches
static CapMatch matches(const Capability &lhs, const IdString &rhs)
Definition: Capability.h:177
zypp::Capability::isInterestingFileSpec
static bool isInterestingFileSpec(const std::string &name_r)
Definition: Capability.h:217
zypp::Capability::c_str
const char * c_str() const
Conversion to const char *
Definition: Capability.cc:311
zypp::ResolverNamespace
ResolverNamespace
The resolvers dependency namespaces.
Definition: ResolverNamespace.h:24
zypp::Capability::matches
CapMatch matches(const IdString &rhs) const
Definition: Capability.h:197
zypp::Rel::ANY
static const Rel ANY
Definition: Rel.h:56
zypp::CapDetail::Kind
Kind
Definition: Capability.h:301
zypp::Capability::_doMatch
static CapMatch _doMatch(sat::detail::IdType lhs, sat::detail::IdType rhs)
Match two Capabilities.
Definition: Capability.cc:314
zypp::Capability::empty
bool empty() const
Whether the Capability is empty.
Definition: Capability.h:150
zypp::Capability::CtorFlag
CtorFlag
Definition: Capability.h:62
zypp::Capability::matches
static CapMatch matches(const std::string &lhs, const Capability &rhs)
Definition: Capability.h:186
zypp::Capability::isInterestingFileSpec
static bool isInterestingFileSpec(const IdString &name_r)
Test for a filename that is likely being REQUIRED.
Definition: Capability.h:216
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition: PoolMember.h:104
zypp::CapDetail::kind
Kind kind() const
Definition: Capability.h:334
zypp::Capability::Matches::operator()
CapMatch operator()(const Capability &lhs, const Capability &rhs) const
Definition: Capability.h:206
zypp::Capability::Null
static const Capability Null
No or Null Capability ( Id 0 ).
Definition: Capability.h:137
zypp::Capability::matches
static CapMatch matches(const IdString &lhs, const Capability &rhs)
Definition: Capability.h:181
IdString.h
zypp::CapDetail::CAP_NAMESPACE
Definition: Capability.h:318
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::Capability::matches
static CapMatch matches(const char *lhs, const char *rhs)
Definition: Capability.h:194
zypp::Capability::operator<
bool operator<(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:278
zypp::CapDetail::CapDetail
CapDetail(const Capability &cap_r)
Definition: Capability.h:326
zypp::Capability::Empty
static const Capability Empty
Empty Capability.
Definition: Capability.h:140
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition: IdString.h:115
zypp::Capability::Capability
Capability(ResolverNamespace namespace_r, const char *value_r)
Definition: Capability.h:132
zypp::Capability::Capability
Capability(ResolverNamespace namespace_r, const std::string &value_r)
Definition: Capability.h:133
zypp::CapDetail::CAP_ARCH
Definition: Capability.h:319
zypp::Capability::matches
static CapMatch matches(const std::string &lhs, const char *rhs)
Definition: Capability.h:189
zypp::Capability::matches
static CapMatch matches(const IdString &lhs, const char *rhs)
Definition: Capability.h:184
zypp::Capability::guessPackageSpec
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
zypp::Capability
A sat capability.
Definition: Capability.h:59
zypp::CapDetail::NAMED
Definition: Capability.h:304
zypp::Capability::UNPARSED
Definition: Capability.h:62
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
zypp::Capability::detail
CapDetail detail() const
Helper providing more detailed information about a Capability.
Definition: Capability.h:379
zypp::CapMatch
Tri state Capability match result.
Definition: CapMatch.h:37
zypp::CapDetail::_lhs
sat::detail::IdType _lhs
Definition: Capability.h:361
zypp::Capability::PARSED
Definition: Capability.h:62
zypp::CapDetail::_archIfSimple
sat::detail::IdType _archIfSimple
Definition: Capability.h:364
zypp::CapDetail::_rhs
sat::detail::IdType _rhs
Definition: Capability.h:362
zypp::CapDetail::_flag
unsigned _flag
Definition: Capability.h:363
zypp::sat::detail::PoolMember
Backlink to the associated PoolImpl.
Definition: PoolMember.h:88
zypp::CapDetail::hasArch
bool hasArch() const
Definition: Capability.h:343
zypp::CapDetail::name
IdString name() const
Definition: Capability.h:345
ZYPP_DEFINE_ID_HASHABLE
ZYPP_DEFINE_ID_HASHABLE(::zypp::Capability)
str
String related utilities and Regular expression matching.
zypp::Capability::Capability
Capability()
Default ctor, Empty capability.
Definition: Capability.h:66
zypp::CapDetail::isSimple
bool isSimple() const
Definition: Capability.h:338
zypp::dumpOn
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:443
zypp::CapDetail::CapRel
CapRel
Enum values corresponding with libsolv defines.
Definition: Capability.h:312
zypp::Capability::matches
static CapMatch matches(const std::string &lhs, const std::string &rhs)
Definition: Capability.h:188
zypp::CapDetail::rhs
Capability rhs() const
Definition: Capability.h:354
zypp::Capability::operator==
bool operator==(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:270
zypp::ResKind
Resolvable kinds. A lowercased string and used as identification. Comparison against string values is...
Definition: ResKind.h:32
zypp::CapDetail::CAP_AND
Definition: Capability.h:315
zypp::Capability::matches
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:176
zypp::CapDetail
Helper providing more detailed information about a Capability.
Definition: Capability.h:298
zypp::Capability::_id
sat::detail::IdType _id
Definition: Capability.h:259
zypp::CapDetail::EXPRESSION
Definition: Capability.h:306