26#include "ns3/core-config.h"
30#include <unordered_map>
55std::pair<bool, std::string>
58 static std::unordered_map<std::string, std::string> dict;
62 const char* envVar = getenv(
"NS_ATTRIBUTE_DEFAULT");
63 if (envVar !=
nullptr && std::strlen(envVar) > 0)
65 std::string env = envVar;
66 std::string::size_type cur = 0;
67 std::string::size_type next = 0;
68 while (next != std::string::npos)
70 next = env.find(
';', cur);
71 std::string tmp = std::string(env, cur, next - cur);
72 std::string::size_type equal = tmp.find(
'=');
73 if (equal != std::string::npos)
75 std::string name = tmp.substr(0, equal);
76 std::string envval = tmp.substr(equal + 1, tmp.size() - equal - 1);
77 dict.insert({name, envval});
85 dict.insert({
"",
""});
92 auto loc = dict.find(key);
93 if (loc != dict.end())
98 return {found,
value};
147#define LOG_WHERE_VALUE(where, value) \
150 std::string valStr{"nothing"}; \
153 valStr = "\"" + value->SerializeToString(info.checker) + "\""; \
155 NS_LOG_DEBUG(where << " gave " << valStr); \
158#define LOG_WHERE_VALUE(where, value)
177 std::string where =
"argument";
200 <<
": initial value cannot be set using attributes");
209 value = Create<StringValue>(val);
215 bool initial =
false;
220 where =
"initial value";
240#undef LOG_WHERE_VALUE
253 bool ok = accessor->Set(
this, *v);
263 if (!tid.LookupAttributeByName(name, &info))
266 "Attribute name=" << name <<
" does not exist for this object: tid=" << tid.GetName());
271 "Attribute name=" << name <<
" is not settable for this object: tid=" << tid.GetName());
275 NS_FATAL_ERROR(
"Attribute name=" << name <<
" could not be set for this object: tid="
286 if (!tid.LookupAttributeByName(name, &info))
303 if (!tid.LookupAttributeByName(name, &info))
306 "Attribute name=" << name <<
" does not exist for this object: tid=" << tid.GetName());
311 "Attribute name=" << name <<
" is not gettable for this object: tid=" << tid.GetName());
321 NS_FATAL_ERROR(
"Attribute name=" << name <<
" tid=" << tid.GetName()
322 <<
": input value is not a string");
328 NS_FATAL_ERROR(
"Attribute name=" << name <<
" tid=" << tid.GetName()
329 <<
": could not get value");
340 if (!tid.LookupAttributeByName(name, &info))
378 bool ok = accessor->ConnectWithoutContext(
this, cb);
392 bool ok = accessor->Connect(
this, context, cb);
406 bool ok = accessor->DisconnectWithoutContext(
this, cb);
420 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 GetObjectIid()
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly.
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
virtual TypeId GetInstanceTypeId() const =0
Get the most derived TypeId for this Object.
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()
Notifier called once the ObjectBase is fully constructed.
static TypeId GetTypeId()
Get the type ID.
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
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.
@ 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.
std::size_t GetAttributeN() const
Get the number of attributes.
TypeId GetParent() const
Get the parent of this TypeId.
TypeId SetGroupName(std::string groupName)
Set the group name.
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::string GetName() 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.