diff -r 4e8cb1577144 -r 4b28e9740e3b src/core/object-base.cc --- a/src/core/object-base.cc Mon Apr 14 16:19:17 2008 -0700 +++ b/src/core/object-base.cc Thu Apr 17 13:42:25 2008 -0700 @@ -20,6 +20,7 @@ #include "object-base.h" #include "log.h" #include "trace-source-accessor.h" +#include "attribute-list.h" #include "string.h" NS_LOG_COMPONENT_DEFINE ("ObjectBase"); @@ -58,8 +59,8 @@ NS_LOG_DEBUG ("construct tid="<checker == checker) { // We have a matching attribute value. - DoSet (paramSpec, initial, checker, j->value); + DoSet (accessor, checker, *j->value); NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<< tid.GetAttributeName (i)<<"\""); found = true; @@ -91,7 +92,7 @@ if (j->checker == checker) { // We have a matching attribute value. - DoSet (paramSpec, initial, checker, j->value); + DoSet (accessor, checker, *j->value); NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<< tid.GetAttributeName (i)<<"\" from global"); found = true; @@ -102,7 +103,7 @@ if (!found) { // No matching attribute value so we set the default value. - paramSpec->Set (this, initial); + DoSet (accessor, checker, *initial); NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<< tid.GetAttributeName (i)<<"\" from initial value."); } @@ -113,70 +114,39 @@ } bool -ObjectBase::DoSet (Ptr spec, Attribute initialValue, - Ptr checker, Attribute value) +ObjectBase::DoSet (Ptr spec, + Ptr checker, + const AttributeValue &value) { bool ok = checker->Check (value); + if (ok) + { + ok = spec->Set (this, value); + return ok; + } + // attempt to convert to string + const StringValue *str = dynamic_cast (&value); + if (str == 0) + { + return false; + } + // attempt to convert back from string. + Ptr v = checker->Create (); + ok = v->DeserializeFromString (str->Get (), checker); if (!ok) { - // attempt to convert to string - const StringValue *str = value.DynCast (); - if (str == 0) - { - return false; - } - // attempt to convert back from string. - Attribute v = checker->Create (); - ok = v.DeserializeFromString (str->Get ().Get (), checker); - if (!ok) - { - return false; - } - ok = checker->Check (v); - if (!ok) - { - return false; - } - value = v; + return false; } - ok = spec->Set (this, value); + ok = checker->Check (*v); + if (!ok) + { + return false; + } + ok = spec->Set (this, *v); return ok; } void -ObjectBase::SetAttribute (std::string name, Attribute value) -{ - struct TypeId::AttributeInfo info; - TypeId tid = GetInstanceTypeId (); - if (!tid.LookupAttributeByName (name, &info)) - { - NS_FATAL_ERROR ("Attribute name="< v = info.checker->Create (); + ok = info.accessor->Get (this, *PeekPointer (v)); + if (!ok) + { + NS_FATAL_ERROR ("Attribute name="<Set (v->SerializeToString (info.checker)); } + bool -ObjectBase::GetAttributeFailSafe (std::string name, Attribute &value) const +ObjectBase::GetAttributeFailSafe (std::string name, AttributeValue &value) const { struct TypeId::AttributeInfo info; TypeId tid = GetInstanceTypeId (); @@ -251,13 +224,29 @@ { return false; } - if (!(info.flags & TypeId::ATTR_GET)) + if (!(info.flags & TypeId::ATTR_GET) || + !info.accessor->HasGetter ()) { return false; } - value = info.checker->Create (); bool ok = info.accessor->Get (this, value); - return ok; + if (ok) + { + return true; + } + StringValue *str = dynamic_cast (&value); + if (str == 0) + { + return false; + } + Ptr v = info.checker->Create (); + ok = info.accessor->Get (this, *PeekPointer (v)); + if (!ok) + { + return false; + } + str->Set (v->SerializeToString (info.checker)); + return true; } bool