libzypp  17.25.1
ResKind.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 
14 #include <zypp/base/String.h>
15 
16 #include <zypp/ResKind.h>
17 #include <zypp/ResTraits.h>
18 
19 using std::endl;
20 
22 namespace zypp
23 {
24 
25  const ResKind ResKind::nokind;
26  const ResKind ResKind::package ( "package" );
27  const ResKind ResKind::patch ( "patch" );
28  const ResKind ResKind::pattern ( "pattern" );
29  const ResKind ResKind::product ( "product" );
30  const ResKind ResKind::srcpackage ( "srcpackage" );
31  const ResKind ResKind::application ( "application" );
32 
33  template<>
35  template<>
36  const ResKind ResTraits<Patch> ::kind( ResKind::patch );
37  template<>
39  template<>
41  template<>
43  template<>
45 
46  ResKind ResKind::explicitBuiltin( const char * str_r )
47  {
48  if ( str_r && str_r[0] && str_r[1] && str_r[2] )
49  {
50  switch ( str_r[3] )
51  {
52  // NOTE: it needs to be assertd that the separating ':' is present
53  // if a known kind is retuirned. Dependent code relies on this!
54  #define OUTS(K,S) if ( !::strncmp( str_r, ResKind::K.c_str(), S ) && str_r[S] == ':' ) return ResKind::K
55  // ----v
56  case 'c': OUTS( patch, 5 ); break;
57  case 'd': OUTS( product, 7 ); break;
58  case 'k': OUTS( package, 7 ); break;
59  case 'l': OUTS( application, 11 );break;
60  case 'p': OUTS( srcpackage, 10 ); break;
61  case 't': OUTS( pattern, 7 ); break;
62  #undef OUTS
63  }
64  }
65  return nokind;
66  }
67 
68  std::string ResKind::satIdent( const ResKind & refers_r, const std::string & name_r )
69  {
70  if ( ! refers_r || refers_r == package || refers_r == srcpackage )
71  return name_r;
72  return str::form( "%s:%s", refers_r.c_str(), name_r.c_str() );
73  }
74 
76 } // namespace zypp
zypp::ResKind::patch
static const ResKind patch
Definition: ResKind.h:41
zypp::ResKind::package
static const ResKind package
Definition: ResKind.h:40
ResTraits.h
ResKind.h
zypp::ResKind::product
static const ResKind product
Definition: ResKind.h:43
zypp::ResKind::nokind
static const ResKind nokind
Value representing nokind ("")
Definition: ResKind.h:38
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:35
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::ResKind::application
static const ResKind application
Definition: ResKind.h:45
zypp::ResKind::satIdent
static std::string satIdent(const ResKind &refers_r, const std::string &name_r)
Return libsolv identifier for name.
Definition: ResKind.cc:68
zypp::ResKind::srcpackage
static const ResKind srcpackage
Definition: ResKind.h:44
String.h
OUTS
#define OUTS(K, S)
zypp::ResKind::pattern
static const ResKind pattern
Definition: ResKind.h:42
zypp::IdStringType::c_str
const char * c_str() const
Definition: IdStringType.h:105
zypp::ResTraits::kind
const ResKind kind
Definition: ResTraits.h:93
zypp::ResKind
Resolvable kinds. A lowercased string and used as identification. Comparison against string values is...
Definition: ResKind.h:32
zypp::ResKind::explicitBuiltin
static ResKind explicitBuiltin(const char *str_r)
Return the builtin kind if str_r explicitly prefixed.
Definition: ResKind.cc:46