20 #include "object-base.h"
22 #include "trace-source-accessor.h"
23 #include "attribute-construction-list.h"
25 #include "ns3/core-config.h"
34 NS_OBJECT_ENSURE_REGISTERED (ObjectBase);
40 TypeId tid = TypeId (
"ns3::ObjectBase");
46 ObjectBase::GetTypeId (
void)
49 static TypeId tid = GetObjectIid ();
53 ObjectBase::~ObjectBase ()
88 if (DoSet (info.accessor, info.checker, *value))
100 char *envVar = getenv (
"NS_ATTRIBUTE_DEFAULT");
103 std::string env = std::string (envVar);
104 std::string::size_type cur = 0;
105 std::string::size_type next = 0;
106 while (next != std::string::npos)
108 next = env.find (
";", cur);
109 std::string tmp = std::string (env, cur, next-cur);
110 std::string::size_type equal = tmp.find (
"=");
111 if (equal != std::string::npos)
113 std::string name = tmp.substr (0, equal);
114 std::string value = tmp.substr (equal+1, tmp.size () - equal - 1);
117 if (DoSet (info.accessor, info.checker,
StringValue (value)))
120 info.name <<
"\" from env var");
134 DoSet (info.accessor, info.checker, *info.initialValue);
136 info.name <<
"\" from initial value.");
140 }
while (tid != ObjectBase::GetTypeId ());
155 bool ok = accessor->Set (
this, *v);
165 if (!tid.LookupAttributeByName (name, &info))
167 NS_FATAL_ERROR (
"Attribute name="<<name<<
" does not exist for this object: tid="<<tid.GetName ());
170 !info.accessor->HasSetter ())
172 NS_FATAL_ERROR (
"Attribute name="<<name<<
" is not settable for this object: tid="<<tid.GetName ());
174 if (!DoSet (info.accessor, info.checker, value))
176 NS_FATAL_ERROR (
"Attribute name="<<name<<
" could not be set for this object: tid="<<tid.GetName ());
185 if (!tid.LookupAttributeByName (name, &info))
190 !info.accessor->HasSetter ())
194 return DoSet (info.accessor, info.checker, value);
203 if (!tid.LookupAttributeByName (name, &info))
205 NS_FATAL_ERROR (
"Attribute name="<<name<<
" does not exist for this object: tid="<<tid.GetName ());
208 !info.accessor->HasGetter ())
210 NS_FATAL_ERROR (
"Attribute name="<<name<<
" is not gettable for this object: tid="<<tid.GetName ());
212 bool ok = info.accessor->Get (
this, value);
220 NS_FATAL_ERROR (
"Attribute name="<<name<<
" tid="<<tid.GetName () <<
": input value is not a string");
223 ok = info.accessor->Get (
this, *PeekPointer (v));
226 NS_FATAL_ERROR (
"Attribute name="<<name<<
" tid="<<tid.GetName () <<
": could not get value");
228 str->Set (v->SerializeToString (info.checker));
238 if (!tid.LookupAttributeByName (name, &info))
243 !info.accessor->HasGetter ())
247 bool ok = info.accessor->Get (
this, value);
258 ok = info.accessor->Get (
this, *PeekPointer (v));
263 str->Set (v->SerializeToString (info.checker));
277 bool ok = accessor->ConnectWithoutContext (
this, cb);
290 bool ok = accessor->Connect (
this, context, cb);
303 bool ok = accessor->DisconnectWithoutContext (
this, cb);
316 bool ok = accessor->Disconnect (
this, context, cb);
uint32_t GetAttributeN(void) const
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
hold variables of type string
Hold a value for an Attribute.
#define NS_LOG_COMPONENT_DEFINE(name)
TypeId GetParent(void) const
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
#define NS_LOG_FUNCTION_NOARGS()
#define NS_FATAL_ERROR(msg)
fatal error handling
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
bool TraceDisconnect(std::string name, std::string context, const CallbackBase &cb)
virtual void NotifyConstructionCompleted(void)
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
void ConstructSelf(const AttributeConstructionList &attributes)
std::string GetName(void) const
virtual Ptr< AttributeValue > Create(void) const =0
void GetAttribute(std::string name, AttributeValue &value) const
virtual TypeId GetInstanceTypeId(void) const =0
#define NS_LOG_DEBUG(msg)
bool TraceConnect(std::string name, std::string context, const CallbackBase &cb)
std::string GetAttributeFullName(uint32_t i) const
bool GetAttributeFailSafe(std::string name, AttributeValue &attribute) const
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
void SetAttribute(std::string name, const AttributeValue &value)
a unique identifier for an interface.