libzypp: zypp/Rel.cc Source File

libzypp 17.38.10

Rel.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <map>
14
15#include <zypp-core/base/Exception.h>
16
17#include <zypp/Rel.h>
18
20namespace zypp
21{
22
23 namespace
24 {
25 std::map<std::string,Rel::for_use_in_switch> _table;
26
27 std::map<std::string,Rel::for_use_in_switch>::const_iterator findStr( const std::string & strval_r )
28 {
29 if ( _table.empty() )
30 {
31 // initialize it
32 _table["EQ"] = _table["eq"] = _table["=="] = _table["="] = Rel::EQ_e;
33 _table["NE"] = _table["ne"] = _table["!="] = Rel::NE_e;
34 _table["LT"] = _table["lt"] = _table["<"] = Rel::LT_e;
35 _table["LE"] = _table["le"] = _table["lte"] = _table["<="] = Rel::LE_e;
36 _table["GT"] = _table["gt"] = _table[">"] = Rel::GT_e;
37 _table["GE"] = _table["ge"] = _table["gte"] = _table[">="] = Rel::GE_e;
38 _table["ANY"] = _table["any"] = _table["(any)"] = _table[""] = Rel::ANY_e;
39 _table["NONE"] = _table["none"] = Rel::NONE_e;
40 }
41
42 return _table.find( strval_r );
43 }
44
45 Rel::for_use_in_switch parse( const std::string & strval_r )
46 {
47 std::map<std::string,Rel::for_use_in_switch>::const_iterator it = findStr( strval_r );
48 if ( it == _table.end() )
49 {
50 ZYPP_THROW( Exception("Rel parse: illegal string value '"+strval_r+"'") );
51 }
52 return it->second;
53 }
54
55 Rel::for_use_in_switch parse( const std::string & strval_r, const Rel & default_r )
56 {
57 std::map<std::string,Rel::for_use_in_switch>::const_iterator it = findStr( strval_r );
58 if ( it == _table.end() )
59 {
60 return default_r.inSwitch();
61 }
62 return it->second;
63 }
64 }
66
67 const Rel Rel::EQ( Rel::EQ_e );
68 const Rel Rel::NE( Rel::NE_e );
69 const Rel Rel::LT( Rel::LT_e );
70 const Rel Rel::LE( Rel::LE_e );
71 const Rel Rel::GT( Rel::GT_e );
72 const Rel Rel::GE( Rel::GE_e );
73 const Rel Rel::ANY( Rel::ANY_e );
74 const Rel Rel::NONE( Rel::NONE_e );
75
77 //
78 // METHOD NAME : Rel::Rel
79 // METHOD TYPE : Constructor
80 //
81 Rel::Rel( const std::string & strval_r )
82 : _op( parse( strval_r ) )
83 {}
84
85 Rel::Rel( const std::string & strval_r, const Rel & default_r )
86 : _op( parse( strval_r, default_r ) )
87 {}
88
89 bool Rel::parseFrom( const std::string & strval_r )
90 {
91 std::map<std::string,Rel::for_use_in_switch>::const_iterator it = findStr( strval_r );
92 if ( it == _table.end() )
93 {
94 return false;
95 }
96 _op = it->second;
97 return true;
98 }
99
101 //
102 // METHOD NAME : Rel::asString
103 // METHOD TYPE : const std::string &
104 //
105 const std::string & Rel::asString() const
106 {
107 static std::map<for_use_in_switch,std::string> _table;
108 if ( _table.empty() )
109 {
110 // initialize it
111 _table[EQ_e] = "=";
112 _table[NE_e] = "!=";
113 _table[LT_e] = "<";
114 _table[LE_e] = "<=";
115 _table[GT_e] = ">";
116 _table[GE_e] = ">=";
117 _table[ANY_e] = "ANY";
118 _table[NONE_e] = "NONE";
119 }
120 return _table[_op];
121 }
122
124} // namespace zypp
Exception.h
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
Rel.h
zypp::Exception
Base class for Exception.
Definition Exception.h:153
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::Rel
Relational operators.
Definition Rel.h:46
zypp::Rel::LT
static const Rel LT
Definition Rel.h:54
zypp::Rel::parseFrom
bool parseFrom(const std::string &strval_r)
Assign from string IFF it contains a legal value.
Definition Rel.cc:89
zypp::Rel::GT
static const Rel GT
Definition Rel.h:56
zypp::Rel::Rel
Rel()
DefaultCtor ANY.
Definition Rel.h:79
zypp::Rel::LE
static const Rel LE
Definition Rel.h:55
zypp::Rel::GE
static const Rel GE
Definition Rel.h:57
zypp::Rel::NONE
static const Rel NONE
Definition Rel.h:59
zypp::Rel::NE
static const Rel NE
Definition Rel.h:53
zypp::Rel::ANY
static const Rel ANY
Definition Rel.h:58
zypp::Rel::EQ
static const Rel EQ
Definition Rel.h:52
zypp::Rel::for_use_in_switch
for_use_in_switch
Enumarators provided only for use inSwitch statement.
Definition Rel.h:67
zypp::Rel::ANY_e
@ ANY_e
Definition Rel.h:75
zypp::Rel::LT_e
@ LT_e
Definition Rel.h:71
zypp::Rel::GT_e
@ GT_e
Definition Rel.h:69
zypp::Rel::NE_e
@ NE_e
Definition Rel.h:74
zypp::Rel::LE_e
@ LE_e
Definition Rel.h:73
zypp::Rel::NONE_e
@ NONE_e
Definition Rel.h:68
zypp::Rel::EQ_e
@ EQ_e
Definition Rel.h:70
zypp::Rel::GE_e
@ GE_e
Definition Rel.h:72
zypp::Rel::_op
for_use_in_switch _op
The operator.
Definition Rel.h:156
zypp::Rel::asString
const std::string & asString() const
String representation of relational operator.
Definition Rel.cc:105