X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=zypp%2FRel.cc;h=1839c63f2f8ac6cb0a179503228ab073ccb45caa;hb=HEAD;hp=804c107c6c14039a36a1eca0d2ecfdf1666b2633;hpb=1632791c27e74f47d60187eb246050689480b950;p=platform%2Fupstream%2Flibzypp.git diff --git a/zypp/Rel.cc b/zypp/Rel.cc index 804c107..0c94026 100644 --- a/zypp/Rel.cc +++ b/zypp/Rel.cc @@ -9,47 +9,60 @@ /** \file zypp/Rel.cc * */ +#include #include -#include "zypp/base/Exception.h" +#include -#include "zypp/Rel.h" - -using namespace std; +#include /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// -namespace -{ - - map _table; - - Rel::for_use_in_switch parse( const std::string & strval_r ) + namespace { - if ( _table.empty() ) + std::map _table; + + std::map::const_iterator findStr( const std::string & strval_r ) + { + if ( _table.empty() ) { // initialize it - _table["EQ"] = _table["eq"] = _table["=="] = _table["="] = Rel::EQ_e; - _table["NE"] = _table["ne"] = _table["!="] = Rel::NE_e; - _table["LT"] = _table["lt"] = _table["<"] = Rel::LT_e; - _table["LE"] = _table["le"] = _table["<="] = Rel::LE_e; - _table["GT"] = _table["gt"] = _table[">"] = Rel::GT_e; - _table["GE"] = _table["ge"] = _table[">="] = Rel::GE_e; - _table["ANY"] = _table["any"] = _table[""] = Rel::ANY_e; - _table["NONE"] = _table["none"] = Rel::NONE_e; + _table["EQ"] = _table["eq"] = _table["=="] = _table["="] = Rel::EQ_e; + _table["NE"] = _table["ne"] = _table["!="] = Rel::NE_e; + _table["LT"] = _table["lt"] = _table["<"] = Rel::LT_e; + _table["LE"] = _table["le"] = _table["lte"] = _table["<="] = Rel::LE_e; + _table["GT"] = _table["gt"] = _table[">"] = Rel::GT_e; + _table["GE"] = _table["ge"] = _table["gte"] = _table[">="] = Rel::GE_e; + _table["ANY"] = _table["any"] = _table["(any)"] = _table[""] = Rel::ANY_e; + _table["NONE"] = _table["none"] = Rel::NONE_e; } - map::const_iterator it - = _table.find( strval_r ); - if ( it == _table.end() ) + return _table.find( strval_r ); + } + + Rel::for_use_in_switch parse( const std::string & strval_r ) + { + std::map::const_iterator it = findStr( strval_r ); + if ( it == _table.end() ) { - ZYPP_THROW( Exception("Rel parse: illegal string value") ); + ZYPP_THROW( Exception("Rel parse: illegal string value '"+strval_r+"'") ); } - return it->second; + return it->second; + } + + Rel::for_use_in_switch parse( const std::string & strval_r, const Rel & default_r ) + { + std::map::const_iterator it = findStr( strval_r ); + if ( it == _table.end() ) + { + return default_r.inSwitch(); + } + return it->second; + } } -} + /////////////////////////////////////////////////////////////////// const Rel Rel::EQ( Rel::EQ_e ); const Rel Rel::NE( Rel::NE_e ); @@ -69,6 +82,21 @@ namespace : _op( parse( strval_r ) ) {} + Rel::Rel( const std::string & strval_r, const Rel & default_r ) + : _op( parse( strval_r, default_r ) ) + {} + + bool Rel::parseFrom( const std::string & strval_r ) + { + std::map::const_iterator it = findStr( strval_r ); + if ( it == _table.end() ) + { + return false; + } + _op = it->second; + return true; + } + /////////////////////////////////////////////////////////////////// // // METHOD NAME : Rel::asString @@ -76,7 +104,7 @@ namespace // const std::string & Rel::asString() const { - static map _table; + static std::map _table; if ( _table.empty() ) { // initialize it