From 8ed4a31c7fe1eac778e3f6611b6b98178280a89c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 18 Apr 2012 09:35:58 -0700 Subject: [PATCH] Support PointerValue::DeserializeFromString() --- src/core/model/global-value.cc | 4 ++-- src/core/model/pointer.cc | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/model/global-value.cc b/src/core/model/global-value.cc index a95ce8666..4950eca98 100644 --- a/src/core/model/global-value.cc +++ b/src/core/model/global-value.cc @@ -41,13 +41,13 @@ GlobalValue::GlobalValue (std::string name, std::string help, { 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 (); diff --git a/src/core/model/pointer.cc b/src/core/model/pointer.cc index c4f4607de..aa6742e57 100644 --- a/src/core/model/pointer.cc +++ b/src/core/model/pointer.cc @@ -18,6 +18,8 @@ * Authors: Mathieu Lacage */ #include "pointer.h" +#include "object-factory.h" +#include namespace ns3 { @@ -59,8 +61,19 @@ PointerValue::SerializeToString (Ptr checker) const bool PointerValue::DeserializeFromString (std::string value, Ptr 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 (); + return true; } } // namespace ns3