libzypp: zypp/ResKind.cc Source File

libzypp 17.38.10

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-core/base/String.h>
15
16#include <zypp/ResKind.h>
17#include <zypp/ResTraits.h>
18
19using std::endl;
20
22namespace 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<>
34 const ResKind ResTraits<Package> ::kind( ResKind::package );
35 template<>
36 const ResKind ResTraits<Patch> ::kind( ResKind::patch );
37 template<>
38 const ResKind ResTraits<Pattern> ::kind( ResKind::pattern );
39 template<>
40 const ResKind ResTraits<Product> ::kind( ResKind::product );
41 template<>
42 const ResKind ResTraits<SrcPackage> ::kind( ResKind::srcpackage );
43 template<>
44 const ResKind ResTraits<Application>::kind( ResKind::application );
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
OUTS
#define OUTS(VAL)
ResKind.h
ResTraits.h
String.h
zypp::ResKind
Resolvable kinds.
Definition ResKind.h:33
zypp::ResKind::srcpackage
static const ResKind srcpackage
Definition ResKind.h:44
zypp::ResKind::application
static const ResKind application
Definition ResKind.h:45
zypp::ResKind::pattern
static const ResKind pattern
Definition ResKind.h:42
zypp::ResKind::product
static const ResKind product
Definition ResKind.h:43
zypp::ResKind::patch
static const ResKind patch
Definition ResKind.h:41
zypp::ResKind::explicitBuiltin
static ResKind explicitBuiltin(const char *str_r)
Return the builtin kind if str_r explicitly prefixed.
Definition ResKind.cc:46
zypp::ResKind::nokind
static const ResKind nokind
Value representing nokind ("").
Definition ResKind.h:38
zypp::ResKind::package
static const ResKind package
Definition ResKind.h:40
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::ResKind
ResKind()
Default ctor: nokind.
Definition ResKind.h:63
zyppng::IdStringType::c_str
const char * c_str() const
Definition IdStringType.h:115
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::ResTraits
ResTraits.
Definition ResTraits.h:80