diff --git a/src/core/global-value.cc b/src/core/global-value.cc index be40f4c03..c296f8bf8 100644 --- a/src/core/global-value.cc +++ b/src/core/global-value.cc @@ -21,6 +21,10 @@ #include "fatal-error.h" #include "attribute.h" #include "string.h" +#include "ns3/core-config.h" +#ifdef HAVE_STDLIB_H +#include +#endif namespace ns3 { @@ -37,6 +41,39 @@ GlobalValue::GlobalValue (std::string name, std::string help, NS_FATAL_ERROR ("Checker should not be zero."); } GetVector ()->push_back (this); + InitializeFromEnv (); +} + +void +GlobalValue::InitializeFromEnv (void) +{ +#ifdef HAVE_GETENV + char *envVar = getenv ("NS_GLOBAL_VALUE"); + if (envVar == 0) + { + return; + } + 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 == m_name) + { + SetValue (StringValue (value)); + } + } + cur = next + 1; + } + +#endif /* HAVE_GETENV */ } std::string diff --git a/src/core/global-value.h b/src/core/global-value.h index e8d1a3232..fb957621e 100644 --- a/src/core/global-value.h +++ b/src/core/global-value.h @@ -109,6 +109,7 @@ public: private: friend class GlobalValueTests; static Vector *GetVector (void); + void InitializeFromEnv (void); std::string m_name; std::string m_help; Ptr m_initialValue;