get rid of Value::ConvertFrom method.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 15 Feb 2008 03:52:56 +0100
changeset 2421 00ef5829bbe8
parent 2420 7b145012b2eb
child 2422 6cbcb8fe4551
get rid of Value::ConvertFrom method.
src/core/object.cc
src/core/value.cc
src/core/value.h
--- a/src/core/object.cc	Fri Feb 15 02:08:55 2008 +0100
+++ b/src/core/object.cc	Fri Feb 15 03:52:56 2008 +0100
@@ -691,12 +691,21 @@
   bool ok = spec->Check (value);
   if (!ok)
     {
+      // attempt to convert to string.
+      std::string str = value.SerializeToString (0);
+      // attempt to convert back to value.
       PValue v = spec->CreateValue ();
-      ok = v.ConvertFrom (value, spec);
+      ok = v.DeserializeFromString (str, spec);
       if (!ok)
         {
           return false;
         }
+      ok = spec->Check (v);
+      if (!ok)
+        {
+          return false;
+        }
+      value = v;
     }
   DoSetOne (spec, value);
   return true;
@@ -903,18 +912,21 @@
   bool ok = spec->Check (value);
   if (!ok)
     {
+      // attempt to convert to string
+      std::string str = value.SerializeToString (0);
+      // attempt to convert back from string.
       PValue v = spec->CreateValue ();
-      ok = v.ConvertFrom (value, spec);
+      ok = v.DeserializeFromString (str, spec);
+      if (!ok)
+        {
+          return false;
+        }
+      ok = spec->Check (v);
       if (!ok)
         {
           return false;
         }
       value = v;
-      ok = spec->Check (value);
-      if (!ok)
-        {
-          return false;
-        }
     }
   ok = spec->Set (this, value);
   return ok;
--- a/src/core/value.cc	Fri Feb 15 02:08:55 2008 +0100
+++ b/src/core/value.cc	Fri Feb 15 03:52:56 2008 +0100
@@ -20,11 +20,6 @@
 }
 Value::~Value ()
 {}
-bool 
-Value::ConvertFrom (PValue value, Ptr<const ParamSpec> spec)
-{
-  return false;
-}
 
 /***************************************************************
  *   Big interesting warning.
@@ -117,16 +112,6 @@
 {
   return m_value->DeserializeFromString (value, spec);
 }
-bool 
-PValue::ConvertFrom (PValue value, Ptr<const ParamSpec> spec)
-{
-  const StringValue *str = value.DynCast<const StringValue *> ();
-  if (str == 0)
-    {
-      return false;
-    }
-  return DeserializeFromString (str->Get (), spec);
-}
 
 PValue::PValue (const char *value)
   : m_value (new StringValue (value))
--- a/src/core/value.h	Fri Feb 15 02:08:55 2008 +0100
+++ b/src/core/value.h	Fri Feb 15 03:52:56 2008 +0100
@@ -22,7 +22,6 @@
   virtual PValue Copy (void) const = 0;
   virtual std::string SerializeToString (Ptr<const ParamSpec> spec) const = 0;
   virtual bool DeserializeFromString (std::string value, Ptr<const ParamSpec> spec) = 0;
-  virtual bool ConvertFrom (PValue value, Ptr<const ParamSpec> spec);
 private:
   friend class PValue;
   uint32_t m_count;
@@ -39,7 +38,6 @@
   PValue Copy (void) const;
   std::string SerializeToString (Ptr<const ParamSpec> spec) const;
   bool DeserializeFromString (std::string value, Ptr<const ParamSpec> spec);
-  bool ConvertFrom (PValue value, Ptr<const ParamSpec> spec);
 
   template <typename T>
   static PValue Create (void);