- Switched from size()>0 to empty().

- Code cleanup.
This commit is contained in:
spx 2011-11-08 17:21:29 +00:00
parent f2f97743ef
commit 569a151c6c
8 changed files with 31 additions and 36 deletions

View File

@ -599,7 +599,7 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
if (&strValue == &strDefault) if (&strValue == &strDefault)
{ {
// If the template is defined read the value from there. // If the template is defined read the value from there.
if (m_StyleTemplate.size() > 0) if (!m_StyleTemplate.empty())
{ {
std::vector<std::wstring>::const_reverse_iterator iter = m_StyleTemplate.rbegin(); std::vector<std::wstring>::const_reverse_iterator iter = m_StyleTemplate.rbegin();
for ( ; iter != m_StyleTemplate.rend(); ++iter) for ( ; iter != m_StyleTemplate.rend(); ++iter)
@ -618,7 +618,7 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
} }
} }
if (m_LastUsedStyle.size() == 0) // No template found if (m_LastUsedStyle.empty()) // No template found
{ {
result = strDefault; result = strDefault;
m_LastDefaultUsed = true; m_LastDefaultUsed = true;
@ -630,7 +630,7 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
result = strValue; result = strValue;
} }
if (result.size() > 0) if (!result.empty())
{ {
m_LastValueDefined = true; m_LastValueDefined = true;
@ -662,7 +662,7 @@ bool CConfigParser::IsKeyDefined(LPCTSTR section, LPCTSTR key)
bool CConfigParser::IsValueDefined(LPCTSTR section, LPCTSTR key) bool CConfigParser::IsValueDefined(LPCTSTR section, LPCTSTR key)
{ {
const std::wstring& result = ReadString(section, key, L"", false); const std::wstring& result = ReadString(section, key, L"", false);
return (!m_LastDefaultUsed && result.size() > 0); return (!m_LastDefaultUsed && !result.empty());
} }
void CConfigParser::AddMeasure(CMeasure* pMeasure) void CConfigParser::AddMeasure(CMeasure* pMeasure)
@ -695,7 +695,7 @@ std::vector<Gdiplus::REAL> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR ke
{ {
std::vector<Gdiplus::REAL> result; std::vector<Gdiplus::REAL> result;
const std::wstring& string = ReadString(section, key, L""); const std::wstring& string = ReadString(section, key, L"");
if (string.size() > 0) if (!string.empty())
{ {
std::wstring tmp = string; std::wstring tmp = string;
if (tmp[tmp.length() - 1] != L';') if (tmp[tmp.length() - 1] != L';')
@ -734,7 +734,7 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
const std::wstring& result = ReadString(section, key, L""); const std::wstring& result = ReadString(section, key, L"");
// Formulas must be surrounded by parenthesis // Formulas must be surrounded by parenthesis
if (result.size() > 0 && result[0] == L'(' && result[result.size() - 1] == L')') if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')')
{ {
double resultValue = defValue; double resultValue = defValue;
char* errMsg = MathParser_Parse(m_Parser, ConvertToAscii(result.c_str()).c_str(), &resultValue); char* errMsg = MathParser_Parse(m_Parser, ConvertToAscii(result.c_str()).c_str(), &resultValue);
@ -761,7 +761,7 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
bool CConfigParser::ReadFormula(const std::wstring& result, double* resultValue) bool CConfigParser::ReadFormula(const std::wstring& result, double* resultValue)
{ {
// Formulas must be surrounded by parenthesis // Formulas must be surrounded by parenthesis
if (result.size() > 0 && result[0] == L'(' && result[result.size() - 1] == L')') if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')')
{ {
char* errMsg = MathParser_Parse(m_Parser, ConvertToAscii(result.c_str()).c_str(), resultValue); char* errMsg = MathParser_Parse(m_Parser, ConvertToAscii(result.c_str()).c_str(), resultValue);
if (errMsg != NULL) if (errMsg != NULL)
@ -833,7 +833,7 @@ std::vector<std::wstring> CConfigParser::Tokenize(const std::wstring& str, const
*/ */
void CConfigParser::Shrink(std::vector<std::wstring>& vec) void CConfigParser::Shrink(std::vector<std::wstring>& vec)
{ {
if (vec.size() > 0) if (!vec.empty())
{ {
std::vector<std::wstring>::iterator iter = vec.begin(); std::vector<std::wstring>::iterator iter = vec.begin();
while (iter != vec.end()) while (iter != vec.end())
@ -1059,7 +1059,7 @@ void CConfigParser::ReadIniFile(const std::vector<std::wstring>& iniFileMappings
// Avoid "IniFileMapping" // Avoid "IniFileMapping"
std::wstring iniRead = CSystem::GetTemporaryFile(iniFileMappings, iniFile); std::wstring iniRead = CSystem::GetTemporaryFile(iniFileMappings, iniFile);
bool temporary = (iniRead.size() > 0 && iniRead != L"<>"); bool temporary = (!iniRead.empty() && (iniRead.size() != 1 || iniRead[0] != L'?'));
if (temporary) if (temporary)
{ {

View File

@ -27,12 +27,12 @@
*/ */
void CGroup::InitializeGroup(const std::wstring& groups) void CGroup::InitializeGroup(const std::wstring& groups)
{ {
if (groups != m_OldGroups) if (wcscmp(groups.c_str(), m_OldGroups.c_str()) != 0)
{ {
m_OldGroups = groups; m_OldGroups = groups;
m_Groups.clear(); m_Groups.clear();
if (groups.size() > 0) if (!groups.empty())
{ {
std::vector<std::wstring> vGroups = CConfigParser::Tokenize(groups, L"|"); std::vector<std::wstring> vGroups = CConfigParser::Tokenize(groups, L"|");
@ -40,7 +40,7 @@ void CGroup::InitializeGroup(const std::wstring& groups)
for ( ; iter != vGroups.end(); ++iter) for ( ; iter != vGroups.end(); ++iter)
{ {
std::wstring group = CreateGroup(*iter); std::wstring group = CreateGroup(*iter);
if (group.size() > 0) if (!group.empty())
{ {
m_Groups.insert(group); m_Groups.insert(group);
} }

View File

@ -349,16 +349,16 @@ bool CMeasure::ParseSubstitute(std::wstring buffer)
{ {
std::wstring word1 = ExtractWord(buffer); std::wstring word1 = ExtractWord(buffer);
std::wstring sep = ExtractWord(buffer); std::wstring sep = ExtractWord(buffer);
if (sep != L":") return false; if (sep.size() != 1 || sep[0] != L':') return false;
std::wstring word2 = ExtractWord(buffer); std::wstring word2 = ExtractWord(buffer);
if (word1 != word2) if (wcscmp(word1.c_str(), word2.c_str()) != 0)
{ {
m_Substitute.push_back(std::pair<std::wstring, std::wstring>(word1, word2)); m_Substitute.push_back(std::pair<std::wstring, std::wstring>(word1, word2));
} }
sep = ExtractWord(buffer); std::wstring sep2 = ExtractWord(buffer);
if (!sep.empty() && sep != L",") return false; if (!sep2.empty() && (sep2.size() != 1 || sep2[0] != L',')) return false;
} }
while (!buffer.empty()); while (!buffer.empty());
@ -374,12 +374,10 @@ bool CMeasure::ParseSubstitute(std::wstring buffer)
*/ */
std::wstring CMeasure::ExtractWord(std::wstring& buffer) std::wstring CMeasure::ExtractWord(std::wstring& buffer)
{ {
std::wstring::size_type end, len; std::wstring::size_type end, len = buffer.size();
std::wstring ret; std::wstring ret;
if (buffer.empty()) return ret; if (len == 0) return ret;
len = buffer.size();
// Remove whitespaces // Remove whitespaces
end = 0; end = 0;

View File

@ -113,7 +113,7 @@ bool CMeasureTime::Update()
m_Time.QuadPart += m_DeltaTime.QuadPart; m_Time.QuadPart += m_DeltaTime.QuadPart;
if (m_Format.size() > 0) if (!m_Format.empty())
{ {
// If there is some date format, parse the value from it instead // If there is some date format, parse the value from it instead
WCHAR* tmpSz = new WCHAR[MAX_LINE_LENGTH]; WCHAR* tmpSz = new WCHAR[MAX_LINE_LENGTH];
@ -195,7 +195,7 @@ const WCHAR* CMeasureTime::GetStringValue(AUTOSCALE autoScale, double scale, int
today.tm_year = sysToday.wYear - 1900; today.tm_year = sysToday.wYear - 1900;
// Create the string // Create the string
if (m_Format.size() > 0) if (!m_Format.empty())
{ {
if (_wcsicmp(L"locale-time", m_Format.c_str()) == 0) if (_wcsicmp(L"locale-time", m_Format.c_str()) == 0)
{ {

View File

@ -2563,15 +2563,12 @@ bool CMeterWindow::ResizeWindow(bool reset)
SetWindowSizeVariables(m_WindowW, m_WindowH); SetWindowSizeVariables(m_WindowW, m_WindowH);
// If Background is not set, take a copy from the desktop if (!m_NativeTransparency)
if (m_Background == NULL)
{ {
if (m_BackgroundMode == BGMODE_COPY) // If Background is not set, take a copy from the desktop
if (m_Background == NULL && m_BackgroundMode == BGMODE_COPY)
{ {
if (!m_NativeTransparency) m_Background = GrabDesktop(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH);
{
m_Background = GrabDesktop(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH);
}
} }
} }

View File

@ -344,7 +344,7 @@ std::vector<std::wstring> CRainmeter::ParseString(LPCTSTR str)
} }
} }
if (arg.size() > 0) if (!arg.empty())
{ {
// Strip quotes // Strip quotes
while ((pos = arg.find(L'"')) != std::wstring::npos) while ((pos = arg.find(L'"')) != std::wstring::npos)
@ -652,7 +652,7 @@ void CRainmeter::RainmeterWriteKeyValue(const WCHAR* arg)
std::vector<std::wstring> iniFileMappings; std::vector<std::wstring> iniFileMappings;
CSystem::GetIniFileMappingList(iniFileMappings); CSystem::GetIniFileMappingList(iniFileMappings);
std::wstring iniWrite = CSystem::GetTemporaryFile(iniFileMappings, iniFile); std::wstring iniWrite = CSystem::GetTemporaryFile(iniFileMappings, iniFile);
if (iniWrite == L"<>") // error occurred if (iniWrite.size() == 1 && iniWrite[0] == L'?') // error occurred
{ {
return; return;
} }

View File

@ -1229,7 +1229,7 @@ void CSystem::GetIniFileMappingList(std::vector<std::wstring>& iniFileMappings)
** GetTemporaryFile ** GetTemporaryFile
** **
** Prepares a temporary file if iniFile is included in the "IniFileMapping" entries. ** Prepares a temporary file if iniFile is included in the "IniFileMapping" entries.
** If iniFile is not included, returns a empty string. If error occurred, returns "<>". ** If iniFile is not included, returns a empty string. If error occurred, returns "?".
** Note that a temporary file must be deleted by caller. ** Note that a temporary file must be deleted by caller.
** **
*/ */
@ -1272,14 +1272,14 @@ std::wstring CSystem::GetTemporaryFile(const std::vector<std::wstring>& iniFileM
else // temporary is reserved or failed else // temporary is reserved or failed
{ {
RemoveFile(temporary); RemoveFile(temporary);
if (tmp.empty()) tmp = L"<>"; if (tmp.empty()) tmp = L"?";
return tmp; return tmp;
} }
} }
else // failed else // failed
{ {
LogWithArgs(LOG_ERROR, L"Unable to create temporary file to: %s", temporary.c_str()); LogWithArgs(LOG_ERROR, L"Unable to create temporary file to: %s", temporary.c_str());
return L"<>"; return L"?";
} }
} }
} }

View File

@ -205,9 +205,9 @@ HICON CTrayWindow::CreateTrayIcon(double value)
trayBitmap.GetHICON(&icon); trayBitmap.GetHICON(&icon);
return icon; return icon;
} }
else if (m_MeterType == TRAY_METER_TYPE_BITMAP && (m_Bitmap || m_TrayIcons.size() > 0)) else if (m_MeterType == TRAY_METER_TYPE_BITMAP && (m_Bitmap || !m_TrayIcons.empty()))
{ {
if (m_TrayIcons.size() > 0) if (!m_TrayIcons.empty())
{ {
size_t frame = 0; size_t frame = 0;
size_t frameCount = m_TrayIcons.size(); size_t frameCount = m_TrayIcons.size();