add support for NS_ATTRIBUTE_DEFAULT
This commit is contained in:
@@ -22,6 +22,10 @@
|
||||
#include "trace-source-accessor.h"
|
||||
#include "attribute-list.h"
|
||||
#include "string.h"
|
||||
#include "ns3/core-config.h"
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("ObjectBase");
|
||||
|
||||
@@ -76,25 +80,10 @@ ObjectBase::ConstructSelf (const AttributeList &attributes)
|
||||
if (j->checker == checker)
|
||||
{
|
||||
// We have a matching attribute value.
|
||||
DoSet (accessor, checker, *j->value);
|
||||
NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
|
||||
tid.GetAttributeName (i)<<"\"");
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
// is this attribute stored in the global instance instance ?
|
||||
for (AttributeList::Attrs::const_iterator j = AttributeList::GetGlobal ()->m_attributes.begin ();
|
||||
j != AttributeList::GetGlobal ()->m_attributes.end (); j++)
|
||||
{
|
||||
if (j->checker == checker)
|
||||
if (DoSet (accessor, checker, *j->value))
|
||||
{
|
||||
// We have a matching attribute value.
|
||||
DoSet (accessor, checker, *j->value);
|
||||
NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
|
||||
tid.GetAttributeName (i)<<"\" from global");
|
||||
tid.GetAttributeName (i)<<"\"");
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -102,7 +91,61 @@ ObjectBase::ConstructSelf (const AttributeList &attributes)
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
// No matching attribute value so we set the default value.
|
||||
// is this attribute stored in the global instance ?
|
||||
for (AttributeList::Attrs::const_iterator j = AttributeList::GetGlobal ()->m_attributes.begin ();
|
||||
j != AttributeList::GetGlobal ()->m_attributes.end (); j++)
|
||||
{
|
||||
if (j->checker == checker)
|
||||
{
|
||||
// We have a matching attribute value.
|
||||
if (DoSet (accessor, checker, *j->value))
|
||||
{
|
||||
NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
|
||||
tid.GetAttributeName (i)<<"\" from global");
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
// No matching attribute value so we try to look at the env var.
|
||||
#ifdef HAVE_GETENV
|
||||
char *envVar = getenv ("NS_ATTRIBUTE_DEFAULT");
|
||||
if (envVar != 0)
|
||||
{
|
||||
std::string env = std::string (envVar);
|
||||
std::string::size_type cur = 0;
|
||||
std::string::size_type next = 0;
|
||||
while (next != std::string::npos)
|
||||
{
|
||||
next = env.find (";", cur);
|
||||
std::string tmp = std::string (env, cur, next-cur);
|
||||
std::string::size_type equal = tmp.find ("=");
|
||||
if (equal != std::string::npos)
|
||||
{
|
||||
std::string name = tmp.substr (0, equal);
|
||||
std::string value = tmp.substr (equal+1, tmp.size () - equal - 1);
|
||||
if (name == tid.GetAttributeFullName (i))
|
||||
{
|
||||
if (DoSet (accessor, checker, StringValue (value)))
|
||||
{
|
||||
NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
|
||||
tid.GetAttributeName (i)<<"\" from env var");
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cur = next + 1;
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_GETENV */
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
// No matching attribute value so we try to set the default value.
|
||||
DoSet (accessor, checker, *initial);
|
||||
NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
|
||||
tid.GetAttributeName (i)<<"\" from initial value.");
|
||||
|
||||
Reference in New Issue
Block a user