Code cleanup.

This commit is contained in:
spx 2011-01-24 10:15:05 +00:00
parent d6789cc23f
commit 0ad2ef9414
15 changed files with 57 additions and 56 deletions

View File

@ -108,7 +108,7 @@ void UpdateAboutDialog()
{
int sel = 3;
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for( ; iter != windows.end(); ++iter)
{
@ -181,7 +181,7 @@ void UpdateAboutStatistics(LPCTSTR entryName)
{
int current = 3;
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for( ; iter != windows.end(); ++iter)
{
@ -192,7 +192,7 @@ void UpdateAboutStatistics(LPCTSTR entryName)
int count = ListView_GetItemCount(widget);
CMeterWindow* meterWindow = (*iter).second;
std::list<CMeasure*>& measures = meterWindow->GetMeasures();
const std::list<CMeasure*>& measures = meterWindow->GetMeasures();
int index = 0;
std::list<CMeasure*>::const_iterator i = measures.begin();
@ -440,7 +440,7 @@ BOOL OnInitAboutDialog(HWND window)
// Add entries for each config
widget = GetDlgItem(window, IDC_ABOUT_ENTRIES);
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for( ; iter != windows.end(); ++iter)
{

View File

@ -25,22 +25,25 @@
**
**
*/
void CGroup::InitializeGroup(const std::wstring& group)
void CGroup::InitializeGroup(const std::wstring& groups)
{
if (group != m_OldGroup)
if (groups != m_OldGroups)
{
m_OldGroup = group;
m_Group.clear();
m_OldGroups = groups;
m_Groups.clear();
std::vector<std::wstring> vGroup = CConfigParser::Tokenize(group, L"|");
if (!groups.empty())
{
std::vector<std::wstring> vGroups = CConfigParser::Tokenize(groups, L"|");
std::vector<std::wstring>::const_iterator iter = vGroup.begin();
for ( ; iter != vGroup.end(); ++iter)
std::vector<std::wstring>::const_iterator iter = vGroups.begin();
for ( ; iter != vGroups.end(); ++iter)
{
std::wstring group = CreateGroup(*iter);
if (!group.empty())
{
m_Group.insert(group);
m_Groups.insert(group);
}
}
}
}
@ -53,7 +56,7 @@ void CGroup::InitializeGroup(const std::wstring& group)
*/
bool CGroup::BelongsToGroup(const std::wstring& group)
{
return (m_Group.find(CreateGroup(group)) != m_Group.end());
return (m_Groups.find(CreateGroup(group)) != m_Groups.end());
}
std::wstring CGroup::CreateGroup(const std::wstring& str)

View File

@ -21,7 +21,6 @@
#pragma warning(disable: 4786)
#include <windows.h>
#include <string>
#include <set>
@ -29,19 +28,18 @@ class CGroup
{
public:
bool BelongsToGroup(const std::wstring& group);
const std::set<std::wstring>& GetGroup() { return m_Group; }
protected:
CGroup() {}
virtual ~CGroup() {}
void InitializeGroup(const std::wstring& group);
void InitializeGroup(const std::wstring& groups);
private:
std::wstring CreateGroup(const std::wstring& str);
std::set<std::wstring> m_Group;
std::wstring m_OldGroup;
std::set<std::wstring> m_Groups;
std::wstring m_OldGroups;
};

View File

@ -173,14 +173,15 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section)
(subs[0] != L'\'' || subs[subs.length() - 1] != L'\"'))
{
// Add quotes since they are removed by the GetProfileString
subs = L"\"" + subs + L"\"";
subs.insert(0, L"\"");
subs.append(L"\"");
}
if (!ParseSubstitute(subs))
{
LogWithArgs(LOG_WARNING, L"Incorrect substitute string: %s", subs.c_str());
}
std::wstring group = parser.ReadString(section, L"Group", L"");
const std::wstring& group = parser.ReadString(section, L"Group", L"");
InitializeGroup(group);
}

View File

@ -102,7 +102,7 @@ void CMeasureCalc::UpdateVariableMap(CMeterWindow& meterWindow)
// Create the variable map
c_VarMap = Strmap_Create(sizeof(double), 0);
std::list<CMeasure*>& measures = meterWindow.GetMeasures();
const std::list<CMeasure*>& measures = meterWindow.GetMeasures();
std::list<CMeasure*>::const_iterator iter = measures.begin();
for( ; iter != measures.end(); ++iter)
@ -199,11 +199,11 @@ void CMeasureCalc::FormulaReplace()
*/
bool CMeasureCalc::IsDelimiter(WCHAR ch)
{
const WCHAR symbols[] = L" \t\n()+-/*^~<>%$,?:=&|;";
const WCHAR* symbols = L" \t\n()+-/*^~<>%$,?:=&|;";
for (size_t i = 0, len = wcslen(symbols); i < len; ++i)
for (const WCHAR* sch = symbols; *sch != L'\0'; ++sch)
{
if (ch == symbols[i])
if (ch == *sch)
{
return true;
}

View File

@ -117,8 +117,7 @@ void CMeasureRegistry::ReadConfig(CConfigParser& parser, const WCHAR* section)
{
CMeasure::ReadConfig(parser, section);
std::wstring keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER");
const std::wstring& keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER");
if(_wcsicmp(keyname.c_str(), L"HKEY_CLASSES_ROOT") == 0)
{
m_HKey = HKEY_CLASSES_ROOT;

View File

@ -115,9 +115,8 @@ bool CMeasureTime::Update()
m_Time.LowPart = ftUTCTime.dwLowDateTime;
m_Time.QuadPart += m_DeltaTime.QuadPart;
m_Value = (double)(m_Time.QuadPart / 10000000);
if (m_Format.size() != 0)
if (m_Format.size() > 0)
{
// If there is some date format, parse the value from it instead
WCHAR tmpSz[MAX_LINE_LENGTH];
@ -157,6 +156,10 @@ bool CMeasureTime::Update()
m_Value = wcstod(tmpSz, NULL);
}
else
{
m_Value = (double)(m_Time.QuadPart / 10000000);
}
return PostUpdate();
}
@ -229,14 +232,12 @@ void CMeasureTime::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_Format = parser.ReadString(section, L"Format", L"");
std::wstring timezone = parser.ReadString(section, L"TimeZone", L"local");
bool dst = 1 == parser.ReadInt(section, L"DaylightSavingTime", 1);
if (_wcsicmp(L"local", timezone.c_str()) == 0)
{
SYSTEMTIME sysLocalTime, sysUTCTime;
GetLocalTime(&sysLocalTime);
GetSystemTime(&sysUTCTime);
if (_wcsicmp(L"local", timezone.c_str()) == 0)
{
FILETIME ftLocalTime, ftUTCTime;
SystemTimeToFileTime(&sysLocalTime, &ftLocalTime);
SystemTimeToFileTime(&sysUTCTime, &ftUTCTime);
@ -252,6 +253,7 @@ void CMeasureTime::ReadConfig(CConfigParser& parser, const WCHAR* section)
else
{
double zone = wcstod(timezone.c_str(), NULL);
bool dst = 1 == parser.ReadInt(section, L"DaylightSavingTime", 1);
struct tm* today;
time_t now;

View File

@ -105,7 +105,7 @@ int CMeter::GetX(bool abs)
{
if (m_RelativeMeter == NULL)
{
std::list<CMeter*>& meters = m_MeterWindow->GetMeters();
const std::list<CMeter*>& meters = m_MeterWindow->GetMeters();
std::list<CMeter*>::const_iterator iter = meters.begin();
// Find this meter
@ -153,7 +153,7 @@ int CMeter::GetY(bool abs)
{
if (m_RelativeMeter == NULL)
{
std::list<CMeter*>& meters = m_MeterWindow->GetMeters();
const std::list<CMeter*>& meters = m_MeterWindow->GetMeters();
std::list<CMeter*>::const_iterator iter = meters.begin();
// Find this meter
@ -431,7 +431,7 @@ void CMeter::ReadConfig(const WCHAR* section)
LogWithArgs(LOG_WARNING, L"The transformation matrix has incorrect number of values: %s", parser.ReadString(section, L"TransformationMatrix", L"").c_str());
}
std::wstring group = parser.ReadString(section, L"Group", L"");
const std::wstring& group = parser.ReadString(section, L"Group", L"");
InitializeGroup(group);
}
@ -585,7 +585,7 @@ void CMeter::ReadMeasureNames(CConfigParser& parser, const WCHAR* section, std::
do
{
_snwprintf_s(tmpName, _TRUNCATE, L"MeasureName%i", i);
std::wstring measure = parser.ReadString(section, tmpName, L"");
const std::wstring& measure = parser.ReadString(section, tmpName, L"");
if (!measure.empty())
{
measureNames.push_back(measure);

View File

@ -121,8 +121,7 @@ void CMeterBar::ReadConfig(const WCHAR* section)
m_Flip = parser.ReadInt(section, L"Flip", 0) == 1;
std::wstring orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL");
const std::wstring& orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL");
if(_wcsicmp(L"VERTICAL", orientation.c_str()) == 0)
{
m_Orientation = VERTICAL;

View File

@ -197,8 +197,7 @@ void CMeterBitmap::ReadConfig(const WCHAR* section)
m_TransitionFrameCount = parser.ReadInt(section, L"BitmapTransitionFrames", 0);
std::wstring align = parser.ReadString(section, L"BitmapAlign", L"LEFT");
const std::wstring& align = parser.ReadString(section, L"BitmapAlign", L"LEFT");
if(_wcsicmp(align.c_str(), L"LEFT") == 0)
{
m_Align = ALIGN_LEFT;

View File

@ -333,7 +333,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
m_Angle = (Gdiplus::REAL)parser.ReadFloat(section, L"Angle", 0.0);
std::wstring autoscale = parser.ReadString(section, L"AutoScale", L"0");
const std::wstring& autoscale = parser.ReadString(section, L"AutoScale", L"0");
int autoscaleValue = _wtoi(autoscale.c_str());
if (autoscaleValue == 0)
{
@ -351,7 +351,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
}
}
std::wstring scale = parser.ReadString(section, L"Scale", L"1");
const std::wstring& scale = parser.ReadString(section, L"Scale", L"1");
if (scale.find(L'.') == std::wstring::npos)
{
m_NoDecimals = true;
@ -362,7 +362,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
}
m_Scale = wcstod(scale.c_str(), NULL);
std::wstring align = parser.ReadString(section, L"StringAlign", L"LEFT");
const std::wstring& align = parser.ReadString(section, L"StringAlign", L"LEFT");
if(_wcsicmp(align.c_str(), L"LEFT") == 0)
{
m_Align = ALIGN_LEFT;
@ -384,7 +384,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
throw CError(error, __LINE__, __FILE__);
}
std::wstring stringCase = parser.ReadString(section, L"StringCase", L"NONE");
const std::wstring& stringCase = parser.ReadString(section, L"StringCase", L"NONE");
if(_wcsicmp(stringCase.c_str(), L"NONE") == 0)
{
m_textCase = TEXTCASE_NONE;
@ -410,7 +410,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
throw CError(error, __LINE__, __FILE__);
}
std::wstring style = parser.ReadString(section, L"StringStyle", L"NORMAL");
const std::wstring& style = parser.ReadString(section, L"StringStyle", L"NORMAL");
if(_wcsicmp(style.c_str(), L"NORMAL") == 0)
{
m_Style = NORMAL;
@ -436,7 +436,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
throw CError(error, __LINE__, __FILE__);
}
std::wstring effect = parser.ReadString(section, L"StringEffect", L"NONE");
const std::wstring& effect = parser.ReadString(section, L"StringEffect", L"NONE");
if(_wcsicmp(effect.c_str(), L"NONE") == 0)
{
m_Effect = EFFECT_NONE;

View File

@ -68,7 +68,7 @@ private:
TEXTCASE_NONE,
TEXTCASE_UPPER,
TEXTCASE_LOWER,
TEXTCASE_PROPER,
TEXTCASE_PROPER
};
bool DrawString(Gdiplus::Graphics& graphics, Gdiplus::RectF* rect);

View File

@ -3783,7 +3783,7 @@ LRESULT CMeterWindow::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lPara
}
// Snap to other windows
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for( ; iter != windows.end(); ++iter)
{
@ -4710,7 +4710,7 @@ LRESULT CMeterWindow::OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Check that we're still alive
bool found = false;
std::map<std::wstring, CMeterWindow*>& meters = Rainmeter->GetAllMeterWindows();
const std::map<std::wstring, CMeterWindow*>& meters = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = meters.begin();
for ( ; iter != meters.end(); ++iter)

View File

@ -980,7 +980,7 @@ LRESULT CALLBACK CSystem::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
if (Rainmeter)
{
// Deliver WM_DISPLAYCHANGE / WM_SETTINGCHANGE message to all meter windows
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for( ; iter != windows.end(); ++iter)
{

View File

@ -530,7 +530,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
{
// Forward the message to correct window
int index = (int)(wParam >> 16);
std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
if (index < (int)windows.size())
{