libzypp 17.31.23
Dep.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <map>
13#include <iostream>
14
15#include <zypp/base/Exception.h>
16#include <zypp/base/Gettext.h>
17#include <zypp/base/String.h>
18
19#include <zypp/Dep.h>
20
22namespace zypp
23{
24
25 namespace
26 {
27 inline Dep::for_use_in_switch parse( const std::string & strval_r )
28 {
29 const std::map<std::string,Dep::for_use_in_switch> _table = {
30 { "provides", Dep::PROVIDES_e },
31 { "prerequires", Dep::PREREQUIRES_e },
32 { "requires", Dep::REQUIRES_e },
33 { "conflicts", Dep::CONFLICTS_e },
34 { "obsoletes", Dep::OBSOLETES_e },
35 { "recommends", Dep::RECOMMENDS_e },
36 { "suggests", Dep::SUGGESTS_e },
37 { "enhances", Dep::ENHANCES_e },
38 { "supplements", Dep::SUPPLEMENTS_e }
39 };
40
41 auto it = _table.find( str::toLower( strval_r ) );
42 if ( it == _table.end() )
43 {
44 ZYPP_THROW( Exception("Dep parse: illegal string value '"+strval_r+"'") );
45 }
46 return it->second;
47 }
48 }
49
51
52 const Dep Dep::PROVIDES ( Dep::PROVIDES_e );
54 const Dep Dep::REQUIRES ( Dep::REQUIRES_e );
55 const Dep Dep::CONFLICTS ( Dep::CONFLICTS_e );
56 const Dep Dep::OBSOLETES ( Dep::OBSOLETES_e );
58 const Dep Dep::SUGGESTS ( Dep::SUGGESTS_e );
59 const Dep Dep::ENHANCES ( Dep::ENHANCES_e );
61
63 //
64 // METHOD NAME : Dep::Dep
65 // METHOD TYPE : Ctor
66 //
67 Dep::Dep( const std::string & strval_r )
68 : _type( parse( strval_r ) )
69 {}
70
72 //
73 // METHOD NAME : Dep::asString
74 // METHOD TYPE : const std::string &
75 //
76 const std::string & Dep::asString() const
77 {
78 static const std::map<for_use_in_switch,std::string> _table = {
79 { PROVIDES_e, "provides" },
80 { PREREQUIRES_e, "prerequires" },
81 { REQUIRES_e, "requires" },
82 { CONFLICTS_e, "conflicts" },
83 { OBSOLETES_e, "obsoletes" },
84 { RECOMMENDS_e, "recommends" },
85 { SUGGESTS_e, "suggests" },
86 { ENHANCES_e, "enhances" },
87 { SUPPLEMENTS_e, "supplements" }
88 };
89 return _table.at(_type);
90 }
91
92 std::string Dep::asUserString() const
93 {
94 switch ( inSwitch() )
95 {
96 case PROVIDES_e: return _("Provides"); break;
97 case PREREQUIRES_e: return _("Prerequires"); break;
98 case REQUIRES_e: return _("Requires"); break;
99 case CONFLICTS_e: return _("Conflicts"); break;
100 case OBSOLETES_e: return _("Obsoletes"); break;
101 case RECOMMENDS_e: return _("Recommends"); break;
102 case SUGGESTS_e: return _("Suggests"); break;
103 case ENHANCES_e: return _("Enhances"); break;
104 case SUPPLEMENTS_e: return _("Supplements"); break;
105 }
106 return "<missing translation>";
107 }
108
110} // namespace zypp
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition: String.cc:177
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
static const Dep SUGGESTS
Definition: Dep.h:48
static const Dep CONFLICTS
Definition: Dep.h:45
for_use_in_switch
Enumarators provided only for use inSwitch statement.
Definition: Dep.h:56
@ SUGGESTS_e
Definition: Dep.h:63
@ REQUIRES_e
Definition: Dep.h:59
@ PREREQUIRES_e
Definition: Dep.h:58
@ RECOMMENDS_e
Definition: Dep.h:62
@ SUPPLEMENTS_e
Definition: Dep.h:65
@ PROVIDES_e
Definition: Dep.h:57
@ CONFLICTS_e
Definition: Dep.h:60
@ ENHANCES_e
Definition: Dep.h:64
@ OBSOLETES_e
Definition: Dep.h:61
static const Dep REQUIRES
Definition: Dep.h:44
static const Dep RECOMMENDS
Definition: Dep.h:47
static const Dep SUPPLEMENTS
Definition: Dep.h:50
for_use_in_switch _type
The operator.
Definition: Dep.h:98
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Dep.h:89
static const Dep PROVIDES
Definition: Dep.h:42
static const Dep OBSOLETES
Definition: Dep.h:46
std::string asUserString() const
Translated dependency type (capitalized).
Definition: Dep.cc:92
const std::string & asString() const
String representation of dependency type.
Definition: Dep.cc:76
static const Dep PREREQUIRES
Definition: Dep.h:43
static const Dep ENHANCES
Definition: Dep.h:49
Dep(const std::string &strval_r)
Ctor from string.
Definition: Dep.cc:67
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:428
#define _(MSG)
Definition: Gettext.h:37