Provide non-throwing Rel::parseFrom(std::string)
authorMichael Andres <ma@suse.de>
Fri, 28 Aug 2009 14:36:06 +0000 (16:36 +0200)
committerMichael Andres <ma@suse.de>
Fri, 28 Aug 2009 14:36:06 +0000 (16:36 +0200)
zypp/Rel.cc
zypp/Rel.h

index 089ca7c..1839c63 100644 (file)
@@ -86,6 +86,17 @@ namespace zypp
   : _op( parse( strval_r, default_r ) )
   {}
 
+  bool Rel::parseFrom( const std::string & strval_r )
+  {
+    std::map<std::string,Rel::for_use_in_switch>::const_iterator it = findStr( strval_r );
+    if ( it == _table.end() )
+    {
+      return false;
+    }
+    _op = it->second;
+    return true;
+  }
+
   ///////////////////////////////////////////////////////////////////
   //
   //   METHOD NAME : Rel::asString
index a5ca5f8..1162abe 100644 (file)
@@ -87,15 +87,20 @@ namespace zypp
      *
      * \throw PARSE if \a strval_r is not legal.
      * \todo refine exceptions and check throw.
-    */
+     */
     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 );
 
+    /** Assign from string IFF it contains a legal value.
+     * \return Whether \a strval_r contained a legal value.
+    */
+    bool parseFrom( const std::string & strval_r );
+
     /** Ctor from bits. */
     explicit
     Rel( unsigned bits_r )