implemented GlobalValue::GetValueByName ()
authorNicola Baldo <nbaldo@cttc.es>
Fri, 03 Jul 2009 13:43:43 +0200
changeset 4649 a61205fbe4a6
parent 4645 d53223aae797
child 4650 d548d8ed08cc
implemented GlobalValue::GetValueByName ()
src/core/global-value.cc
src/core/global-value.h
--- a/src/core/global-value.cc	Thu Jul 02 16:38:53 2009 +0200
+++ b/src/core/global-value.cc	Fri Jul 03 13:43:43 2009 +0200
@@ -174,6 +174,30 @@
 {
   return GetVector ()->end ();
 }
+
+bool
+GlobalValue::GetValueByNameFailSafe (std::string name, AttributeValue &value)
+{
+  for (GlobalValue::Iterator gvit = GlobalValue::Begin (); gvit != GlobalValue::End (); ++gvit)
+    {
+      if ((*gvit)->GetName () == name)
+         {
+           (*gvit)->GetValue (value);  
+           return true;
+         }
+    } 
+  return false; // not found
+}
+
+void
+GlobalValue::GetValueByName (std::string name, AttributeValue &value)
+{
+  if (! GetValueByNameFailSafe (name, value))
+    {
+      NS_FATAL_ERROR ("Could not find GlobalValue named \"" << name << "\"");
+    }
+}
+
 GlobalValue::Vector *
 GlobalValue::GetVector (void)
 {
--- a/src/core/global-value.h	Thu Jul 02 16:38:53 2009 +0200
+++ b/src/core/global-value.h	Fri Jul 03 13:43:43 2009 +0200
@@ -114,6 +114,30 @@
    * \returns an iterator which represents a pointer to the last GlobalValue registered.
    */
   static Iterator End (void);
+
+
+  /** 
+   * finds the GlobalValue with the given name and returns its value
+   * 
+   * @param name the name of the GlobalValue to be found
+   * @param value where to store the value of the found GlobalValue
+   * 
+   * @return true if the GlobalValue was found, false otherwise
+   */
+  static bool GetValueByNameFailSafe (std::string name, AttributeValue &value);
+
+  /** 
+   * finds the GlobalValue with the given name and returns its
+   * value. This method cannot fail, i.e., it will trigger a
+   * NS_FATAL_ERROR if the requested GlobalValue is not found.
+   * 
+   * @param name the name of the GlobalValue to be found
+   * @param value where to store the value of the found GlobalValue
+   * 
+   */
+  static void GetValueByName (std::string name, AttributeValue &value);
+  
+
 private:
   friend class GlobalValueTests;
   static Vector *GetVector (void);