diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 4e558957..15f3ba45 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -26,7 +26,7 @@ extern CRainmeter* Rainmeter; using namespace Gdiplus; -std::map CConfigParser::c_MonitorVariables; +stdext::hash_map CConfigParser::c_MonitorVariables; /* ** CConfigParser @@ -143,13 +143,11 @@ void CConfigParser::ReadVariables() ** \param strVariable ** \param strValue */ -void CConfigParser::SetVariable(std::map& variables, const std::wstring& strVariable, const std::wstring& strValue) +void CConfigParser::SetVariable(stdext::hash_map& variables, const std::wstring& strVariable, const std::wstring& strValue) { - // LogWithArgs(LOG_DEBUG, L"Variable: %s=%s (size=%i)", strVariable.c_str(), strValue.c_str(), (int)m_Variables.size()); + // LogWithArgs(LOG_DEBUG, L"Variable: %s=%s (size=%i)", strVariable.c_str(), strValue.c_str(), (int)variables.size()); - std::wstring strTmp(strVariable); - std::transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::towlower); - variables[strTmp] = strValue; + variables[StrToLower(strVariable)] = strValue; } /** @@ -161,11 +159,10 @@ void CConfigParser::SetVariable(std::map& variables, */ bool CConfigParser::GetVariable(const std::wstring& strVariable, std::wstring& strValue) { - std::wstring strTmp(strVariable); - std::transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::towlower); + std::wstring strTmp = StrToLower(strVariable); // #1: Built-in variables - std::map::const_iterator iter = m_BuiltInVariables.find(strTmp); + stdext::hash_map::const_iterator iter = m_BuiltInVariables.find(strTmp); if (iter != m_BuiltInVariables.end()) { // Built-in variable found @@ -692,19 +689,16 @@ void CConfigParser::AddMeasure(CMeasure* pMeasure) { if (pMeasure) { - m_Measures[pMeasure->GetName()] = pMeasure; + m_Measures[StrToLower(pMeasure->GetName())] = pMeasure; } } CMeasure* CConfigParser::GetMeasure(const std::wstring& name) { - std::map::const_iterator iter = m_Measures.begin(); - for ( ; iter != m_Measures.end(); ++iter) + std::map::const_iterator iter = m_Measures.find(StrToLower(name)); + if (iter != m_Measures.end()) { - if (_wcsicmp((*iter).first.c_str(), name.c_str()) == 0) - { - return (*iter).second; - } + return (*iter).second; } return NULL; @@ -1094,8 +1088,7 @@ void CConfigParser::ReadIniFile(const std::vector& iniFileMappings { if (*pos) { - std::wstring strTmp(pos); - std::transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::towlower); + std::wstring strTmp = StrToLower(pos); if (m_Keys.find(strTmp) == m_Keys.end()) { m_Keys[strTmp] = std::vector(); @@ -1193,10 +1186,8 @@ void CConfigParser::SetValue(const std::wstring& strSection, const std::wstring& { // LogWithArgs(LOG_DEBUG, L"[%s] %s=%s (size: %i)", strSection.c_str(), strKey.c_str(), strValue.c_str(), (int)m_Values.size()); - std::wstring strTmpSection(strSection); - std::wstring strTmpKey(strKey); - std::transform(strTmpSection.begin(), strTmpSection.end(), strTmpSection.begin(), ::towlower); - std::transform(strTmpKey.begin(), strTmpKey.end(), strTmpKey.begin(), ::towlower); + std::wstring strTmpSection = StrToLower(strSection); + std::wstring strTmpKey = StrToLower(strKey); stdext::hash_map >::iterator iter = m_Keys.find(strTmpSection); if (iter != m_Keys.end()) @@ -1221,11 +1212,10 @@ void CConfigParser::SetValue(const std::wstring& strSection, const std::wstring& */ const std::wstring& CConfigParser::GetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strDefault) { - std::wstring strTmp(strSection + L"::"); + std::wstring strTmp = strSection + L"::"; strTmp += strKey; - std::transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::towlower); - stdext::hash_map::const_iterator iter = m_Values.find(strTmp); + stdext::hash_map::const_iterator iter = m_Values.find(StrToLower(strTmp)); if (iter != m_Values.end()) { return (*iter).second; @@ -1254,10 +1244,7 @@ const std::vector& CConfigParser::GetSections() */ std::vector CConfigParser::GetKeys(const std::wstring& strSection) { - std::wstring strTmp(strSection); - std::transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::towlower); - - stdext::hash_map >::const_iterator iter = m_Keys.find(strTmp); + stdext::hash_map >::const_iterator iter = m_Keys.find(StrToLower(strSection)); if (iter != m_Keys.end()) { return (*iter).second; diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index 19cd785b..1630fb4a 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -26,8 +26,10 @@ #include #include #include +#include #include #include "ccalc-0.5.1/mparser.h" +#include "Litestep.h" class CRainmeter; class CMeterWindow; @@ -44,6 +46,7 @@ public: 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); } + bool GetVariable(const std::wstring& strVariable, std::wstring& strValue); void SetStyleTemplate(const std::wstring& strStyle) { m_StyleTemplate = Tokenize(strStyle, L"|"); } void ClearStyleTemplate() { m_StyleTemplate.clear(); } @@ -83,11 +86,6 @@ public: static void ClearMultiMonitorVariables() { c_MonitorVariables.clear(); } static void UpdateWorkareaVariables() { SetMultiMonitorVariables(false); } - // Updated by Peter Souza IV / psouza4 / 2010.12.13 - // - // Made this public so the plugin bridge can read variables directly - bool GetVariable(const std::wstring& strVariable, std::wstring& strValue); - private: void SetBuiltInVariables(CRainmeter* pRainmeter, CMeterWindow* meterWindow); @@ -102,11 +100,13 @@ private: void SetAutoSelectedMonitorVariables(CMeterWindow* meterWindow); - static void SetVariable(std::map& variables, const std::wstring& strVariable, const std::wstring& strValue); + static void SetVariable(stdext::hash_map& variables, const std::wstring& strVariable, const std::wstring& strValue); static void SetMultiMonitorVariables(bool reset); static void SetMonitorVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(c_MonitorVariables, strVariable, strValue); } + static std::wstring StrToLower(const std::wstring& str) { std::wstring strTmp(str); std::transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::towlower); return strTmp; } + std::wstring m_Filename; hqMathParser* m_Parser; @@ -122,10 +122,10 @@ private: stdext::hash_map > m_Keys; stdext::hash_map m_Values; - std::map m_BuiltInVariables; // Built-in variables - std::map m_Variables; // User-defined variables + stdext::hash_map m_BuiltInVariables; // Built-in variables + stdext::hash_map m_Variables; // User-defined variables - static std::map c_MonitorVariables; // Monitor variables + static stdext::hash_map c_MonitorVariables; // Monitor variables }; #endif diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index cfc9acd3..650bffa7 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -718,7 +718,7 @@ void CMeterString::FreeFontCache(PrivateFontCollection* collection) WCHAR buffer[32]; _snwprintf_s(buffer, _TRUNCATE, L"<%p>", collection); prefix = buffer; - std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::towlower); + StringToLower(prefix); } std::map::iterator iter2 = c_Fonts.begin(); @@ -757,7 +757,7 @@ std::wstring CMeterString::FontFaceToString(const std::wstring& fontFace, Privat WCHAR buffer[32]; _snwprintf_s(buffer, _TRUNCATE, L"<%p>", collection); std::wstring strTmp = buffer + fontFace; - std::transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::towlower); + StringToLower(strTmp); return strTmp; }