diff --git a/src/core/object.cc b/src/core/object.cc index dac166c7d..e608b181f 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -694,7 +694,7 @@ Parameters::DoSet (Ptr spec, std::string value) { return false; } - PValue v = spec->CreateInitialValue (); + PValue v = spec->CreateValue (); bool ok = v.DeserializeFromString (value, spec); if (!ok) { @@ -790,7 +790,7 @@ Parameters::DeserializeFromString (std::string str) value = str.substr (equal+1, next - (equal+1)); cur++; } - PValue val = spec->CreateInitialValue (); + PValue val = spec->CreateValue (); bool ok = val.DeserializeFromString (value, spec); if (!ok) { @@ -890,7 +890,7 @@ Object::Construct (const Parameters ¶meters) if (!found) { // No matching parameter value so we set the default value. - PValue initial = paramSpec->CreateInitialValue (); + PValue initial = paramSpec->GetInitialValue (); paramSpec->Set (this, initial); NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<< tid.GetParameterName (i)<<"\" from local"); @@ -929,7 +929,7 @@ Object::Set (std::string name, std::string value) { return false; } - PValue v = spec->CreateInitialValue (); + PValue v = spec->CreateValue (); bool ok = v.DeserializeFromString (value, spec); if (!ok) { @@ -951,7 +951,7 @@ Object::Get (std::string name, std::string &value) const { return false; } - PValue v = paramSpec->CreateInitialValue (); + PValue v = paramSpec->CreateValue (); bool ok = paramSpec->Get (this, v); if (ok) { @@ -968,7 +968,7 @@ Object::Get (std::string name) const { return PValue (); } - PValue value = paramSpec->CreateInitialValue (); + PValue value = paramSpec->CreateValue (); bool ok = paramSpec->Get (this, value); if (!ok) { diff --git a/src/core/param-spec-helper.h b/src/core/param-spec-helper.h index 5e024893e..77851e632 100644 --- a/src/core/param-spec-helper.h +++ b/src/core/param-spec-helper.h @@ -31,7 +31,8 @@ public: virtual bool Set (ObjectBase * object, PValue value) const; virtual bool Get (const ObjectBase * object, PValue value) const; virtual bool Check (PValue value) const; - virtual PValue CreateInitialValue (void) const; + virtual PValue GetInitialValue (void) const; + virtual PValue CreateValue (void) const; private: virtual void DoSet (T *object, const U *v) const = 0; @@ -244,11 +245,18 @@ ParamSpecHelper::Check (PValue value) const } template PValue -ParamSpecHelper::CreateInitialValue (void) const +ParamSpecHelper::GetInitialValue (void) const { return m_initialValue; } +template +PValue +ParamSpecHelper::CreateValue (void) const +{ + return m_initialValue.Copy (); +} + } // namespace ns3 #endif /* PARAM_SPEC_HELPER_H */ diff --git a/src/core/value.h b/src/core/value.h index 652d5e1f1..db5bf22b6 100644 --- a/src/core/value.h +++ b/src/core/value.h @@ -74,7 +74,8 @@ public: virtual bool Set (ObjectBase * object, PValue value) const = 0; virtual bool Get (const ObjectBase * object, PValue value) const = 0; virtual bool Check (PValue value) const = 0; - virtual PValue CreateInitialValue (void) const = 0; + virtual PValue GetInitialValue (void) const = 0; + virtual PValue CreateValue (void) const = 0; private: mutable uint32_t m_count; }; @@ -246,7 +247,10 @@ public: } return true; } - virtual PValue CreateInitialValue (void) const { + virtual PValue GetInitialValue (void) const { + return CreateValue (); + } + virtual PValue CreateValue (void) const { return PValue::Create > (Ptr (0)); } private: