When creating an Option, OptionManager takes it's initial value from it's parent if possible

This commit is contained in:
Maxime Coste 2012-06-12 18:28:25 +00:00
parent bc359d7c90
commit cab03ef1c6

View File

@ -10,10 +10,23 @@ Option& OptionManager::operator[] (const String& name)
auto it = m_options.find(name); auto it = m_options.find(name);
if (it != m_options.end()) if (it != m_options.end())
return it->second; return it->second;
else if (m_parent)
return (*m_parent)[name];
else else
return m_options[name]; {
Option& res = m_options[name];
OptionManager* parent = m_parent;
while (parent)
{
auto parent_it = parent->m_options.find(name);
if (parent_it != parent->m_options.end())
{
res = parent_it->second;
break;
}
else
parent = parent->m_parent;
}
return res;
}
} }
const Option& OptionManager::operator[] (const String& name) const const Option& OptionManager::operator[] (const String& name) const