A Discrete-Event Network Simulator
API
global-value.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef GLOBAL_VALUE_H
21 #define GLOBAL_VALUE_H
22 
23 #include <string>
24 #include <vector>
25 #include "ptr.h"
26 #include "attribute.h"
27 
35 
36 namespace ns3 {
37 
71 {
73  typedef std::vector<GlobalValue *> Vector;
74 
75 public:
77  typedef Vector::const_iterator Iterator;
78 
90  GlobalValue (std::string name, std::string help,
91  const AttributeValue &initialValue,
93 
98  std::string GetName (void) const;
103  std::string GetHelp (void) const;
110  void GetValue (AttributeValue &value) const;
121  bool SetValue (const AttributeValue &value);
122 
124  void ResetInitialValue (void);
125 
135  static void Bind (std::string name, const AttributeValue &value);
136 
146  static bool BindFailSafe (std::string name, const AttributeValue &value);
147 
152  static Iterator Begin (void);
157  static Iterator End (void);
158 
159 
168  static bool GetValueByNameFailSafe (std::string name, AttributeValue &value);
169 
180  static void GetValueByName (std::string name, AttributeValue &value);
181 
182 
183 private:
184  friend class ::GlobalValueTestCase;
185 
191  static Vector *GetVector (void);
193  void InitializeFromEnv (void);
194 
196  std::string m_name;
198  std::string m_help;
205 };
206 
207 } // namespace ns3
208 
209 #endif /* GLOBAL_VALUE_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
std::string m_help
The help string.
Definition: global-value.h:198
Smart pointer implementation.
Hold a value for an Attribute.
Definition: attribute.h:68
Vector::const_iterator Iterator
Iterator type for the list of all global values.
Definition: global-value.h:77
Ptr< AttributeValue > m_initialValue
The initial value.
Definition: global-value.h:200
Hold a so-called 'global value'.
Definition: global-value.h:70
GlobalValue(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeChecker > checker)
Constructor.
Definition: global-value.cc:42
std::string GetName(void) const
Get the name.
void ResetInitialValue(void)
Reset to the initial value.
static Vector * GetVector(void)
Get the static vector of all GlobalValues.
static Iterator Begin(void)
The Begin iterator.
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Ptr< const AttributeChecker > m_checker
The AttributeChecker for this GlobalValue.
Definition: global-value.h:204
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
Definition: global-value.h:73
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool SetValue(const AttributeValue &value)
Set the value of this GlobalValue.
std::string m_name
The name of this GlobalValue.
Definition: global-value.h:196
Ptr< AttributeValue > m_currentValue
The current value.
Definition: global-value.h:202
static Iterator End(void)
The End iterator.
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...
std::string GetHelp(void) const
Get the help string.
static void GetValueByName(std::string name, AttributeValue &value)
Finds the GlobalValue with the given name and returns its value.
Ptr< const AttributeChecker > GetChecker(void) const
Get the AttributeChecker.
void InitializeFromEnv(void)
Initialize from the NS_GLOBAL_VALUE environment variable.
Definition: global-value.cc:67
void GetValue(AttributeValue &value) const
Get the value.