Author: mlandres Date: Fri Dec 7 17:10:47 2007 New Revision: 8062 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8062&view=rev Log: Add a non-throwing way of Rel construction Modified: trunk/libzypp/zypp/Rel.cc trunk/libzypp/zypp/Rel.h Modified: trunk/libzypp/zypp/Rel.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Rel.cc?rev=8062&... ============================================================================== --- trunk/libzypp/zypp/Rel.cc (original) +++ trunk/libzypp/zypp/Rel.cc Fri Dec 7 17:10:47 2007 @@ -22,34 +22,46 @@ namespace { - std::mapstd::string,Rel::for_use_in_switch _table; - Rel::for_use_in_switch parse( const std::string & strval_r ) + std::mapstd::string,Rel::for_use_in_switch::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["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; - } + { + // 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["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; + } - std::mapstd::string,Rel::for_use_in_switch::const_iterator it - = _table.find( strval_r ); + return _table.find( strval_r ); + } + + Rel::for_use_in_switch parse( const std::string & strval_r ) + { + std::mapstd::string,Rel::for_use_in_switch::const_iterator it = findStr( strval_r ); if ( it == _table.end() ) - { - ZYPP_THROW( Exception("Rel parse: illegal string value '"+strval_r+"'") ); - } + { + ZYPP_THROW( Exception("Rel parse: illegal string value '"+strval_r+"'") ); + } return it->second; } - } + Rel::for_use_in_switch parse( const std::string & strval_r, const Rel & default_r ) + { + std::mapstd::string,Rel::for_use_in_switch::const_iterator it = findStr( strval_r ); + if ( it == _table.end() ) + { + return default_r.inSwitch(); + } + return it->second; + } + } /////////////////////////////////////////////////////////////////// const Rel Rel::EQ( Rel::EQ_e ); @@ -70,6 +82,10 @@ : _op( parse( strval_r ) ) {} + Rel::Rel( const std::string & strval_r, const Rel & default_r ) + : _op( parse( strval_r, default_r ) ) + {} + /////////////////////////////////////////////////////////////////// // // METHOD NAME : Rel::asString Modified: trunk/libzypp/zypp/Rel.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Rel.h?rev=8062&r... ============================================================================== --- trunk/libzypp/zypp/Rel.h (original) +++ trunk/libzypp/zypp/Rel.h Fri Dec 7 17:10:47 2007 @@ -91,6 +91,11 @@ explicit Rel( const std::string & strval_r ); + /** Ctor from string (non-throwing). + * Illegal string values resolve to \c default_r + */ + Rel( const std::string & strval_r, const Rel & default_r ); + /** Ctor from bits. */ explicit Rel( unsigned bits_r ) -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org