From e4e088d37070bab69b1457621706d65472874243 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 21 Feb 2018 18:33:29 +0300 Subject: SmileyAdd: C++'11 iterators --- plugins/SmileyAdd/src/anim.cpp | 16 +++++------ plugins/SmileyAdd/src/customsmiley.cpp | 12 ++++---- plugins/SmileyAdd/src/dlgboxsubclass.cpp | 14 +++++----- plugins/SmileyAdd/src/options.cpp | 26 +++++++++--------- plugins/SmileyAdd/src/services.cpp | 24 ++++++++-------- plugins/SmileyAdd/src/smileyroutines.cpp | 8 +++--- plugins/SmileyAdd/src/smileys.cpp | 47 +++++++++++++++++--------------- plugins/SmileyAdd/src/smileys.h | 10 +++---- 8 files changed, 79 insertions(+), 78 deletions(-) (limited to 'plugins') diff --git a/plugins/SmileyAdd/src/anim.cpp b/plugins/SmileyAdd/src/anim.cpp index 4e04871e89..59ed0135ad 100644 --- a/plugins/SmileyAdd/src/anim.cpp +++ b/plugins/SmileyAdd/src/anim.cpp @@ -142,24 +142,24 @@ void AnimatedPack::Add(SmileyType *sml, RECT rect, bool clip) void AnimatedPack::Draw(HDC hdc) { - for (int i = 0; i < m_AniList.getCount(); i++) - m_AniList[i].Draw(hdc); + for (auto &it : m_AniList) + it->Draw(hdc); } void AnimatedPack::SetOffset(int off) { - for (int i = 0; i < m_AniList.getCount(); i++) - m_AniList[i].SetOffset(off, m_wsize); + for (auto &it : m_AniList) + it->SetOffset(off, m_wsize); } void AnimatedPack::SetSel(RECT &rect) { - for (int i = 0; i < m_AniList.getCount(); i++) - m_AniList[i].SetSel(rect.left, rect.top); + for (auto &it : m_AniList) + it->SetSel(rect.left, rect.top); } void AnimatedPack::ProcessTimerTick(HWND hwnd) { - for (int i = 0; i < m_AniList.getCount(); i++) - m_AniList[i].ProcessTimerTick(hwnd); + for (auto &it : m_AniList) + it->ProcessTimerTick(hwnd); } diff --git a/plugins/SmileyAdd/src/customsmiley.cpp b/plugins/SmileyAdd/src/customsmiley.cpp index 72690198d3..686560a9d0 100644 --- a/plugins/SmileyAdd/src/customsmiley.cpp +++ b/plugins/SmileyAdd/src/customsmiley.cpp @@ -51,9 +51,9 @@ bool SmileyPackCListType::AddSmiley(MCONTACT hContact, wchar_t *path) SmileyPackCType* SmileyPackCListType::GetSmileyPack(MCONTACT id) { - for (int i = 0; i < m_SmileyPacks.getCount(); i++) - if (m_SmileyPacks[i].GetId() == id) - return &m_SmileyPacks[i]; + for (auto &it : m_SmileyPacks) + if (it->GetId() == id) + return it; return nullptr; } @@ -131,9 +131,9 @@ bool SmileyPackCType::LoadSmiley(wchar_t *path) CMStringW name = dirs.Mid(slash + 1, dot - slash - 1); - for (int i = 0; i < m_SmileyList.getCount(); i++) - if (m_SmileyList[i].GetTriggerText() == name) { - m_SmileyList[i].LoadFromResource(dirs, 0); + for (auto &it : m_SmileyList) + if (it->GetTriggerText() == name) { + it->LoadFromResource(dirs, 0); return true; } diff --git a/plugins/SmileyAdd/src/dlgboxsubclass.cpp b/plugins/SmileyAdd/src/dlgboxsubclass.cpp index b502c72000..61964955f1 100644 --- a/plugins/SmileyAdd/src/dlgboxsubclass.cpp +++ b/plugins/SmileyAdd/src/dlgboxsubclass.cpp @@ -62,11 +62,11 @@ int UpdateSrmmDlg(WPARAM wParam, LPARAM) { mir_cslock lck(csWndList); - for (int i = 0; i < g_MsgWndList.getCount(); ++i) { - if (wParam == 0 || g_MsgWndList[i]->hContact == wParam) { - SendMessage(g_MsgWndList[i]->hwnd, WM_SETREDRAW, FALSE, 0); - SendMessage(g_MsgWndList[i]->hwnd, DM_OPTIONSAPPLIED, 0, 0); - SendMessage(g_MsgWndList[i]->hwnd, WM_SETREDRAW, TRUE, 0); + for (auto &it : g_MsgWndList) { + if (wParam == 0 || it->hContact == wParam) { + SendMessage(it->hwnd, WM_SETREDRAW, FALSE, 0); + SendMessage(it->hwnd, DM_OPTIONSAPPLIED, 0, 0); + SendMessage(it->hwnd, WM_SETREDRAW, TRUE, 0); } } return 0; @@ -256,7 +256,7 @@ void InstallDialogBoxHook(void) void RemoveDialogBoxHook(void) { mir_cslock lck(csWndList); - for (int i = 0; i < g_MsgWndList.getCount(); i++) - delete g_MsgWndList[i]; + for (auto &it : g_MsgWndList) + delete it; g_MsgWndList.destroy(); } diff --git a/plugins/SmileyAdd/src/options.cpp b/plugins/SmileyAdd/src/options.cpp index 84a84a3bb2..3f1551fd42 100644 --- a/plugins/SmileyAdd/src/options.cpp +++ b/plugins/SmileyAdd/src/options.cpp @@ -281,13 +281,13 @@ void OptionsDialogType::UpdateVisibleSmPackList(void) bool usePhysProto = IsDlgButtonChecked(m_hwndDialog, IDC_USEPHYSPROTO) == BST_CHECKED; SmileyCategoryListType::SmileyCategoryVectorType &smc = *tmpsmcat.GetSmileyCategoryList(); - for (int i = 0; i < smc.getCount(); i++) { - bool visiblecat = usePhysProto ? !smc[i].IsAcc() : !smc[i].IsPhysProto(); - bool visible = useOne ? !smc[i].IsProto() : visiblecat; + for (auto &it : smc) { + bool visiblecat = usePhysProto ? !it->IsAcc() : !it->IsPhysProto(); + bool visible = useOne ? !it->IsProto() : visiblecat; - if (!visible && smc[i].IsAcc() && !useOne) { + if (!visible && it->IsAcc() && !useOne) { CMStringW PhysProtoName = L"AllProto"; - CMStringW ProtoName = smc[i].GetName(); + CMStringW ProtoName = it->GetName(); DBVARIANT dbv; if (db_get_ws(NULL, _T2A(ProtoName.GetBuffer()), "AM_BaseProto", &dbv) == 0) { ProtoName = dbv.ptszVal; @@ -307,7 +307,7 @@ void OptionsDialogType::UpdateVisibleSmPackList(void) } } - smc[i].SetVisible(visible); + it->SetVisible(visible); } } @@ -388,12 +388,12 @@ void OptionsDialogType::InitDialog(void) tmpsmcat = g_SmileyCategories; SmileyCategoryListType::SmileyCategoryVectorType &smc = *g_SmileyCategories.GetSmileyCategoryList(); - for (int i = 0; i < smc.getCount(); i++) { + for (auto &it : smc) { HICON hIcon = nullptr; - if (smc[i].IsProto()) { - hIcon = (HICON)CallProtoService(_T2A(smc[i].GetName().c_str()), PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0); + if (it->IsProto()) { + hIcon = (HICON)CallProtoService(_T2A(it->GetName().c_str()), PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0); if (hIcon == nullptr || (INT_PTR)hIcon == CALLSERVICE_NOTFOUND) - hIcon = (HICON)CallProtoService(_T2A(smc[i].GetName().c_str()), PS_LOADICON, PLI_PROTOCOL, 0); + hIcon = (HICON)CallProtoService(_T2A(it->GetName().c_str()), PS_LOADICON, PLI_PROTOCOL, 0); } if (hIcon == nullptr || hIcon == (HICON)CALLSERVICE_NOTFOUND) hIcon = GetDefaultIcon(); @@ -445,9 +445,9 @@ void OptionsDialogType::ApplyChanges(void) // Cleanup database CMStringW empty; SmileyCategoryListType::SmileyCategoryVectorType &smc = *g_SmileyCategories.GetSmileyCategoryList(); - for (int i = 0; i < smc.getCount(); i++) - if (tmpsmcat.GetSmileyCategory(smc[i].GetName()) == nullptr) - opt.WritePackFileName(empty, smc[i].GetName()); + for (auto &it : smc) + if (tmpsmcat.GetSmileyCategory(it->GetName()) == nullptr) + opt.WritePackFileName(empty, it->GetName()); g_SmileyCategories = tmpsmcat; g_SmileyCategories.SaveSettings(); diff --git a/plugins/SmileyAdd/src/services.cpp b/plugins/SmileyAdd/src/services.cpp index 21305d4184..9cfacbd516 100644 --- a/plugins/SmileyAdd/src/services.cpp +++ b/plugins/SmileyAdd/src/services.cpp @@ -195,20 +195,20 @@ INT_PTR ParseTextBatch(WPARAM, LPARAM lParam) SMADD_BATCHPARSERES *res = new SMADD_BATCHPARSERES[smllist.getCount()]; SMADD_BATCHPARSERES *cres = res; - for (int j = 0; j < smllist.getCount(); j++) { - cres->startChar = smllist[j].loc.cpMin; - cres->size = smllist[j].loc.cpMax - smllist[j].loc.cpMin; - if (smllist[j].sml) { + for (auto &it : smllist) { + cres->startChar = it->loc.cpMin; + cres->size = it->loc.cpMax - it->loc.cpMin; + if (it->sml) { if (smre->flag & SAFL_PATH) - cres->filepath = smllist[j].sml->GetFilePath().c_str(); + cres->filepath = it->sml->GetFilePath().c_str(); else - cres->hIcon = smllist[j].sml->GetIconDup(); + cres->hIcon = it->sml->GetIconDup(); } else { if (smre->flag & SAFL_PATH) - cres->filepath = smllist[j].smlc->GetFilePath().c_str(); + cres->filepath = it->smlc->GetFilePath().c_str(); else - cres->hIcon = smllist[j].smlc->GetIcon(); + cres->hIcon = it->smlc->GetIcon(); } cres++; @@ -256,8 +256,8 @@ INT_PTR CustomCatMenu(WPARAM hContact, LPARAM lParam) NotifyEventHooks(hEvent1, hContact, 0); } - for (int i = 0; i < menuHandleArray.getCount(); i++) - Menu_RemoveItem((HGENMENU)menuHandleArray[i]); + for (auto &it : menuHandleArray) + Menu_RemoveItem((HGENMENU)it); menuHandleArray.destroy(); return TRUE; @@ -272,8 +272,8 @@ int RebuildContactMenu(WPARAM wParam, LPARAM) bool haveMenu = IsSmileyProto(protnam); if (haveMenu && opt.UseOneForAll) { unsigned cnt = 0; - for (int i = 0; i < smc.getCount(); i++) - cnt += smc[i].IsCustom(); + for (auto &it : smc) + cnt += it->IsCustom(); haveMenu = cnt != 0; } diff --git a/plugins/SmileyAdd/src/smileyroutines.cpp b/plugins/SmileyAdd/src/smileyroutines.cpp index 2741cab5d6..199c5e4a2b 100644 --- a/plugins/SmileyAdd/src/smileyroutines.cpp +++ b/plugins/SmileyAdd/src/smileyroutines.cpp @@ -52,14 +52,14 @@ void LookupAllSmileys(SmileyPackType *smileyPack, SmileyPackCType *smileyCPack, int i = 0; if (sml) - for (int j=0; j < sml->getCount(); j++) { - (*sml)[j].Find(tmpstr, smileys[i], false); + for (auto &it : *sml) { + it->Find(tmpstr, smileys[i], false); i++; } if (smlc) - for (int j=0; j < smlc->getCount(); j++) { - (*smlc)[j].Find(tmpstr, smileys[i], false); + for (auto &it : *smlc) { + it->Find(tmpstr, smileys[i], false); i++; } diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index b1d72a35b1..56fb2ddf14 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -109,8 +109,8 @@ void SmileyType::MoveToNextFrame() { m_index = m_xepimg->SelectNextFrame(m_index); - for (int i = 0; i < m_arSmileys.getCount(); i++) - m_arSmileys[i]->Draw(); + for (auto &it : m_arSmileys) + it->Draw(); SetFrameDelay(); // reset timer } @@ -260,18 +260,19 @@ void SmileyPackType::AddTriggersToSmileyLookup(void) m_SmileyLookup.insert(new SmileyLookup(timeRegEx, true, -1, emptystr)); for (int dist = 0; dist < m_SmileyList.getCount(); dist++) { - if (m_SmileyList[dist].IsRegEx()) { - SmileyLookup *dats = new SmileyLookup(m_SmileyList[dist].GetTriggerText(), true, dist, GetFilename()); + auto &p = m_SmileyList[dist]; + if (p.IsRegEx()) { + SmileyLookup *dats = new SmileyLookup(p.GetTriggerText(), true, dist, GetFilename()); if (dats->IsValid()) m_SmileyLookup.insert(dats); else errorFound = true; - if (m_SmileyList[dist].m_InsertText.IsEmpty()) - m_SmileyList[dist].m_InsertText = m_SmileyList[dist].m_ToolText; + if (p.m_InsertText.IsEmpty()) + p.m_InsertText = p.m_ToolText; } - else if (!m_SmileyList[dist].IsService()) { + else if (!p.IsService()) { bool first = true; - const CMStringW &text = m_SmileyList[dist].GetTriggerText(); + const CMStringW &text = p.GetTriggerText(); int iStart = 0; while (true) { CMStringW wszWord = text.Tokenize(L" \t", iStart); @@ -283,7 +284,7 @@ void SmileyPackType::AddTriggersToSmileyLookup(void) if (dats->IsValid()) { m_SmileyLookup.insert(dats); if (first) { - m_SmileyList[dist].m_InsertText = wszWord; + p.m_InsertText = wszWord; first = false; } } @@ -528,10 +529,11 @@ SmileyPackType* SmileyPackListType::GetSmileyPack(CMStringW &filename) CMStringW modpath; pathToAbsolute(filename, modpath); - for (int i = 0; i < m_SmileyPacks.getCount(); i++) { + for (auto &it : m_SmileyPacks) { CMStringW modpath1; - pathToAbsolute(m_SmileyPacks[i].GetFilename(), modpath1); - if (mir_wstrcmpi(modpath.c_str(), modpath1.c_str()) == 0) return &m_SmileyPacks[i]; + pathToAbsolute(it->GetFilename(), modpath1); + if (mir_wstrcmpi(modpath.c_str(), modpath1.c_str()) == 0) + return it; } return nullptr; } @@ -587,15 +589,15 @@ void SmileyCategoryListType::ClearAndLoadAll(void) { m_pSmileyPackStore->ClearAndFreeAll(); - for (int i = 0; i < m_SmileyCategories.getCount(); i++) - m_SmileyCategories[i].Load(); + for (auto &it : m_SmileyCategories) + it->Load(); } SmileyCategoryType* SmileyCategoryListType::GetSmileyCategory(const CMStringW &name) { - for (int i = 0; i < m_SmileyCategories.getCount(); i++) - if (name.CompareNoCase(m_SmileyCategories[i].GetName()) == 0) - return &m_SmileyCategories[i]; + for (auto &it : m_SmileyCategories) + if (name.CompareNoCase(it->GetName()) == 0) + return it; return nullptr; } @@ -614,11 +616,12 @@ SmileyPackType* SmileyCategoryListType::GetSmileyPack(CMStringW &categoryname) void SmileyCategoryListType::SaveSettings(void) { CMStringW catstr; - for (int i = 0; i < m_SmileyCategories.getCount(); i++) { - m_SmileyCategories[i].SaveSettings(); - if (m_SmileyCategories[i].IsCustom()) { - if (!catstr.IsEmpty()) catstr += '#'; - catstr += m_SmileyCategories[i].GetName(); + for (auto &it : m_SmileyCategories) { + it->SaveSettings(); + if (it->IsCustom()) { + if (!catstr.IsEmpty()) + catstr += '#'; + catstr += it->GetName(); } } opt.WriteCustomCategories(catstr); diff --git a/plugins/SmileyAdd/src/smileys.h b/plugins/SmileyAdd/src/smileys.h index 4e174987d0..c44f1858fb 100644 --- a/plugins/SmileyAdd/src/smileys.h +++ b/plugins/SmileyAdd/src/smileys.h @@ -112,17 +112,15 @@ template struct SMOBJLIST : public OBJLIST SMOBJLIST& operator += (const SMOBJLIST& lst) { - for (int i = 0; i < lst.getCount(); i++) { - T *p = new T(lst[i]); - insert(p); - } + for (auto &it : lst) + insert(new T(*it)); return *this; } void splice(SMOBJLIST &lst) { - for (int i = 0; i < lst.getCount(); i++) - insert(&lst[i]); + for (auto &it : lst) + insert(it); lst.LIST::destroy(); } }; -- cgit v1.2.3