Tweak GetSectionVariable()

This commit is contained in:
Birunthan Mohanathas 2014-01-04 18:47:14 +02:00
parent 9541e72707
commit c31ecbfc83

View File

@ -231,28 +231,28 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
// Scale: [Measure:/scale], [Measure:/scale, dec] // Scale: [Measure:/scale], [Measure:/scale, dec]
// Max/Min: [Measure:MaxValue], [Measure:MaxValue:/scale, dec] ('%' cannot be used) // Max/Min: [Measure:MaxValue], [Measure:MaxValue:/scale, dec] ('%' cannot be used)
// EscapeRegExp: [Measure:EscapeRegExp] (Escapes regular expression syntax, used for 'IfMatch') // EscapeRegExp: [Measure:EscapeRegExp] (Escapes regular expression syntax, used for 'IfMatch')
enum VALUETYPE enum class ValueType
{ {
RAW = 0, Raw,
PERCENTUAL = 1, Percentual,
MAX = 2, Max,
MIN = 3, Min,
SPECIAL = 4 EscapeRegExp
} valueType = RAW; } valueType = ValueType::Raw;
if (isKeySelector) if (isKeySelector)
{ {
if (_wcsicmp(selectorSz, L"MaxValue") == 0) if (_wcsicmp(selectorSz, L"MaxValue") == 0)
{ {
valueType = MAX; valueType = ValueType::Max;
} }
else if (_wcsicmp(selectorSz, L"MinValue") == 0) else if (_wcsicmp(selectorSz, L"MinValue") == 0)
{ {
valueType = MIN; valueType = ValueType::Min;
} }
else if (_wcsicmp(selectorSz, L"EscapeRegExp") == 0) else if (_wcsicmp(selectorSz, L"EscapeRegExp") == 0)
{ {
valueType = SPECIAL; valueType = ValueType::EscapeRegExp;
} }
else else
{ {
@ -272,11 +272,11 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
if (_wcsicmp(keySelectorSz, L"MaxValue") == 0) if (_wcsicmp(keySelectorSz, L"MaxValue") == 0)
{ {
valueType = MAX; valueType = ValueType::Max;
} }
else if (_wcsicmp(keySelectorSz, L"MinValue") == 0) else if (_wcsicmp(keySelectorSz, L"MinValue") == 0)
{ {
valueType = MIN; valueType = ValueType::Min;
} }
else else
{ {
@ -293,16 +293,11 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
Measure* measure = m_MeterWindow->GetMeasure(strVariable); Measure* measure = m_MeterWindow->GetMeasure(strVariable);
if (measure) if (measure)
{ {
if (valueType == SPECIAL) // "Special" functions: EscapeRegExp if (valueType == ValueType::EscapeRegExp)
{ {
if (_wcsicmp(selector.c_str(), L"EscapeRegExp") == 0) std::wstring str = measure->GetStringValue();
{ EscapeRegExp(str);
std::wstring str = measure->GetStringValue(); strValue.assign(str);
EscapeRegExp(str);
strValue.assign(str);
}
//else if (_wcsicmp(selector.c_str(), L"") == 0)
return true; return true;
} }
@ -316,12 +311,12 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
if (*selectorSz == L'%') // Percentual if (*selectorSz == L'%') // Percentual
{ {
if (valueType == MAX || valueType == MIN) // '%' cannot be used with MAX/MIN value if (valueType == ValueType::Max || valueType == ValueType::Min) // '%' cannot be used with MAX/MIN value
{ {
return false; return false;
} }
valueType = PERCENTUAL; valueType = ValueType::Percentual;
} }
else if (*selectorSz == L'/') // Scale else if (*selectorSz == L'/') // Scale
{ {
@ -342,12 +337,12 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
decimalsSz = selectorSz; decimalsSz = selectorSz;
} }
double value = (valueType == PERCENTUAL) ? measure->GetRelativeValue() * 100.0 const double value =
: (valueType == MAX) ? measure->GetMaxValue() / scale (valueType == ValueType::Percentual) ? measure->GetRelativeValue() * 100.0 :
: (valueType == MIN) ? measure->GetMinValue() / scale (valueType == ValueType::Max) ? measure->GetMaxValue() / scale :
: measure->GetValue() / scale; (valueType == ValueType::Min) ? measure->GetMinValue() / scale :
measure->GetValue() / scale;
int decimals = 10; int decimals = 10;
if (decimalsSz) if (decimalsSz)
{ {
while (iswspace(*decimalsSz)) ++decimalsSz; while (iswspace(*decimalsSz)) ++decimalsSz;