libzypp  13.10.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 
25 #include "zypp/CapMatch.h"
26 
28 namespace zypp
29 {
30 
31  class Capability;
32  class CapDetail;
33  class Arch;
34 
35  typedef std::tr1::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 
126  public:
128  static const Capability Null;
129 
131  static const Capability Empty;
132 
133  public:
135  explicit operator bool() const
136  { return ! empty(); }
137 
141  bool empty() const
142  { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
143 
144  public:
146  const char * c_str() const;
147 
149  std::string asString() const
150  { return c_str(); }
151 
152  public:
154  CapDetail detail() const;
155 
156  public:
167  static CapMatch matches( const Capability & lhs, const Capability & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
168  static CapMatch matches( const Capability & lhs, const IdString & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
169  static CapMatch matches( const Capability & lhs, const std::string & rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
170  static CapMatch matches( const Capability & lhs, const char * rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() );}
171 
172  static CapMatch matches( const IdString & lhs, const Capability & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
173  static CapMatch matches( const IdString & lhs, const IdString & rhs ) { return _doMatch( lhs.id(), rhs.id() ); }
174  static CapMatch matches( const IdString & lhs, const std::string & rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
175  static CapMatch matches( const IdString & lhs, const char * rhs ) { return _doMatch( lhs.id(), Capability(rhs).id() ); }
176 
177  static CapMatch matches( const std::string & lhs, const Capability & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() );}
178  static CapMatch matches( const std::string & lhs, const IdString & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() ); }
179  static CapMatch matches( const std::string & lhs, const std::string & rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
180  static CapMatch matches( const std::string & lhs, const char * rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
181 
182  static CapMatch matches( const char * lhs, const Capability & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() );}
183  static CapMatch matches( const char * lhs, const IdString & rhs ) { return _doMatch( Capability(lhs).id(), rhs.id() ); }
184  static CapMatch matches( const char * lhs, const std::string & rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
185  static CapMatch matches( const char * lhs, const char * rhs ) { return _doMatch( Capability(lhs).id(), Capability(rhs).id() ); }
186 
187  CapMatch matches( const Capability & rhs ) const { return _doMatch( id(), rhs.id() ); }
188  CapMatch matches( const IdString & rhs ) const { return _doMatch( id(), rhs.id() ); }
189  CapMatch matches( const std::string & rhs ) const { return _doMatch( id(), Capability(rhs).id() ); }
190  CapMatch matches( const char * rhs ) const { return _doMatch( id(), Capability(rhs).id() ); }
192 
195  struct Matches: public std::binary_function<Capability,Capability,CapMatch>
196  {
197  CapMatch operator()( const Capability & lhs, const Capability & rhs ) const
198  { return Capability::matches( lhs, rhs ); }
199  };
200 
201  public:
207  static bool isInterestingFileSpec( const IdString & name_r ) { return isInterestingFileSpec( name_r.c_str() ); }
208  static bool isInterestingFileSpec( const std::string & name_r ) { return isInterestingFileSpec( name_r.c_str() ); }
209  static bool isInterestingFileSpec( const char * name_r );
210 
235  static Capability guessPackageSpec( const std::string & str_r );
240  static Capability guessPackageSpec( const std::string & str_r, bool & rewrote_r );
241 
242  public:
245  { return _id; }
246  private:
249  private:
251  };
253 
255  std::ostream & operator<<( std::ostream & str, const Capability & obj );
256 
258  std::ostream & dumpOn( std::ostream & str, const Capability & obj );
259 
261  inline bool operator==( const Capability & lhs, const Capability & rhs )
262  { return lhs.id() == rhs.id(); }
263 
265  inline bool operator!=( const Capability & lhs, const Capability & rhs )
266  { return lhs.id() != rhs.id(); }
267 
269  inline bool operator<( const Capability & lhs, const Capability & rhs )
270  { return lhs.id() < rhs.id(); }
271 
273  //
274  // CLASS NAME : CapDetail
275  //
290  {
291  public:
292  enum Kind
293  {
294  NOCAP = 0x00,
295  NAMED = 0x01,
296  VERSIONED = 0x02,
297  EXPRESSION = 0x04
298  };
299 
303  enum CapRel
304  {
305  REL_NONE = 0,
306  CAP_AND = 16,
307  CAP_OR = 17,
308  CAP_WITH = 18,
310  CAP_ARCH = 20
311  };
312 
313  public:
315  : _kind( NOCAP ), _lhs( 0 ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
316  {}
317  explicit CapDetail( const Capability & cap_r )
318  : _kind( NOCAP ), _lhs( cap_r.id() ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
319  { _init(); }
321  : _kind( NOCAP ), _lhs( id_r ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
322  { _init(); }
323 
324  public:
325  Kind kind() const { return _kind; }
326  bool isNull() const { return _kind == NOCAP; }
327  bool isNamed() const { return _kind == NAMED; }
328  bool isVersioned() const { return _kind == VERSIONED; }
329  bool isSimple() const { return _kind & (NAMED|VERSIONED); }
330  bool isExpression() const { return _kind == EXPRESSION; }
331 
334  bool hasArch() const { return _archIfSimple; }
335  IdString arch() const { return _archIfSimple ? IdString( _archIfSimple ) : IdString(); }
336  IdString name() const { return isSimple() ? IdString( _lhs ) : IdString(); }
337  Rel op() const { return isVersioned() ? Rel( _flag ) : Rel::ANY; }
338  Edition ed() const { return isVersioned() ? Edition( _rhs ) : Edition(); }
340 
344  CapRel capRel() const { return isExpression() ? CapRel(_flag) : REL_NONE; }
347 
348  private:
349  void _init();
350  private:
354  unsigned _flag;
356  };
358 
360  std::ostream & operator<<( std::ostream & str, const CapDetail & obj );
361 
363  std::ostream & operator<<( std::ostream & str, CapDetail::Kind obj );
364 
366  std::ostream & operator<<( std::ostream & str, CapDetail::CapRel obj );
367 
369 
370  inline CapDetail Capability::detail() const { return CapDetail( _id ); }
371 
373 } // namespace zypp
375 
377 
378 #endif // ZYPP_CAPABILITY_H
static CapMatch matches(const IdString &lhs, const std::string &rhs)
Definition: Capability.h:174
int IdType
Generic Id type.
Definition: PoolMember.h:82
CapRel capRel() const
Definition: Capability.h:344
static CapMatch _doMatch(sat::detail::IdType lhs, sat::detail::IdType rhs)
Match two Capabilities.
Definition: Capability.cc:305
static Capability guessPackageSpec(const std::string &str_r)
Capability parser also guessing &quot;libzypp-1.2.3-4.5.x86_64&quot; formats.
Definition: Capability.cc:419
Helper providing more detailed information about a Capability.
Definition: Capability.h:289
static CapMatch matches(const std::string &lhs, const char *rhs)
Definition: Capability.h:180
static CapMatch matches(const Capability &lhs, const std::string &rhs)
Definition: Capability.h:169
Architecture.
Definition: Arch.h:36
static CapMatch matches(const IdString &lhs, const char *rhs)
Definition: Capability.h:175
IdType id() const
Expert backdoor.
Definition: IdString.h:103
Relational operators.
Definition: Rel.h:43
CapDetail(sat::detail::IdType id_r)
Definition: Capability.h:320
bool isNamed() const
Definition: Capability.h:327
static CapMatch matches(const Capability &lhs, const char *rhs)
Definition: Capability.h:170
bool isNull() const
Definition: Capability.h:326
static CapMatch matches(const char *lhs, const IdString &rhs)
Definition: Capability.h:183
Capability(sat::detail::IdType id_r)
Ctor from id.
Definition: Capability.h:69
Access to the sat-pools string space.
Definition: IdString.h:39
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
static const Rel ANY
Definition: Rel.h:56
CapMatch operator()(const Capability &lhs, const Capability &rhs) const
Definition: Capability.h:197
static bool isInterestingFileSpec(const IdString &name_r)
Test for a filename that is likely being REQUIRED.
Definition: Capability.h:207
std::tr1::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
Capability lhs() const
Definition: Capability.h:343
static bool isInterestingFileSpec(const std::string &name_r)
Definition: Capability.h:208
CapDetail detail() const
Helper providing more detailed information about a Capability.
Definition: Capability.h:370
Backlink to the associated PoolImpl.
Definition: PoolMember.h:66
static const IdType emptyId(1)
bool isVersioned() const
Definition: Capability.h:328
bool operator<(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:269
static CapMatch matches(const char *lhs, const std::string &rhs)
Definition: Capability.h:184
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
Kind kind() const
Definition: Capability.h:325
CapMatch matches(const char *rhs) const
Definition: Capability.h:190
Provides API related macros.
CapMatch matches(const std::string &rhs) const
Definition: Capability.h:189
bool empty() const
Whether the Capability is empty.
Definition: Capability.h:141
#define ZYPP_DEFINE_ID_HASHABLE(C)
Define hash function for id based classes.
Definition: Tr1hash.h:26
IdString arch() const
Definition: Capability.h:335
static CapMatch matches(const Capability &lhs, const IdString &rhs)
Definition: Capability.h:168
static CapMatch matches(const char *lhs, const char *rhs)
Definition: Capability.h:185
static CapMatch matches(const IdString &lhs, const Capability &rhs)
Definition: Capability.h:172
CapDetail(const Capability &cap_r)
Definition: Capability.h:317
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:435
Tri state Capability match result.
Definition: CapMatch.h:37
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:42
static const Capability Null
No or Null Capability ( Id 0 ).
Definition: Capability.h:128
bool isExpression() const
Definition: Capability.h:330
matches functor.
Definition: Capability.h:195
sat::detail::IdType _lhs
Definition: Capability.h:352
static CapMatch matches(const char *lhs, const Capability &rhs)
Definition: Capability.h:182
CapMatch matches(const Capability &rhs) const
Definition: Capability.h:187
sat::detail::IdType _archIfSimple
Definition: Capability.h:355
A sat capability.
Definition: Capability.h:59
unsigned _flag
Definition: Capability.h:354
bool isSimple() const
Definition: Capability.h:329
bool operator!=(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:265
static const IdType noId(0)
static CapMatch matches(const std::string &lhs, const Capability &rhs)
Definition: Capability.h:177
Edition ed() const
Definition: Capability.h:338
sat::detail::IdType _id
Definition: Capability.h:250
static const Capability Empty
Empty Capability.
Definition: Capability.h:131
Capability()
Default ctor, Empty capability.
Definition: Capability.h:66
const char * c_str() const
Conversion to const char *
Definition: Capability.cc:302
Capability rhs() const
Definition: Capability.h:345
static CapMatch matches(const IdString &lhs, const IdString &rhs)
Definition: Capability.h:173
sat::detail::IdType _rhs
Definition: Capability.h:353
CapRel
Enum values corresponding with libsolv defines.
Definition: Capability.h:303
std::string asString() const
Definition: Capability.h:149
CapMatch matches(const IdString &rhs) const
Definition: Capability.h:188
Resolvable kinds.
Definition: ResKind.h:35
bool operator==(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:261
Rel op() const
Definition: Capability.h:337
IdString name() const
Definition: Capability.h:336
static CapMatch matches(const std::string &lhs, const IdString &rhs)
Definition: Capability.h:178
bool hasArch() const
Definition: Capability.h:334
static CapMatch matches(const Capability &lhs, const Capability &rhs)
Definition: Capability.h:167
sat::detail::IdType id() const
Expert backdoor.
Definition: Capability.h:244
static CapMatch matches(const std::string &lhs, const std::string &rhs)
Definition: Capability.h:179