1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
15 #include "zypp/base/Exception.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
25 std::map<std::string,Rel::for_use_in_switch> _table;
27 std::map<std::string,Rel::for_use_in_switch>::const_iterator findStr( const std::string & strval_r )
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;
42 return _table.find( strval_r );
45 Rel::for_use_in_switch parse( const std::string & strval_r )
47 std::map<std::string,Rel::for_use_in_switch>::const_iterator it = findStr( strval_r );
48 if ( it == _table.end() )
50 ZYPP_THROW( Exception("Rel parse: illegal string value '"+strval_r+"'") );
55 Rel::for_use_in_switch parse( const std::string & strval_r, const Rel & default_r )
57 std::map<std::string,Rel::for_use_in_switch>::const_iterator it = findStr( strval_r );
58 if ( it == _table.end() )
60 return default_r.inSwitch();
65 ///////////////////////////////////////////////////////////////////
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 );
76 ///////////////////////////////////////////////////////////////////
78 // METHOD NAME : Rel::Rel
79 // METHOD TYPE : Constructor
81 Rel::Rel( const std::string & strval_r )
82 : _op( parse( strval_r ) )
85 Rel::Rel( const std::string & strval_r, const Rel & default_r )
86 : _op( parse( strval_r, default_r ) )
89 bool Rel::parseFrom( const std::string & strval_r )
91 std::map<std::string,Rel::for_use_in_switch>::const_iterator it = findStr( strval_r );
92 if ( it == _table.end() )
100 ///////////////////////////////////////////////////////////////////
102 // METHOD NAME : Rel::asString
103 // METHOD TYPE : const std::string &
105 const std::string & Rel::asString() const
107 static std::map<for_use_in_switch,std::string> _table;
108 if ( _table.empty() )
117 _table[ANY_e] = "ANY";
118 _table[NONE_e] = "NONE";
123 /////////////////////////////////////////////////////////////////
125 ///////////////////////////////////////////////////////////////////