00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2008 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef GLOBAL_VALUE_H 00021 #define GLOBAL_VALUE_H 00022 00023 #include <string> 00024 #include <vector> 00025 #include "ptr.h" 00026 #include "attribute.h" 00027 00028 00029 namespace ns3 { 00030 00031 /** 00032 * \ingroup Core 00033 * 00034 * \brief hold a so-called 'global value'. 00035 * 00036 * Instances of this class are expected to be allocated as static 00037 * global variables and should be used to store configurable global state. 00038 */ 00039 class GlobalValue 00040 { 00041 typedef std::vector<GlobalValue *> Vector; 00042 public: 00043 typedef Vector::const_iterator Iterator; 00044 00045 /** 00046 * \param name the name of this global value. 00047 * \param help some help text which describes the purpose of this 00048 * global value. 00049 * \param initialValue the value to assign to this global value 00050 * during construction. 00051 * \param checker a pointer to an AttributeChecker which can verify 00052 * that any user-supplied value to override the initial 00053 * value matches the requested type constraints. 00054 */ 00055 GlobalValue (std::string name, std::string help, 00056 const AttributeValue &initialValue, 00057 Ptr<const AttributeChecker> checker); 00058 00059 /** 00060 * \returns the name of this GlobalValue. 00061 */ 00062 std::string GetName (void) const; 00063 /** 00064 * \returns the help text of this GlobalValue. 00065 */ 00066 std::string GetHelp (void) const; 00067 /** 00068 * \returns the current value of this GlobalValue. 00069 */ 00070 void GetValue (AttributeValue &value) const; 00071 /** 00072 * \returns the checker associated to this GlobalValue. 00073 */ 00074 Ptr<const AttributeChecker> GetChecker (void) const; 00075 /** 00076 * \param value the new value to set in this GlobalValue. 00077 */ 00078 bool SetValue (const AttributeValue &value); 00079 00080 /** 00081 * \param name the name of the global value 00082 * \param value the value to set in the requested global value. 00083 * 00084 * Iterate over the set of GlobalValues until a matching name is found 00085 * and then set its value with GlobalValue::SetValue. 00086 * 00087 * This method cannot fail. It will crash if the input is not valid. 00088 */ 00089 static void Bind (std::string name, const AttributeValue &value); 00090 00091 /** 00092 * \param name the name of the global value 00093 * \param value the value to set in the requested global value. 00094 * \returns true if the value could be set successfully, false otherwise. 00095 * 00096 * Iterate over the set of GlobalValues until a matching name is found 00097 * and then set its value with GlobalValue::SetValue. 00098 */ 00099 static bool BindFailSafe (std::string name, const AttributeValue &value); 00100 00101 /** 00102 * \returns an iterator which represents a pointer to the first GlobalValue registered. 00103 */ 00104 static Iterator Begin (void); 00105 /** 00106 * \returns an iterator which represents a pointer to the last GlobalValue registered. 00107 */ 00108 static Iterator End (void); 00109 private: 00110 friend class GlobalValueTests; 00111 static Vector *GetVector (void); 00112 std::string m_name; 00113 std::string m_help; 00114 Ptr<AttributeValue> m_initialValue; 00115 Ptr<const AttributeChecker> m_checker; 00116 }; 00117 00118 } // namespace ns3 00119 00120 #endif /* GLOBAL_VALUE_H */