00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <map>
00013
00014 #include "zypp/base/Exception.h"
00015
00016 #include "zypp/Rel.h"
00017
00019 namespace zypp
00020 {
00021
00022 namespace
00023 {
00024
00025 std::map<std::string,Rel::for_use_in_switch> _table;
00026
00027 Rel::for_use_in_switch parse( const std::string & strval_r )
00028 {
00029 if ( _table.empty() )
00030 {
00031
00032 _table["EQ"] = _table["eq"] = _table["=="] = _table["="] = Rel::EQ_e;
00033 _table["NE"] = _table["ne"] = _table["!="] = Rel::NE_e;
00034 _table["LT"] = _table["lt"] = _table["<"] = Rel::LT_e;
00035 _table["LE"] = _table["le"] = _table["lte"] = _table["<="] = Rel::LE_e;
00036 _table["GT"] = _table["gt"] = _table[">"] = Rel::GT_e;
00037 _table["GE"] = _table["ge"] = _table["gte"] = _table[">="] = Rel::GE_e;
00038 _table["ANY"] = _table["any"] = _table["(any)"] = _table[""] = Rel::ANY_e;
00039 _table["NONE"] = _table["none"] = Rel::NONE_e;
00040 }
00041
00042 std::map<std::string,Rel::for_use_in_switch>::const_iterator it
00043 = _table.find( strval_r );
00044 if ( it == _table.end() )
00045 {
00046 ZYPP_THROW( Exception("Rel parse: illegal string value '"+strval_r+"'") );
00047 }
00048 return it->second;
00049 }
00050 }
00051
00053
00054 const Rel Rel::EQ( Rel::EQ_e );
00055 const Rel Rel::NE( Rel::NE_e );
00056 const Rel Rel::LT( Rel::LT_e );
00057 const Rel Rel::LE( Rel::LE_e );
00058 const Rel Rel::GT( Rel::GT_e );
00059 const Rel Rel::GE( Rel::GE_e );
00060 const Rel Rel::ANY( Rel::ANY_e );
00061 const Rel Rel::NONE( Rel::NONE_e );
00062
00064
00065
00066
00067
00068 Rel::Rel( const std::string & strval_r )
00069 : _op( parse( strval_r ) )
00070 {}
00071
00073
00074
00075
00076
00077 const std::string & Rel::asString() const
00078 {
00079 static std::map<for_use_in_switch,std::string> _table;
00080 if ( _table.empty() )
00081 {
00082
00083 _table[EQ_e] = "==";
00084 _table[NE_e] = "!=";
00085 _table[LT_e] = "<";
00086 _table[LE_e] = "<=";
00087 _table[GT_e] = ">";
00088 _table[GE_e] = ">=";
00089 _table[ANY_e] = "ANY";
00090 _table[NONE_e] = "NONE";
00091 }
00092 return _table[_op];
00093 }
00094
00096 }