7979d75d3f86fa0c4c84a6d4ec991c474c0b170c
[platform/upstream/libzypp.git] / zypp / Rel.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Rel.cc
10  *
11 */
12 #include <map>
13
14 #include "zypp/base/Exception.h"
15
16 #include "zypp/Rel.h"
17
18 using namespace std;
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24 namespace
25 {
26
27   map<string,Rel::for_use_in_switch> _table;
28
29   Rel::for_use_in_switch parse( const std::string & strval_r )
30   {
31     if ( _table.empty() )
32       {
33         // initialize it
34         _table["EQ"] = _table["eq"] = _table["=="] = _table["="] = Rel::EQ_e;
35         _table["NE"] = _table["ne"] = _table["!="] = Rel::NE_e;
36         _table["LT"] = _table["lt"] = _table["<"]  = Rel::LT_e;
37         _table["LE"] = _table["le"] = _table["<="] = Rel::LE_e;
38         _table["GT"] = _table["gt"] = _table[">"]  = Rel::GT_e;
39         _table["GE"] = _table["ge"] = _table[">="] = Rel::GE_e;
40         _table["ANY"]  = _table["any"] = _table[""] = Rel::ANY_e;
41         _table["NONE"] = _table["none"]             = Rel::NONE_e;
42       }
43
44     map<string,Rel::for_use_in_switch>::const_iterator it
45       = _table.find( strval_r );
46     if ( it == _table.end() )
47       {
48         ZYPP_THROW( "Rel parse: illegal string value" );
49       }
50     return it->second;
51   }
52 }
53
54   const Rel Rel::EQ( Rel::EQ_e );
55   const Rel Rel::NE( Rel::NE_e );
56   const Rel Rel::LT( Rel::LT_e );
57   const Rel Rel::LE( Rel::LE_e );
58   const Rel Rel::GT( Rel::GT_e );
59   const Rel Rel::GE( Rel::GE_e );
60   const Rel Rel::ANY( Rel::ANY_e );
61   const Rel Rel::NONE( Rel::NONE_e );
62
63   ///////////////////////////////////////////////////////////////////
64   //
65   //    METHOD NAME : Rel::Rel
66   //    METHOD TYPE : Constructor
67   //
68   Rel::Rel( const std::string & strval_r )
69   : _op( parse( strval_r ) )
70   {}
71
72   ///////////////////////////////////////////////////////////////////
73   //
74   //    METHOD NAME : Rel::asString
75   //    METHOD TYPE : const std::string &
76   //
77   const std::string & Rel::asString() const
78   {
79     static map<for_use_in_switch,string> _table;
80     if ( _table.empty() )
81       {
82         // initialize it
83         _table[EQ_e]   = "==";
84         _table[NE_e]   = "!=";
85         _table[LT_e]   = "<";
86         _table[LE_e]   = "<=";
87         _table[GT_e]   = ">";
88         _table[GE_e]   = ">=";
89         _table[ANY_e]  = "ANY";
90         _table[NONE_e] = "NONE";
91       }
92     return _table[_op];
93   }
94
95   /////////////////////////////////////////////////////////////////
96 } // namespace zypp
97 ///////////////////////////////////////////////////////////////////