Hold a so-called 'global value'. More...
#include "global-value.h"
Public Types | |
typedef Vector::const_iterator | Iterator |
Iterator type for the list of all global values. More... | |
Public Member Functions | |
GlobalValue (std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeChecker > checker) | |
Constructor. More... | |
Ptr< const AttributeChecker > | GetChecker (void) const |
Get the AttributeChecker. More... | |
std::string | GetHelp (void) const |
Get the help string. More... | |
std::string | GetName (void) const |
Get the name. More... | |
void | GetValue (AttributeValue &value) const |
Get the value. More... | |
void | ResetInitialValue (void) |
Reset to the initial value. More... | |
bool | SetValue (const AttributeValue &value) |
Set the value of this GlobalValue. More... | |
Static Public Member Functions | |
static Iterator | Begin (void) |
The Begin iterator. More... | |
static void | Bind (std::string name, const AttributeValue &value) |
Iterate over the set of GlobalValues until a matching name is found and then set its value with GlobalValue::SetValue. More... | |
static bool | BindFailSafe (std::string name, const AttributeValue &value) |
Iterate over the set of GlobalValues until a matching name is found and then set its value with GlobalValue::SetValue. More... | |
static Iterator | End (void) |
The End iterator. More... | |
static void | GetValueByName (std::string name, AttributeValue &value) |
Finds the GlobalValue with the given name and returns its value. More... | |
static bool | GetValueByNameFailSafe (std::string name, AttributeValue &value) |
Finds the GlobalValue with the given name and returns its value. More... | |
Private Types | |
typedef std::vector< GlobalValue * > | Vector |
Container type for holding all the GlobalValues. More... | |
Private Member Functions | |
void | InitializeFromEnv (void) |
Initialize from the NS_GLOBAL_VALUE environment variable. More... | |
Static Private Member Functions | |
static Vector * | GetVector (void) |
Get the static vector of all GlobalValues. More... | |
Private Attributes | |
Ptr< const AttributeChecker > | m_checker |
The AttributeChecker for this GlobalValue. More... | |
Ptr< AttributeValue > | m_currentValue |
The current value. More... | |
std::string | m_help |
The help string. More... | |
Ptr< AttributeValue > | m_initialValue |
The initial value. More... | |
std::string | m_name |
The name of this GlobalValue. More... | |
Friends | |
class | tests::GlobalValueTestCase |
Test case needs direct access to GetVector() More... | |
Hold a so-called 'global value'.
A GlobalValue will get its value from (in order):
NS_GLOBAL_VALUE
environment variable,Instances of this class are expected to be allocated as static global variables and should be used to store configurable global state. For example:
GlobalValues can be set directly by calling GlobalValue::SetValue() but they can also be set through the NS_GLOBAL_VALUE
environment variable. For example, NS_GLOBAL_VALUE='Name=Value
;OtherName=OtherValue;' would set global values Name
and OtherName
to Value
and OtherValue
, respectively.
Users of the CommandLine class also get the ability to set global values through command line arguments to their program: –Name=Value
will set global value Name
to Value
.
Definition at line 73 of file global-value.h.
typedef Vector::const_iterator ns3::GlobalValue::Iterator |
Iterator type for the list of all global values.
Definition at line 80 of file global-value.h.
|
private |
Container type for holding all the GlobalValues.
Definition at line 76 of file global-value.h.
ns3::GlobalValue::GlobalValue | ( | std::string | name, |
std::string | help, | ||
const AttributeValue & | initialValue, | ||
Ptr< const AttributeChecker > | checker | ||
) |
Constructor.
[in] | name | the name of this global value. |
[in] | help | some help text which describes the purpose of this global value. |
[in] | initialValue | the value to assign to this global value during construction. |
[in] | checker | a pointer to an AttributeChecker which can verify that any user-supplied value to override the initial value matches the requested type constraints. |
Definition at line 43 of file global-value.cc.
References GetVector(), InitializeFromEnv(), m_checker, m_currentValue, m_initialValue, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
|
static |
The Begin iterator.
Definition at line 187 of file global-value.cc.
References GetVector(), and NS_LOG_FUNCTION_NOARGS.
Referenced by Bind(), BindFailSafe(), GetValueByNameFailSafe(), ns3::RawTextConfigSave::Global(), ns3::XmlConfigSave::Global(), PrintAllGlobals(), ns3::CommandLine::PrintGlobals(), and ns3::Config::Reset().
|
static |
Iterate over the set of GlobalValues until a matching name is found and then set its value with GlobalValue::SetValue.
[in] | name | the name of the global value |
[in] | value | the value to set in the requested global value. |
This method cannot fail. It will crash if the input is not valid.
Definition at line 155 of file global-value.cc.
References Begin(), End(), NS_FATAL_ERROR, and NS_LOG_FUNCTION.
Referenced by ns3::Config::SetGlobal(), and ns3::MpiInterface::SetParallelSimulatorImpl().
|
static |
Iterate over the set of GlobalValues until a matching name is found and then set its value with GlobalValue::SetValue.
[in] | name | the name of the global value |
[in] | value | the value to set in the requested global value. |
true
if the value could be set successfully, false
otherwise. Definition at line 173 of file global-value.cc.
References Begin(), End(), and NS_LOG_FUNCTION.
Referenced by ns3::Config::SetGlobalFailSafe().
|
static |
The End iterator.
Definition at line 194 of file global-value.cc.
References GetVector(), and NS_LOG_FUNCTION_NOARGS.
Referenced by Bind(), BindFailSafe(), GetValueByNameFailSafe(), ns3::RawTextConfigSave::Global(), ns3::XmlConfigSave::Global(), PrintAllGlobals(), ns3::CommandLine::PrintGlobals(), and ns3::Config::Reset().
Ptr< const AttributeChecker > ns3::GlobalValue::GetChecker | ( | void | ) | const |
Get the AttributeChecker.
Definition at line 133 of file global-value.cc.
References m_checker, and NS_LOG_FUNCTION.
std::string ns3::GlobalValue::GetHelp | ( | void | ) | const |
Get the help string.
Definition at line 111 of file global-value.cc.
References m_help, and NS_LOG_FUNCTION_NOARGS.
std::string ns3::GlobalValue::GetName | ( | void | ) | const |
Get the name.
Definition at line 105 of file global-value.cc.
References m_name, and NS_LOG_FUNCTION_NOARGS.
void ns3::GlobalValue::GetValue | ( | AttributeValue & | value | ) | const |
Get the value.
[out] | value | The AttributeValue to set to the value of this GlobalValue |
Definition at line 117 of file global-value.cc.
References m_checker, m_currentValue, m_name, NS_FATAL_ERROR, NS_LOG_FUNCTION, and ns3::StringValue::Set().
Referenced by ns3::Node::ChecksumEnabled(), ns3::tests::GlobalValueTestCase::DoRun(), ns3::GetImpl(), ns3::RngSeedManager::GetRun(), ns3::RngSeedManager::GetSeed(), and ns3::Simulator::SetImplementation().
|
static |
Finds the GlobalValue with the given name and returns its value.
This method cannot fail, i.e., it will trigger a NS_FATAL_ERROR if the requested GlobalValue is not found.
[in] | name | the name of the GlobalValue to be found |
[out] | value | where to store the value of the found GlobalValue |
Definition at line 223 of file global-value.cc.
References GetValueByNameFailSafe(), NS_FATAL_ERROR, and NS_LOG_FUNCTION.
|
static |
Finds the GlobalValue with the given name and returns its value.
[in] | name | the name of the GlobalValue to be found |
[out] | value | where to store the value of the found GlobalValue |
true
if the GlobalValue was found, false
otherwise Definition at line 208 of file global-value.cc.
References Begin(), End(), and NS_LOG_FUNCTION.
Referenced by GetValueByName(), and ns3::MpiInterface::SetParallelSimulatorImpl().
|
staticprivate |
Get the static vector of all GlobalValues.
Definition at line 233 of file global-value.cc.
References NS_LOG_FUNCTION_NOARGS.
Referenced by GlobalValue(), Begin(), ns3::tests::GlobalValueTestCase::DoRun(), and End().
|
private |
Initialize from the NS_GLOBAL_VALUE
environment variable.
Definition at line 68 of file global-value.cc.
References m_checker, m_currentValue, m_initialValue, m_name, and NS_LOG_FUNCTION.
Referenced by GlobalValue().
void ns3::GlobalValue::ResetInitialValue | ( | void | ) |
Reset to the initial value.
Definition at line 201 of file global-value.cc.
References m_currentValue, m_initialValue, and NS_LOG_FUNCTION.
bool ns3::GlobalValue::SetValue | ( | const AttributeValue & | value | ) |
Set the value of this GlobalValue.
[in] | value | the new value to set in this GlobalValue. |
true
if the Global Value was set successfully. Definition at line 141 of file global-value.cc.
References m_checker, m_currentValue, and NS_LOG_FUNCTION.
Referenced by VanetRoutingExperiment::SetGlobalsFromConfig().
|
friend |
Test case needs direct access to GetVector()
Definition at line 186 of file global-value.h.
|
private |
The AttributeChecker for this GlobalValue.
Definition at line 206 of file global-value.h.
Referenced by GlobalValue(), GetChecker(), GetValue(), InitializeFromEnv(), and SetValue().
|
private |
The current value.
Definition at line 204 of file global-value.h.
Referenced by GlobalValue(), GetValue(), InitializeFromEnv(), ResetInitialValue(), and SetValue().
|
private |
|
private |
The initial value.
Definition at line 202 of file global-value.h.
Referenced by GlobalValue(), InitializeFromEnv(), and ResetInitialValue().
|
private |
The name of this GlobalValue.
Definition at line 198 of file global-value.h.
Referenced by GetName(), GetValue(), and InitializeFromEnv().