This commit is contained in:
Birunthan Mohanathas 2012-08-05 16:12:36 +03:00
parent a162451e87
commit fd111c0657
4 changed files with 17 additions and 23 deletions

View File

@ -153,10 +153,10 @@ void CConfigParser::SetVariable(std::unordered_map<std::wstring, std::wstring>&
} }
/* /*
** Gets a value for the variable. Returns true if variable found. ** Gets a value for the variable. Returns NULL if not found.
** **
*/ */
bool CConfigParser::GetVariable(const std::wstring& strVariable, std::wstring& strValue) const std::wstring* CConfigParser::GetVariable(const std::wstring& strVariable)
{ {
const std::wstring strTmp = StrToUpper(strVariable); const std::wstring strTmp = StrToUpper(strVariable);
@ -164,31 +164,24 @@ bool CConfigParser::GetVariable(const std::wstring& strVariable, std::wstring& s
std::unordered_map<std::wstring, std::wstring>::const_iterator iter = m_BuiltInVariables.find(strTmp); std::unordered_map<std::wstring, std::wstring>::const_iterator iter = m_BuiltInVariables.find(strTmp);
if (iter != m_BuiltInVariables.end()) if (iter != m_BuiltInVariables.end())
{ {
// Built-in variable found return &(*iter).second;
strValue = (*iter).second;
return true;
} }
// #2: Monitor variables // #2: Monitor variables
iter = c_MonitorVariables.find(strTmp); iter = c_MonitorVariables.find(strTmp);
if (iter != c_MonitorVariables.end()) if (iter != c_MonitorVariables.end())
{ {
// SCREENAREA/WORKAREA variable found return &(*iter).second;
strValue = (*iter).second;
return true;
} }
// #3: User-defined variables // #3: User-defined variables
iter = m_Variables.find(strTmp); iter = m_Variables.find(strTmp);
if (iter != m_Variables.end()) if (iter != m_Variables.end())
{ {
// Variable found return &(*iter).second;
strValue = (*iter).second;
return true;
} }
// Not found return NULL;
return false;
} }
/* /*
@ -577,13 +570,12 @@ bool CConfigParser::ReplaceVariables(std::wstring& result)
else else
{ {
std::wstring strVariable = result.substr(si, end - si); std::wstring strVariable = result.substr(si, end - si);
std::wstring strValue; const std::wstring* value = GetVariable(strVariable);
if (value)
if (GetVariable(strVariable, strValue))
{ {
// Variable found, replace it with the value // Variable found, replace it with the value
result.replace(start, end - start + 1, strValue); result.replace(start, end - start + 1, *value);
start += strValue.length(); start += (*value).length();
replaced = true; replaced = true;
} }
else else

View File

@ -46,7 +46,7 @@ public:
void AddMeasure(CMeasure* pMeasure); void AddMeasure(CMeasure* pMeasure);
CMeasure* GetMeasure(const std::wstring& name); CMeasure* GetMeasure(const std::wstring& name);
bool GetVariable(const std::wstring& strVariable, std::wstring& strValue); const std::wstring* GetVariable(const std::wstring& strVariable);
void SetVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_Variables, strVariable, strValue); } void SetVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_Variables, strVariable, strValue); }
void SetBuiltInVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_BuiltInVariables, strVariable, strValue); } void SetBuiltInVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_BuiltInVariables, strVariable, strValue); }

View File

@ -178,9 +178,10 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
{ {
const std::wstring& variable = subStrings[1]; const std::wstring& variable = subStrings[1];
if (meterWindow->GetParser().GetVariable(variable, g_Buffer)) const std::wstring* value = meterWindow->GetParser().GetVariable(variable);
if (value)
{ {
return g_Buffer.c_str(); return (*value).c_str();
} }
} }
} }

View File

@ -108,9 +108,10 @@ static int GetVariable(lua_State* L)
CMeterWindow* self = GetSelf(L); CMeterWindow* self = GetSelf(L);
std::wstring strTmp = LuaManager::ToWide(L, 2); std::wstring strTmp = LuaManager::ToWide(L, 2);
if (self->GetParser().GetVariable(strTmp, strTmp)) const std::wstring* value = self->GetParser().GetVariable(strTmp);
if (value)
{ {
LuaManager::PushWide(L, strTmp.c_str()); LuaManager::PushWide(L, (*value).c_str());
} }
else else
{ {