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 
34 namespace ns3 {
35 
36  /* Forward declaration */
37  namespace tests {
38  class GlobalValueTestCase;
39  }
40 
74 {
76  typedef std::vector<GlobalValue *> Vector;
77 
78 public:
80  typedef Vector::const_iterator Iterator;
81 
93  GlobalValue (std::string name, std::string help,
94  const AttributeValue &initialValue,
96 
101  std::string GetName (void) const;
106  std::string GetHelp (void) const;
113  void GetValue (AttributeValue &value) const;
124  bool SetValue (const AttributeValue &value);
125 
127  void ResetInitialValue (void);
128 
138  static void Bind (std::string name, const AttributeValue &value);
139 
149  static bool BindFailSafe (std::string name, const AttributeValue &value);
150 
155  static Iterator Begin (void);
160  static Iterator End (void);
161 
162 
171  static bool GetValueByNameFailSafe (std::string name, AttributeValue &value);
172 
183  static void GetValueByName (std::string name, AttributeValue &value);
184 
185 
186 private:
187  // Test case needs direct access to GetVector()
189 
195  static Vector *GetVector (void);
197  void InitializeFromEnv (void);
198 
200  std::string m_name;
202  std::string m_help;
209 };
210 
211 } // namespace ns3
212 
213 #endif /* GLOBAL_VALUE_H */
std::string GetName(void) const
Get the name.
void GetValue(AttributeValue &value) const
Get the value.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
std::string GetHelp(void) const
Get the help string.
std::string m_help
The help string.
Definition: global-value.h:202
ns3::Ptr smart pointer declaration and 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:80
Ptr< AttributeValue > m_initialValue
The initial value.
Definition: global-value.h:204
Hold a so-called &#39;global value&#39;.
Definition: global-value.h:73
GlobalValue(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeChecker > checker)
Constructor.
Definition: global-value.cc:42
Test for the ability to get at a GlobalValue.
Ptr< const AttributeChecker > GetChecker(void) const
Get the AttributeChecker.
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:208
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
Definition: global-value.h:76
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:200
Ptr< AttributeValue > m_currentValue
The current value.
Definition: global-value.h:206
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...
static void GetValueByName(std::string name, AttributeValue &value)
Finds the GlobalValue with the given name and returns its value.
void InitializeFromEnv(void)
Initialize from the NS_GLOBAL_VALUE environment variable.
Definition: global-value.cc:67