25 #include "ns3/core-config.h"
29 #include <unordered_map>
52 std::pair<bool, std::string>
55 static std::unordered_map<std::string, std::string> dict;
57 if (dict.size () == 0)
59 const char *envVar = getenv (
"NS_ATTRIBUTE_DEFAULT");
60 if (envVar != 0 && std::strlen (envVar) > 0)
62 std::string env = envVar;
63 std::string::size_type cur = 0;
64 std::string::size_type next = 0;
65 while (next != std::string::npos)
67 next = env.find (
";", cur);
68 std::string tmp = std::string (env, cur, next - cur);
69 std::string::size_type equal = tmp.find (
"=");
70 if (equal != std::string::npos)
72 std::string name = tmp.substr (0, equal);
73 std::string envval = tmp.substr (equal + 1, tmp.size () - equal - 1);
74 dict.insert ({name, envval});
82 dict.insert ({
"",
""});
89 auto loc = dict.find (key);
90 if (loc != dict.end ())
95 return {found, value};
144 #ifdef NS3_LOG_ENABLE
145 #define LOG_WHERE_VALUE(where, value) \
147 std::string valStr {"nothing"}; \
150 valStr = "\"" + value->SerializeToString (info.checker) + "\""; \
152 NS_LOG_DEBUG (where << " gave " << valStr); \
155 #define LOG_WHERE_VALUE(where, value)
176 std::string where =
"argument";
189 NS_LOG_DEBUG (
"skipping, not settable at construction");
197 NS_FATAL_ERROR (
"Attribute name=" << info.
name <<
" tid=" << tid.
GetName () <<
": initial value cannot be set using attributes");
206 value = Create<StringValue> (val);
212 bool initial =
false;
217 where =
"initial value";
228 info.
name <<
"\" from " << where);
238 #undef LOG_WHERE_VALUE
251 bool ok = accessor->Set (
this, *v);
261 if (!tid.LookupAttributeByName (name, &info))
263 NS_FATAL_ERROR (
"Attribute name=" << name <<
" does not exist for this object: tid=" << tid.GetName ());
268 NS_FATAL_ERROR (
"Attribute name=" << name <<
" is not settable for this object: tid=" << tid.GetName ());
272 NS_FATAL_ERROR (
"Attribute name=" << name <<
" could not be set for this object: tid=" << tid.GetName ());
281 if (!tid.LookupAttributeByName (name, &info))
299 if (!tid.LookupAttributeByName (name, &info))
301 NS_FATAL_ERROR (
"Attribute name=" << name <<
" does not exist for this object: tid=" << tid.GetName ());
306 NS_FATAL_ERROR (
"Attribute name=" << name <<
" is not gettable for this object: tid=" << tid.GetName ());
308 bool ok = info.
accessor->Get (
this, value);
316 NS_FATAL_ERROR (
"Attribute name=" << name <<
" tid=" << tid.GetName () <<
": input value is not a string");
322 NS_FATAL_ERROR (
"Attribute name=" << name <<
" tid=" << tid.GetName () <<
": could not get value");
324 str->
Set (v->SerializeToString (info.
checker));
334 if (!tid.LookupAttributeByName (name, &info))
343 bool ok = info.
accessor->Get (
this, value);
359 str->
Set (v->SerializeToString (info.
checker));
373 bool ok = accessor->ConnectWithoutContext (
this, cb);
386 bool ok = accessor->Connect (
this, context, cb);
399 bool ok = accessor->DisconnectWithoutContext (
this, cb);
412 bool ok = accessor->Disconnect (
this, context, cb);
ns3::AttributeConstructionList declaration.
List of Attribute name, value and checker triples used to construct Objects.
Ptr< AttributeValue > Find(Ptr< const AttributeChecker > checker) const
Find an Attribute in the list from its AttributeChecker.
Hold a value for an Attribute.
Base class for Callback class.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
bool TraceDisconnect(std::string name, std::string context, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected with a context.
static TypeId GetTypeId(void)
Get the type ID.
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
static TypeId GetObjectIid(void)
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly.
void ConstructSelf(const AttributeConstructionList &attributes)
Complete construction of ObjectBase; invoked by derived classes.
virtual ~ObjectBase()
Virtual destructor.
bool GetAttributeFailSafe(std::string name, AttributeValue &value) const
Get the value of an attribute without raising erros.
virtual void NotifyConstructionCompleted(void)
Notifier called once the ObjectBase is fully constructed.
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
virtual TypeId GetInstanceTypeId(void) const =0
Get the most derived TypeId for this Object.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
bool TraceConnect(std::string name, std::string context, const CallbackBase &cb)
Connect a TraceSource to a Callback with a context.
bool DoSet(Ptr< const AttributeAccessor > spec, Ptr< const AttributeChecker > checker, const AttributeValue &value)
Attempt to set the value referenced by the accessor spec to a valid value according to the checker,...
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
void Set(const std::string &value)
Set the value.
a unique identifier for an interface.
std::size_t GetAttributeN(void) const
Get the number of attributes.
@ ATTR_GET
The attribute can be read.
@ ATTR_SET
The attribute can be written.
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
std::string GetAttributeFullName(std::size_t i) const
Get the Attribute name by index.
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
TypeId SetGroupName(std::string groupName)
Set the group name.
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
TypeId GetParent(void) const
Get the parent of this TypeId.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::string GetName(void) const
Get the name.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
std::pair< bool, std::string > EnvDictionary(std::string key)
Get key, value pairs from the "NS_ATTRIBUTE_DEFAULT" environment variable.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
#define LOG_WHERE_VALUE(where, value)
Log where and what value we find for the attribute.
ns3::ObjectBase declaration and NS_OBJECT_ENSURE_REGISTERED() madro definition.
ns3::StringValue attribute value declarations.
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.