--- a/src/core/object.cc Sun Feb 17 00:46:24 2008 +0100
+++ b/src/core/object.cc Sun Feb 17 04:38:34 2008 +0100
@@ -61,11 +61,12 @@
std::string name,
std::string help,
uint32_t flags,
+ ns3::PValue initialValue,
ns3::Ptr<const ns3::ParamSpec> spec);
uint32_t GetParametersN (uint16_t uid) const;
std::string GetParameterName (uint16_t uid, uint32_t i) const;
uint32_t GetParameterFlags (uint16_t uid, uint32_t i) const;
- uint32_t GetParameterUid (uint16_t uid, uint32_t i) const;
+ ns3::PValue GetParameterInitialValue (uint16_t uid, uint32_t i) const;
ns3::Ptr<const ns3::ParamSpec> GetParameterParamSpec (uint16_t uid, uint32_t i) const;
private:
struct ConstructorInformation {
@@ -76,7 +77,7 @@
std::string name;
std::string help;
uint32_t flags;
- uint32_t uid;
+ ns3::PValue initialValue;
ns3::Ptr<const ns3::ParamSpec> param;
};
struct IidInformation {
@@ -246,6 +247,7 @@
std::string name,
std::string help,
uint32_t flags,
+ ns3::PValue initialValue,
ns3::Ptr<const ns3::ParamSpec> spec)
{
struct IidInformation *information = LookupInformation (uid);
@@ -262,6 +264,7 @@
param.name = name;
param.help = help;
param.flags = flags;
+ param.initialValue = initialValue;
param.param = spec;
information->parameters.push_back (param);
}
@@ -287,6 +290,13 @@
NS_ASSERT (i < information->parameters.size ());
return information->parameters[i].flags;
}
+ns3::PValue
+IidManager::GetParameterInitialValue (uint16_t uid, uint32_t i) const
+{
+ struct IidInformation *information = LookupInformation (uid);
+ NS_ASSERT (i < information->parameters.size ());
+ return information->parameters[i].initialValue;
+}
ns3::Ptr<const ns3::ParamSpec>
IidManager::GetParameterParamSpec (uint16_t uid, uint32_t i) const
{
@@ -295,7 +305,6 @@
return information->parameters[i].param;
}
-
} // anonymous namespace
/*********************************************************************
@@ -431,6 +440,7 @@
{
info->spec = GetParameterParamSpec (i);
info->flags = GetParameterFlags (i);
+ info->initialValue = tid.GetParameterInitialValue (i);
return true;
}
}
@@ -452,6 +462,7 @@
{
info->spec = tid.GetParameterParamSpec (j);
info->flags = tid.GetParameterFlags (j);
+ info->initialValue = tid.GetParameterInitialValue (j);
return true;
}
cur++;
@@ -522,9 +533,10 @@
TypeId
TypeId::AddParameter (std::string name,
std::string help,
+ PValue initialValue,
Ptr<const ParamSpec> param)
{
- Singleton<IidManager>::Get ()->AddParameter (m_tid, name, help, PARAM_SGC, param);
+ Singleton<IidManager>::Get ()->AddParameter (m_tid, name, help, PARAM_SGC, initialValue, param);
return *this;
}
@@ -532,9 +544,10 @@
TypeId::AddParameter (std::string name,
std::string help,
uint32_t flags,
+ PValue initialValue,
Ptr<const ParamSpec> param)
{
- Singleton<IidManager>::Get ()->AddParameter (m_tid, name, help, flags, param);
+ Singleton<IidManager>::Get ()->AddParameter (m_tid, name, help, flags, initialValue, param);
return *this;
}
@@ -578,6 +591,12 @@
{
return GetName () + "::" + GetParameterName (i);
}
+PValue
+TypeId::GetParameterInitialValue (uint32_t i) const
+{
+ PValue value = Singleton<IidManager>::Get ()->GetParameterInitialValue (m_tid, i);
+ return value;
+}
Ptr<const ParamSpec>
TypeId::GetParameterParamSpec (uint32_t i) const
{
@@ -644,7 +663,7 @@
{
struct TypeId::ParameterInfo info;
TypeId::LookupParameterByFullName (name, &info);
- bool ok = DoSet (info.spec, value);
+ bool ok = DoSet (&info, value);
return ok;
}
void
@@ -652,14 +671,14 @@
{
struct TypeId::ParameterInfo info;
tid.LookupParameterByName (name, &info);
- DoSet (info.spec, value);
+ DoSet (&info, value);
}
void
Parameters::SetWithTid (TypeId tid, uint32_t position, PValue value)
{
struct TypeId::ParameterInfo info;
tid.LookupParameterByPosition (position, &info);
- DoSet (info.spec, value);
+ DoSet (&info, value);
}
void
@@ -682,32 +701,36 @@
m_parameters.push_back (p);
}
bool
-Parameters::DoSet (Ptr<const ParamSpec> spec, PValue value)
+Parameters::DoSet (struct TypeId::ParameterInfo *info, PValue value)
{
- if (spec == 0)
+ if (info->spec == 0)
{
return false;
}
- bool ok = spec->Check (value);
+ bool ok = info->spec->Check (value);
if (!ok)
{
// attempt to convert to string.
- std::string str = value.SerializeToString (0);
+ const StringValue *str = value.DynCast<const StringValue *> ();
+ if (str == 0)
+ {
+ return false;
+ }
// attempt to convert back to value.
- PValue v = spec->GetInitialValue ().Copy ();
- ok = v.DeserializeFromString (str, spec);
+ PValue v = info->initialValue.Copy ();
+ ok = v.DeserializeFromString (str->Get (), info->spec);
if (!ok)
{
return false;
}
- ok = spec->Check (v);
+ ok = info->spec->Check (v);
if (!ok)
{
return false;
}
value = v;
}
- DoSetOne (spec, value);
+ DoSetOne (info->spec, value);
return true;
}
void
@@ -792,7 +815,7 @@
value = str.substr (equal+1, next - (equal+1));
cur++;
}
- PValue val = info.spec->GetInitialValue ().Copy ();
+ PValue val = info.initialValue.Copy ();
bool ok = val.DeserializeFromString (value, info.spec);
if (!ok)
{
@@ -855,6 +878,7 @@
for (uint32_t i = 0; i < tid.GetParametersN (); i++)
{
Ptr<const ParamSpec> paramSpec = tid.GetParameterParamSpec (i);
+ PValue initial = tid.GetParameterInitialValue (i);
NS_LOG_DEBUG ("try to construct \""<< tid.GetName ()<<"::"<<
tid.GetParameterName (i)<<"\"");
if (!(tid.GetParameterFlags (i) & TypeId::PARAM_CONSTRUCT))
@@ -869,7 +893,7 @@
if (j->spec == paramSpec)
{
// We have a matching parameter value.
- DoSet (paramSpec, j->value);
+ DoSet (paramSpec, initial, j->value);
NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
tid.GetParameterName (i)<<"\"");
found = true;
@@ -885,7 +909,7 @@
if (j->spec == paramSpec)
{
// We have a matching parameter value.
- DoSet (paramSpec, j->value);
+ DoSet (paramSpec, initial, j->value);
NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
tid.GetParameterName (i)<<"\" from global");
found = true;
@@ -896,7 +920,6 @@
if (!found)
{
// No matching parameter value so we set the default value.
- PValue initial = paramSpec->GetInitialValue ();
paramSpec->Set (this, initial);
NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
tid.GetParameterName (i)<<"\" from local");
@@ -907,16 +930,20 @@
NotifyConstructionCompleted ();
}
bool
-Object::DoSet (Ptr<const ParamSpec> spec, PValue value)
+Object::DoSet (Ptr<const ParamSpec> spec, PValue initialValue, PValue value)
{
bool ok = spec->Check (value);
if (!ok)
{
// attempt to convert to string
- std::string str = value.SerializeToString (0);
+ const StringValue *str = value.DynCast<const StringValue *> ();
+ if (str == 0)
+ {
+ return false;
+ }
// attempt to convert back from string.
- PValue v = spec->GetInitialValue ().Copy ();
- ok = v.DeserializeFromString (str, spec);
+ PValue v = initialValue.Copy ();
+ ok = v.DeserializeFromString (str->Get (), spec);
if (!ok)
{
return false;
@@ -943,7 +970,7 @@
{
return false;
}
- return DoSet (info.spec, value);
+ return DoSet (info.spec, info.initialValue, value);
}
bool
Object::SetUint (std::string name, uint64_t value)
@@ -978,7 +1005,7 @@
{
return false;
}
- PValue v = info.spec->GetInitialValue ().Copy ();
+ PValue v = info.initialValue.Copy ();
bool ok = info.spec->Get (this, v);
if (ok)
{
@@ -999,7 +1026,7 @@
{
return PValue ();
}
- PValue value = info.spec->GetInitialValue ().Copy ();
+ PValue value = info.initialValue.Copy ();
bool ok = info.spec->Get (this, value);
if (!ok)
{