A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ns3::GlobalValue Class Reference

hold a so-called 'global value'. More...

#include <global-value.h>

+ Collaboration diagram for ns3::GlobalValue:

Public Types

typedef Vector::const_iterator Iterator
 

Public Member Functions

 GlobalValue (std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeChecker > checker)
 
Ptr< const AttributeCheckerGetChecker (void) const
 
std::string GetHelp (void) const
 
std::string GetName (void) const
 
void GetValue (AttributeValue &value) const
 
void ResetInitialValue (void)
 
bool SetValue (const AttributeValue &value)
 

Static Public Member Functions

static Iterator Begin (void)
 
static void Bind (std::string name, const AttributeValue &value)
 
static bool BindFailSafe (std::string name, const AttributeValue &value)
 
static Iterator End (void)
 
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
 

Private Member Functions

void InitializeFromEnv (void)
 

Static Private Member Functions

static VectorGetVector (void)
 

Private Attributes

Ptr< const AttributeCheckerm_checker
 
Ptr< AttributeValuem_currentValue
 
std::string m_help
 
Ptr< AttributeValuem_initialValue
 
std::string m_name
 

Friends

class GlobalValueTestCase
 

Detailed Description

hold a so-called 'global value'.

Instances of this class are expected to be allocated as static global variables and should be used to store configurable global state. GlobalValues can be set directly by calling ns3::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 ns3::CommandLine class also get the ability to set global values through commandline arguments to their program: –Name=Value will set global value Name to Value.

Definition at line 47 of file global-value.h.

Member Typedef Documentation

typedef Vector::const_iterator ns3::GlobalValue::Iterator

Definition at line 51 of file global-value.h.

typedef std::vector<GlobalValue *> ns3::GlobalValue::Vector
private

Definition at line 49 of file global-value.h.

Constructor & Destructor Documentation

ns3::GlobalValue::GlobalValue ( std::string  name,
std::string  help,
const AttributeValue initialValue,
Ptr< const AttributeChecker checker 
)
Parameters
namethe name of this global value.
helpsome help text which describes the purpose of this global value.
initialValuethe value to assign to this global value during construction.
checkera 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 37 of file global-value.cc.

References GetVector(), InitializeFromEnv(), m_checker, m_currentValue, m_initialValue, NS_FATAL_ERROR, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

Member Function Documentation

GlobalValue::Iterator ns3::GlobalValue::Begin ( void  )
static
Returns
an iterator which represents a pointer to the first GlobalValue registered.

Definition at line 182 of file global-value.cc.

References GetVector(), and NS_LOG_FUNCTION_NOARGS.

Referenced by Bind(), BindFailSafe(), GetValueByNameFailSafe(), ns3::RawTextConfigSave::Global(), ns3::XmlConfigSave::Global(), main(), ns3::CommandLine::PrintGlobals(), and ns3::Config::Reset().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::GlobalValue::Bind ( std::string  name,
const AttributeValue value 
)
static
Parameters
namethe name of the global value
valuethe value to set in the requested global value.

Iterate over the set of GlobalValues until a matching name is found and then set its value with GlobalValue::SetValue.

This method cannot fail. It will crash if the input is not valid.

Definition at line 150 of file global-value.cc.

References Begin(), End(), NS_FATAL_ERROR, and NS_LOG_FUNCTION.

Referenced by ns3::MpiInterface::Enable(), main(), ns3::Config::SetGlobal(), and test().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ns3::GlobalValue::BindFailSafe ( std::string  name,
const AttributeValue value 
)
static
Parameters
namethe name of the global value
valuethe value to set in the requested global value.
Returns
true if the value could be set successfully, false otherwise.

Iterate over the set of GlobalValues until a matching name is found and then set its value with GlobalValue::SetValue.

Definition at line 168 of file global-value.cc.

References Begin(), End(), and NS_LOG_FUNCTION.

Referenced by ns3::Config::SetGlobalFailSafe().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GlobalValue::Iterator ns3::GlobalValue::End ( void  )
static
Returns
an iterator which represents a pointer to the last GlobalValue registered.

Definition at line 189 of file global-value.cc.

References GetVector(), and NS_LOG_FUNCTION_NOARGS.

Referenced by Bind(), BindFailSafe(), GetValueByNameFailSafe(), ns3::RawTextConfigSave::Global(), ns3::XmlConfigSave::Global(), main(), ns3::CommandLine::PrintGlobals(), and ns3::Config::Reset().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Ptr< const AttributeChecker > ns3::GlobalValue::GetChecker ( void  ) const
Returns
the checker associated to this GlobalValue.

Definition at line 128 of file global-value.cc.

References m_checker, and NS_LOG_FUNCTION.

std::string ns3::GlobalValue::GetHelp ( void  ) const
Returns
the help text of this GlobalValue.

Definition at line 106 of file global-value.cc.

References m_help, and NS_LOG_FUNCTION_NOARGS.

std::string ns3::GlobalValue::GetName ( void  ) const
Returns
the name of this GlobalValue.

Definition at line 100 of file global-value.cc.

References m_name, and NS_LOG_FUNCTION_NOARGS.

void ns3::GlobalValue::GetValue ( AttributeValue value) const
Returns
the current value of this GlobalValue.

Definition at line 112 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::GlobalValueTestCase::DoRun(), ns3::GetImpl(), ns3::RngSeedManager::GetRun(), ns3::RngSeedManager::GetSeed(), and ns3::Simulator::SetImplementation().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::GlobalValue::GetValueByName ( std::string  name,
AttributeValue value 
)
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.

Parameters
namethe name of the GlobalValue to be found
valuewhere to store the value of the found GlobalValue

Definition at line 218 of file global-value.cc.

References GetValueByNameFailSafe(), NS_FATAL_ERROR, and NS_LOG_FUNCTION.

Referenced by main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ns3::GlobalValue::GetValueByNameFailSafe ( std::string  name,
AttributeValue value 
)
static

finds the GlobalValue with the given name and returns its value

Parameters
namethe name of the GlobalValue to be found
valuewhere to store the value of the found GlobalValue
Returns
true if the GlobalValue was found, false otherwise

Definition at line 203 of file global-value.cc.

References Begin(), End(), and NS_LOG_FUNCTION.

Referenced by ns3::MpiInterface::Enable(), and GetValueByName().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GlobalValue::Vector * ns3::GlobalValue::GetVector ( void  )
staticprivate

Definition at line 228 of file global-value.cc.

References NS_LOG_FUNCTION_NOARGS.

Referenced by Begin(), ns3::GlobalValueTestCase::DoRun(), End(), and GlobalValue().

+ Here is the caller graph for this function:

void ns3::GlobalValue::InitializeFromEnv ( void  )
private

Definition at line 62 of file global-value.cc.

References m_checker, m_currentValue, m_initialValue, m_name, and NS_LOG_FUNCTION.

Referenced by GlobalValue().

+ Here is the caller graph for this function:

void ns3::GlobalValue::ResetInitialValue ( void  )

Definition at line 196 of file global-value.cc.

References m_currentValue, m_initialValue, and NS_LOG_FUNCTION.

bool ns3::GlobalValue::SetValue ( const AttributeValue value)
Parameters
valuethe new value to set in this GlobalValue.

Definition at line 136 of file global-value.cc.

References m_checker, m_currentValue, and NS_LOG_FUNCTION.

Friends And Related Function Documentation

friend class GlobalValueTestCase
friend

Definition at line 144 of file global-value.h.

Member Data Documentation

Ptr<const AttributeChecker> ns3::GlobalValue::m_checker
private

Definition at line 152 of file global-value.h.

Referenced by GetChecker(), GetValue(), GlobalValue(), InitializeFromEnv(), and SetValue().

Ptr<AttributeValue> ns3::GlobalValue::m_currentValue
private

Definition at line 151 of file global-value.h.

Referenced by GetValue(), GlobalValue(), InitializeFromEnv(), ResetInitialValue(), and SetValue().

std::string ns3::GlobalValue::m_help
private

Definition at line 149 of file global-value.h.

Referenced by GetHelp().

Ptr<AttributeValue> ns3::GlobalValue::m_initialValue
private

Definition at line 150 of file global-value.h.

Referenced by GlobalValue(), InitializeFromEnv(), and ResetInitialValue().

std::string ns3::GlobalValue::m_name
private

Definition at line 148 of file global-value.h.

Referenced by GetName(), GetValue(), and InitializeFromEnv().


The documentation for this class was generated from the following files: