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);
@ -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);
if (iter != m_BuiltInVariables.end())
{
// Built-in variable found
strValue = (*iter).second;
return true;
return &(*iter).second;
}
// #2: Monitor variables
iter = c_MonitorVariables.find(strTmp);
if (iter != c_MonitorVariables.end())
{
// SCREENAREA/WORKAREA variable found
strValue = (*iter).second;
return true;
return &(*iter).second;
}
// #3: User-defined variables
iter = m_Variables.find(strTmp);
if (iter != m_Variables.end())
{
// Variable found
strValue = (*iter).second;
return true;
return &(*iter).second;
}
// Not found
return false;
return NULL;
}
/*
@ -577,13 +570,12 @@ bool CConfigParser::ReplaceVariables(std::wstring& result)
else
{
std::wstring strVariable = result.substr(si, end - si);
std::wstring strValue;
if (GetVariable(strVariable, strValue))
const std::wstring* value = GetVariable(strVariable);
if (value)
{
// Variable found, replace it with the value
result.replace(start, end - start + 1, strValue);
start += strValue.length();
result.replace(start, end - start + 1, *value);
start += (*value).length();
replaced = true;
}
else

View File

@ -46,7 +46,7 @@ public:
void AddMeasure(CMeasure* pMeasure);
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 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];
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);
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
{