A Discrete-Event Network Simulator
API
global-value.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #ifndef GLOBAL_VALUE_H
20 #define GLOBAL_VALUE_H
21 
22 #include "attribute.h"
23 #include "ptr.h"
24 
25 #include <string>
26 #include <vector>
27 
34 namespace ns3
35 {
36 
37 /* Forward declaration */
38 namespace tests
39 {
40 class GlobalValueTestCase;
41 }
42 
76 {
78  typedef std::vector<GlobalValue*> Vector;
79 
80  public:
82  typedef Vector::const_iterator Iterator;
83 
95  GlobalValue(std::string name,
96  std::string help,
97  const AttributeValue& initialValue,
99 
104  std::string GetName() const;
109  std::string GetHelp() const;
115  void GetValue(AttributeValue& value) const;
126  bool SetValue(const AttributeValue& value);
127 
129  void ResetInitialValue();
130 
140  static void Bind(std::string name, const AttributeValue& value);
141 
151  static bool BindFailSafe(std::string name, const AttributeValue& value);
152 
157  static Iterator Begin();
162  static Iterator End();
163 
172  static bool GetValueByNameFailSafe(std::string name, AttributeValue& value);
173 
184  static void GetValueByName(std::string name, AttributeValue& value);
185 
186  private:
189 
195  static Vector* GetVector();
197  void InitializeFromEnv();
198 
200  std::string m_name;
202  std::string m_help;
209 };
210 
211 } // namespace ns3
212 
213 #endif /* GLOBAL_VALUE_H */
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Hold a value for an Attribute.
Definition: attribute.h:70
Hold a so-called 'global value'.
Definition: global-value.h:76
Vector::const_iterator Iterator
Iterator type for the list of all global values.
Definition: global-value.h:82
std::string GetHelp() const
Get the help string.
Definition: global-value.cc:91
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
Definition: global-value.h:78
void GetValue(AttributeValue &value) const
Get the value.
Definition: global-value.cc:98
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 Globa...
static bool GetValueByNameFailSafe(std::string name, AttributeValue &value)
Finds the GlobalValue with the given name and returns its value.
static Iterator Begin()
The Begin iterator.
std::string GetName() const
Get the name.
Definition: global-value.cc:84
std::string m_help
The help string.
Definition: global-value.h:202
Ptr< const AttributeChecker > m_checker
The AttributeChecker for this GlobalValue.
Definition: global-value.h:208
Ptr< AttributeValue > m_currentValue
The current value.
Definition: global-value.h:206
bool SetValue(const AttributeValue &value)
Set the value of this GlobalValue.
static void GetValueByName(std::string name, AttributeValue &value)
Finds the GlobalValue with the given name and returns its value.
void ResetInitialValue()
Reset to the initial value.
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 Globa...
Ptr< const AttributeChecker > GetChecker() const
Get the AttributeChecker.
Ptr< AttributeValue > m_initialValue
The initial value.
Definition: global-value.h:204
static Iterator End()
The End iterator.
GlobalValue(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeChecker > checker)
Constructor.
Definition: global-value.cc:41
std::string m_name
The name of this GlobalValue.
Definition: global-value.h:200
void InitializeFromEnv()
Initialize from the NS_GLOBAL_VALUE environment variable.
Definition: global-value.cc:67
static Vector * GetVector()
Get the static vector of all GlobalValues.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Test for the ability to get at a GlobalValue.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ptr smart pointer declaration and implementation.