A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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.
 

Public Member Functions

 GlobalValue (std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeChecker > checker)
 Constructor.
 
Ptr< const AttributeCheckerGetChecker () const
 Get the AttributeChecker.
 
std::string GetHelp () const
 Get the help string.
 
std::string GetName () const
 Get the name.
 
void GetValue (AttributeValue &value) const
 Get the value.
 
void ResetInitialValue ()
 Reset to the initial value.
 
bool SetValue (const AttributeValue &value)
 Set the value of this GlobalValue.
 

Static Public Member Functions

static Iterator Begin ()
 The Begin iterator.
 
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.
 
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.
 
static Iterator End ()
 The End iterator.
 
static void GetValueByName (std::string name, AttributeValue &value)
 Finds the GlobalValue with the given name and returns its value.
 
static bool GetValueByNameFailSafe (std::string name, AttributeValue &value)
 Finds the GlobalValue with the given name and returns its value.
 

Private Types

typedef std::vector< GlobalValue * > Vector
 Container type for holding all the GlobalValues.
 

Private Member Functions

void InitializeFromEnv ()
 Initialize from the NS_GLOBAL_VALUE environment variable.
 

Static Private Member Functions

static VectorGetVector ()
 Get the static vector of all GlobalValues.
 

Private Attributes

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

Friends

class tests::GlobalValueTestCase
 Test case needs direct access to GetVector()
 

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 ...",
Hold a so-called 'global value'.
Definition: global-value.h:76
Hold a signed integer type.
Definition: integer.h:45
Ptr< const AttributeChecker > MakeIntegerChecker()
Definition: integer.h:110

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 75 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 82 of file global-value.h.

◆ Vector

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

Container type for holding all the GlobalValues.

Definition at line 78 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 41 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 ( )
static

The Begin iterator.

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

Definition at line 171 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 137 of file global-value.cc.

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

Referenced by ns3::Config::SetGlobal(), and ns3::MpiInterface::SetParallelSimulatorImpl().

+ 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 156 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 ( )
static

The End iterator.

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

Definition at line 179 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 ( ) const

Get the AttributeChecker.

Returns
The checker associated to this GlobalValue.

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

References m_checker, and NS_LOG_FUNCTION.

◆ GetHelp()

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

Get the help string.

Returns
The help text of this GlobalValue.

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

References m_help, and NS_LOG_FUNCTION_NOARGS.

◆ GetName()

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

Get the name.

Returns
The name of this GlobalValue.

Definition at line 84 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

Definition at line 98 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 208 of file global-value.cc.

References GetValueByNameFailSafe(), NS_FATAL_ERROR, and NS_LOG_FUNCTION.

Referenced by NotifyViaProbe(), and NotifyViaTraceSource().

+ Here is the call graph for this function:
+ Here is the caller 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 193 of file global-value.cc.

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

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

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

◆ GetVector()

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

Get the static vector of all GlobalValues.

Returns
The vector.

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

References NS_LOG_FUNCTION_NOARGS.

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

+ Here is the caller graph for this function:

◆ InitializeFromEnv()

void ns3::GlobalValue::InitializeFromEnv ( )
private

Initialize from the NS_GLOBAL_VALUE environment variable.

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

References ns3::EnvironmentVariable::Get(), m_checker, m_currentValue, m_initialValue, m_name, and NS_LOG_FUNCTION.

Referenced by GlobalValue().

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

◆ ResetInitialValue()

void ns3::GlobalValue::ResetInitialValue ( )

Reset to the initial value.

Definition at line 186 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 123 of file global-value.cc.

References m_checker, m_currentValue, and NS_LOG_FUNCTION.

Friends And Related Function Documentation

◆ tests::GlobalValueTestCase

friend class tests::GlobalValueTestCase
friend

Test case needs direct access to GetVector()

Definition at line 188 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 208 of file global-value.h.

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

◆ m_currentValue

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

The current value.

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

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

◆ m_help

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

The help string.

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

Referenced by GetHelp().

◆ m_initialValue

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

The initial value.

Definition at line 204 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 200 of file global-value.h.

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


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