Difference between revisions of "GlobalValues"
From Nsnam
(Initial page collecting tidbits on working w/ GlobalValue objects) |
m |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | <code>GlobalValue</code> objects provide a mechanism for default values not associated with particular object instantiations. This is useful, for example, when working with global functions. | |
+ | |||
+ | == Specific Types == | ||
+ | |||
+ | === Doubles === | ||
+ | |||
+ | To declare a double valued global parameter, do something like the following: | ||
+ | |||
+ | <code><pre> | ||
+ | #include "ns3/global-value.h" | ||
+ | #include "ns3/double.h" | ||
+ | |||
+ | GlobalValue g_sampleInterval("SampleInterval", | ||
+ | "How frequently samples are made.", | ||
+ | Double(2.0), | ||
+ | MakeDoubleChecker<double>(0.0)); | ||
+ | </pre></code> | ||
+ | |||
+ | The optional parameter to <code>MakeDoubleChecker</code> defines the minimum for the value. A second optional parameter would define the maximum. By creating a <code>Double</code> object w/ value 2, we set 2 as the default for this parameter. | ||
+ | |||
+ | To fetch the value at any point, do something like: | ||
+ | |||
+ | <code><pre> | ||
+ | Simulator::Schedule(Seconds(((Double)(g_sampleInterval | ||
+ | .GetValue())).Get()), | ||
+ | Example::Sample); | ||
+ | </pre></code> | ||
+ | |||
+ | [[Category:Samples]] |
Latest revision as of 19:43, 25 March 2008
GlobalValue
objects provide a mechanism for default values not associated with particular object instantiations. This is useful, for example, when working with global functions.
Specific Types
Doubles
To declare a double valued global parameter, do something like the following:
#include "ns3/global-value.h"
#include "ns3/double.h"
GlobalValue g_sampleInterval("SampleInterval",
"How frequently samples are made.",
Double(2.0),
MakeDoubleChecker<double>(0.0));
The optional parameter to MakeDoubleChecker
defines the minimum for the value. A second optional parameter would define the maximum. By creating a Double
object w/ value 2, we set 2 as the default for this parameter.
To fetch the value at any point, do something like:
Simulator::Schedule(Seconds(((Double)(g_sampleInterval
.GetValue())).Get()),
Example::Sample);