This commit is contained in:
Gustavo J. A. M. Carneiro
2009-07-03 14:14:25 +01:00
2 changed files with 48 additions and 0 deletions

View File

@@ -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)
{

View File

@@ -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);