fixup Fix to build with libxml 2.12.x (fixes #505)
[platform/upstream/libzypp.git] / zypp / Rel.cc
index 7979d75..0c94026 100644 (file)
@@ -9,47 +9,60 @@
 /** \file zypp/Rel.cc
  *
 */
+#include <iostream>
 #include <map>
 
-#include "zypp/base/Exception.h"
+#include <zypp/base/Exception.h>
 
-#include "zypp/Rel.h"
-
-using namespace std;
+#include <zypp/Rel.h>
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
-namespace
-{
-
-  map<string,Rel::for_use_in_switch> _table;
-
-  Rel::for_use_in_switch parse( const std::string & strval_r )
+  namespace
   {
-    if ( _table.empty() )
+    std::map<std::string,Rel::for_use_in_switch> _table;
+
+    std::map<std::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["<="] = 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<string,Rel::for_use_in_switch>::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<std::string,Rel::for_use_in_switch>::const_iterator it = findStr( strval_r );
+      if ( it == _table.end() )
       {
-        ZYPP_THROW( "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<std::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 );
   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<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
@@ -76,7 +104,7 @@ namespace
   //
   const std::string & Rel::asString() const
   {
-    static map<for_use_in_switch,string> _table;
+    static std::map<for_use_in_switch,std::string> _table;
     if ( _table.empty() )
       {
         // initialize it