- Create the cache directly from the schema (installed) file.
[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 ///////////////////////////////////////////////////////////////////
19 namespace zypp
20 { /////////////////////////////////////////////////////////////////
21
22   namespace
23   {
24
25     std::map<std::string,Rel::for_use_in_switch> _table;
26
27     Rel::for_use_in_switch parse( 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       std::map<std::string,Rel::for_use_in_switch>::const_iterator it
43       = _table.find( strval_r );
44       if ( it == _table.end() )
45         {
46           ZYPP_THROW( Exception("Rel parse: illegal string value '"+strval_r+"'") );
47         }
48       return it->second;
49     }
50   }
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 std::map<for_use_in_switch,std::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 ///////////////////////////////////////////////////////////////////