Support PointerValue::DeserializeFromString()
authorMathieu Lacage <mathieu.lacage@gmail.com>
Wed, 18 Apr 2012 09:35:58 -0700
changeset 7856 71b642707bef
parent 7855 015c4b6a0e07
child 7857 3a5a7fb38536
Support PointerValue::DeserializeFromString()
src/core/model/global-value.cc
src/core/model/pointer.cc
--- a/src/core/model/global-value.cc	Tue Apr 17 11:26:31 2012 +0100
+++ b/src/core/model/global-value.cc	Wed Apr 18 09:35:58 2012 -0700
@@ -41,13 +41,13 @@
 {
   if (m_checker == 0)
     {
-      NS_FATAL_ERROR ("Checker should not be zero.");
+      NS_FATAL_ERROR ("Checker should not be zero on " << name );
     }
   m_initialValue = m_checker->CreateValidValue (initialValue);
   m_currentValue = m_initialValue;
   if (m_initialValue == 0)
     {
-      NS_FATAL_ERROR ("Value set by user is invalid.");
+      NS_FATAL_ERROR ("Value set by user on " << name << " is invalid.");
     }
   GetVector ()->push_back (this);
   InitializeFromEnv ();
--- a/src/core/model/pointer.cc	Tue Apr 17 11:26:31 2012 +0100
+++ b/src/core/model/pointer.cc	Wed Apr 18 09:35:58 2012 -0700
@@ -18,6 +18,8 @@
  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 #include "pointer.h"
+#include "object-factory.h"
+#include <sstream>
 
 namespace ns3 {
 
@@ -59,8 +61,19 @@
 bool 
 PointerValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
 {
-  NS_FATAL_ERROR ("It is not possible to deserialize a pointer.");
-  return false;
+  // We assume that the string you want to deserialize contains
+  // a description for an ObjectFactory to create an object and then assign it to the
+  // member variable.
+  ObjectFactory factory;
+  std::istringstream iss;
+  iss.str(value);
+  iss >> factory;
+  if (iss.fail())
+    {
+      return false;
+    }
+  m_value = factory.Create<Object> ();
+  return true;
 }
 
 } // namespace ns3