From 6bdfdc8dc53be254b9ccf99218ad97c0029e3e86 Mon Sep 17 00:00:00 2001 From: Nicola Baldo Date: Fri, 3 Jul 2009 13:43:43 +0200 Subject: [PATCH] implemented GlobalValue::GetValueByName () --- src/core/global-value.cc | 24 ++++++++++++++++++++++++ src/core/global-value.h | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/core/global-value.cc b/src/core/global-value.cc index 70a226e55..506fb11b8 100644 --- a/src/core/global-value.cc +++ b/src/core/global-value.cc @@ -174,6 +174,30 @@ GlobalValue::End (void) { 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) { diff --git a/src/core/global-value.h b/src/core/global-value.h index a40d2244f..c744247dd 100644 --- a/src/core/global-value.h +++ b/src/core/global-value.h @@ -114,6 +114,30 @@ public: * \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);