merge
This commit is contained in:
@@ -28,10 +28,10 @@ class BooleanParamSpec : public ParamSpec {};
|
||||
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeBooleanParamSpec (T1 a1, bool initialValue);
|
||||
Ptr<ParamSpec> MakeBooleanParamSpec (T1 a1);
|
||||
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeBooleanParamSpec (T1 a1, T2 a2, bool initialValue);
|
||||
Ptr<ParamSpec> MakeBooleanParamSpec (T1 a1, T2 a2);
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -40,15 +40,15 @@ Ptr<ParamSpec> MakeBooleanParamSpec (T1 a1, T2 a2, bool initialValue);
|
||||
namespace ns3 {
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeBooleanParamSpec (T1 a1, bool initialValue)
|
||||
Ptr<ParamSpec> MakeBooleanParamSpec (T1 a1)
|
||||
{
|
||||
return MakeParamSpecHelper<BooleanParamSpec> (a1, BooleanValue (initialValue));
|
||||
return MakeParamSpecHelper<BooleanParamSpec,BooleanValue> (a1);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeBooleanParamSpec (T1 a1, T2 a2, bool initialValue)
|
||||
Ptr<ParamSpec> MakeBooleanParamSpec (T1 a1, T2 a2)
|
||||
{
|
||||
return MakeParamSpecHelper<BooleanParamSpec> (a1, a2, BooleanValue (initialValue));
|
||||
return MakeParamSpecHelper<BooleanParamSpec,BooleanValue> (a1, a2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,17 +78,17 @@ ClassValueHelperConvertTo (const T *self)
|
||||
|
||||
template <typename T, typename U, typename BASE, typename T1>
|
||||
Ptr<ParamSpec>
|
||||
MakeClassValueHelperParamSpec (T1 a1, const T &initialValue)
|
||||
MakeClassValueHelperParamSpec (T1 a1)
|
||||
{
|
||||
return MakeParamSpecHelper<BASE> (a1, ClassValue<T,U> (initialValue));
|
||||
return MakeParamSpecHelper<BASE,ClassValue<T,U> > (a1);
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename U, typename BASE, typename T1, typename T2>
|
||||
Ptr<ParamSpec>
|
||||
MakeClassValueHelperParamSpec (T1 a1, T2 a2, const T &initialValue)
|
||||
MakeClassValueHelperParamSpec (T1 a1, T2 a2)
|
||||
{
|
||||
return MakeParamSpecHelper<BASE> (a1, a2, ClassValue<T,U> (initialValue));
|
||||
return MakeParamSpecHelper<BASE,ClassValue<T,U> > (a1, a2);
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -127,19 +127,4 @@ EnumParamSpec::Check (PValue value) const
|
||||
return false;
|
||||
}
|
||||
|
||||
PValue
|
||||
EnumParamSpec::GetInitialValue (void) const
|
||||
{
|
||||
NS_ASSERT (!m_valueSet.empty ());
|
||||
return PValue::Create<EnumValue> (m_valueSet.front ().first);
|
||||
}
|
||||
|
||||
PValue
|
||||
EnumParamSpec::CreateValue (void) const
|
||||
{
|
||||
return PValue::Create<EnumValue> (m_valueSet.front ().first);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -36,8 +36,6 @@ public:
|
||||
virtual bool Get (const ObjectBase* object, PValue value) const;
|
||||
virtual bool Check (PValue value) const;
|
||||
|
||||
virtual PValue GetInitialValue (void) const;
|
||||
virtual PValue CreateValue (void) const;
|
||||
private:
|
||||
virtual bool DoSet (ObjectBase *object, const EnumValue *value) const = 0;
|
||||
virtual bool DoGet (const ObjectBase *object, EnumValue *value) const = 0;
|
||||
|
||||
@@ -28,11 +28,9 @@ private:
|
||||
class FpParamSpec : public ParamSpec {};
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeFpParamSpec (T1 a1,
|
||||
double initialValue);
|
||||
Ptr<ParamSpec> MakeFpParamSpec (T1 a1);
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeFpParamSpec (T1 a1, T2 a2,
|
||||
double initialValue,
|
||||
double minValue,
|
||||
double maxValue);
|
||||
|
||||
@@ -68,36 +66,32 @@ private:
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec>
|
||||
MakeFpParamSpec (T1 a1,
|
||||
double initialValue)
|
||||
MakeFpParamSpec (T1 a1)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<FpParamSpec> (a1, FpValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<FpParamSpec,FpValue> (a1,
|
||||
FpValueChecker::Create (a1));
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeFpParamSpec (T1 a1,
|
||||
double initialValue,
|
||||
double minValue,
|
||||
double maxValue)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<FpParamSpec> (a1, FpValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<FpParamSpec,FpValue> (a1,
|
||||
FpValueChecker (minValue, maxValue));
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeFpParamSpec (T1 a1, T2 a2,
|
||||
double initialValue)
|
||||
Ptr<ParamSpec> MakeFpParamSpec (T1 a1, T2 a2)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<FpParamSpec> (a1, a2, FpValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<FpParamSpec,FpValue> (a1, a2,
|
||||
FpValueChecker::Create (a1));
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeFpParamSpec (T1 a1, T2 a2,
|
||||
double initialValue,
|
||||
double minValue,
|
||||
double maxValue)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<FpParamSpec> (a1, a2, FpValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<FpParamSpec,FpValue> (a1, a2,
|
||||
FpValueChecker (minValue, maxValue));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,19 +27,15 @@ private:
|
||||
class IntParamSpec : public ParamSpec {};
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1,
|
||||
int64_t initialValue);
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1);
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1,
|
||||
int64_t initialValue,
|
||||
int64_t minValue,
|
||||
int64_t maxValue);
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1, T2 a2,
|
||||
int64_t initialValue);
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1, T2 a2);
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1, T2 a2,
|
||||
int64_t initialValue,
|
||||
int64_t minValue,
|
||||
int64_t maxValue);
|
||||
|
||||
@@ -75,36 +71,32 @@ private:
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec>
|
||||
MakeIntParamSpec (T1 a1,
|
||||
int64_t initialValue)
|
||||
MakeIntParamSpec (T1 a1)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<IntParamSpec> (a1, IntValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<IntParamSpec,IntValue> (a1,
|
||||
IntValueChecker::Create (a1));
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1,
|
||||
int64_t initialValue,
|
||||
int64_t minValue,
|
||||
int64_t maxValue)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<IntParamSpec> (a1, IntValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<IntParamSpec,IntValue> (a1,
|
||||
IntValueChecker (minValue, maxValue));
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1, T2 a2,
|
||||
int64_t initialValue)
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1, T2 a2)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<IntParamSpec> (a1, a2, IntValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<IntParamSpec,IntValue> (a1, a2,
|
||||
IntValueChecker::Create (a1));
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeIntParamSpec (T1 a1, T2 a2,
|
||||
int64_t initialValue,
|
||||
int64_t minValue,
|
||||
int64_t maxValue)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<IntParamSpec> (a1, a2, IntValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<IntParamSpec,IntValue> (a1, a2,
|
||||
IntValueChecker (minValue, maxValue));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,11 @@ ObjectVector::ObjectVector (PValue value)
|
||||
*this = v->Get ();
|
||||
}
|
||||
|
||||
ObjectVector::operator PValue () const
|
||||
{
|
||||
return PValue::Create<ObjectVectorValue> ();
|
||||
}
|
||||
|
||||
ObjectVectorValue::ObjectVectorValue ()
|
||||
: m_vector ()
|
||||
{}
|
||||
@@ -102,16 +107,5 @@ ObjectVectorParamSpec::Check (PValue value) const
|
||||
const ObjectVectorValue *v = value.DynCast<const ObjectVectorValue *> ();
|
||||
return v != 0;
|
||||
}
|
||||
PValue
|
||||
ObjectVectorParamSpec::GetInitialValue (void) const
|
||||
{
|
||||
return PValue::Create<ObjectVectorValue> ();
|
||||
}
|
||||
PValue
|
||||
ObjectVectorParamSpec::CreateValue (void) const
|
||||
{
|
||||
return PValue::Create<ObjectVectorValue> ();
|
||||
}
|
||||
|
||||
|
||||
} // name
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
Ptr<Object> Get (uint32_t i) const;
|
||||
|
||||
ObjectVector (PValue value);
|
||||
operator PValue () const;
|
||||
private:
|
||||
friend class ObjectVectorParamSpec;
|
||||
std::vector<Ptr<Object> > m_objects;
|
||||
@@ -68,8 +69,6 @@ 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 GetInitialValue (void) const;
|
||||
virtual PValue CreateValue (void) const;
|
||||
private:
|
||||
virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const = 0;
|
||||
virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i) const = 0;
|
||||
|
||||
@@ -57,11 +57,12 @@ public:
|
||||
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 {
|
||||
@@ -72,7 +73,7 @@ private:
|
||||
std::string name;
|
||||
std::string help;
|
||||
uint32_t flags;
|
||||
uint32_t uid;
|
||||
ns3::PValue initialValue;
|
||||
ns3::Ptr<const ns3::ParamSpec> param;
|
||||
};
|
||||
struct IidInformation {
|
||||
@@ -242,6 +243,7 @@ IidManager::AddParameter (uint16_t uid,
|
||||
std::string name,
|
||||
std::string help,
|
||||
uint32_t flags,
|
||||
ns3::PValue initialValue,
|
||||
ns3::Ptr<const ns3::ParamSpec> spec)
|
||||
{
|
||||
struct IidInformation *information = LookupInformation (uid);
|
||||
@@ -258,6 +260,7 @@ IidManager::AddParameter (uint16_t uid,
|
||||
param.name = name;
|
||||
param.help = help;
|
||||
param.flags = flags;
|
||||
param.initialValue = initialValue;
|
||||
param.param = spec;
|
||||
information->parameters.push_back (param);
|
||||
}
|
||||
@@ -283,6 +286,13 @@ IidManager::GetParameterFlags (uint16_t uid, uint32_t i) const
|
||||
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
|
||||
{
|
||||
@@ -291,7 +301,6 @@ IidManager::GetParameterParamSpec (uint16_t uid, uint32_t i) const
|
||||
return information->parameters[i].param;
|
||||
}
|
||||
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
/*********************************************************************
|
||||
@@ -427,6 +436,7 @@ TypeId::LookupParameterByName (std::string name, struct TypeId::ParameterInfo *i
|
||||
{
|
||||
info->spec = GetParameterParamSpec (i);
|
||||
info->flags = GetParameterFlags (i);
|
||||
info->initialValue = tid.GetParameterInitialValue (i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -448,6 +458,7 @@ TypeId::LookupParameterByPosition (uint32_t i, struct TypeId::ParameterInfo *inf
|
||||
{
|
||||
info->spec = tid.GetParameterParamSpec (j);
|
||||
info->flags = tid.GetParameterFlags (j);
|
||||
info->initialValue = tid.GetParameterInitialValue (j);
|
||||
return true;
|
||||
}
|
||||
cur++;
|
||||
@@ -518,9 +529,10 @@ TypeId::DoAddConstructor (CallbackBase cb, uint32_t nArguments)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -528,9 +540,10 @@ TypeId
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -574,6 +587,12 @@ TypeId::GetParameterFullName (uint32_t i) const
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -640,7 +659,7 @@ Parameters::Set (std::string name, PValue value)
|
||||
{
|
||||
struct TypeId::ParameterInfo info;
|
||||
TypeId::LookupParameterByFullName (name, &info);
|
||||
bool ok = DoSet (info.spec, value);
|
||||
bool ok = DoSet (&info, value);
|
||||
return ok;
|
||||
}
|
||||
void
|
||||
@@ -648,14 +667,14 @@ Parameters::SetWithTid (TypeId tid, std::string name, PValue value)
|
||||
{
|
||||
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
|
||||
@@ -678,23 +697,36 @@ Parameters::DoSetOne (Ptr<const ParamSpec> spec, PValue value)
|
||||
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)
|
||||
{
|
||||
PValue v = spec->CreateValue ();
|
||||
ok = v.ConvertFrom (value, spec);
|
||||
// attempt to convert to string.
|
||||
const StringValue *str = value.DynCast<const StringValue *> ();
|
||||
if (str == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// attempt to convert back to value.
|
||||
PValue v = info->initialValue.Copy ();
|
||||
ok = v.DeserializeFromString (str->Get (), info->spec);
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ok = info->spec->Check (v);
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
value = v;
|
||||
}
|
||||
DoSetOne (spec, value);
|
||||
DoSetOne (info->spec, value);
|
||||
return true;
|
||||
}
|
||||
void
|
||||
@@ -779,7 +811,7 @@ Parameters::DeserializeFromString (std::string str)
|
||||
value = str.substr (equal+1, next - (equal+1));
|
||||
cur++;
|
||||
}
|
||||
PValue val = info.spec->CreateValue ();
|
||||
PValue val = info.initialValue.Copy ();
|
||||
bool ok = val.DeserializeFromString (value, info.spec);
|
||||
if (!ok)
|
||||
{
|
||||
@@ -842,6 +874,7 @@ Object::Construct (const Parameters ¶meters)
|
||||
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))
|
||||
@@ -856,7 +889,7 @@ Object::Construct (const Parameters ¶meters)
|
||||
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;
|
||||
@@ -872,7 +905,7 @@ Object::Construct (const Parameters ¶meters)
|
||||
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;
|
||||
@@ -883,7 +916,6 @@ Object::Construct (const Parameters ¶meters)
|
||||
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");
|
||||
@@ -894,23 +926,30 @@ Object::Construct (const Parameters ¶meters)
|
||||
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)
|
||||
{
|
||||
PValue v = spec->CreateValue ();
|
||||
ok = v.ConvertFrom (value, spec);
|
||||
// attempt to convert to string
|
||||
const StringValue *str = value.DynCast<const StringValue *> ();
|
||||
if (str == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// attempt to convert back from string.
|
||||
PValue v = initialValue.Copy ();
|
||||
ok = v.DeserializeFromString (str->Get (), 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;
|
||||
@@ -927,7 +966,7 @@ Object::Set (std::string name, PValue value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return DoSet (info.spec, value);
|
||||
return DoSet (info.spec, info.initialValue, value);
|
||||
}
|
||||
bool
|
||||
Object::Get (std::string name, std::string &value) const
|
||||
@@ -941,7 +980,7 @@ Object::Get (std::string name, std::string &value) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
PValue v = info.spec->CreateValue ();
|
||||
PValue v = info.initialValue.Copy ();
|
||||
bool ok = info.spec->Get (this, v);
|
||||
if (ok)
|
||||
{
|
||||
@@ -962,7 +1001,7 @@ Object::Get (std::string name) const
|
||||
{
|
||||
return PValue ();
|
||||
}
|
||||
PValue value = info.spec->CreateValue ();
|
||||
PValue value = info.initialValue.Copy ();
|
||||
bool ok = info.spec->Get (this, value);
|
||||
if (!ok)
|
||||
{
|
||||
|
||||
@@ -141,6 +141,8 @@ public:
|
||||
*/
|
||||
std::string GetParameterFullName (uint32_t i) const;
|
||||
|
||||
PValue GetParameterInitialValue (uint32_t i) const;
|
||||
|
||||
Ptr<Object> CreateObject (const Parameters ¶meters) const;
|
||||
|
||||
|
||||
@@ -209,7 +211,9 @@ public:
|
||||
* Record in this TypeId the fact that a new parameter exists.
|
||||
*/
|
||||
TypeId AddParameter (std::string name,
|
||||
std::string help, Ptr<const ParamSpec> spec);
|
||||
std::string help,
|
||||
PValue initialValue,
|
||||
Ptr<const ParamSpec> spec);
|
||||
|
||||
/**
|
||||
* \param name the name of the new parameter
|
||||
@@ -224,6 +228,7 @@ public:
|
||||
TypeId AddParameter (std::string name,
|
||||
std::string help,
|
||||
uint32_t flags,
|
||||
PValue initialValue,
|
||||
Ptr<const ParamSpec> spec);
|
||||
|
||||
// construct an invalid TypeId.
|
||||
@@ -237,6 +242,7 @@ private:
|
||||
|
||||
struct ParameterInfo {
|
||||
Ptr<const ParamSpec> spec;
|
||||
PValue initialValue;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
@@ -323,7 +329,7 @@ private:
|
||||
|
||||
|
||||
|
||||
bool DoSet (Ptr<const ParamSpec> spec, PValue param);
|
||||
bool DoSet (struct TypeId::ParameterInfo *info, PValue param);
|
||||
void DoSetOne (Ptr<const ParamSpec> spec, PValue param);
|
||||
std::string LookupParameterFullNameByParamSpec (Ptr<const ParamSpec> spec) const;
|
||||
|
||||
@@ -463,7 +469,7 @@ private:
|
||||
friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7);
|
||||
|
||||
|
||||
bool DoSet (Ptr<const ParamSpec> spec, PValue value);
|
||||
bool DoSet (Ptr<const ParamSpec> spec, PValue intialValue, PValue value);
|
||||
Ptr<Object> DoGetObject (TypeId tid) const;
|
||||
void DoCollectSources (std::string path, const TraceContext &context,
|
||||
TraceResolver::SourceCollection *collection) const;
|
||||
|
||||
@@ -3,21 +3,21 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
template <typename BASE, typename T1, typename V>
|
||||
template <typename BASE, typename V, typename T1>
|
||||
Ptr<ParamSpec>
|
||||
MakeParamSpecHelper (T1 a1, V initialValue);
|
||||
MakeParamSpecHelper (T1 a1);
|
||||
|
||||
template <typename BASE, typename T1, typename T2, typename V>
|
||||
template <typename BASE, typename V, typename T1, typename T2>
|
||||
Ptr<ParamSpec>
|
||||
MakeParamSpecHelper (T1 a1, T2 a2, V initialValue);
|
||||
MakeParamSpecHelper (T1 a1, T2 a2);
|
||||
|
||||
template <typename BASE, typename T1, typename V, typename CHECKER>
|
||||
template <typename BASE, typename V, typename T1, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
MakeParamSpecHelperWithChecker (T1 a1, V initialValue, CHECKER checker);
|
||||
MakeParamSpecHelperWithChecker (T1 a1, CHECKER checker);
|
||||
|
||||
template <typename BASE, typename T1, typename T2, typename V, typename CHECKER>
|
||||
template <typename BASE, typename V, typename T1, typename T2, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
MakeParamSpecHelperWithChecker (T1 a1, T2 a2, V initialValue, CHECKER checker);
|
||||
MakeParamSpecHelperWithChecker (T1 a1, T2 a2, CHECKER checker);
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -33,9 +33,8 @@ template <typename BASE, typename T, typename U, typename CHECKER>
|
||||
class ParamSpecHelper : public BASE
|
||||
{
|
||||
public:
|
||||
ParamSpecHelper (PValue initialValue, CHECKER checker)
|
||||
: m_initialValue (initialValue),
|
||||
m_checker (checker) {}
|
||||
ParamSpecHelper (CHECKER checker)
|
||||
: m_checker (checker) {}
|
||||
|
||||
virtual bool Set (ObjectBase * object, PValue val) const {
|
||||
const U *value = val.DynCast<const U*> ();
|
||||
@@ -74,19 +73,10 @@ public:
|
||||
return m_checker.Check (val->Get ());
|
||||
}
|
||||
|
||||
virtual PValue GetInitialValue (void) const {
|
||||
return m_initialValue;
|
||||
}
|
||||
|
||||
virtual PValue CreateValue (void) const {
|
||||
return m_initialValue.Copy ();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
virtual bool DoSet (T *object, const U *v) const = 0;
|
||||
virtual bool DoGet (const T *object, U *v) const = 0;
|
||||
PValue m_initialValue;
|
||||
CHECKER m_checker;
|
||||
};
|
||||
|
||||
@@ -97,15 +87,15 @@ public:
|
||||
bool Check (const T &value) const {return true;}
|
||||
};
|
||||
|
||||
template <typename BASE, typename T, typename U, typename V, typename CHECKER>
|
||||
template <typename BASE, typename V, typename T, typename U, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperOne (U T::*memberVariable, V initialValue, CHECKER checker)
|
||||
DoMakeParamSpecHelperOne (U T::*memberVariable, CHECKER checker)
|
||||
{
|
||||
class MemberVariable : public ParamSpecHelper<BASE,T,V,CHECKER>
|
||||
{
|
||||
public:
|
||||
MemberVariable (U T::*memberVariable, V initialValue, CHECKER checker)
|
||||
: ParamSpecHelper<BASE,T,V,CHECKER> (initialValue, checker),
|
||||
MemberVariable (U T::*memberVariable, CHECKER checker)
|
||||
: ParamSpecHelper<BASE,T,V,CHECKER> (checker),
|
||||
m_memberVariable (memberVariable)
|
||||
{}
|
||||
private:
|
||||
@@ -120,27 +110,27 @@ DoMakeParamSpecHelperOne (U T::*memberVariable, V initialValue, CHECKER checker)
|
||||
|
||||
U T::*m_memberVariable;
|
||||
};
|
||||
return Ptr<ParamSpec> (new MemberVariable (memberVariable, initialValue, checker), false);
|
||||
return Ptr<ParamSpec> (new MemberVariable (memberVariable, checker), false);
|
||||
}
|
||||
template <typename BASE, typename T, typename U, typename V>
|
||||
template <typename BASE, typename V, typename T, typename U>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperOne (U T::*memberVariable, V initialValue)
|
||||
DoMakeParamSpecHelperOne (U T::*memberVariable)
|
||||
{
|
||||
return DoMakeParamSpecHelperOne<BASE> (memberVariable, initialValue, ParamSpecHelperSimpleChecker<U> ());
|
||||
return DoMakeParamSpecHelperOne<BASE,V> (memberVariable, ParamSpecHelperSimpleChecker<U> ());
|
||||
}
|
||||
|
||||
|
||||
template <typename BASE, typename T, typename U, typename V, typename CHECKER>
|
||||
template <typename BASE, typename V, typename T, typename U, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperOne (U (T::*getter) (void) const,
|
||||
V initialValue, CHECKER checker)
|
||||
CHECKER checker)
|
||||
{
|
||||
class MemberMethod : public ParamSpecHelper<BASE,T,V,CHECKER>
|
||||
{
|
||||
public:
|
||||
MemberMethod (U (T::*getter) (void) const,
|
||||
V initialValue, CHECKER checker)
|
||||
: ParamSpecHelper<BASE,T,V,CHECKER> (initialValue, checker),
|
||||
CHECKER checker)
|
||||
: ParamSpecHelper<BASE,T,V,CHECKER> (checker),
|
||||
m_getter (getter)
|
||||
{}
|
||||
private:
|
||||
@@ -153,30 +143,29 @@ DoMakeParamSpecHelperOne (U (T::*getter) (void) const,
|
||||
}
|
||||
U (T::*m_getter) (void) const;
|
||||
};
|
||||
return Ptr<ParamSpec> (new MemberMethod (getter, initialValue, checker), false);
|
||||
return Ptr<ParamSpec> (new MemberMethod (getter, checker), false);
|
||||
}
|
||||
|
||||
template <typename BASE, typename T, typename U, typename V>
|
||||
template <typename BASE, typename V, typename T, typename U>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperOne (U (T::*getter) (void) const,
|
||||
V initialValue)
|
||||
DoMakeParamSpecHelperOne (U (T::*getter) (void) const)
|
||||
{
|
||||
return DoMakeParamSpecHelperOne<BASE> (getter, initialValue, ParamSpecHelperSimpleChecker<U> ());
|
||||
return DoMakeParamSpecHelperOne<BASE,V> (getter, ParamSpecHelperSimpleChecker<U> ());
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename BASE, typename T, typename U, typename V, typename CHECKER>
|
||||
template <typename BASE, typename V, typename T, typename U, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperOne (void (T::*setter) (U),
|
||||
V initialValue, CHECKER checker)
|
||||
CHECKER checker)
|
||||
{
|
||||
class MemberMethod : public ParamSpecHelper<BASE,T,V,CHECKER>
|
||||
{
|
||||
public:
|
||||
MemberMethod (void (T::*setter) (U),
|
||||
V initialValue, CHECKER checker)
|
||||
: ParamSpecHelper<BASE,T,V,CHECKER> (initialValue, checker),
|
||||
CHECKER checker)
|
||||
: ParamSpecHelper<BASE,T,V,CHECKER> (checker),
|
||||
m_setter (setter)
|
||||
{}
|
||||
private:
|
||||
@@ -189,24 +178,22 @@ DoMakeParamSpecHelperOne (void (T::*setter) (U),
|
||||
}
|
||||
void (T::*m_setter) (U);
|
||||
};
|
||||
return Ptr<ParamSpec> (new MemberMethod (setter, initialValue, checker), false);
|
||||
return Ptr<ParamSpec> (new MemberMethod (setter, checker), false);
|
||||
}
|
||||
|
||||
template <typename BASE, typename T, typename U, typename V>
|
||||
template <typename BASE, typename V, typename T, typename U>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperOne (void (T::*setter) (U),
|
||||
V initialValue)
|
||||
DoMakeParamSpecHelperOne (void (T::*setter) (U))
|
||||
{
|
||||
return DoMakeParamSpecHelperOne<BASE> (setter, initialValue,
|
||||
return DoMakeParamSpecHelperOne<BASE,V> (setter,
|
||||
ParamSpecHelperSimpleChecker<typename TypeTraits<U>::ReferencedType> ());
|
||||
}
|
||||
|
||||
|
||||
template <typename BASE, typename T, typename U, typename V, typename W, typename CHECKER>
|
||||
template <typename BASE, typename W, typename T, typename U, typename V, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperTwo (void (T::*setter) (U),
|
||||
V (T::*getter) (void) const,
|
||||
W initialValue,
|
||||
CHECKER checker = ParamSpecHelperSimpleChecker<V> ())
|
||||
{
|
||||
class MemberMethod : public ParamSpecHelper<BASE,T,W,CHECKER>
|
||||
@@ -214,8 +201,8 @@ DoMakeParamSpecHelperTwo (void (T::*setter) (U),
|
||||
public:
|
||||
MemberMethod (void (T::*setter) (U),
|
||||
V (T::*getter) (void) const,
|
||||
W initialValue, CHECKER checker)
|
||||
: ParamSpecHelper<BASE,T,W,CHECKER> (initialValue, checker),
|
||||
CHECKER checker)
|
||||
: ParamSpecHelper<BASE,T,W,CHECKER> (checker),
|
||||
m_setter (setter),
|
||||
m_getter (getter)
|
||||
{}
|
||||
@@ -231,63 +218,60 @@ DoMakeParamSpecHelperTwo (void (T::*setter) (U),
|
||||
void (T::*m_setter) (U);
|
||||
V (T::*m_getter) (void) const;
|
||||
};
|
||||
return Ptr<ParamSpec> (new MemberMethod (setter, getter, initialValue, checker), false);
|
||||
return Ptr<ParamSpec> (new MemberMethod (setter, getter, checker), false);
|
||||
}
|
||||
|
||||
template <typename BASE, typename T, typename U, typename V, typename W>
|
||||
template <typename BASE, typename W, typename T, typename U, typename V>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperTwo (void (T::*setter) (U),
|
||||
V (T::*getter) (void) const,
|
||||
W initialValue)
|
||||
V (T::*getter) (void) const)
|
||||
{
|
||||
return DoMakeParamSpecHelperTwo<BASE> (setter, getter, initialValue, ParamSpecHelperSimpleChecker<V> ());
|
||||
return DoMakeParamSpecHelperTwo<BASE,W> (setter, getter, ParamSpecHelperSimpleChecker<V> ());
|
||||
}
|
||||
|
||||
template <typename BASE, typename T, typename U, typename V, typename W, typename CHECKER>
|
||||
template <typename BASE, typename W, typename T, typename U, typename V, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperTwo (V (T::*getter) (void) const,
|
||||
void (T::*setter) (U),
|
||||
W initialValue,
|
||||
CHECKER checker)
|
||||
{
|
||||
return DoMakeParamSpecHelperTwo<BASE> (setter, getter, initialValue, checker);
|
||||
return DoMakeParamSpecHelperTwo<BASE,W> (setter, getter, checker);
|
||||
}
|
||||
|
||||
template <typename BASE, typename T, typename U, typename V, typename W, typename CHECKER>
|
||||
template <typename BASE, typename W, typename T, typename U, typename V, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
DoMakeParamSpecHelperTwo (V (T::*getter) (void) const,
|
||||
void (T::*setter) (U),
|
||||
W initialValue)
|
||||
void (T::*setter) (U))
|
||||
{
|
||||
return DoMakeParamSpecHelperTwo<BASE> (setter, getter, initialValue);
|
||||
return DoMakeParamSpecHelperTwo<BASE,W> (setter, getter);
|
||||
}
|
||||
|
||||
template <typename BASE, typename T1, typename V>
|
||||
template <typename BASE, typename V, typename T1>
|
||||
Ptr<ParamSpec>
|
||||
MakeParamSpecHelper (T1 a1, V initialValue)
|
||||
MakeParamSpecHelper (T1 a1)
|
||||
{
|
||||
return DoMakeParamSpecHelperOne<BASE> (a1, initialValue);
|
||||
return DoMakeParamSpecHelperOne<BASE,V> (a1);
|
||||
}
|
||||
|
||||
template <typename BASE, typename T1, typename T2, typename V>
|
||||
template <typename BASE, typename V, typename T1, typename T2>
|
||||
Ptr<ParamSpec>
|
||||
MakeParamSpecHelper (T1 a1, T2 a2, V initialValue)
|
||||
MakeParamSpecHelper (T1 a1, T2 a2)
|
||||
{
|
||||
return DoMakeParamSpecHelperTwo<BASE> (a1, a2, initialValue);
|
||||
return DoMakeParamSpecHelperTwo<BASE,V> (a1, a2);
|
||||
}
|
||||
|
||||
template <typename BASE, typename T1, typename V, typename CHECKER>
|
||||
template <typename BASE, typename V, typename T1, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
MakeParamSpecHelperWithChecker (T1 a1, V initialValue, CHECKER checker)
|
||||
MakeParamSpecHelperWithChecker (T1 a1, CHECKER checker)
|
||||
{
|
||||
return DoMakeParamSpecHelperOne<BASE> (a1, initialValue, checker);
|
||||
return DoMakeParamSpecHelperOne<BASE,V> (a1, checker);
|
||||
}
|
||||
|
||||
template <typename BASE, typename T1, typename T2, typename V, typename CHECKER>
|
||||
template <typename BASE, typename V, typename T1, typename T2, typename CHECKER>
|
||||
Ptr<ParamSpec>
|
||||
MakeParamSpecHelperWithChecker (T1 a1, T2 a2, V initialValue, CHECKER checker)
|
||||
MakeParamSpecHelperWithChecker (T1 a1, T2 a2, CHECKER checker)
|
||||
{
|
||||
return DoMakeParamSpecHelperTwo<BASE> (a1, a2, initialValue, checker);
|
||||
return DoMakeParamSpecHelperTwo<BASE,V> (a1, a2, checker);
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -669,11 +669,9 @@ class RandomVariableValue : public Value {};
|
||||
class RandomVariableParamSpec : public ParamSpec {};
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeRandomVariableParamSpec (T1 a1,
|
||||
RandomVariable initialValue);
|
||||
Ptr<ParamSpec> MakeRandomVariableParamSpec (T1 a1);
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeRandomVariableParamSpec (T1 a1, T2 a2,
|
||||
RandomVariable initialValue);
|
||||
Ptr<ParamSpec> MakeRandomVariableParamSpec (T1 a1, T2 a2);
|
||||
|
||||
|
||||
}//namespace ns3
|
||||
@@ -682,19 +680,17 @@ Ptr<ParamSpec> MakeRandomVariableParamSpec (T1 a1, T2 a2,
|
||||
namespace ns3 {
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeRandomVariableParamSpec (T1 a1,
|
||||
RandomVariable initialValue)
|
||||
Ptr<ParamSpec> MakeRandomVariableParamSpec (T1 a1)
|
||||
{
|
||||
return MakeClassValueHelperParamSpec<RandomVariable,
|
||||
RandomVariableValue, RandomVariableParamSpec> (a1, initialValue);
|
||||
RandomVariableValue, RandomVariableParamSpec> (a1);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeRandomVariableParamSpec (T1 a1, T2 a2,
|
||||
RandomVariable initialValue)
|
||||
Ptr<ParamSpec> MakeRandomVariableParamSpec (T1 a1, T2 a2)
|
||||
{
|
||||
return MakeClassValueHelperParamSpec<RandomVariable,
|
||||
RandomVariableValue,RandomVariableParamSpec> (a1, a2, initialValue);
|
||||
RandomVariableValue,RandomVariableParamSpec> (a1, a2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,19 +27,15 @@ private:
|
||||
class UintParamSpec : public ParamSpec {};
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1,
|
||||
uint64_t initialValue);
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1);
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1,
|
||||
uint64_t initialValue,
|
||||
uint64_t minValue,
|
||||
uint64_t maxValue);
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1, T2 a2,
|
||||
uint64_t initialValue);
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1, T2 a2);
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1, T2 a2,
|
||||
uint64_t initialValue,
|
||||
uint64_t minValue,
|
||||
uint64_t maxValue);
|
||||
|
||||
@@ -75,36 +71,32 @@ private:
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec>
|
||||
MakeUintParamSpec (T1 a1,
|
||||
uint64_t initialValue)
|
||||
MakeUintParamSpec (T1 a1)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<UintParamSpec> (a1, UintValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<UintParamSpec,UintValue> (a1,
|
||||
UintValueChecker::Create (a1));
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1,
|
||||
uint64_t initialValue,
|
||||
uint64_t minValue,
|
||||
uint64_t maxValue)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<UintParamSpec> (a1, UintValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<UintParamSpec,UintValue> (a1,
|
||||
UintValueChecker (minValue, maxValue));
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1, T2 a2,
|
||||
uint64_t initialValue)
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1, T2 a2)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<UintParamSpec> (a1, a2, UintValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<UintParamSpec,UintValue> (a1, a2,
|
||||
UintValueChecker::Create (a1));
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
Ptr<ParamSpec> MakeUintParamSpec (T1 a1, T2 a2,
|
||||
uint64_t initialValue,
|
||||
uint64_t minValue,
|
||||
uint64_t maxValue)
|
||||
{
|
||||
return MakeParamSpecHelperWithChecker<UintParamSpec> (a1, a2, UintValue (initialValue),
|
||||
return MakeParamSpecHelperWithChecker<UintParamSpec,UintValue> (a1, a2,
|
||||
UintValueChecker (minValue, maxValue));
|
||||
}
|
||||
|
||||
|
||||
36
src/core/value-helper.h
Normal file
36
src/core/value-helper.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef VALUE_HELPER_H
|
||||
#define VALUE_HELPER_H
|
||||
|
||||
#include "class-value-helper.h"
|
||||
|
||||
#define VALUE_HELPER_HEADER_1(type) \
|
||||
type (PValue value); \
|
||||
operator PValue () const;
|
||||
|
||||
#define VALUE_HELPER_HEADER_2(type) \
|
||||
class type##Value : public Value {}; \
|
||||
class type##ParamSpec : public ParamSpec {}; \
|
||||
template <typename T1> \
|
||||
Ptr<ParamSpec> Make##type##ParamSpec (T1 a1) \
|
||||
{ \
|
||||
return MakeClassValueHelperParamSpec< type , \
|
||||
type##Value, type##ParamSpec> (a1); \
|
||||
} \
|
||||
template <typename T1, typename T2> \
|
||||
Ptr<ParamSpec> Make##type##ParamSpec (T1 a1, T2 a2) \
|
||||
{ \
|
||||
return MakeClassValueHelperParamSpec<type, \
|
||||
type##Value,type##ParamSpec> (a1, a2); \
|
||||
}
|
||||
|
||||
#define VALUE_HELPER_CPP(type) \
|
||||
type::type (PValue value) \
|
||||
{ \
|
||||
*this = ClassValueHelperExtractFrom<type,type##Value> (value); \
|
||||
} \
|
||||
type::operator PValue () const \
|
||||
{ \
|
||||
return ClassValueHelperConvertTo<type,type##Value> (this); \
|
||||
}
|
||||
|
||||
#endif /* VALUE_HELPER_H */
|
||||
@@ -42,39 +42,46 @@ public:
|
||||
static TypeId tid = TypeId ("ParamSpecObjectTest")
|
||||
.SetParent<Object> ()
|
||||
.AddParameter ("TestBoolName", "help text",
|
||||
MakeBooleanParamSpec (&ParamSpecObjectTest::m_boolTest, false))
|
||||
BooleanValue (false),
|
||||
MakeBooleanParamSpec (&ParamSpecObjectTest::m_boolTest))
|
||||
.AddParameter ("TestBoolA", "help text",
|
||||
BooleanValue (false),
|
||||
MakeBooleanParamSpec (&ParamSpecObjectTest::DoSetTestB,
|
||||
&ParamSpecObjectTest::DoGetTestB,
|
||||
false))
|
||||
&ParamSpecObjectTest::DoGetTestB))
|
||||
.AddParameter ("TestPtr", "help text",
|
||||
Ptr<Derived> (0),
|
||||
MakePtrParamSpec (&ParamSpecObjectTest::m_derived))
|
||||
.AddParameter ("TestInt16", "help text",
|
||||
MakeIntParamSpec (&ParamSpecObjectTest::m_int16,
|
||||
-2))
|
||||
IntValue (-2),
|
||||
MakeIntParamSpec (&ParamSpecObjectTest::m_int16))
|
||||
.AddParameter ("TestInt16WithBounds", "help text",
|
||||
IntValue (-2),
|
||||
MakeIntParamSpec (&ParamSpecObjectTest::m_int16WithBounds,
|
||||
-2, -5, 10))
|
||||
-5, 10))
|
||||
.AddParameter ("TestInt16SetGet", "help text",
|
||||
IntValue (6),
|
||||
MakeIntParamSpec (&ParamSpecObjectTest::DoSetInt16,
|
||||
&ParamSpecObjectTest::DoGetInt16,
|
||||
6))
|
||||
&ParamSpecObjectTest::DoGetInt16))
|
||||
.AddParameter ("TestUint8", "help text",
|
||||
MakeUintParamSpec (&ParamSpecObjectTest::m_uint8,
|
||||
1))
|
||||
UintValue (1),
|
||||
MakeUintParamSpec (&ParamSpecObjectTest::m_uint8))
|
||||
.AddParameter ("TestEnum", "help text",
|
||||
EnumValue (TEST_A),
|
||||
MakeEnumParamSpec (&ParamSpecObjectTest::m_enum,
|
||||
TEST_A, "TestA",
|
||||
TEST_B, "TestB",
|
||||
TEST_C, "TestC"))
|
||||
.AddParameter ("TestRandom", "help text",
|
||||
MakeRandomVariableParamSpec (&ParamSpecObjectTest::m_random,
|
||||
ConstantVariable (1.0)))
|
||||
ConstantVariable (1.0),
|
||||
MakeRandomVariableParamSpec (&ParamSpecObjectTest::m_random))
|
||||
.AddParameter ("TestFloat", "help text",
|
||||
MakeFpParamSpec (&ParamSpecObjectTest::m_float, -1.1))
|
||||
FpValue (-1.1),
|
||||
MakeFpParamSpec (&ParamSpecObjectTest::m_float))
|
||||
.AddParameter ("TestVector1", "help text",
|
||||
ObjectVector (),
|
||||
MakeObjectVectorParamSpec (&ParamSpecObjectTest::m_vector1))
|
||||
.AddParameter ("TestVector2", "help text",
|
||||
ObjectVector (),
|
||||
MakeObjectVectorParamSpec (&ParamSpecObjectTest::DoGetVectorN,
|
||||
&ParamSpecObjectTest::DoGetVector))
|
||||
;
|
||||
|
||||
@@ -20,11 +20,6 @@ Value::operator = (const Value &o)
|
||||
}
|
||||
Value::~Value ()
|
||||
{}
|
||||
bool
|
||||
Value::ConvertFrom (PValue value, Ptr<const ParamSpec> spec)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* Big interesting warning.
|
||||
@@ -117,16 +112,6 @@ PValue::DeserializeFromString (std::string value, Ptr<const ParamSpec> spec)
|
||||
{
|
||||
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))
|
||||
|
||||
@@ -22,7 +22,6 @@ public:
|
||||
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 @@ public:
|
||||
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);
|
||||
@@ -78,8 +76,6 @@ 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 GetInitialValue (void) const = 0;
|
||||
virtual PValue CreateValue (void) const = 0;
|
||||
private:
|
||||
mutable uint32_t m_count;
|
||||
};
|
||||
@@ -274,12 +270,6 @@ public:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual PValue GetInitialValue (void) const {
|
||||
return CreateValue ();
|
||||
}
|
||||
virtual PValue CreateValue (void) const {
|
||||
return PValue::Create<PtrValue<U> > (Ptr<U> (0));
|
||||
}
|
||||
private:
|
||||
virtual void DoSet (T *object, Ptr<U> value) const = 0;
|
||||
virtual Ptr<U> DoGet (const T *object) const = 0;
|
||||
|
||||
@@ -114,5 +114,6 @@ def build(bld):
|
||||
'enum-value.h',
|
||||
'object-factory.h',
|
||||
'class-value-helper.h',
|
||||
'value-helper.h',
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user