--- a/src/core/global-value.cc Mon Apr 14 16:19:17 2008 -0700
+++ b/src/core/global-value.cc Thu Apr 17 13:42:25 2008 -0700
@@ -25,11 +25,11 @@
namespace ns3 {
GlobalValue::GlobalValue (std::string name, std::string help,
- Attribute initialValue,
+ const AttributeValue &initialValue,
Ptr<const AttributeChecker> checker)
: m_name (name),
m_help (help),
- m_initialValue (initialValue),
+ m_initialValue (initialValue.Copy ()),
m_checker (checker)
{
if (m_checker == 0)
@@ -49,10 +49,20 @@
{
return m_help;
}
-Attribute
-GlobalValue::GetValue (void) const
+void
+GlobalValue::GetValue (AttributeValue &value) const
{
- return m_initialValue;
+ bool ok = m_checker->Copy (*m_initialValue, value);
+ if (ok)
+ {
+ return;
+ }
+ StringValue *str = dynamic_cast<StringValue *> (&value);
+ if (str == 0)
+ {
+ NS_FATAL_ERROR ("GlobalValue name="<<m_name<<": input value is not a string");
+ }
+ str->Set (m_initialValue->SerializeToString (m_checker));
}
Ptr<const AttributeChecker>
GlobalValue::GetChecker (void) const
@@ -61,37 +71,37 @@
}
bool
-GlobalValue::SetValue (Attribute value)
+GlobalValue::SetValue (const AttributeValue &value)
{
if (m_checker->Check (value))
{
- m_initialValue = value;
+ m_initialValue = value.Copy ();
return true;
}
// attempt to convert to string.
- const StringValue *str = value.DynCast<const StringValue *> ();
+ const StringValue *str = dynamic_cast<const StringValue *> (&value);
if (str == 0)
{
return false;
}
// attempt to convert back to value.
- Attribute v = m_checker->Create ();
- bool ok = v.DeserializeFromString (str->Get ().Get (), m_checker);
+ Ptr<AttributeValue> v = m_checker->Create ();
+ bool ok = v->DeserializeFromString (str->Get (), m_checker);
if (!ok)
{
return false;
}
- ok = m_checker->Check (v);
+ ok = m_checker->Check (*v);
if (!ok)
{
return false;
}
- m_initialValue = v;
+ m_checker->Copy (*v, *PeekPointer (m_initialValue));
return true;
}
void
-GlobalValue::Bind (std::string name, Attribute value)
+GlobalValue::Bind (std::string name, const AttributeValue &value)
{
for (Iterator i = Begin (); i != End (); i++)
{
@@ -107,7 +117,7 @@
NS_FATAL_ERROR ("Non-existant global value: "<<name);
}
bool
-GlobalValue::BindFailSafe (std::string name, Attribute value)
+GlobalValue::BindFailSafe (std::string name, const AttributeValue &value)
{
for (Iterator i = Begin (); i != End (); i++)
{
@@ -160,11 +170,13 @@
{
bool result = true;
GlobalValue uint = GlobalValue ("TestUint", "help text",
- Uinteger (10),
+ UintegerValue (10),
MakeUintegerChecker<uint32_t> ());
- NS_TEST_ASSERT_EQUAL (10, Uinteger (uint.GetValue ()).Get ());
+ UintegerValue v;
+ uint.GetValue (v);
+ NS_TEST_ASSERT_EQUAL (10, v.Get ());
GlobalValue::Vector *vector = GlobalValue::GetVector ();
for (GlobalValue::Vector::iterator i = vector->begin (); i != vector->end (); ++i)