Code cleanup

This commit is contained in:
Birunthan Mohanathas 2012-09-21 21:42:44 +03:00
parent b6011b40ad
commit 1e3d6c156d

View File

@ -1337,41 +1337,36 @@ void CMeterWindow::SetVariable(const std::wstring& variable, const std::wstring&
*/ */
void CMeterWindow::SetOption(const std::wstring& section, const std::wstring& option, const std::wstring& value, bool group) void CMeterWindow::SetOption(const std::wstring& section, const std::wstring& option, const std::wstring& value, bool group)
{ {
auto setValue = [&](CSection* section, const std::wstring& option, const std::wstring& value)
{
// Force DynamicVariables temporarily (until next ReadOptions()).
section->SetDynamicVariables(true);
if (value.empty())
{
m_Parser.DeleteValue(section->GetOriginalName(), option);
}
else
{
m_Parser.SetValue(section->GetOriginalName(), option, value);
}
};
if (group) if (group)
{ {
for (std::vector<CMeter*>::const_iterator j = m_Meters.begin(); j != m_Meters.end(); ++j) for (auto j = m_Meters.begin(); j != m_Meters.end(); ++j)
{ {
if ((*j)->BelongsToGroup(section)) if ((*j)->BelongsToGroup(section))
{ {
// Force DynamicVariables temporarily (it will reset back to original setting in ReadOptions()) setValue(*j, option, value);
(*j)->SetDynamicVariables(true);
if (value.empty())
{
GetParser().DeleteValue((*j)->GetOriginalName(), option);
}
else
{
GetParser().SetValue((*j)->GetOriginalName(), option, value);
}
} }
} }
for (std::vector<CMeasure*>::const_iterator i = m_Measures.begin(); i != m_Measures.end(); ++i) for (auto i = m_Measures.begin(); i != m_Measures.end(); ++i)
{ {
if ((*i)->BelongsToGroup(section)) if ((*i)->BelongsToGroup(section))
{ {
// Force DynamicVariables temporarily (it will reset back to original setting in ReadOptions()) setValue(*i, option, value);
(*i)->SetDynamicVariables(true);
if (value.empty())
{
GetParser().DeleteValue((*i)->GetOriginalName(), option);
}
else
{
GetParser().SetValue((*i)->GetOriginalName(), option, value);
}
} }
} }
} }
@ -1380,36 +1375,14 @@ void CMeterWindow::SetOption(const std::wstring& section, const std::wstring& op
CMeter* meter = GetMeter(section); CMeter* meter = GetMeter(section);
if (meter) if (meter)
{ {
// Force DynamicVariables temporarily (it will reset back to original setting in ReadOptions()) setValue(meter, option, value);
meter->SetDynamicVariables(true);
if (value.empty())
{
GetParser().DeleteValue(section, option);
}
else
{
GetParser().SetValue(section, option, value);
}
return; return;
} }
CMeasure* measure = GetMeasure(section); CMeter* measure = GetMeter(section);
if (measure) if (measure)
{ {
// Force DynamicVariables temporarily (it will reset back to original setting in ReadOptions()) setValue(measure, option, value);
measure->SetDynamicVariables(true);
if (value.empty())
{
GetParser().DeleteValue(section, option);
}
else
{
GetParser().SetValue(section, option, value);
}
return; return;
} }