src/core/model/global-value.cc
changeset 7169 358f71a624d8
parent 7003 a0b1500cdaad
child 7399 520706f801e8
equal deleted inserted replaced
7168:7c724be8f9a6 7169:358f71a624d8
    29 #endif
    29 #endif
    30 
    30 
    31 namespace ns3 {
    31 namespace ns3 {
    32 
    32 
    33 GlobalValue::GlobalValue (std::string name, std::string help,
    33 GlobalValue::GlobalValue (std::string name, std::string help,
    34 			  const AttributeValue &initialValue,
    34                           const AttributeValue &initialValue,
    35 			  Ptr<const AttributeChecker> checker)
    35                           Ptr<const AttributeChecker> checker)
    36   : m_name (name),
    36   : m_name (name),
    37     m_help (help),
    37     m_help (help),
    38     m_initialValue (initialValue.Copy ()),
    38     m_initialValue (initialValue.Copy ()),
    39     m_checker (checker)
    39     m_checker (checker)
    40 {
    40 {
   105 Ptr<const AttributeChecker> 
   105 Ptr<const AttributeChecker> 
   106 GlobalValue::GetChecker (void) const
   106 GlobalValue::GetChecker (void) const
   107 {
   107 {
   108   return m_checker;
   108   return m_checker;
   109 }
   109 }
   110   
   110 
   111 bool
   111 bool
   112 GlobalValue::SetValue (const AttributeValue &value)
   112 GlobalValue::SetValue (const AttributeValue &value)
   113 {
   113 {
   114   if (m_checker->Check (value))
   114   if (m_checker->Check (value))
   115     {
   115     {
   142 GlobalValue::Bind (std::string name, const AttributeValue &value)
   142 GlobalValue::Bind (std::string name, const AttributeValue &value)
   143 {
   143 {
   144   for (Iterator i = Begin (); i != End (); i++)
   144   for (Iterator i = Begin (); i != End (); i++)
   145     {
   145     {
   146       if ((*i)->GetName () == name)
   146       if ((*i)->GetName () == name)
   147 	{
   147         {
   148 	  if (!(*i)->SetValue (value))
   148           if (!(*i)->SetValue (value))
   149 	    {
   149             {
   150 	      NS_FATAL_ERROR ("Invalid new value for global value: "<<name);
   150               NS_FATAL_ERROR ("Invalid new value for global value: "<<name);
   151 	    }
   151             }
   152 	  return;
   152           return;
   153 	}
   153         }
   154     }
   154     }
   155   NS_FATAL_ERROR ("Non-existant global value: "<<name);
   155   NS_FATAL_ERROR ("Non-existant global value: "<<name);
   156 }
   156 }
   157 bool 
   157 bool 
   158 GlobalValue::BindFailSafe (std::string name, const AttributeValue &value)
   158 GlobalValue::BindFailSafe (std::string name, const AttributeValue &value)
   159 {
   159 {
   160   for (Iterator i = Begin (); i != End (); i++)
   160   for (Iterator i = Begin (); i != End (); i++)
   161     {
   161     {
   162       if ((*i)->GetName () == name)
   162       if ((*i)->GetName () == name)
   163 	{
   163         {
   164 	  return (*i)->SetValue (value);
   164           return (*i)->SetValue (value);
   165 	}
   165         }
   166     }
   166     }
   167   return false;
   167   return false;
   168 }
   168 }
   169 GlobalValue::Iterator 
   169 GlobalValue::Iterator 
   170 GlobalValue::Begin (void)
   170 GlobalValue::Begin (void)
   181 GlobalValue::GetValueByNameFailSafe (std::string name, AttributeValue &value)
   181 GlobalValue::GetValueByNameFailSafe (std::string name, AttributeValue &value)
   182 {
   182 {
   183   for (GlobalValue::Iterator gvit = GlobalValue::Begin (); gvit != GlobalValue::End (); ++gvit)
   183   for (GlobalValue::Iterator gvit = GlobalValue::Begin (); gvit != GlobalValue::End (); ++gvit)
   184     {
   184     {
   185       if ((*gvit)->GetName () == name)
   185       if ((*gvit)->GetName () == name)
   186          {
   186         {
   187            (*gvit)->GetValue (value);  
   187           (*gvit)->GetValue (value);
   188            return true;
   188           return true;
   189          }
   189         }
   190     } 
   190     } 
   191   return false; // not found
   191   return false; // not found
   192 }
   192 }
   193 
   193 
   194 void
   194 void
   195 GlobalValue::GetValueByName (std::string name, AttributeValue &value)
   195 GlobalValue::GetValueByName (std::string name, AttributeValue &value)
   196 {
   196 {
   197   if (! GetValueByNameFailSafe (name, value))
   197   if (!GetValueByNameFailSafe (name, value))
   198     {
   198     {
   199       NS_FATAL_ERROR ("Could not find GlobalValue named \"" << name << "\"");
   199       NS_FATAL_ERROR ("Could not find GlobalValue named \"" << name << "\"");
   200     }
   200     }
   201 }
   201 }
   202 
   202