libzypp 17.37.10

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
22 namespace 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 );
53 const Dep Dep::PREREQUIRES( Dep::PREREQUIRES_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 );
57 const Dep Dep::RECOMMENDS ( Dep::RECOMMENDS_e );
58 const Dep Dep::SUGGESTS ( Dep::SUGGESTS_e );
59 const Dep Dep::ENHANCES ( Dep::ENHANCES_e );
60 const Dep Dep::SUPPLEMENTS( Dep::SUPPLEMENTS_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
Dep.h
zypp::Exception
Base class for Exception.
Definition Exception.h:153
zypp::sat::parse
void parse(const C_Str &spec_r)
Parse and add spec from a string (IDENT or provides:CAPABILITY`).
zypp::str::toLower
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition String.cc:180
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::Dep
Enumeration class of dependency types.
Definition Dep.h:30
zypp::Dep::asUserString
std::string asUserString() const ZYPP_API
Translated dependency type (capitalized).
Definition Dep.cc:92
zypp::Dep::for_use_in_switch
for_use_in_switch
Enumarators provided only for use inSwitch statement.
Definition Dep.h:56
zypp::Dep::SUGGESTS_e
@ SUGGESTS_e
Definition Dep.h:63
zypp::Dep::REQUIRES_e
@ REQUIRES_e
Definition Dep.h:59
zypp::Dep::PREREQUIRES_e
@ PREREQUIRES_e
Definition Dep.h:58
zypp::Dep::RECOMMENDS_e
@ RECOMMENDS_e
Definition Dep.h:62
zypp::Dep::SUPPLEMENTS_e
@ SUPPLEMENTS_e
Definition Dep.h:65
zypp::Dep::PROVIDES_e
@ PROVIDES_e
Definition Dep.h:57
zypp::Dep::CONFLICTS_e
@ CONFLICTS_e
Definition Dep.h:60
zypp::Dep::ENHANCES_e
@ ENHANCES_e
Definition Dep.h:64
zypp::Dep::OBSOLETES_e
@ OBSOLETES_e
Definition Dep.h:61
zypp::Dep::_type
for_use_in_switch _type
The operator.
Definition Dep.h:98
zypp::Dep::inSwitch
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition Dep.h:89
zypp::Dep::asString
const std::string & asString() const ZYPP_API
String representation of dependency type.
Definition Dep.cc:76
zypp::Dep::Dep
Dep(const std::string &strval_r)
Ctor from string.
Definition Dep.cc:67
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
_
#define _(MSG)
Definition Gettext.h:39
Exception.h
Gettext.h
Interface to gettext.
String.h