1.1 --- a/src/core/global-value.cc Thu Jul 02 16:38:53 2009 +0200
1.2 +++ b/src/core/global-value.cc Fri Jul 03 13:43:43 2009 +0200
1.3 @@ -174,6 +174,30 @@
1.4 {
1.5 return GetVector ()->end ();
1.6 }
1.7 +
1.8 +bool
1.9 +GlobalValue::GetValueByNameFailSafe (std::string name, AttributeValue &value)
1.10 +{
1.11 + for (GlobalValue::Iterator gvit = GlobalValue::Begin (); gvit != GlobalValue::End (); ++gvit)
1.12 + {
1.13 + if ((*gvit)->GetName () == name)
1.14 + {
1.15 + (*gvit)->GetValue (value);
1.16 + return true;
1.17 + }
1.18 + }
1.19 + return false; // not found
1.20 +}
1.21 +
1.22 +void
1.23 +GlobalValue::GetValueByName (std::string name, AttributeValue &value)
1.24 +{
1.25 + if (! GetValueByNameFailSafe (name, value))
1.26 + {
1.27 + NS_FATAL_ERROR ("Could not find GlobalValue named \"" << name << "\"");
1.28 + }
1.29 +}
1.30 +
1.31 GlobalValue::Vector *
1.32 GlobalValue::GetVector (void)
1.33 {
2.1 --- a/src/core/global-value.h Thu Jul 02 16:38:53 2009 +0200
2.2 +++ b/src/core/global-value.h Fri Jul 03 13:43:43 2009 +0200
2.3 @@ -114,6 +114,30 @@
2.4 * \returns an iterator which represents a pointer to the last GlobalValue registered.
2.5 */
2.6 static Iterator End (void);
2.7 +
2.8 +
2.9 + /**
2.10 + * finds the GlobalValue with the given name and returns its value
2.11 + *
2.12 + * @param name the name of the GlobalValue to be found
2.13 + * @param value where to store the value of the found GlobalValue
2.14 + *
2.15 + * @return true if the GlobalValue was found, false otherwise
2.16 + */
2.17 + static bool GetValueByNameFailSafe (std::string name, AttributeValue &value);
2.18 +
2.19 + /**
2.20 + * finds the GlobalValue with the given name and returns its
2.21 + * value. This method cannot fail, i.e., it will trigger a
2.22 + * NS_FATAL_ERROR if the requested GlobalValue is not found.
2.23 + *
2.24 + * @param name the name of the GlobalValue to be found
2.25 + * @param value where to store the value of the found GlobalValue
2.26 + *
2.27 + */
2.28 + static void GetValueByName (std::string name, AttributeValue &value);
2.29 +
2.30 +
2.31 private:
2.32 friend class GlobalValueTests;
2.33 static Vector *GetVector (void);