A Discrete-Event Network Simulator
API
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
 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 AttributeCheckerGetChecker (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 VectorGetVector (void)
 Get the static vector of all GlobalValues. More...
 

Private Attributes

Ptr< const AttributeCheckerm_checker
 The AttributeChecker for this GlobalValue. More...
 
Ptr< AttributeValuem_currentValue
 The current value. More...
 
std::string m_help
 The help string. More...
 
Ptr< AttributeValuem_initialValue
 The initial value. More...
 
std::string m_name
 The name of this GlobalValue. More...
 

Friends

class tests::GlobalValueTestCase
 

Detailed Description

Hold a so-called 'global value'.

A GlobalValue will get its value from (in order):

  • The initial value configured where it is defined,
  • From the NS_GLOBAL_VALUE environment variable,
  • From the command line,
  • By explicit call to SetValue() or Bind().

Instances of this class are expected to be allocated as static global variables and should be used to store configurable global state. For example:

// source.cc:
static GlobalValue g_myGlobal =
GlobalValue ("myGlobal", "My global value for ...",
IntegerValue (12),

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.

Member Typedef Documentation

◆ Iterator

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.

◆ Vector

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

Container type for holding all the GlobalValues.

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

Constructor & Destructor Documentation

◆ GlobalValue()

ns3::GlobalValue::GlobalValue ( std::string  name,
std::string  help,
const AttributeValue initialValue,
Ptr< const AttributeChecker checker 
)

Constructor.

Parameters
[in]namethe name of this global value.
[in]helpsome help text which describes the purpose of this global value.
[in]initialValuethe value to assign to this global value during construction.
[in]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 42 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

◆ Begin()

GlobalValue::Iterator ns3::GlobalValue::Begin ( void  )
static

The Begin iterator.

Returns
An iterator which represents a pointer to the first GlobalValue registered.

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Bind()

void ns3::GlobalValue::Bind ( std::string  name,
const AttributeValue value 
)
static

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

Parameters
[in]namethe name of the global value
[in]valuethe 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::MpiInterface::Enable(), and ns3::Config::SetGlobal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ BindFailSafe()

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

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

Parameters
[in]namethe name of the global value
[in]valuethe value to set in the requested global value.
Returns
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ End()

GlobalValue::Iterator ns3::GlobalValue::End ( void  )
static

The End iterator.

Returns
An iterator which represents a pointer to the last GlobalValue registered.

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetChecker()

Ptr< const AttributeChecker > ns3::GlobalValue::GetChecker ( void  ) const

Get the AttributeChecker.

Returns
The checker associated to this GlobalValue.

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

References m_checker, and NS_LOG_FUNCTION.

◆ GetHelp()

std::string ns3::GlobalValue::GetHelp ( void  ) const

Get the help string.

Returns
The help text of this GlobalValue.

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

References m_help, and NS_LOG_FUNCTION_NOARGS.

◆ GetName()

std::string ns3::GlobalValue::GetName ( void  ) const

Get the name.

Returns
The name of this GlobalValue.

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

References m_name, and NS_LOG_FUNCTION_NOARGS.

◆ GetValue()

void ns3::GlobalValue::GetValue ( AttributeValue value) const

Get the value.

Parameters
[out]valueThe AttributeValue to set to the value of this GlobalValue
Returns
The current 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetValueByName()

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
[in]namethe name of the GlobalValue to be found
[out]valuewhere 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.

+ Here is the call graph for this function:

◆ GetValueByNameFailSafe()

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

Finds the GlobalValue with the given name and returns its value.

Parameters
[in]namethe name of the GlobalValue to be found
[out]valuewhere to store the value of the found GlobalValue
Returns
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 ns3::MpiInterface::Enable(), and GetValueByName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetVector()

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

Get the static vector of all GlobalValues.

Returns
The vector.

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

References NS_LOG_FUNCTION_NOARGS.

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

+ Here is the caller graph for this function:

◆ InitializeFromEnv()

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

Initialize from the NS_GLOBAL_VALUE environment variable.

Definition at line 67 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:

◆ ResetInitialValue()

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.

◆ SetValue()

bool ns3::GlobalValue::SetValue ( const AttributeValue value)

Set the value of this GlobalValue.

Parameters
[in]valuethe new value to set in this GlobalValue.
Returns
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().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ tests::GlobalValueTestCase

friend class tests::GlobalValueTestCase
friend

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

Member Data Documentation

◆ m_checker

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

The AttributeChecker for this GlobalValue.

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

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

◆ m_currentValue

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

The current value.

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

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

◆ m_help

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

The help string.

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

Referenced by GetHelp().

◆ m_initialValue

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

The initial value.

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

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

◆ m_name

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

The name of this GlobalValue.

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

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


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