20 #include "global-value.h"
21 #include "fatal-error.h"
22 #include "attribute.h"
27 #include "ns3/core-config.h"
50 m_initialValue = m_checker->CreateValidValue (initialValue);
51 m_currentValue = m_initialValue;
52 if (m_initialValue == 0)
54 NS_FATAL_ERROR (
"Value set by user on " << name <<
" is invalid.");
56 GetVector ()->push_back (
this);
61 GlobalValue::InitializeFromEnv (
void)
65 char *envVar = getenv (
"NS_GLOBAL_VALUE");
70 std::string env = std::string (envVar);
71 std::string::size_type cur = 0;
72 std::string::size_type next = 0;
73 while (next != std::string::npos)
75 next = env.find (
";", cur);
76 std::string tmp = std::string (env, cur, next-cur);
77 std::string::size_type equal = tmp.find (
"=");
78 if (equal != std::string::npos)
80 std::string name = tmp.substr (0, equal);
81 std::string value = tmp.substr (equal+1, tmp.size () - equal - 1);
84 Ptr<AttributeValue> v = m_checker->CreateValidValue (StringValue (value));
114 bool ok = m_checker->Copy (*m_currentValue, value);
122 NS_FATAL_ERROR (
"GlobalValue name="<<m_name<<
": input value is not a string");
124 str->Set (m_currentValue->SerializeToString (m_checker));
153 for (Iterator i =
Begin (); i !=
End (); i++)
155 if ((*i)->GetName () == name)
157 if (!(*i)->SetValue (value))
171 for (Iterator i =
Begin (); i !=
End (); i++)
173 if ((*i)->GetName () == name)
175 return (*i)->SetValue (value);
180 GlobalValue::Iterator
185 return GetVector ()->begin ();
187 GlobalValue::Iterator
191 return GetVector ()->end ();
195 GlobalValue::ResetInitialValue (
void)
198 m_currentValue = m_initialValue;
207 if ((*gvit)->GetName () == name)
209 (*gvit)->GetValue (value);
222 NS_FATAL_ERROR (
"Could not find GlobalValue named \"" << name <<
"\"");
226 GlobalValue::Vector *
227 GlobalValue::GetVector (
void)
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)
#define NS_LOG_FUNCTION_NOARGS()
GlobalValue(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeChecker > checker)
#define NS_FATAL_ERROR(msg)
fatal error handling
std::string GetName(void) const
static Iterator Begin(void)
static void Bind(std::string name, const AttributeValue &value)
static bool GetValueByNameFailSafe(std::string name, AttributeValue &value)
bool SetValue(const AttributeValue &value)
static Iterator End(void)
static bool BindFailSafe(std::string name, const AttributeValue &value)
std::string GetHelp(void) const
static void GetValueByName(std::string name, AttributeValue &value)
Ptr< const AttributeChecker > GetChecker(void) const
void GetValue(AttributeValue &value) const