diff --git a/daemon/connect/TlsSocket.cpp b/daemon/connect/TlsSocket.cpp index 787c021c..ed0eaf35 100644 --- a/daemon/connect/TlsSocket.cpp +++ b/daemon/connect/TlsSocket.cpp @@ -199,9 +199,9 @@ void TlsSocket::Final() #ifdef NEED_GCRYPT_LOCKING // fixing memory leak in gcryptlib - for (Mutexes::iterator it = g_GCryptLibMutexes->begin(); it != g_GCryptLibMutexes->end(); it++) + for (Mutex* mutex : *g_GCryptLibMutexes) { - delete *it; + delete mutex; } delete g_GCryptLibMutexes; #endif /* NEED_GCRYPT_LOCKING */ diff --git a/daemon/extension/NzbScript.cpp b/daemon/extension/NzbScript.cpp index 9c6708bf..5fc3078c 100644 --- a/daemon/extension/NzbScript.cpp +++ b/daemon/extension/NzbScript.cpp @@ -38,9 +38,8 @@ void NzbScriptController::PrepareEnvParameters(NzbParameterList* parameters, con { int prefixLen = stripPrefix ? strlen(stripPrefix) : 0; - for (NzbParameterList::iterator it = parameters->begin(); it != parameters->end(); it++) + for (NzbParameter& parameter : *parameters) { - NzbParameter& parameter = *it; const char* value = parameter.GetValue(); if (stripPrefix && !strncmp(parameter.GetName(), stripPrefix, prefixLen) && (int)strlen(parameter.GetName()) > prefixLen) @@ -73,10 +72,8 @@ void NzbScriptController::PrepareEnvScript(NzbParameterList* parameters, const c void NzbScriptController::ExecuteScriptList(const char* scriptList) { - for (ScriptConfig::Scripts::iterator it = g_ScriptConfig->GetScripts()->begin(); it != g_ScriptConfig->GetScripts()->end(); it++) + for (ScriptConfig::Script& script : *g_ScriptConfig->GetScripts()) { - ScriptConfig::Script& script = *it; - if (scriptList && *scriptList) { // split szScriptList into tokens diff --git a/daemon/extension/PostScript.cpp b/daemon/extension/PostScript.cpp index 827517e4..187e76d7 100644 --- a/daemon/extension/PostScript.cpp +++ b/daemon/extension/PostScript.cpp @@ -53,9 +53,8 @@ void PostScriptController::Run() // the locking is needed for accessing the members of NZBInfo DownloadQueue::Lock(); - for (NzbParameterList::iterator it = m_postInfo->GetNzbInfo()->GetParameters()->begin(); it != m_postInfo->GetNzbInfo()->GetParameters()->end(); it++) + for (NzbParameter& parameter : *m_postInfo->GetNzbInfo()->GetParameters()) { - NzbParameter& parameter = *it; const char* varname = parameter.GetName(); if (strlen(varname) > 0 && varname[0] != '*' && varname[strlen(varname)-1] == ':' && (!strcasecmp(parameter.GetValue(), "yes") || !strcasecmp(parameter.GetValue(), "on") || !strcasecmp(parameter.GetValue(), "1"))) @@ -171,10 +170,8 @@ void PostScriptController::PrepareParams(const char* scriptName) SetIntEnvVar("NZBPP_SUCCESSARTICLES", (int)m_postInfo->GetNzbInfo()->GetSuccessArticles()); SetIntEnvVar("NZBPP_FAILEDARTICLES", (int)m_postInfo->GetNzbInfo()->GetFailedArticles()); - for (ServerStatList::iterator it = m_postInfo->GetNzbInfo()->GetServerStats()->begin(); it != m_postInfo->GetNzbInfo()->GetServerStats()->end(); it++) + for (ServerStat& serverStat : *m_postInfo->GetNzbInfo()->GetServerStats()) { - ServerStat& serverStat = *it; - SetIntEnvVar(BString<1024>("NZBPP_SERVER%i_SUCCESSARTICLES", serverStat.GetServerId()), serverStat.GetSuccessArticles()); diff --git a/daemon/extension/QueueScript.cpp b/daemon/extension/QueueScript.cpp index b3fe1f17..c56bdc7e 100644 --- a/daemon/extension/QueueScript.cpp +++ b/daemon/extension/QueueScript.cpp @@ -234,18 +234,17 @@ QueueScriptCoordinator::QueueScriptCoordinator() QueueScriptCoordinator::~QueueScriptCoordinator() { delete m_curItem; - for (Queue::iterator it = m_queue.begin(); it != m_queue.end(); it++ ) + for (QueueItem* queueItem : m_queue) { - delete *it; + delete queueItem; } } void QueueScriptCoordinator::InitOptions() { m_hasQueueScripts = false; - for (ScriptConfig::Scripts::iterator it = g_ScriptConfig->GetScripts()->begin(); it != g_ScriptConfig->GetScripts()->end(); it++) + for (ScriptConfig::Script& script : *g_ScriptConfig->GetScripts()) { - ScriptConfig::Script& script = *it; if (script.GetQueueScript()) { m_hasQueueScripts = true; @@ -290,10 +289,8 @@ void QueueScriptCoordinator::EnqueueScript(NzbInfo* nzbInfo, EEvent event) return; } - for (ScriptConfig::Scripts::iterator it = g_ScriptConfig->GetScripts()->begin(); it != g_ScriptConfig->GetScripts()->end(); it++) + for (ScriptConfig::Script& script : *g_ScriptConfig->GetScripts()) { - ScriptConfig::Script& script = *it; - if (!script.GetQueueScript()) { continue; @@ -320,9 +317,8 @@ void QueueScriptCoordinator::EnqueueScript(NzbInfo* nzbInfo, EEvent event) // check post-processing-scripts if (!useScript) { - for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) + for (NzbParameter& parameter : *nzbInfo->GetParameters()) { - NzbParameter& parameter = *it; const char* varname = parameter.GetName(); if (strlen(varname) > 0 && varname[0] != '*' && varname[strlen(varname)-1] == ':' && (!strcasecmp(parameter.GetValue(), "yes") || @@ -348,9 +344,8 @@ void QueueScriptCoordinator::EnqueueScript(NzbInfo* nzbInfo, EEvent event) if (event == qeFileDownloaded) { // check if this script is already queued for this nzb - for (Queue::iterator it2 = m_queue.begin(); it2 != m_queue.end(); it2++) + for (QueueItem* queueItem : m_queue) { - QueueItem* queueItem = *it2; if (queueItem->GetNzbId() == nzbInfo->GetId() && queueItem->GetScript() == &script) { alreadyQueued = true; @@ -384,9 +379,8 @@ NzbInfo* QueueScriptCoordinator::FindNzbInfo(DownloadQueue* downloadQueue, int n NzbInfo* nzbInfo = downloadQueue->GetQueue()->Find(nzbId); if (!nzbInfo) { - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetNzbInfo() && historyInfo->GetNzbInfo()->GetId() == nzbId) { nzbInfo = historyInfo->GetNzbInfo(); @@ -465,9 +459,8 @@ bool QueueScriptCoordinator::HasJob(int nzbId, bool* active) } if (!working) { - for (Queue::iterator it = m_queue.begin(); it != m_queue.end(); it++) + for (QueueItem* queueItem : m_queue) { - QueueItem* queueItem = *it; working = queueItem->GetNzbId() == nzbId; if (working) { diff --git a/daemon/extension/ScriptConfig.cpp b/daemon/extension/ScriptConfig.cpp index 0f635e66..077858b9 100644 --- a/daemon/extension/ScriptConfig.cpp +++ b/daemon/extension/ScriptConfig.cpp @@ -139,10 +139,8 @@ bool ScriptConfig::SaveConfig(Options::OptEntries* optEntries) // write config file back to disk, replace old values of existing options with new values infile.Seek(0); - for (std::vector::iterator it = config.begin(); it != config.end(); it++) + for (CString& buf : config) { - CString& buf = *it; - const char* eq = strchr(buf, '='); if (eq && buf[0] != '#') { @@ -168,9 +166,8 @@ bool ScriptConfig::SaveConfig(Options::OptEntries* optEntries) } // write new options - for (Options::OptEntries::iterator it = optEntries->begin(); it != optEntries->end(); it++) + for (Options::OptEntry& optEntry : *optEntries) { - Options::OptEntry& optEntry = *it; std::set::iterator fit = writtenOptions.find(&optEntry); if (fit == writtenOptions.end()) { @@ -209,10 +206,8 @@ bool ScriptConfig::LoadConfigTemplates(ConfigTemplates* configTemplates) const int beginSignatureLen = strlen(BEGIN_SCRIPT_SIGNATURE); const int queueEventsSignatureLen = strlen(QUEUE_EVENTS_SIGNATURE); - for (Scripts::iterator it = scriptList.begin(); it != scriptList.end(); it++) + for (Script& script : scriptList) { - Script& script = *it; - DiskFile infile; if (!infile.Open(script.GetLocation(), DiskFile::omRead)) { @@ -405,19 +400,15 @@ void ScriptConfig::BuildScriptDisplayNames(Scripts* scripts) // trying to use short name without path and extension. // if there are other scripts with the same short name - using a longer name instead (with ot without extension) - for (Scripts::iterator it = scripts->begin(); it != scripts->end(); it++) + for (Script& script : *scripts) { - Script& script = *it; - BString<1024> shortName = script.GetName(); if (char* ext = strrchr(shortName, '.')) *ext = '\0'; // strip file extension const char* displayName = FileSystem::BaseFileName(shortName); - for (Scripts::iterator it2 = scripts->begin(); it2 != scripts->end(); it2++) + for (Script& script2 : *scripts) { - Script& script2 = *it2; - BString<1024> shortName2 = script2.GetName(); if (char* ext = strrchr(shortName2, '.')) *ext = '\0'; // strip file extension diff --git a/daemon/feed/FeedCoordinator.cpp b/daemon/feed/FeedCoordinator.cpp index c32966e6..def28b35 100644 --- a/daemon/feed/FeedCoordinator.cpp +++ b/daemon/feed/FeedCoordinator.cpp @@ -108,16 +108,16 @@ FeedCoordinator::~FeedCoordinator() g_Log->UnregisterDebuggable(this); debug("Deleting FeedDownloaders"); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (FeedDownloader* feedDownloader : m_activeDownloads) { - delete *it; + delete feedDownloader; } m_activeDownloads.clear(); debug("Deleting Feeds"); - for (Feeds::iterator it = m_feeds.begin(); it != m_feeds.end(); it++) + for (FeedInfo* feedInfo : m_feeds) { - delete *it; + delete feedInfo; } m_feeds.clear(); @@ -169,9 +169,8 @@ void FeedCoordinator::Run() { m_force = false; // check feed list and update feeds - for (Feeds::iterator it = m_feeds.begin(); it != m_feeds.end(); it++) + for (FeedInfo* feedInfo : m_feeds) { - FeedInfo* feedInfo = *it; if (((feedInfo->GetInterval() > 0 && (current - feedInfo->GetLastUpdate() >= feedInfo->GetInterval() * 60 || current < feedInfo->GetLastUpdate())) || @@ -228,9 +227,9 @@ void FeedCoordinator::Stop() debug("Stopping UrlDownloads"); m_downloadsMutex.Lock(); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (FeedDownloader* feedDownloader : m_activeDownloads) { - (*it)->Stop(); + feedDownloader->Stop(); } m_downloadsMutex.Unlock(); debug("UrlDownloads are notified"); @@ -281,9 +280,8 @@ void FeedCoordinator::LogDebugInfo() m_downloadsMutex.Lock(); info(" Active Downloads: %i", (int)m_activeDownloads.size()); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (FeedDownloader* feedDownloader : m_activeDownloads) { - FeedDownloader* feedDownloader = *it; feedDownloader->LogDebugInfo(); } m_downloadsMutex.Unlock(); @@ -388,9 +386,8 @@ void FeedCoordinator::FeedCompleted(FeedDownloader* feedDownloader) m_downloadsMutex.Unlock(); DownloadQueue* downloadQueue = DownloadQueue::Lock(); - for (NzbList::iterator it = addedNzbs.begin(); it != addedNzbs.end(); it++) + for (NzbInfo* nzbInfo : addedNzbs) { - NzbInfo* nzbInfo = *it; downloadQueue->GetQueue()->Add(nzbInfo, false); } downloadQueue->Save(); @@ -414,9 +411,8 @@ void FeedCoordinator::FilterFeed(FeedInfo* feedInfo, FeedItemInfos* feedItemInfo feedFilter = new FeedFilter(feedInfo->GetFilter()); } - for (FeedItemInfos::iterator it = feedItemInfos->begin(); it != feedItemInfos->end(); it++) + for (FeedItemInfo& feedItemInfo : *feedItemInfos) { - FeedItemInfo& feedItemInfo = *it; feedItemInfo.SetMatchStatus(FeedItemInfo::msAccepted); feedItemInfo.SetMatchRule(0); feedItemInfo.SetPauseNzb(feedInfo->GetPauseNzb()); @@ -444,9 +440,8 @@ void FeedCoordinator::ProcessFeed(FeedInfo* feedInfo, FeedItemInfos* feedItemInf bool firstFetch = feedInfo->GetLastUpdate() == 0; int added = 0; - for (FeedItemInfos::iterator it = feedItemInfos->begin(); it != feedItemInfos->end(); it++) + for (FeedItemInfo& feedItemInfo : *feedItemInfos) { - FeedItemInfo& feedItemInfo = *it; if (feedItemInfo.GetMatchStatus() == FeedItemInfo::msAccepted) { FeedHistoryInfo* feedHistoryInfo = m_feedHistory.Find(feedItemInfo.GetUrl()); @@ -546,9 +541,8 @@ bool FeedCoordinator::PreviewFeed(int id, const char* name, const char* url, con if (cacheTimeSec > 0 && *cacheId != '\0') { m_downloadsMutex.Lock(); - for (FeedCache::iterator it = m_feedCache.begin(); it != m_feedCache.end(); it++) + for (FeedCacheItem& feedCacheItem : m_feedCache) { - FeedCacheItem& feedCacheItem = *it; if (!strcmp(feedCacheItem.GetCacheId(), cacheId)) { feedCacheItem.SetLastUsage(Util::CurrentTime()); @@ -566,9 +560,8 @@ bool FeedCoordinator::PreviewFeed(int id, const char* name, const char* url, con m_downloadsMutex.Lock(); bool firstFetch = true; - for (Feeds::iterator it = m_feeds.begin(); it != m_feeds.end(); it++) + for (FeedInfo* feedInfo2 : m_feeds) { - FeedInfo* feedInfo2 = *it; if (!strcmp(feedInfo2->GetUrl(), feedInfo->GetUrl()) && !strcmp(feedInfo2->GetFilter(), feedInfo->GetFilter()) && feedInfo2->GetLastUpdate() > 0) @@ -611,9 +604,8 @@ bool FeedCoordinator::PreviewFeed(int id, const char* name, const char* url, con feedItemInfos->Retain(); delete feedFile; - for (FeedItemInfos::iterator it = feedItemInfos->begin(); it != feedItemInfos->end(); it++) + for (FeedItemInfo& feedItemInfo : *feedItemInfos) { - FeedItemInfo& feedItemInfo = *it; feedItemInfo.SetStatus(firstFetch && feedInfo->GetBacklog() ? FeedItemInfo::isBacklog : FeedItemInfo::isNew); FeedHistoryInfo* feedHistoryInfo = m_feedHistory.Find(feedItemInfo.GetUrl()); if (feedHistoryInfo) @@ -643,9 +635,8 @@ void FeedCoordinator::FetchFeed(int id) debug("FetchFeeds"); m_downloadsMutex.Lock(); - for (Feeds::iterator it = m_feeds.begin(); it != m_feeds.end(); it++) + for (FeedInfo* feedInfo : m_feeds) { - FeedInfo* feedInfo = *it; if (feedInfo->GetId() == id || id == 0) { feedInfo->SetFetch(true); @@ -708,9 +699,8 @@ void FeedCoordinator::CleanupHistory() time_t oldestUpdate = Util::CurrentTime(); - for (Feeds::iterator it = m_feeds.begin(); it != m_feeds.end(); it++) + for (FeedInfo* feedInfo : m_feeds) { - FeedInfo* feedInfo = *it; if (feedInfo->GetLastUpdate() < oldestUpdate) { oldestUpdate = feedInfo->GetLastUpdate(); @@ -746,15 +736,20 @@ void FeedCoordinator::CleanupCache() m_downloadsMutex.Lock(); time_t curTime = Util::CurrentTime(); - for (FeedCache::iterator it = m_feedCache.begin(); it != m_feedCache.end(); it++) + + for (FeedCache::iterator it = m_feedCache.begin(); it != m_feedCache.end(); ) { FeedCacheItem& feedCacheItem = *it; if (feedCacheItem.GetLastUsage() + feedCacheItem.GetCacheTimeSec() < curTime || feedCacheItem.GetLastUsage() > curTime) { debug("Deleting %s from feed cache", feedCacheItem.GetUrl()); - FeedCache::iterator cur = it--; - m_feedCache.erase(cur); + m_feedCache.erase(it); + it = m_feedCache.begin(); + } + else + { + it++; } } diff --git a/daemon/feed/FeedFilter.cpp b/daemon/feed/FeedFilter.cpp index 4c5a87f4..1e4f7af4 100644 --- a/daemon/feed/FeedFilter.cpp +++ b/daemon/feed/FeedFilter.cpp @@ -867,9 +867,8 @@ bool FeedFilter::Rule::MatchExpression(FeedItemInfo& feedItemInfo) char* expr = (char*)malloc(m_terms.size() + 1); int index = 0; - for (TermList::iterator it = m_terms.begin(); it != m_terms.end(); it++, index++) + for (Term& term : m_terms) { - Term& term = *it; switch (term.GetCommand()) { case fcOpeningBrace: @@ -888,6 +887,7 @@ bool FeedFilter::Rule::MatchExpression(FeedItemInfo& feedItemInfo) expr[index] = term.Match(feedItemInfo) ? 'T' : 'F'; break; } + index++; } expr[index] = '\0'; @@ -1008,9 +1008,8 @@ void FeedFilter::CompileRule(char* rulestr) void FeedFilter::Match(FeedItemInfo& feedItemInfo) { int index = 0; - for (RuleList::iterator it = m_rules.begin(); it != m_rules.end(); it++) + for (Rule& rule : m_rules) { - Rule& rule = *it; index++; if (rule.IsValid()) { diff --git a/daemon/feed/FeedInfo.cpp b/daemon/feed/FeedInfo.cpp index 7b4add2d..08a83ae8 100644 --- a/daemon/feed/FeedInfo.cpp +++ b/daemon/feed/FeedInfo.cpp @@ -51,9 +51,8 @@ FeedInfo::FeedInfo(int id, const char* name, const char* url, bool backlog, int FeedItemInfo::Attr* FeedItemInfo::Attributes::Find(const char* name) { - for (iterator it = begin(); it != end(); it++) + for (Attr& attr : *this) { - Attr& attr = *it; if (!strcasecmp(attr.GetName(), name)) { return &attr; @@ -222,9 +221,8 @@ void FeedHistory::Remove(const char* url) FeedHistoryInfo* FeedHistory::Find(const char* url) { - for (iterator it = begin(); it != end(); it++) + for (FeedHistoryInfo& feedHistoryInfo : *this) { - FeedHistoryInfo& feedHistoryInfo = *it; if (!strcmp(feedHistoryInfo.GetUrl(), url)) { return &feedHistoryInfo; diff --git a/daemon/frontend/Frontend.cpp b/daemon/frontend/Frontend.cpp index 6a135a16..bf9009bd 100644 --- a/daemon/frontend/Frontend.cpp +++ b/daemon/frontend/Frontend.cpp @@ -83,9 +83,8 @@ bool Frontend::PrepareData() DownloadQueue *downloadQueue = DownloadQueue::Lock(); m_postJobCount = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; m_postJobCount += nzbInfo->GetPostInfo() ? 1 : 0; } downloadQueue->CalcRemainingSize(&m_remainingSize, nullptr); diff --git a/daemon/frontend/NCursesFrontend.cpp b/daemon/frontend/NCursesFrontend.cpp index c6f28154..3e2f8faf 100644 --- a/daemon/frontend/NCursesFrontend.cpp +++ b/daemon/frontend/NCursesFrontend.cpp @@ -373,9 +373,8 @@ int NCursesFrontend::CalcQueueSize() } else { - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; queueSize += nzbInfo->GetFileList()->size(); } } @@ -696,17 +695,15 @@ void NCursesFrontend::PrintFileQueue() int pausedFiles = 0; int fileNum = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++, fileNum++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; - if (fileNum >= m_queueScrollOffset && fileNum < m_queueScrollOffset + m_queueWinHeight -1) { PrintFilename(fileInfo, lineNr++, fileNum == m_selectedQueueEntry); } + fileNum++; if (fileInfo->GetPaused()) { @@ -862,25 +859,25 @@ void NCursesFrontend::PrintGroupQueue() ResetColWidths(); int calcLineNr = lineNr; int i = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++, i++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; if (i >= m_queueScrollOffset && i < m_queueScrollOffset + m_queueWinHeight -1) { PrintGroupname(nzbInfo, calcLineNr++, false, true); } + i++; } int64 remaining = 0; int64 paused = 0; i = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++, i++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; if (i >= m_queueScrollOffset && i < m_queueScrollOffset + m_queueWinHeight -1) { PrintGroupname(nzbInfo, lineNr++, i == m_selectedQueueEntry, false); } + i++; remaining += nzbInfo->GetRemainingSize(); paused += nzbInfo->GetPausedSize(); } @@ -1057,20 +1054,19 @@ bool NCursesFrontend::EditQueue(DownloadQueue::EEditAction action, int offset) DownloadQueue* downloadQueue = LockQueue(); int fileNum = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++, fileNum++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { if (m_selectedQueueEntry == fileNum) { - FileInfo* fileInfo = *it2; ID = fileInfo->GetId(); if (action == DownloadQueue::eaFilePause) { action = !fileInfo->GetPaused() ? DownloadQueue::eaFilePause : DownloadQueue::eaFileResume; } } + fileNum++; } } diff --git a/daemon/main/Options.cpp b/daemon/main/Options.cpp index 69da064c..aef26a23 100644 --- a/daemon/main/Options.cpp +++ b/daemon/main/Options.cpp @@ -211,9 +211,8 @@ Options::OptEntry* Options::OptEntries::FindOption(const char* name) return nullptr; } - for (iterator it = begin(); it != end(); it++) + for (OptEntry& optEntry : *this) { - OptEntry& optEntry = *it; if (!strcasecmp(optEntry.GetName(), name)) { return &optEntry; @@ -231,9 +230,8 @@ Options::Category* Options::Categories::FindCategory(const char* name, bool sear return nullptr; } - for (iterator it = begin(); it != end(); it++) + for (Category& category : *this) { - Category& category = *it; if (!strcasecmp(category.GetName(), name)) { return &category; @@ -242,12 +240,10 @@ Options::Category* Options::Categories::FindCategory(const char* name, bool sear if (searchAliases) { - for (iterator it = begin(); it != end(); it++) + for (Category& category : *this) { - Category& category = *it; - for (NameList::iterator it2 = category.GetAliases()->begin(); it2 != category.GetAliases()->end(); it2++) + for (CString& alias : *category.GetAliases()) { - const char* alias = *it2; WildMask mask(alias); if (mask.Match(name)) { @@ -429,9 +425,8 @@ Options::~Options() void Options::Dump() { - for (OptEntries::iterator it = m_optEntries.begin(); it != m_optEntries.end(); it++) + for (OptEntry& optEntry : m_optEntries) { - OptEntry& optEntry = *it; printf("%s = \"%s\"\n", optEntry.GetName(), optEntry.GetValue()); } } @@ -1470,9 +1465,8 @@ void Options::LoadConfigFile() void Options::InitCommandLineOptions(CmdOptList* commandLineOptions) { - for (CmdOptList::iterator it = commandLineOptions->begin(); it != commandLineOptions->end(); it++) + for (const char* option : *commandLineOptions) { - const char* option = *it; SetOptionString(option); } } diff --git a/daemon/main/Scheduler.cpp b/daemon/main/Scheduler.cpp index 4077100f..a6900c6b 100644 --- a/daemon/main/Scheduler.cpp +++ b/daemon/main/Scheduler.cpp @@ -58,9 +58,9 @@ Scheduler::~Scheduler() { debug("Destroying Scheduler"); - for (TaskList::iterator it = m_taskList.begin(); it != m_taskList.end(); it++) + for (Task* task : m_taskList) { - delete *it; + delete task; } } @@ -126,9 +126,8 @@ void Scheduler::CheckTasks() m_lastCheck = current - 60*60*24*7; m_executeProcess = false; - for (TaskList::iterator it = m_taskList.begin(); it != m_taskList.end(); it++) + for (Task* task : m_taskList) { - Task* task = *it; task->m_lastExecuted = 0; } } @@ -150,9 +149,8 @@ void Scheduler::CheckTasks() while (loop <= localCurrent) { - for (TaskList::iterator it = m_taskList.begin(); it != m_taskList.end(); it++) + for (Task* task : m_taskList) { - Task* task = *it; if (task->m_lastExecuted != loop) { tm tmAppoint; @@ -280,13 +278,13 @@ void Scheduler::PrintLog() if (m_serverChanged) { int index = 0; - for (Servers::iterator it = g_ServerPool->GetServers()->begin(); it != g_ServerPool->GetServers()->end(); it++, index++) + for (NewsServer* server : *g_ServerPool->GetServers()) { - NewsServer* server = *it; if (server->GetActive() != m_serverStatusList[index]) { info("Scheduler: %s %s", server->GetActive() ? "activating" : "deactivating", server->GetName()); } + index++; } g_ServerPool->Changed(); } @@ -298,9 +296,8 @@ void Scheduler::EditServer(bool active, const char* serverList) while (const char* serverRef = tok.Next()) { int id = atoi(serverRef); - for (Servers::iterator it = g_ServerPool->GetServers()->begin(); it != g_ServerPool->GetServers()->end(); it++) + for (NewsServer* server : *g_ServerPool->GetServers()) { - NewsServer* server = *it; if ((id > 0 && server->GetId() == id) || !strcasecmp(server->GetName(), serverRef)) { @@ -309,9 +306,8 @@ void Scheduler::EditServer(bool active, const char* serverList) // store old server status for logging m_serverStatusList.clear(); m_serverStatusList.reserve(g_ServerPool->GetServers()->size()); - for (Servers::iterator it2 = g_ServerPool->GetServers()->begin(); it2 != g_ServerPool->GetServers()->end(); it2++) + for (NewsServer* server2 : *g_ServerPool->GetServers()) { - NewsServer* server2 = *it2; m_serverStatusList.push_back(server2->GetActive()); } } @@ -329,9 +325,8 @@ void Scheduler::FetchFeed(const char* feedList) while (const char* feedRef = tok.Next()) { int id = atoi(feedRef); - for (Feeds::iterator it = g_FeedCoordinator->GetFeeds()->begin(); it != g_FeedCoordinator->GetFeeds()->end(); it++) + for (FeedInfo* feed : *g_FeedCoordinator->GetFeeds()) { - FeedInfo* feed = *it; if (feed->GetId() == id || !strcasecmp(feed->GetName(), feedRef) || !strcasecmp("0", feedRef)) diff --git a/daemon/nntp/ArticleDownloader.cpp b/daemon/nntp/ArticleDownloader.cpp index 7ba58968..044143a9 100644 --- a/daemon/nntp/ArticleDownloader.cpp +++ b/daemon/nntp/ArticleDownloader.cpp @@ -217,17 +217,15 @@ void ArticleDownloader::Run() // if all servers from all levels were tried, break the loop with failure status bool allServersOnLevelFailed = true; - for (Servers::iterator it = g_ServerPool->GetServers()->begin(); it != g_ServerPool->GetServers()->end(); it++) + for (NewsServer* candidateServer : *g_ServerPool->GetServers()) { - NewsServer* candidateServer = *it; if (candidateServer->GetNormLevel() == level) { bool serverFailed = !candidateServer->GetActive() || candidateServer->GetMaxConnections() == 0; if (!serverFailed) { - for (Servers::iterator it = failedServers.begin(); it != failedServers.end(); it++) + for (NewsServer* ignoreServer : failedServers) { - NewsServer* ignoreServer = *it; if (ignoreServer == candidateServer || (ignoreServer->GetGroup() > 0 && ignoreServer->GetGroup() == candidateServer->GetGroup() && ignoreServer->GetNormLevel() == candidateServer->GetNormLevel())) @@ -303,9 +301,9 @@ ArticleDownloader::EStatus ArticleDownloader::Download() if (m_connection->GetNewsServer()->GetJoinGroup()) { // change group - for (FileInfo::Groups::iterator it = m_fileInfo->GetGroups()->begin(); it != m_fileInfo->GetGroups()->end(); it++) + for (CString& group : *m_fileInfo->GetGroups()) { - response = m_connection->JoinGroup(*it); + response = m_connection->JoinGroup(group); if (response && !strncmp(response, "2", 1)) { break; diff --git a/daemon/nntp/ArticleWriter.cpp b/daemon/nntp/ArticleWriter.cpp index 7b40f6ba..b249b2f3 100644 --- a/daemon/nntp/ArticleWriter.cpp +++ b/daemon/nntp/ArticleWriter.cpp @@ -411,9 +411,8 @@ void ArticleWriter::CompleteFileParts() buffer = (char*)malloc(BUFFER_SIZE); } - for (FileInfo::Articles::iterator it = m_fileInfo->GetArticles()->begin(); it != m_fileInfo->GetArticles()->end(); it++) + for (ArticleInfo* pa : *m_fileInfo->GetArticles()) { - ArticleInfo* pa = *it; if (pa->GetStatus() != ArticleInfo::aiFinished) { continue; @@ -522,9 +521,8 @@ void ArticleWriter::CompleteFileParts() if (!directWrite) { - for (FileInfo::Articles::iterator it = m_fileInfo->GetArticles()->begin(); it != m_fileInfo->GetArticles()->end(); it++) + for (ArticleInfo* pa : *m_fileInfo->GetArticles()) { - ArticleInfo* pa = *it; FileSystem::DeleteFile(pa->GetResultFilename()); } } @@ -594,9 +592,8 @@ void ArticleWriter::FlushCache() cachedArticles.reserve(m_fileInfo->GetArticles()->size()); g_ArticleCache->LockContent(); - for (FileInfo::Articles::iterator it = m_fileInfo->GetArticles()->begin(); it != m_fileInfo->GetArticles()->end(); it++) + for (ArticleInfo* pa : *m_fileInfo->GetArticles()) { - ArticleInfo* pa = *it; if (pa->GetSegmentContent()) { cachedArticles.push_back(pa); @@ -604,7 +601,7 @@ void ArticleWriter::FlushCache() } g_ArticleCache->UnlockContent(); - for (FileInfo::Articles::iterator it = cachedArticles.begin(); it != cachedArticles.end(); it++) + for (ArticleInfo* pa : cachedArticles) { if (m_fileInfo->GetDeleted()) { @@ -612,8 +609,6 @@ void ArticleWriter::FlushCache() break; } - ArticleInfo* pa = *it; - if (directWrite && !outfile.Active()) { if (!outfile.Open(m_fileInfo->GetOutputFilename(), DiskFile::omReadWrite)) @@ -700,10 +695,8 @@ bool ArticleWriter::MoveCompletedFiles(NzbInfo* nzbInfo, const char* oldDestDir) } // move already downloaded files to new destination - for (CompletedFileList::iterator it = nzbInfo->GetCompletedFiles()->begin(); it != nzbInfo->GetCompletedFiles()->end(); it++) + for (CompletedFile& completedFile : *nzbInfo->GetCompletedFiles()) { - CompletedFile& completedFile = *it; - BString<1024> oldFileName("%s%c%s", oldDestDir, (int)PATH_SEPARATOR, completedFile.GetFileName()); BString<1024> newFileName("%s%c%s", nzbInfo->GetDestDir(), (int)PATH_SEPARATOR, completedFile.GetFileName()); @@ -780,9 +773,13 @@ bool ArticleWriter::MoveCompletedFiles(NzbInfo* nzbInfo, const char* oldDestDir) { // check if there are pending writes into directory bool pendingWrites = false; - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end() && !pendingWrites; it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; + if (!pendingWrites) + { + break; + } + if (fileInfo->GetActiveDownloads() > 0) { fileInfo->LockOutputFile(); @@ -906,12 +903,15 @@ bool ArticleCache::CheckFlush(bool flushEverything) BString<1024> infoName; DownloadQueue* downloadQueue = DownloadQueue::Lock(); - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end() && !m_fileInfo; it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + if (m_fileInfo) + { + break; + } + + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; if (fileInfo->GetCachedArticles() > 0 && (fileInfo->GetActiveDownloads() == 0 || flushEverything)) { m_fileInfo = fileInfo; diff --git a/daemon/nntp/ServerPool.cpp b/daemon/nntp/ServerPool.cpp index 6ac07306..ef0af291 100644 --- a/daemon/nntp/ServerPool.cpp +++ b/daemon/nntp/ServerPool.cpp @@ -62,16 +62,16 @@ ServerPool::~ ServerPool() m_levels.clear(); - for (Servers::iterator it = m_servers.begin(); it != m_servers.end(); it++) + for (NewsServer* server : m_servers) { - delete *it; + delete server; } m_servers.clear(); m_sortedServers.clear(); - for (Connections::iterator it = m_connections.begin(); it != m_connections.end(); it++) + for (PooledConnection* connection : m_connections) { - delete *it; + delete connection; } m_connections.clear(); } @@ -101,9 +101,8 @@ void ServerPool::NormalizeLevels() // find minimum level int minLevel = m_sortedServers.front()->GetLevel(); - for (Servers::iterator it = m_sortedServers.begin(); it != m_sortedServers.end(); it++) + for (NewsServer* newsServer : m_sortedServers) { - NewsServer* newsServer = *it; if (newsServer->GetLevel() < minLevel) { minLevel = newsServer->GetLevel(); @@ -112,9 +111,8 @@ void ServerPool::NormalizeLevels() m_maxNormLevel = 0; int lastLevel = minLevel; - for (Servers::iterator it = m_sortedServers.begin(); it != m_sortedServers.end(); it++) + for (NewsServer* newsServer : m_sortedServers) { - NewsServer* newsServer = *it; if ((newsServer->GetActive() && newsServer->GetMaxConnections() > 0) || (newsServer->GetLevel() == minLevel)) { @@ -146,9 +144,8 @@ void ServerPool::InitConnections() NormalizeLevels(); m_levels.clear(); - for (Servers::iterator it = m_sortedServers.begin(); it != m_sortedServers.end(); it++) + for (NewsServer* newsServer : m_sortedServers) { - NewsServer* newsServer = *it; newsServer->SetBlockTime(0); int normLevel = newsServer->GetNormLevel(); if (newsServer->GetNormLevel() > -1) @@ -162,9 +159,8 @@ void ServerPool::InitConnections() { int connections = 0; - for (Connections::iterator it = m_connections.begin(); it != m_connections.end(); it++) + for (PooledConnection* connection : m_connections) { - PooledConnection* connection = *it; if (connection->GetNewsServer() == newsServer) { connections++; @@ -201,9 +197,8 @@ NntpConnection* ServerPool::GetConnection(int level, NewsServer* wantServer, Ser Connections candidates; candidates.reserve(m_connections.size()); - for (Connections::iterator it = m_connections.begin(); it != m_connections.end(); it++) + for (PooledConnection* candidateConnection : m_connections) { - PooledConnection* candidateConnection = *it; NewsServer* candidateServer = candidateConnection->GetNewsServer(); if (!candidateConnection->GetInUse() && candidateServer->GetActive() && candidateServer->GetNormLevel() == level && @@ -218,9 +213,8 @@ NntpConnection* ServerPool::GetConnection(int level, NewsServer* wantServer, Ser bool useConnection = true; if (ignoreServers && !wantServer) { - for (Servers::iterator it = ignoreServers->begin(); it != ignoreServers->end(); it++) + for (NewsServer* ignoreServer : *ignoreServers) { - NewsServer* ignoreServer = *it; if (ignoreServer == candidateServer || (ignoreServer->GetGroup() > 0 && ignoreServer->GetGroup() == candidateServer->GetGroup() && ignoreServer->GetNormLevel() == candidateServer->GetNormLevel())) @@ -339,9 +333,8 @@ void ServerPool::CloseUnusedConnections() // check if we have in-use connections on the level bool hasInUseConnections = false; int inactiveTime = 0; - for (Connections::iterator it = m_connections.begin(); it != m_connections.end(); it++) + for (PooledConnection* connection : m_connections) { - PooledConnection* connection = *it; if (connection->GetNewsServer()->GetNormLevel() == level) { if (connection->GetInUse()) @@ -364,9 +357,8 @@ void ServerPool::CloseUnusedConnections() // expired - close all connections of the level. if (!hasInUseConnections && inactiveTime > CONNECTION_HOLD_SECODNS) { - for (Connections::iterator it = m_connections.begin(); it != m_connections.end(); it++) + for (PooledConnection* connection : m_connections) { - PooledConnection* connection = *it; if (connection->GetNewsServer()->GetNormLevel() == level && connection->GetStatus() == Connection::csConnected) { @@ -399,9 +391,8 @@ void ServerPool::LogDebugInfo() time_t curTime = Util::CurrentTime(); info(" Servers: %i", (int)m_servers.size()); - for (Servers::iterator it = m_servers.begin(); it != m_servers.end(); it++) + for (NewsServer* newsServer : m_servers) { - NewsServer* newsServer = *it; info(" %i) %s (%s): Level=%i, NormLevel=%i, BlockSec=%i", newsServer->GetId(), newsServer->GetName(), newsServer->GetHost(), newsServer->GetLevel(), newsServer->GetNormLevel(), newsServer->GetBlockTime() && newsServer->GetBlockTime() + m_retryInterval > curTime ? @@ -410,16 +401,15 @@ void ServerPool::LogDebugInfo() info(" Levels: %i", (int)m_levels.size()); int index = 0; - for (Levels::iterator it = m_levels.begin(); it != m_levels.end(); it++, index++) + for (int size : m_levels) { - int size = *it; info(" %i: Free connections=%i", index, size); + index++; } info(" Connections: %i", (int)m_connections.size()); - for (Connections::iterator it = m_connections.begin(); it != m_connections.end(); it++) + for (PooledConnection* connection : m_connections) { - PooledConnection* connection = *it; info(" %i) %s (%s): Level=%i, NormLevel=%i, InUse:%i", connection->GetNewsServer()->GetId(), connection->GetNewsServer()->GetName(), connection->GetNewsServer()->GetHost(), connection->GetNewsServer()->GetLevel(), connection->GetNewsServer()->GetNormLevel(), diff --git a/daemon/nntp/StatMeter.cpp b/daemon/nntp/StatMeter.cpp index 421af0ca..ce34d9ed 100644 --- a/daemon/nntp/StatMeter.cpp +++ b/daemon/nntp/StatMeter.cpp @@ -445,11 +445,11 @@ void StatMeter::LogDebugInfo() m_volumeMutex.Lock(); int index = 0; - for (ServerVolumes::iterator it = m_serverVolumes.begin(); it != m_serverVolumes.end(); it++, index++) + for (ServerVolume& serverVolume : m_serverVolumes) { - ServerVolume& serverVolume = *it; info(" ServerVolume %i", index); serverVolume.LogDebugInfo(); + index++; } m_volumeMutex.Unlock(); } @@ -473,9 +473,8 @@ ServerVolumes* StatMeter::LockServerVolumes() m_volumeMutex.Lock(); // update slots - for (ServerVolumes::iterator it = m_serverVolumes.begin(); it != m_serverVolumes.end(); it++) + for (ServerVolume& serverVolume : m_serverVolumes) { - ServerVolume& serverVolume = *it; serverVolume.AddData(0); } @@ -506,9 +505,8 @@ bool StatMeter::Load(bool* perfectServerMatch) bool ok = g_DiskState->LoadStats(g_ServerPool->GetServers(), &m_serverVolumes, perfectServerMatch); - for (ServerVolumes::iterator it = m_serverVolumes.begin(); it != m_serverVolumes.end(); it++) + for (ServerVolume& serverVolume : m_serverVolumes) { - ServerVolume& serverVolume = *it; serverVolume.CalcSlots(serverVolume.GetDataTime() + g_Options->GetLocalTimeOffset()); } diff --git a/daemon/postprocess/ParChecker.cpp b/daemon/postprocess/ParChecker.cpp index 6165c3b0..697acd96 100644 --- a/daemon/postprocess/ParChecker.cpp +++ b/daemon/postprocess/ParChecker.cpp @@ -211,10 +211,9 @@ void Repairer::EndRepair() { if (m_parallel) { - for (Threads::iterator it = m_threads.begin(); it != m_threads.end(); it++) + for (Thread* thread : m_threads) { - RepairThread* repairThread = (RepairThread*)*it; - repairThread->Stop(); + thread->Stop(); } #ifdef WIN32 @@ -233,9 +232,9 @@ bool Repairer::RepairData(Par2::u32 inputindex, size_t blocklength) for (Par2::u32 outputindex = 0; outputindex < missingblockcount; ) { bool jobAdded = false; - for (Threads::iterator it = m_threads.begin(); it != m_threads.end(); it++) + for (Thread* thread : m_threads) { - RepairThread* repairThread = (RepairThread*)*it; + RepairThread* repairThread = (RepairThread*)thread; if (!repairThread->IsWorking()) { repairThread->RepairBlock(inputindex, outputindex, blocklength); @@ -261,9 +260,9 @@ bool Repairer::RepairData(Par2::u32 inputindex, size_t blocklength) while (working) { working = false; - for (Threads::iterator it = m_threads.begin(); it != m_threads.end(); it++) + for (Thread* thread : m_threads) { - RepairThread* repairThread = (RepairThread*)*it; + RepairThread* repairThread = (RepairThread*)thread; if (repairThread->IsWorking()) { working = true; @@ -417,9 +416,8 @@ ParChecker::EStatus ParChecker::RunParCheckAll() m_cancelled = false; m_parFull = true; - for (ParParser::ParFileList::iterator it = fileList.begin(); it != fileList.end(); it++) + for (CString& parFilename : fileList) { - CString& parFilename = *it; debug("Found par: %s", *parFilename); if (!IsStopped() && !m_cancelled) @@ -782,10 +780,9 @@ bool ParChecker::LoadMorePars() m_queuedParFiles.clear(); m_queuedParFilesMutex.Unlock(); - for (FileList::iterator it = moreFiles.begin(); it != moreFiles.end() ;it++) + for (CString& parFilename : moreFiles) { - const char* parFilename = *it; - bool loadedOK = ((Repairer*)m_repairer)->LoadPacketsFromFile(parFilename); + bool loadedOK = ((Repairer*)m_repairer)->LoadPacketsFromFile(*parFilename); if (loadedOK) { PrintMessage(Message::mkInfo, "File %s successfully loaded for par-check", FileSystem::BaseFileName(parFilename)); @@ -823,11 +820,8 @@ bool ParChecker::AddSplittedFragments() { if (strcmp(filename, "_brokenlog.txt") && !IsParredFile(filename) && !IsProcessedFile(filename)) { - for (std::vector::iterator it = ((Repairer*)m_repairer)->sourcefiles.begin(); - it != ((Repairer*)m_repairer)->sourcefiles.end(); it++) + for (Par2::Par2RepairerSourceFile *sourcefile : ((Repairer*)m_repairer)->sourcefiles) { - Par2::Par2RepairerSourceFile *sourcefile = *it; - std::string target = sourcefile->TargetFileName(); const char* filename2 = target.c_str(); const char* basename2 = FileSystem::BaseFileName(filename2); @@ -887,9 +881,8 @@ bool ParChecker::AddDupeFiles() { int wasBlocksMissing = ((Repairer*)m_repairer)->missingblockcount; - for (DupeSourceList::iterator it = m_dupeSources.begin(); it != m_dupeSources.end(); it++) + for (DupeSource& dupeSource : m_dupeSources) { - DupeSource& dupeSource = *it; if (((Repairer*)m_repairer)->missingblockcount > 0 && FileSystem::DirectoryExists(dupeSource.GetDirectory())) { int wasBlocksMissing2 = ((Repairer*)m_repairer)->missingblockcount; @@ -1002,9 +995,8 @@ bool ParChecker::AddExtraFiles(bool onlyMissing, bool externalDir, const char* d bool ParChecker::IsProcessedFile(const char* filename) { - for (FileList::iterator it = m_processedFiles.begin(); it != m_processedFiles.end(); it++) + for (CString& processedFilename : m_processedFiles) { - const char* processedFilename = *it; if (!strcasecmp(FileSystem::BaseFileName(processedFilename), filename)) { return true; @@ -1114,10 +1106,8 @@ void ParChecker::signal_done(std::string str, int available, int total) const char* filename = str.c_str(); bool fileExists = true; - for (std::vector::iterator it = ((Repairer*)m_repairer)->sourcefiles.begin(); - it != ((Repairer*)m_repairer)->sourcefiles.end(); it++) + for (Par2::Par2RepairerSourceFile* sourcefile : ((Repairer*)m_repairer)->sourcefiles) { - Par2::Par2RepairerSourceFile *sourcefile = *it; if (sourcefile && !strcmp(filename, FileSystem::BaseFileName(sourcefile->TargetFileName().c_str())) && !sourcefile->GetTargetExists()) { @@ -1155,11 +1145,8 @@ void ParChecker::signal_done(std::string str, int available, int total) */ void ParChecker::CheckEmptyFiles() { - for (std::vector::iterator it = ((Repairer*)m_repairer)->sourcefiles.begin(); - it != ((Repairer*)m_repairer)->sourcefiles.end(); it++) + for (Par2::Par2RepairerSourceFile* sourcefile : ((Repairer*)m_repairer)->sourcefiles) { - Par2::Par2RepairerSourceFile* sourcefile = *it; - if (sourcefile && sourcefile->GetDescriptionPacket()) { // GetDescriptionPacket()->FileName() returns a temp string object, which we need to hold for a while @@ -1234,10 +1221,8 @@ void ParChecker::SaveSourceList() { // Buliding a list of DiskFile-objects, marked as source-files - for (std::vector::iterator it = ((Repairer*)m_repairer)->sourcefiles.begin(); - it != ((Repairer*)m_repairer)->sourcefiles.end(); it++) + for (Par2::Par2RepairerSourceFile* sourcefile : ((Repairer*)m_repairer)->sourcefiles) { - Par2::Par2RepairerSourceFile* sourcefile = (Par2::Par2RepairerSourceFile*)*it; vector::iterator it2 = sourcefile->SourceBlocks(); for (int i = 0; i < (int)sourcefile->BlockCount(); i++, it2++) { @@ -1258,15 +1243,13 @@ void ParChecker::DeleteLeftovers() // corresponding target-files. If not - the source file was replaced. In this case // the DiskFile-object points to the renamed bak-file, which we can delete. - for (SourceList::iterator it = m_sourceFiles.begin(); it != m_sourceFiles.end(); it++) + for (void* sf : m_sourceFiles) { - Par2::DiskFile* sourceFile = (Par2::DiskFile*)*it; + Par2::DiskFile* sourceFile = (Par2::DiskFile*)sf; bool found = false; - for (std::vector::iterator it2 = ((Repairer*)m_repairer)->sourcefiles.begin(); - it2 != ((Repairer*)m_repairer)->sourcefiles.end(); it2++) + for (Par2::Par2RepairerSourceFile* sourcefile : ((Repairer*)m_repairer)->sourcefiles) { - Par2::Par2RepairerSourceFile* sourcefile = *it2; if (sourcefile->GetTargetFile() == sourceFile) { found = true; @@ -1363,9 +1346,8 @@ ParChecker::EFileStatus ParChecker::VerifyDataFile(void* diskfile, void* sourcef if (!hashEntry || hashEntry->SourceFile() != sourceFile || hashEntry->IsSet()) { // no match found, revert back the changes made by "pHashEntry->SetBlock" - for (std::deque::iterator it = undoList.begin(); it != undoList.end(); it++) + for (const Par2::VerificationHashEntry* undoEntry : undoList) { - const Par2::VerificationHashEntry* undoEntry = *it; undoEntry->SetBlock(nullptr, 0); } return fsUnknown; @@ -1428,9 +1410,8 @@ bool ParChecker::VerifyPartialDataFile(void* diskfile, void* sourcefile, Segment bool blockOK = false; bool blockEndFound = false; Par2::u64 curOffset = 0; - for (SegmentList::iterator it = segments->begin(); it != segments->end(); it++) + for (Segment& segment : *segments) { - Segment& segment = *it; if (!blockOK && segment.GetSuccess() && segment.GetOffset() <= blockStart && segment.GetOffset() + segment.GetSize() >= blockStart) { @@ -1524,10 +1505,8 @@ bool ParChecker::SmartCalcFileRangeCrc(DiskFile& file, int64 start, int64 end, S { uint32 downloadCrc = 0; bool started = false; - for (SegmentList::iterator it = segments->begin(); it != segments->end(); it++) + for (Segment& segment : *segments) { - Segment& segment = *it; - if (!started && segment.GetOffset() > start) { // read start of range from file diff --git a/daemon/postprocess/ParCoordinator.cpp b/daemon/postprocess/ParCoordinator.cpp index 01c3186f..d33dc6b6 100644 --- a/daemon/postprocess/ParCoordinator.cpp +++ b/daemon/postprocess/ParCoordinator.cpp @@ -62,9 +62,8 @@ void ParCoordinator::PostParChecker::RegisterParredFile(const char* filename) bool ParCoordinator::PostParChecker::IsParredFile(const char* filename) { - for (PostInfo::ParredFiles::iterator it = m_postInfo->GetParredFiles()->begin(); it != m_postInfo->GetParredFiles()->end(); it++) + for (CString& parredFile : *m_postInfo->GetParredFiles()) { - const char* parredFile = *it; if (!strcasecmp(parredFile, filename)) { return true; @@ -78,9 +77,8 @@ ParChecker::EFileStatus ParCoordinator::PostParChecker::FindFileCrc(const char* { CompletedFile* completedFile = nullptr; - for (CompletedFileList::iterator it = m_postInfo->GetNzbInfo()->GetCompletedFiles()->begin(); it != m_postInfo->GetNzbInfo()->GetCompletedFiles()->end(); it++) + for (CompletedFile& completedFile2 : *m_postInfo->GetNzbInfo()->GetCompletedFiles()) { - CompletedFile& completedFile2 = *it; if (!strcasecmp(completedFile2.GetFileName(), filename)) { completedFile = &completedFile2; @@ -107,9 +105,8 @@ ParChecker::EFileStatus ParCoordinator::PostParChecker::FindFileCrc(const char* return ParChecker::fsUnknown; } - for (FileInfo::Articles::iterator it = tmpFileInfo->GetArticles()->begin(); it != tmpFileInfo->GetArticles()->end(); it++) + for (ArticleInfo* pa : *tmpFileInfo->GetArticles()) { - ArticleInfo* pa = *it; segments->emplace_back(pa->GetStatus() == ArticleInfo::aiFinished, pa->GetSegmentOffset(), pa->GetSegmentSize(), pa->GetCrc()); } @@ -137,9 +134,8 @@ void ParCoordinator::PostParChecker::RequestDupeSources(DupeSourceList* dupeSour PostDupeMatcher dupeMatcher(m_postInfo); PrintMessage(Message::mkInfo, "Checking %s for dupe scan usability", m_postInfo->GetNzbInfo()->GetName()); bool sizeComparisonPossible = dupeMatcher.Prepare(); - for (NzbList::iterator it = dupeList.begin(); it != dupeList.end(); it++) + for (NzbInfo* dupeNzbInfo : dupeList) { - NzbInfo* dupeNzbInfo = *it; if (sizeComparisonPossible) { PrintMessage(Message::mkInfo, "Checking %s for dupe scan usability", FileSystem::BaseFileName(dupeNzbInfo->GetDestDir())); @@ -165,14 +161,12 @@ void ParCoordinator::PostParChecker::StatDupeSources(DupeSourceList* dupeSourceL DownloadQueue* downloadQueue = DownloadQueue::Lock(); int totalExtraParBlocks = 0; - for (DupeSourceList::iterator it = dupeSourceList->begin(); it != dupeSourceList->end(); it++) + for (DupeSource& dupeSource : *dupeSourceList) { - DupeSource& dupeSource = *it; if (dupeSource.GetUsedBlocks() > 0) { - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetKind() == HistoryInfo::hkNzb && historyInfo->GetNzbInfo()->GetId() == dupeSource.GetId()) { @@ -215,9 +209,8 @@ void ParCoordinator::PostParRenamer::RegisterParredFile(const char* filename) */ void ParCoordinator::PostParRenamer::RegisterRenamedFile(const char* oldFilename, const char* newFileName) { - for (CompletedFileList::iterator it = m_postInfo->GetNzbInfo()->GetCompletedFiles()->begin(); it != m_postInfo->GetNzbInfo()->GetCompletedFiles()->end(); it++) + for (CompletedFile& completedFile : *m_postInfo->GetNzbInfo()->GetCompletedFiles()) { - CompletedFile& completedFile = *it; if (!strcasecmp(completedFile.GetFileName(), oldFilename)) { completedFile.SetFileName(newFileName); @@ -499,9 +492,8 @@ bool ParCoordinator::RequestMorePars(NzbInfo* nzbInfo, const char* parFilename, } bool hasUnpausedParFiles = false; - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; if (fileInfo->GetParFile() && !fileInfo->GetPaused()) { hasUnpausedParFiles = true; @@ -539,9 +531,8 @@ void ParCoordinator::FindPars(DownloadQueue* downloadQueue, NzbInfo* nzbInfo, co mainBaseFilename.Set(baseParFilename, mainBaseLen); for (char* p = mainBaseFilename; *p; p++) *p = tolower(*p); // convert string to lowercase - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; int blockCount = 0; if (ParParser::ParseParFilename(fileInfo->GetFilename(), nullptr, &blockCount) && blockCount > 0) @@ -572,9 +563,8 @@ void ParCoordinator::FindPars(DownloadQueue* downloadQueue, NzbInfo* nzbInfo, co // check if file is not in the list already if (useFile) { - for (Blocks::iterator it = blocks.begin(); it != blocks.end(); it++) + for (BlockInfo& blockInfo : blocks) { - BlockInfo& blockInfo = *it; if (blockInfo.m_fileInfo == fileInfo) { alreadyAdded = true; diff --git a/daemon/postprocess/ParParser.cpp b/daemon/postprocess/ParParser.cpp index fac94267..fc2ab1f6 100644 --- a/daemon/postprocess/ParParser.cpp +++ b/daemon/postprocess/ParParser.cpp @@ -47,9 +47,8 @@ bool ParParser::FindMainPars(const char* path, ParFileList* fileList) // check if the base file already added to list bool exists = false; - for (ParFileList::iterator it = fileList->begin(); it != fileList->end(); it++) + for (CString& filename2 : *fileList) { - const char* filename2 = *it; exists = SameParCollection(filename, filename2); if (exists) { diff --git a/daemon/postprocess/ParRenamer.cpp b/daemon/postprocess/ParRenamer.cpp index 2353f42b..a5e91efc 100644 --- a/daemon/postprocess/ParRenamer.cpp +++ b/daemon/postprocess/ParRenamer.cpp @@ -76,9 +76,8 @@ void ParRenamer::Run() BuildDirList(m_destDir); - for (DirList::iterator it = m_dirList.begin(); it != m_dirList.end(); it++) + for (CString& destDir : m_dirList) { - CString& destDir = *it; debug("Checking %s", *destDir); m_fileHashList.clear(); LoadParFiles(destDir); @@ -146,9 +145,8 @@ void ParRenamer::LoadParFiles(const char* destDir) ParParser::ParFileList parFileList; ParParser::FindMainPars(destDir, &parFileList); - for (ParParser::ParFileList::iterator it = parFileList.begin(); it != parFileList.end(); it++) + for (CString& parFilename : parFileList) { - CString& parFilename = *it; BString<1024> fullParFilename("%s%c%s", destDir, PATH_SEPARATOR, *parFilename); LoadParFile(fullParFilename); } @@ -165,14 +163,14 @@ void ParRenamer::LoadParFile(const char* parFilename) return; } - for (map::iterator it = repairer->sourcefilemap.begin(); it != repairer->sourcefilemap.end(); it++) + for (std::pair& entry : repairer->sourcefilemap) { if (m_cancelled) { break; } - Par2::Par2RepairerSourceFile* sourceFile = (*it).second; + Par2::Par2RepairerSourceFile* sourceFile = entry.second; if (!sourceFile || !sourceFile->GetDescriptionPacket()) { PrintMessage(Message::mkWarning, "Damaged par2-file detected: %s", parFilename); @@ -217,9 +215,8 @@ void ParRenamer::CheckFiles(const char* destDir, bool renamePars) void ParRenamer::CheckMissing() { - for (FileHashList::iterator it = m_fileHashList.begin(); it != m_fileHashList.end(); it++) + for (FileHash& fileHash : m_fileHashList) { - FileHash& fileHash = *it; if (!fileHash.GetFileExists()) { if (Util::MatchFileExt(fileHash.GetFilename(), g_Options->GetParIgnoreExt(), ",;")) @@ -290,9 +287,8 @@ void ParRenamer::CheckRegularFile(const char* destDir, const char* filename) debug("file: %s; hash16k: %s", FileSystem::BaseFileName(filename), hash16k.print().c_str()); - for (FileHashList::iterator it = m_fileHashList.begin(); it != m_fileHashList.end(); it++) + for (FileHash& fileHash : m_fileHashList) { - FileHash& fileHash = *it; if (!strcmp(fileHash.GetHash(), hash16k.print().c_str())) { debug("Found correct filename: %s", fileHash.GetFilename()); diff --git a/daemon/postprocess/PrePostProcessor.cpp b/daemon/postprocess/PrePostProcessor.cpp index 9bdf6625..2c814752 100644 --- a/daemon/postprocess/PrePostProcessor.cpp +++ b/daemon/postprocess/PrePostProcessor.cpp @@ -425,9 +425,8 @@ NzbInfo* PrePostProcessor::GetNextJob(DownloadQueue* downloadQueue) { NzbInfo* nzbInfo = nullptr; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo1: *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo1 = *it; if (nzbInfo1->GetPostInfo() && !g_QueueScriptCoordinator->HasJob(nzbInfo1->GetId(), nullptr) && (!nzbInfo || nzbInfo1->GetPriority() > nzbInfo->GetPriority()) && (!g_Options->GetPausePostProcess() || nzbInfo1->GetForcePriority())) @@ -446,9 +445,8 @@ NzbInfo* PrePostProcessor::GetNextJob(DownloadQueue* downloadQueue) */ void PrePostProcessor::SanitisePostQueue(DownloadQueue* downloadQueue) { - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; PostInfo* postInfo = nzbInfo->GetPostInfo(); if (postInfo) { @@ -682,9 +680,8 @@ bool PrePostProcessor::IsNzbFileCompleted(NzbInfo* nzbInfo, bool ignorePausedPar { int deleted = 0; - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; if (fileInfo->GetDeleted()) { deleted++; @@ -707,9 +704,8 @@ bool PrePostProcessor::IsNzbFileDownloading(NzbInfo* nzbInfo) return true; } - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; if (!fileInfo->GetPaused()) { return true; @@ -750,13 +746,10 @@ bool PrePostProcessor::PostQueueDelete(DownloadQueue* downloadQueue, IdList* idL { bool ok = false; - for (IdList::iterator itId = idList->begin(); itId != idList->end(); itId++) + for (int id : *idList) { - int id = *itId; - - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo: *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; PostInfo* postInfo = nzbInfo->GetPostInfo(); if (postInfo && nzbInfo->GetId() == id) { diff --git a/daemon/queue/DiskState.cpp b/daemon/queue/DiskState.cpp index 4c728a71..27f0acb8 100644 --- a/daemon/queue/DiskState.cpp +++ b/daemon/queue/DiskState.cpp @@ -346,9 +346,8 @@ error: void DiskState::CompleteNzbList12(DownloadQueue* downloadQueue, NzbList* nzbList, int formatVersion) { // put all NZBs referenced from file queue into pDownloadQueue->GetQueue() - for (NzbList::iterator it = nzbList->begin(); it != nzbList->end(); it++) + for (NzbInfo* nzbInfo: *nzbList) { - NzbInfo* nzbInfo = *it; downloadQueue->GetQueue()->push_back(nzbInfo); } @@ -359,9 +358,8 @@ void DiskState::CompleteNzbList12(DownloadQueue* downloadQueue, NzbList* nzbList // here we renumber NZBIDs in order to keep them low. NzbInfo::ResetGenId(false); int id = 1; - for (NzbList::iterator it = nzbList->begin(); it != nzbList->end(); it++) + for (NzbInfo* nzbInfo : *nzbList) { - NzbInfo* nzbInfo = *it; nzbInfo->SetId(id++); } } @@ -371,10 +369,8 @@ void DiskState::CompleteDupList12(DownloadQueue* downloadQueue, int formatVersio { NzbInfo::ResetGenId(true); - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; - if (historyInfo->GetKind() == HistoryInfo::hkDup) { historyInfo->GetDupInfo()->SetId(NzbInfo::GenerateId()); @@ -387,9 +383,8 @@ void DiskState::SaveNzbQueue(DownloadQueue* downloadQueue, DiskFile& outfile) debug("Saving nzb list to disk"); outfile.Print("%i\n", (int)downloadQueue->GetQueue()->size()); - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; SaveNzbInfo(nzbInfo, outfile); } } @@ -465,24 +460,21 @@ void DiskState::SaveNzbInfo(NzbInfo* nzbInfo, DiskFile& outfile) nzbInfo->GetParSec(), nzbInfo->GetRepairSec(), nzbInfo->GetUnpackSec()); outfile.Print("%i\n", (int)nzbInfo->GetCompletedFiles()->size()); - for (CompletedFileList::iterator it = nzbInfo->GetCompletedFiles()->begin(); it != nzbInfo->GetCompletedFiles()->end(); it++) + for (CompletedFile& completedFile : *nzbInfo->GetCompletedFiles()) { - CompletedFile& completedFile = *it; outfile.Print("%i,%i,%u,%s\n", completedFile.GetId(), (int)completedFile.GetStatus(), completedFile.GetCrc(), completedFile.GetFileName()); } outfile.Print("%i\n", (int)nzbInfo->GetParameters()->size()); - for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) + for (NzbParameter& parameter : *nzbInfo->GetParameters()) { - NzbParameter& parameter = *it; outfile.Print("%s=%s\n", parameter.GetName(), parameter.GetValue()); } outfile.Print("%i\n", (int)nzbInfo->GetScriptStatuses()->size()); - for (ScriptStatusList::iterator it = nzbInfo->GetScriptStatuses()->begin(); it != nzbInfo->GetScriptStatuses()->end(); it++) + for (ScriptStatus& scriptStatus : *nzbInfo->GetScriptStatuses()) { - ScriptStatus& scriptStatus = *it; outfile.Print("%i,%s\n", scriptStatus.GetStatus(), scriptStatus.GetName()); } @@ -490,18 +482,16 @@ void DiskState::SaveNzbInfo(NzbInfo* nzbInfo, DiskFile& outfile) // save file-infos int size = 0; - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; if (!fileInfo->GetDeleted()) { size++; } } outfile.Print("%i\n", size); - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; if (!fileInfo->GetDeleted()) { outfile.Print("%i,%i,%i,%i\n", fileInfo->GetId(), (int)fileInfo->GetPaused(), @@ -1074,9 +1064,8 @@ error: void DiskState::SaveServerStats(ServerStatList* serverStatList, DiskFile& outfile) { outfile.Print("%i\n", (int)serverStatList->size()); - for (ServerStatList::iterator it = serverStatList->begin(); it != serverStatList->end(); it++) + for (ServerStat& serverStat : *serverStatList) { - ServerStat& serverStat = *it; outfile.Print("%i,%i,%i\n", serverStat.GetServerId(), serverStat.GetSuccessArticles(), serverStat.GetFailedArticles()); } } @@ -1093,9 +1082,8 @@ bool DiskState::LoadServerStats(ServerStatList* serverStatList, Servers* servers if (servers) { // find server (id could change if config file was edited) - for (Servers::iterator it = servers->begin(); it != servers->end(); it++) + for (NewsServer* newsServer : *servers) { - NewsServer* newsServer = *it; if (newsServer->GetStateId() == serverId) { serverStatList->StatOp(newsServer->GetId(), successArticles, failedArticles, ServerStatList::soSet); @@ -1145,15 +1133,14 @@ bool DiskState::SaveFileInfo(FileInfo* fileInfo, const char* filename) outfile.Print("%i,%i\n", fileInfo->GetTotalArticles(), fileInfo->GetMissedArticles()); outfile.Print("%i\n", (int)fileInfo->GetGroups()->size()); - for (FileInfo::Groups::iterator it = fileInfo->GetGroups()->begin(); it != fileInfo->GetGroups()->end(); it++) + for (CString& group : *fileInfo->GetGroups()) { - outfile.Print("%s\n", **it); + outfile.Print("%s\n", *group); } outfile.Print("%i\n", (int)fileInfo->GetArticles()->size()); - for (FileInfo::Articles::iterator it = fileInfo->GetArticles()->begin(); it != fileInfo->GetArticles()->end(); it++) + for (ArticleInfo* articleInfo : *fileInfo->GetArticles()) { - ArticleInfo* articleInfo = *it; outfile.Print("%i,%i\n", articleInfo->GetPartNumber(), articleInfo->GetSize()); outfile.Print("%s\n", articleInfo->GetMessageId()); } @@ -1310,9 +1297,8 @@ bool DiskState::SaveFileState(FileInfo* fileInfo, bool completed) SaveServerStats(fileInfo->GetServerStats(), outfile); outfile.Print("%i\n", (int)fileInfo->GetArticles()->size()); - for (FileInfo::Articles::iterator it = fileInfo->GetArticles()->begin(); it != fileInfo->GetArticles()->end(); it++) + for (ArticleInfo* articleInfo : *fileInfo->GetArticles()) { - ArticleInfo* articleInfo = *it; outfile.Print("%i,%u,%i,%u\n", (int)articleInfo->GetStatus(), (uint32)articleInfo->GetSegmentOffset(), articleInfo->GetSegmentSize(), (uint32)articleInfo->GetCrc()); } @@ -1428,17 +1414,15 @@ error: void DiskState::DiscardFiles(NzbInfo* nzbInfo) { - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; DiscardFile(fileInfo, true, true, true); } BString<1024> filename; - for (CompletedFileList::iterator it = nzbInfo->GetCompletedFiles()->begin(); it != nzbInfo->GetCompletedFiles()->end(); it++) + for (CompletedFile& completedFile : *nzbInfo->GetCompletedFiles()) { - CompletedFile& completedFile = *it; if (completedFile.GetStatus() != CompletedFile::cfSuccess && completedFile.GetId() > 0) { filename.Format("%s%i", g_Options->GetQueueDir(), completedFile.GetId()); @@ -1571,9 +1555,8 @@ bool DiskState::LoadPostQueue5(DownloadQueue* downloadQueue, NzbList* nzbList) // find NZBInfo based on NZBFilename NzbInfo* nzbInfo = nullptr; - for (NzbList::iterator it = nzbList->begin(); it != nzbList->end(); it++) + for (NzbInfo* nzbInfo2 : *nzbList) { - NzbInfo* nzbInfo2 = *it; if (!strcmp(nzbInfo2->GetFilename(), buf)) { nzbInfo = nzbInfo2; @@ -1829,10 +1812,8 @@ void DiskState::SaveHistory(DownloadQueue* downloadQueue, DiskFile& outfile) debug("Saving history to disk"); outfile.Print("%i\n", (int)downloadQueue->GetHistory()->size()); - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; - outfile.Print("%i,%i,%i\n", historyInfo->GetId(), (int)historyInfo->GetKind(), (int)historyInfo->GetTime()); if (historyInfo->GetKind() == HistoryInfo::hkNzb || historyInfo->GetKind() == HistoryInfo::hkUrl) @@ -1952,9 +1933,8 @@ error: int DiskState::FindNzbInfoIndex(NzbList* nzbList, NzbInfo* nzbInfo) { int nzbIndex = 0; - for (NzbList::iterator it = nzbList->begin(); it != nzbList->end(); it++) + for (NzbInfo* nzbInfo2 : *nzbList) { - NzbInfo* nzbInfo2 = *it; nzbIndex++; if (nzbInfo2 == nzbInfo) { @@ -1969,9 +1949,8 @@ int DiskState::FindNzbInfoIndex(NzbList* nzbList, NzbInfo* nzbInfo) */ NzbInfo* DiskState::FindNzbInfo(DownloadQueue* downloadQueue, int id) { - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; if (nzbInfo->GetId() == id) { return nzbInfo; @@ -2144,10 +2123,8 @@ bool DiskState::SaveFeedStatus(Feeds* feeds, DiskFile& outfile) debug("Saving feed status to disk"); outfile.Print("%i\n", (int)feeds->size()); - for (Feeds::iterator it = feeds->begin(); it != feeds->end(); it++) + for (FeedInfo* feedInfo : *feeds) { - FeedInfo* feedInfo = *it; - outfile.Print("%s\n", feedInfo->GetUrl()); outfile.Print("%u\n", feedInfo->GetFilterHash()); outfile.Print("%i\n", (int)feedInfo->GetLastUpdate()); @@ -2184,10 +2161,8 @@ bool DiskState::LoadFeedStatus(Feeds* feeds, DiskFile& infile, int formatVersion int lastUpdate = 0; if (fscanf(infile, "%i\n", &lastUpdate) != 1) goto error; - for (Feeds::iterator it = feeds->begin(); it != feeds->end(); it++) + for (FeedInfo* feedInfo : *feeds) { - FeedInfo* feedInfo = *it; - if (!strcmp(feedInfo->GetUrl(), url) && ((formatVersion == 1) || (formatVersion == 2 && !strcmp(feedInfo->GetFilter(), filter)) || @@ -2210,10 +2185,8 @@ bool DiskState::SaveFeedHistory(FeedHistory* feedHistory, DiskFile& outfile) debug("Saving feed history to disk"); outfile.Print("%i\n", (int)feedHistory->size()); - for (FeedHistory::iterator it = feedHistory->begin(); it != feedHistory->end(); it++) + for (FeedHistoryInfo& feedHistoryInfo : *feedHistory) { - FeedHistoryInfo& feedHistoryInfo = *it; - outfile.Print("%i,%i\n", (int)feedHistoryInfo.GetStatus(), (int)feedHistoryInfo.GetLastSeen()); outfile.Print("%s\n", feedHistoryInfo.GetUrl()); } @@ -2252,17 +2225,14 @@ error: void DiskState::CalcCriticalHealth(NzbList* nzbList) { // build list of old NZBs which do not have critical health calculated - for (NzbList::iterator it = nzbList->begin(); it != nzbList->end(); it++) + for (NzbInfo* nzbInfo : *nzbList) { - NzbInfo* nzbInfo = *it; if (nzbInfo->CalcCriticalHealth(false) == 1000) { debug("Calculating critical health for %s", nzbInfo->GetName()); - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; - BString<1024> loFileName; loFileName = fileInfo->GetFilename(); for (char* p = loFileName; *p; p++) *p = tolower(*p); // convert string to lowercase @@ -2280,15 +2250,13 @@ void DiskState::CalcCriticalHealth(NzbList* nzbList) void DiskState::CalcFileStats(DownloadQueue* downloadQueue, int formatVersion) { - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; CalcNzbFileStats(nzbInfo, formatVersion); } - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetKind() == HistoryInfo::hkNzb) { CalcNzbFileStats(historyInfo->GetNzbInfo(), formatVersion); @@ -2309,10 +2277,8 @@ void DiskState::CalcNzbFileStats(NzbInfo* nzbInfo, int formatVersion) int64 parSuccessSize = 0; int64 parFailedSize = 0; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; - remainingSize += fileInfo->GetRemainingSize(); successArticles += fileInfo->GetSuccessArticles(); failedArticles += fileInfo->GetFailedArticles(); @@ -2366,12 +2332,10 @@ bool DiskState::LoadAllFileStates(DownloadQueue* downloadQueue, Servers* servers { if (g_Options->GetContinuePartial() && !cacheWasActive) { - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; if (fileInfo->GetId() == id) { if (!LoadArticles(fileInfo)) goto error; @@ -2493,10 +2457,8 @@ bool DiskState::SaveServerInfo(Servers* servers, DiskFile& outfile) debug("Saving server info to disk"); outfile.Print("%i\n", (int)servers->size()); - for (Servers::iterator it = servers->begin(); it != servers->end(); it++) + for (NewsServer* newsServer : *servers) { - NewsServer* newsServer = *it; - outfile.Print("%s\n", newsServer->GetName()); outfile.Print("%s\n", newsServer->GetHost()); outfile.Print("%i\n", newsServer->GetPort()); @@ -2589,9 +2551,8 @@ void FindCandidates(NewsServer* newsServer, ServerRefList* refs, ECriteria crite void MatchServers(Servers* servers, ServerRefList* serverRefs) { // Step 1: trying perfect match - for (Servers::iterator it = servers->begin(); it != servers->end(); it++) + for (NewsServer* newsServer : *servers) { - NewsServer* newsServer = *it; ServerRefList matchedRefs; matchedRefs.insert(matchedRefs.begin(), serverRefs->begin(), serverRefs->end()); FindCandidates(newsServer, &matchedRefs, name, false); @@ -2609,9 +2570,8 @@ void MatchServers(Servers* servers, ServerRefList* serverRefs) } // Step 2: matching host, port, username and server-name - for (Servers::iterator it = servers->begin(); it != servers->end(); it++) + for (NewsServer* newsServer : *servers) { - NewsServer* newsServer = *it; if (!newsServer->GetStateId()) { ServerRefList matchedRefs; @@ -2688,17 +2648,15 @@ bool DiskState::LoadServerInfo(Servers* servers, DiskFile& infile, int formatVer MatchServers(servers, &serverRefs); - for (ServerRefList::iterator it = serverRefs.begin(); it != serverRefs.end(); it++) + for (ServerRef* ref : serverRefs) { - ServerRef* ref = *it; *perfectMatch = *perfectMatch && ref->GetPerfect(); - delete *it; + delete ref; } debug("******** MATCHING NEWS-SERVERS **********"); - for (Servers::iterator it = servers->begin(); it != servers->end(); it++) + for (NewsServer* newsServer : *servers) { - NewsServer* newsServer = *it; *perfectMatch = *perfectMatch && newsServer->GetStateId(); debug("Server %i -> %i", newsServer->GetId(), newsServer->GetStateId()); debug("Server %i.Name: %s", newsServer->GetId(), newsServer->GetName()); @@ -2712,9 +2670,9 @@ bool DiskState::LoadServerInfo(Servers* servers, DiskFile& infile, int formatVer error: error("Error reading server info from disk"); - for (ServerRefList::iterator it = serverRefs.begin(); it != serverRefs.end(); it++) + for (ServerRef* ref : serverRefs) { - delete *it; + delete ref; } return false; @@ -2725,10 +2683,8 @@ bool DiskState::SaveVolumeStat(ServerVolumes* serverVolumes, DiskFile& outfile) debug("Saving volume stats to disk"); outfile.Print("%i\n", (int)serverVolumes->size()); - for (ServerVolumes::iterator it = serverVolumes->begin(); it != serverVolumes->end(); it++) + for (ServerVolume& serverVolume : *serverVolumes) { - ServerVolume& serverVolume = *it; - outfile.Print("%i,%i,%i\n", serverVolume.GetFirstDay(), (int)serverVolume.GetDataTime(), (int)serverVolume.GetCustomTime()); uint32 High1, Low1, High2, Low2; @@ -2743,9 +2699,8 @@ bool DiskState::SaveVolumeStat(ServerVolumes* serverVolumes, DiskFile& outfile) ServerVolume::VolumeArray* volumeArray = VolumeArrays[i]; outfile.Print("%i\n", (int)volumeArray->size()); - for (ServerVolume::VolumeArray::iterator it2 = volumeArray->begin(); it2 != volumeArray->end(); it2++) + for (int64 bytes : *volumeArray) { - int64 bytes = *it2; Util::SplitInt64(bytes, &High1, &Low1); outfile.Print("%u,%u\n", High1, Low1); } @@ -2771,9 +2726,8 @@ bool DiskState::LoadVolumeStat(Servers* servers, ServerVolumes* serverVolumes, D } else { - for (Servers::iterator it = servers->begin(); it != servers->end(); it++) + for (NewsServer* newsServer : *servers) { - NewsServer* newsServer = *it; if (newsServer->GetStateId() == i) { serverVolume = &serverVolumes->at(newsServer->GetId()); diff --git a/daemon/queue/DownloadInfo.cpp b/daemon/queue/DownloadInfo.cpp index 238a07d8..887e11dd 100644 --- a/daemon/queue/DownloadInfo.cpp +++ b/daemon/queue/DownloadInfo.cpp @@ -76,9 +76,8 @@ void NzbParameterList::SetParameter(const char* name, const char* value) NzbParameter* NzbParameterList::Find(const char* name, bool caseSensitive) { - for (iterator it = begin(); it != end(); it++) + for (NzbParameter& parameter : *this) { - NzbParameter& parameter = *it; if ((caseSensitive && !strcmp(parameter.GetName(), name)) || (!caseSensitive && !strcasecmp(parameter.GetName(), name))) { @@ -91,9 +90,8 @@ NzbParameter* NzbParameterList::Find(const char* name, bool caseSensitive) void NzbParameterList::CopyFrom(NzbParameterList* sourceParameters) { - for (iterator it = sourceParameters->begin(); it != sourceParameters->end(); it++) + for (NzbParameter& parameter : *sourceParameters) { - NzbParameter& parameter = *it; SetParameter(parameter.GetName(), parameter.GetValue()); } } @@ -103,9 +101,8 @@ ScriptStatus::EStatus ScriptStatusList::CalcTotalStatus() { ScriptStatus::EStatus status = ScriptStatus::srNone; - for (iterator it = begin(); it != end(); it++) + for (ScriptStatus& scriptStatus : *this) { - ScriptStatus& scriptStatus = *it; // Failure-Status overrides Success-Status if ((scriptStatus.GetStatus() == ScriptStatus::srSuccess && status == ScriptStatus::srNone) || (scriptStatus.GetStatus() == ScriptStatus::srFailure)) @@ -121,9 +118,8 @@ ScriptStatus::EStatus ScriptStatusList::CalcTotalStatus() void ServerStatList::StatOp(int serverId, int successArticles, int failedArticles, EStatOperation statOperation) { ServerStat* serverStat = nullptr; - for (iterator it = begin(); it != end(); it++) + for (ServerStat& serverStat1 : *this) { - ServerStat& serverStat1 = *it; if (serverStat1.GetServerId() == serverId) { serverStat = &serverStat1; @@ -158,9 +154,8 @@ void ServerStatList::StatOp(int serverId, int successArticles, int failedArticle void ServerStatList::ListOp(ServerStatList* serverStats, EStatOperation statOperation) { - for (iterator it = serverStats->begin(); it != serverStats->end(); it++) + for (ServerStat& serverStat : *serverStats) { - ServerStat& serverStat = *it; StatOp(serverStat.GetServerId(), serverStat.GetSuccessArticles(), serverStat.GetFailedArticles(), statOperation); } } @@ -440,9 +435,8 @@ void NzbInfo::UpdateMinMaxTime() m_maxTime = 0; bool first = true; - for (FileList::iterator it = m_fileList.begin(); it != m_fileList.end(); it++) + for (FileInfo* fileInfo : m_fileList) { - FileInfo* fileInfo = *it; if (first) { m_minTime = fileInfo->GetTime(); @@ -542,9 +536,8 @@ void NzbInfo::CopyFileList(NzbInfo* srcNzbInfo) { m_fileList.Clear(); - for (FileList::iterator it = srcNzbInfo->GetFileList()->begin(); it != srcNzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *srcNzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; fileInfo->SetNzbInfo(this); m_fileList.push_back(fileInfo); } @@ -778,9 +771,9 @@ NzbList::~NzbList() void NzbList::Clear() { - for (iterator it = begin(); it != end(); it++) + for (NzbInfo* nzbInfo : *this) { - delete *it; + delete nzbInfo; } clear(); } @@ -808,9 +801,8 @@ void NzbList::Remove(NzbInfo* nzbInfo) NzbInfo* NzbList::Find(int id) { - for (iterator it = begin(); it != end(); it++) + for (NzbInfo* nzbInfo : *this) { - NzbInfo* nzbInfo = *it; if (nzbInfo->GetId() == id) { return nzbInfo; @@ -898,9 +890,9 @@ FileInfo::~ FileInfo() void FileInfo::ClearArticles() { - for (Articles::iterator it = m_articles.begin(); it != m_articles.end() ;it++) + for (ArticleInfo* articleInfo : m_articles) { - delete *it; + delete articleInfo; } m_articles.clear(); } @@ -978,9 +970,9 @@ FileList::~FileList() void FileList::Clear() { - for (iterator it = begin(); it != end(); it++) + for (FileInfo* fileInfo : *this) { - delete *it; + delete fileInfo; } clear(); } @@ -1113,17 +1105,16 @@ const char* HistoryInfo::GetName() HistoryList::~HistoryList() { - for (iterator it = begin(); it != end(); it++) + for (HistoryInfo* historyInfo : *this) { - delete *it; + delete historyInfo; } } HistoryInfo* HistoryList::Find(int id) { - for (iterator it = begin(); it != end(); it++) + for (HistoryInfo* historyInfo : *this) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetId() == id) { return historyInfo; @@ -1150,12 +1141,10 @@ void DownloadQueue::CalcRemainingSize(int64* remaining, int64* remainingForced) int64 remainingSize = 0; int64 remainingForcedSize = 0; - for (NzbList::iterator it = m_queue.begin(); it != m_queue.end(); it++) + for (NzbInfo* nzbInfo : m_queue) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; if (!fileInfo->GetPaused() && !fileInfo->GetDeleted()) { remainingSize += fileInfo->GetRemainingSize(); diff --git a/daemon/queue/DupeCoordinator.cpp b/daemon/queue/DupeCoordinator.cpp index 5729f294..0eb8dbe3 100644 --- a/daemon/queue/DupeCoordinator.cpp +++ b/daemon/queue/DupeCoordinator.cpp @@ -58,9 +58,8 @@ void DupeCoordinator::NzbFound(DownloadQueue* downloadQueue, NzbInfo* nzbInfo) debug("Checking duplicates for %s", nzbInfo->GetName()); // find duplicates in download queue with exactly same content - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* queuedNzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* queuedNzbInfo = *it; bool sameContent = (nzbInfo->GetFullContentHash() > 0 && nzbInfo->GetFullContentHash() == queuedNzbInfo->GetFullContentHash()) || (nzbInfo->GetFilteredContentHash() > 0 && @@ -103,9 +102,8 @@ void DupeCoordinator::NzbFound(DownloadQueue* downloadQueue, NzbInfo* nzbInfo) // take these properties from this item if (Util::EmptyStr(nzbInfo->GetDupeKey()) && nzbInfo->GetDupeScore() == 0) { - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* queuedNzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* queuedNzbInfo = *it; if (!strcmp(queuedNzbInfo->GetName(), nzbInfo->GetName()) && (!Util::EmptyStr(queuedNzbInfo->GetDupeKey()) || queuedNzbInfo->GetDupeScore() != 0)) { @@ -119,9 +117,8 @@ void DupeCoordinator::NzbFound(DownloadQueue* downloadQueue, NzbInfo* nzbInfo) } if (Util::EmptyStr(nzbInfo->GetDupeKey()) && nzbInfo->GetDupeScore() == 0) { - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetKind() == HistoryInfo::hkNzb && !strcmp(historyInfo->GetNzbInfo()->GetName(), nzbInfo->GetName()) && (!Util::EmptyStr(historyInfo->GetNzbInfo()->GetDupeKey()) || historyInfo->GetNzbInfo()->GetDupeScore() != 0)) @@ -155,10 +152,8 @@ void DupeCoordinator::NzbFound(DownloadQueue* downloadQueue, NzbInfo* nzbInfo) // find duplicates in history having exactly same content // also: nzb-files having duplicates marked as good are skipped // also (only in score mode): nzb-files having success-duplicates in dup-history but not having duplicates in recent history are skipped - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; - if (historyInfo->GetKind() == HistoryInfo::hkNzb && ((nzbInfo->GetFullContentHash() > 0 && nzbInfo->GetFullContentHash() == historyInfo->GetNzbInfo()->GetFullContentHash()) || @@ -214,9 +209,8 @@ void DupeCoordinator::NzbFound(DownloadQueue* downloadQueue, NzbInfo* nzbInfo) if (!sameContent && !good && nzbInfo->GetDupeMode() == dmScore) { // nzb-files having success-duplicates in recent history (with different content) are added to history for backup - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetKind() == HistoryInfo::hkNzb && historyInfo->GetNzbInfo()->GetDupeMode() != dmForce && SameNameOrKey(historyInfo->GetNzbInfo()->GetName(), historyInfo->GetNzbInfo()->GetDupeKey(), @@ -328,9 +322,8 @@ void DupeCoordinator::ReturnBestDupe(DownloadQueue* downloadQueue, NzbInfo* nzbI // check if history (recent or dup) has other success-duplicates or good-duplicates bool dupeFound = false; int historyScore = 0; - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; bool goodDupe = false; if (historyInfo->GetKind() == HistoryInfo::hkNzb && @@ -370,9 +363,8 @@ void DupeCoordinator::ReturnBestDupe(DownloadQueue* downloadQueue, NzbInfo* nzbI // check if duplicates exist in download queue bool queueDupe = false; int queueScore = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* queuedNzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* queuedNzbInfo = *it; if (queuedNzbInfo != nzbInfo && queuedNzbInfo->GetKind() == NzbInfo::nkNzb && queuedNzbInfo->GetDupeMode() != dmForce && @@ -387,9 +379,8 @@ void DupeCoordinator::ReturnBestDupe(DownloadQueue* downloadQueue, NzbInfo* nzbI // find dupe-backup with highest score, whose score is also higher than other // success-duplicates and higher than already queued items HistoryInfo* historyDupe = nullptr; - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetKind() == HistoryInfo::hkNzb && historyInfo->GetNzbInfo()->GetDupeMode() != dmForce && historyInfo->GetNzbInfo()->GetDeleteStatus() == NzbInfo::dsDupe && @@ -507,9 +498,8 @@ DupeCoordinator::EDupeStatus DupeCoordinator::GetDupeStatus(DownloadQueue* downl EDupeStatus statuses = dsNone; // find duplicates in download queue - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; if (SameNameOrKey(name, dupeKey, nzbInfo->GetName(), nzbInfo->GetDupeKey())) { if (nzbInfo->GetSuccessArticles() + nzbInfo->GetFailedArticles() > 0) @@ -524,10 +514,8 @@ DupeCoordinator::EDupeStatus DupeCoordinator::GetDupeStatus(DownloadQueue* downl } // find duplicates in history - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; - if (historyInfo->GetKind() == HistoryInfo::hkNzb && SameNameOrKey(name, dupeKey, historyInfo->GetNzbInfo()->GetName(), historyInfo->GetNzbInfo()->GetDupeKey())) { @@ -573,10 +561,8 @@ void DupeCoordinator::ListHistoryDupes(DownloadQueue* downloadQueue, NzbInfo* nz } // find duplicates in history - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; - if (historyInfo->GetKind() == HistoryInfo::hkNzb && historyInfo->GetNzbInfo()->GetDupeMode() != dmForce && SameNameOrKey(historyInfo->GetNzbInfo()->GetName(), historyInfo->GetNzbInfo()->GetDupeKey(), diff --git a/daemon/queue/HistoryCoordinator.cpp b/daemon/queue/HistoryCoordinator.cpp index 561ab610..8c6c8697 100644 --- a/daemon/queue/HistoryCoordinator.cpp +++ b/daemon/queue/HistoryCoordinator.cpp @@ -229,9 +229,8 @@ void HistoryCoordinator::PrepareEdit(DownloadQueue* downloadQueue, IdList* idLis // this will later (on second step) avoid moving other items to download queue, if they are marked bad too. if (action == DownloadQueue::eaHistoryMarkBad) { - for (IdList::iterator itId = idList->begin(); itId != idList->end(); itId++) + for (int id : *idList) { - int id = *itId; HistoryInfo* historyInfo = downloadQueue->GetHistory()->Find(id); if (historyInfo && historyInfo->GetKind() == HistoryInfo::hkNzb) { @@ -246,9 +245,8 @@ bool HistoryCoordinator::EditList(DownloadQueue* downloadQueue, IdList* idList, bool ok = false; PrepareEdit(downloadQueue, idList, action); - for (IdList::iterator itId = idList->begin(); itId != idList->end(); itId++) + for (int id : *idList) { - int id = *itId; for (HistoryList::iterator itHistory = downloadQueue->GetHistory()->begin(); itHistory != downloadQueue->GetHistory()->end(); itHistory++) { HistoryInfo* historyInfo = *itHistory; @@ -381,9 +379,8 @@ void HistoryCoordinator::HistoryReturn(DownloadQueue* downloadQueue, HistoryList // unpark files bool unparked = false; - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; detail("Unpark file %s", fileInfo->GetFilename()); unparked = true; } @@ -487,9 +484,8 @@ void HistoryCoordinator::HistoryRedownload(DownloadQueue* downloadQueue, History info("Returning %s from history back to queue", nzbInfo->GetName()); - for (FileList::iterator it = nzbFile->GetNzbInfo()->GetFileList()->begin(); it != nzbFile->GetNzbInfo()->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbFile->GetNzbInfo()->GetFileList()) { - FileInfo* fileInfo = *it; fileInfo->SetPaused(paused); } diff --git a/daemon/queue/NzbFile.cpp b/daemon/queue/NzbFile.cpp index 2876c25c..1ff4d896 100644 --- a/daemon/queue/NzbFile.cpp +++ b/daemon/queue/NzbFile.cpp @@ -294,17 +294,15 @@ bool NzbFile::HasDuplicateFilenames() */ void NzbFile::BuildFilenames() { - for (FileList::iterator it = m_nzbInfo->GetFileList()->begin(); it != m_nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *m_nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; ParseSubject(fileInfo, true); } if (HasDuplicateFilenames()) { - for (FileList::iterator it = m_nzbInfo->GetFileList()->begin(); it != m_nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *m_nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; ParseSubject(fileInfo, false); } } @@ -312,9 +310,8 @@ void NzbFile::BuildFilenames() if (HasDuplicateFilenames()) { m_nzbInfo->SetManyDupeFiles(true); - for (FileList::iterator it = m_nzbInfo->GetFileList()->begin(); it != m_nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *m_nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; fileInfo->SetFilename(fileInfo->GetSubject()); } } @@ -329,9 +326,9 @@ void NzbFile::CalcHashes() { TempFileList fileList; - for (FileList::iterator it = m_nzbInfo->GetFileList()->begin(); it != m_nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *m_nzbInfo->GetFileList()) { - fileList.push_back(*it); + fileList.push_back(fileInfo); } fileList.sort(CompareFileInfo); @@ -340,17 +337,14 @@ void NzbFile::CalcHashes() uint32 filteredContentHash = 0; int useForFilteredCount = 0; - for (TempFileList::iterator it = fileList.begin(); it != fileList.end(); it++) + for (FileInfo* fileInfo : fileList) { - FileInfo* fileInfo = *it; - // check file extension bool skip = !fileInfo->GetParFile() && Util::MatchFileExt(fileInfo->GetFilename(), g_Options->GetParIgnoreExt(), ",;"); - for (FileInfo::Articles::iterator it = fileInfo->GetArticles()->begin(); it != fileInfo->GetArticles()->end(); it++) + for (ArticleInfo* article: *fileInfo->GetArticles()) { - ArticleInfo* article = *it; int len = strlen(article->GetMessageId()); fullContentHash = Util::HashBJ96(article->GetMessageId(), len, fullContentHash); if (!skip) @@ -375,9 +369,8 @@ void NzbFile::ProcessFiles() { BuildFilenames(); - for (FileList::iterator it = m_nzbInfo->GetFileList()->begin(); it != m_nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *m_nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; fileInfo->MakeValidFilename(); BString<1024> loFileName = fileInfo->GetFilename(); @@ -407,9 +400,8 @@ void NzbFile::ProcessFiles() if (g_Options->GetSaveQueue() && g_Options->GetServerMode()) { - for (FileList::iterator it = m_nzbInfo->GetFileList()->begin(); it != m_nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *m_nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; g_DiskState->SaveFile(fileInfo); fileInfo->ClearArticles(); } diff --git a/daemon/queue/QueueCoordinator.cpp b/daemon/queue/QueueCoordinator.cpp index 852aa972..c7ac326a 100644 --- a/daemon/queue/QueueCoordinator.cpp +++ b/daemon/queue/QueueCoordinator.cpp @@ -92,9 +92,9 @@ QueueCoordinator::~QueueCoordinator() g_Log->UnregisterDebuggable(this); debug("Deleting ArticleDownloaders"); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (ArticleDownloader* articleDownloader : m_activeDownloads) { - delete *it; + delete articleDownloader; } m_activeDownloads.clear(); @@ -143,15 +143,12 @@ void QueueCoordinator::Load() // re-save file states into diskstate to update server ids if (g_Options->GetServerMode() && g_Options->GetSaveQueue()) { - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - if (g_Options->GetContinuePartial()) { - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; if (!fileInfo->GetArticles()->empty()) { g_DiskState->SaveFileState(fileInfo, false); @@ -159,9 +156,8 @@ void QueueCoordinator::Load() } } - for (CompletedFileList::iterator it2 = nzbInfo->GetCompletedFiles()->begin(); it2 != nzbInfo->GetCompletedFiles()->end(); it2++) + for (CompletedFile& completedFile : *nzbInfo->GetCompletedFiles()) { - CompletedFile& completedFile = *it2; if (completedFile.GetStatus() != CompletedFile::cfSuccess && completedFile.GetId() > 0) { FileInfo* fileInfo = new FileInfo(completedFile.GetId()); @@ -304,9 +300,8 @@ void QueueCoordinator::AdjustDownloadsLimit() int downloadsLimit = 2; // allow one thread per 0-level (main) and 1-level (backup) server connection - for (Servers::iterator it = g_ServerPool->GetServers()->begin(); it != g_ServerPool->GetServers()->end(); it++) + for (NewsServer* newsServer : *g_ServerPool->GetServers()) { - NewsServer* newsServer = *it; if ((newsServer->GetNormLevel() == 0 || newsServer->GetNormLevel() == 1) && newsServer->GetActive()) { downloadsLimit += newsServer->GetMaxConnections(); @@ -332,9 +327,8 @@ void QueueCoordinator::AddNzbFileToQueue(NzbFile* nzbFile, NzbInfo* urlInfo, boo if (deleteStatus != NzbInfo::dsNone) { bool allPaused = !nzbInfo->GetFileList()->empty(); - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo: *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; allPaused &= fileInfo->GetPaused(); if (g_Options->GetSaveQueue() && g_Options->GetServerMode()) { @@ -416,17 +410,14 @@ void QueueCoordinator::CheckDupeFileInfos(NzbInfo* nzbInfo) FileList dupeList(true); int index1 = 0; - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { index1++; - FileInfo* fileInfo = *it; - bool dupe = false; int index2 = 0; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo2 : *nzbInfo->GetFileList()) { index2++; - FileInfo* fileInfo2 = *it2; if (fileInfo != fileInfo2 && !strcmp(fileInfo->GetFilename(), fileInfo2->GetFilename()) && (fileInfo->GetSize() < fileInfo2->GetSize() || @@ -444,9 +435,8 @@ void QueueCoordinator::CheckDupeFileInfos(NzbInfo* nzbInfo) } } - for (FileList::iterator it = dupeList.begin(); it != dupeList.end(); it++) + for (FileInfo* fileInfo : dupeList) { - FileInfo* fileInfo = *it; StatFileInfo(fileInfo, false); nzbInfo->GetFileList()->Remove(fileInfo); if (g_Options->GetSaveQueue() && g_Options->GetServerMode()) @@ -462,9 +452,9 @@ void QueueCoordinator::Stop() debug("Stopping ArticleDownloads"); DownloadQueue::Lock(); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (ArticleDownloader* articleDownloader : m_activeDownloads) { - (*it)->Stop(); + articleDownloader->Stop(); } DownloadQueue::Unlock(); debug("ArticleDownloads are notified"); @@ -496,12 +486,10 @@ bool QueueCoordinator::GetNextArticle(DownloadQueue* downloadQueue, FileInfo* &f int num = 0; int fileNum = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo1 : *nzbInfo->GetFileList()) { - FileInfo* fileInfo1 = *it2; if ((!checkedFiles || !checkedFiles[num]) && !fileInfo1->GetPaused() && !fileInfo1->GetDeleted() && (g_Options->GetPropagationDelay() == 0 || @@ -531,11 +519,11 @@ bool QueueCoordinator::GetNextArticle(DownloadQueue* downloadQueue, FileInfo* &f } // check if the file has any articles left for download - for (FileInfo::Articles::iterator at = fileInfo->GetArticles()->begin(); at != fileInfo->GetArticles()->end(); at++) + for (ArticleInfo* article : *fileInfo->GetArticles()) { - articleInfo = *at; - if (articleInfo->GetStatus() == ArticleInfo::aiUndefined) + if (article->GetStatus() == ArticleInfo::aiUndefined) { + articleInfo = article; ok = true; break; } @@ -547,9 +535,8 @@ bool QueueCoordinator::GetNextArticle(DownloadQueue* downloadQueue, FileInfo* &f if (!checkedFiles) { int totalFileCount = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; totalFileCount += nzbInfo->GetFileList()->size(); } @@ -692,9 +679,8 @@ void QueueCoordinator::ArticleCompleted(ArticleDownloader* articleDownloader) CheckHealth(downloadQueue, fileInfo); bool hasOtherDownloaders = false; - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (ArticleDownloader* downloader : m_activeDownloads) { - ArticleDownloader* downloader = *it; if (downloader != articleDownloader && downloader->GetFileInfo() == fileInfo) { hasOtherDownloaders = true; @@ -815,9 +801,8 @@ void QueueCoordinator::DiscardDiskFile(FileInfo* fileInfo) if (!g_Options->GetDirectWrite()) { - for (FileInfo::Articles::iterator it = fileInfo->GetArticles()->begin(); it != fileInfo->GetArticles()->end(); it++) + for (ArticleInfo* pa : *fileInfo->GetArticles()) { - ArticleInfo* pa = *it; if (pa->GetResultFilename()) { FileSystem::DeleteFile(pa->GetResultFilename()); @@ -840,12 +825,10 @@ void QueueCoordinator::SavePartialState() DownloadQueue* downloadQueue = DownloadQueue::Lock(); - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; if (fileInfo->GetPartialChanged()) { debug("Saving partial state for %s", fileInfo->GetFilename()); @@ -903,9 +886,8 @@ void QueueCoordinator::LogDebugInfo() info(" ---------- QueueCoordinator"); info(" Active Downloads: %i, Limit: %i", (int)m_activeDownloads.size(), m_downloadsLimit); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (ArticleDownloader* articleDownloader : m_activeDownloads) { - ArticleDownloader* articleDownloader = *it; articleDownloader->LogDebugInfo(); } DownloadQueue::Unlock(); @@ -974,9 +956,8 @@ bool QueueCoordinator::DeleteQueueEntry(DownloadQueue* downloadQueue, FileInfo* { fileInfo->SetDeleted(true); bool downloading = false; - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (ArticleDownloader* articleDownloader : m_activeDownloads) { - ArticleDownloader* articleDownloader = *it; if (articleDownloader->GetFileInfo() == fileInfo) { downloading = true; @@ -1061,9 +1042,8 @@ bool QueueCoordinator::MergeQueueEntries(DownloadQueue* downloadQueue, NzbInfo* SetQueueEntryCategory(downloadQueue, srcNzbInfo, destNzbInfo->GetCategory()); // reattach file items to new NZBInfo-object - for (FileList::iterator it = srcNzbInfo->GetFileList()->begin(); it != srcNzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *srcNzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; fileInfo->SetNzbInfo(destNzbInfo); destNzbInfo->GetFileList()->push_back(fileInfo); } @@ -1110,9 +1090,8 @@ bool QueueCoordinator::MergeQueueEntries(DownloadQueue* downloadQueue, NzbInfo* destNzbInfo->GetDownloadStartTime() : srcNzbInfo->GetDownloadStartTime()); // reattach completed file items to new NZBInfo-object - for (CompletedFileList::iterator it = srcNzbInfo->GetCompletedFiles()->begin(); it != srcNzbInfo->GetCompletedFiles()->end(); it++) + for (CompletedFile& completedFile : *srcNzbInfo->GetCompletedFiles()) { - CompletedFile& completedFile = *it; destNzbInfo->GetCompletedFiles()->push_back(std::move(completedFile)); } srcNzbInfo->GetCompletedFiles()->clear(); @@ -1143,9 +1122,8 @@ bool QueueCoordinator::SplitQueueEntries(DownloadQueue* downloadQueue, FileList* NzbInfo* srcNzbInfo = nullptr; - for (FileList::iterator it = fileList->begin(); it != fileList->end(); it++) + for (FileInfo* fileInfo : *fileList) { - FileInfo* fileInfo = *it; if (fileInfo->GetActiveDownloads() > 0 || fileInfo->GetCompletedArticles() > 0) { error("Could not split %s. File is already (partially) downloaded", fileInfo->GetFilename()); @@ -1178,10 +1156,8 @@ bool QueueCoordinator::SplitQueueEntries(DownloadQueue* downloadQueue, FileList* srcNzbInfo->SetFullContentHash(0); srcNzbInfo->SetFilteredContentHash(0); - for (FileList::iterator it = fileList->begin(); it != fileList->end(); it++) + for (FileInfo* fileInfo : *fileList) { - FileInfo* fileInfo = *it; - DownloadQueue::Aspect aspect = { DownloadQueue::eaFileDeleted, downloadQueue, fileInfo->GetNzbInfo(), fileInfo }; downloadQueue->Notify(&aspect); diff --git a/daemon/queue/QueueEditor.cpp b/daemon/queue/QueueEditor.cpp index 15fdf58e..4f482175 100644 --- a/daemon/queue/QueueEditor.cpp +++ b/daemon/queue/QueueEditor.cpp @@ -147,9 +147,8 @@ bool GroupSorter::operator()(NzbInfo* nzbInfo1, NzbInfo* nzbInfo2) const bool sortItem1 = m_sortItemList->empty(); bool sortItem2 = m_sortItemList->empty(); - for (QueueEditor::ItemList::iterator it = m_sortItemList->begin(); it != m_sortItemList->end(); it++) + for (QueueEditor::EditItem* item : *m_sortItemList) { - QueueEditor::EditItem* item = *it; sortItem1 |= item->m_nzbInfo == nzbInfo1; sortItem2 |= item->m_nzbInfo == nzbInfo2; } @@ -207,9 +206,8 @@ void GroupSorter::AlignSelectedGroups() NzbInfo* nzbInfo = m_nzbList->at(num); bool selected = false; - for (QueueEditor::ItemList::iterator it = m_sortItemList->begin(); it != m_sortItemList->end(); it++) + for (QueueEditor::EditItem* item : *m_sortItemList) { - QueueEditor::EditItem* item = *it; if (item->m_nzbInfo == nzbInfo) { selected = true; @@ -255,12 +253,10 @@ QueueEditor::~QueueEditor() FileInfo* QueueEditor::FindFileInfo(int id) { - for (NzbList::iterator it = m_downloadQueue->GetQueue()->begin(); it != m_downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *m_downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; if (fileInfo->GetId() == id) { return fileInfo; @@ -295,9 +291,8 @@ void QueueEditor::DeleteEntry(FileInfo* fileInfo) void QueueEditor::MoveEntry(FileInfo* fileInfo, int offset) { int entry = 0; - for (FileList::iterator it = fileInfo->GetNzbInfo()->GetFileList()->begin(); it != fileInfo->GetNzbInfo()->GetFileList()->end(); it++) + for (FileInfo* fileInfo2 : *fileInfo->GetNzbInfo()->GetFileList()) { - FileInfo* fileInfo2 = *it; if (fileInfo2 == fileInfo) { break; @@ -330,9 +325,8 @@ void QueueEditor::MoveEntry(FileInfo* fileInfo, int offset) void QueueEditor::MoveGroup(NzbInfo* nzbInfo, int offset) { int entry = 0; - for (NzbList::iterator it = m_downloadQueue->GetQueue()->begin(); it != m_downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo2 : *m_downloadQueue->GetQueue()) { - NzbInfo* nzbInfo2 = *it; if (nzbInfo2 == nzbInfo) { break; @@ -431,9 +425,8 @@ bool QueueEditor::InternEditList(ItemList* itemList, break; default: - for (ItemList::iterator it = itemList->begin(); it != itemList->end(); it++) + for (EditItem* item : *itemList) { - EditItem* item = *it; switch (action) { case DownloadQueue::eaFilePause: @@ -531,9 +524,8 @@ void QueueEditor::PrepareList(ItemList* itemList, IdList* idList, (action == DownloadQueue::eaFileMoveOffset || action == DownloadQueue::eaFileMoveTop || action == DownloadQueue::eaFileMoveBottom)) { // add IDs to list in order they currently have in download queue - for (NzbList::iterator it = m_downloadQueue->GetQueue()->begin(); it != m_downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *m_downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; int nrEntries = (int)nzbInfo->GetFileList()->size(); int lastDestPos = -1; int start, end, step; @@ -645,12 +637,10 @@ void QueueEditor::PrepareList(ItemList* itemList, IdList* idList, // check ID range int maxId = 0; int minId = MAX_ID; - for (NzbList::iterator it = m_downloadQueue->GetQueue()->begin(); it != m_downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *m_downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; int ID = fileInfo->GetId(); if (ID > maxId) { @@ -664,9 +654,8 @@ void QueueEditor::PrepareList(ItemList* itemList, IdList* idList, } //add IDs to list in order they were transmitted in command - for (IdList::iterator it = idList->begin(); it != idList->end(); it++) + for (int id : *idList) { - int id = *it; if (minId <= id && id <= maxId) { FileInfo* fileInfo = FindFileInfo(id); @@ -682,9 +671,8 @@ void QueueEditor::PrepareList(ItemList* itemList, IdList* idList, // check ID range int maxId = 0; int minId = MAX_ID; - for (NzbList::iterator it = m_downloadQueue->GetQueue()->begin(); it != m_downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *m_downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; int ID = nzbInfo->GetId(); if (ID > maxId) { @@ -697,14 +685,12 @@ void QueueEditor::PrepareList(ItemList* itemList, IdList* idList, } //add IDs to list in order they were transmitted in command - for (IdList::iterator it = idList->begin(); it != idList->end(); it++) + for (int id : *idList) { - int id = *it; if (minId <= id && id <= maxId) { - for (NzbList::iterator it2 = m_downloadQueue->GetQueue()->begin(); it2 != m_downloadQueue->GetQueue()->end(); it2++) + for (NzbInfo* nzbInfo : *m_downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it2; if (id == nzbInfo->GetId()) { itemList->push_back(new EditItem(nullptr, nzbInfo, offset)); @@ -726,10 +712,8 @@ bool QueueEditor::BuildIdListFromNameList(IdList* idList, NameList* nameList, Do std::set uniqueIds; - for (NameList::iterator it = nameList->begin(); it != nameList->end(); it++) + for (CString& name : *nameList) { - const char* name = *it; - RegEx *regEx = nullptr; if (matchMode == DownloadQueue::mmRegEx) { @@ -743,13 +727,10 @@ bool QueueEditor::BuildIdListFromNameList(IdList* idList, NameList* nameList, Do bool found = false; - for (NzbList::iterator it3 = m_downloadQueue->GetQueue()->begin(); it3 != m_downloadQueue->GetQueue()->end(); it3++) + for (NzbInfo* nzbInfo : *m_downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it3; - - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; if (action < DownloadQueue::eaGroupMoveOffset) { // file action @@ -796,9 +777,8 @@ bool QueueEditor::EditGroup(NzbInfo* nzbInfo, DownloadQueue::EEditAction action, int id = nzbInfo->GetId(); // collecting files belonging to group - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; itemList.push_back(new EditItem(fileInfo, nullptr, 0)); allPaused &= fileInfo->GetPaused(); } @@ -906,9 +886,8 @@ void QueueEditor::PausePars(FileList* fileList, bool extraParsOnly) FileList Pars, Vols; - for (FileList::iterator it = fileList->begin(); it != fileList->end(); it++) + for (FileInfo* fileInfo : *fileList) { - FileInfo* fileInfo = *it; BString<1024> loFileName = fileInfo->GetFilename(); for (char* p = loFileName; *p; p++) *p = tolower(*p); // convert string to lowercase @@ -936,9 +915,8 @@ void QueueEditor::PausePars(FileList* fileList, bool extraParsOnly) { if (!Pars.empty()) { - for (FileList::iterator it = Vols.begin(); it != Vols.end(); it++) + for (FileInfo* fileInfo : Vols) { - FileInfo* fileInfo = *it; fileInfo->SetPaused(true); } } @@ -946,9 +924,8 @@ void QueueEditor::PausePars(FileList* fileList, bool extraParsOnly) { // pausing all Vol-files except the smallest one FileInfo* smallest = nullptr; - for (FileList::iterator it = Vols.begin(); it != Vols.end(); it++) + for (FileInfo* fileInfo : Vols) { - FileInfo* fileInfo = *it; if (!smallest) { smallest = fileInfo; @@ -1078,9 +1055,8 @@ bool QueueEditor::CanCleanupDisk(NzbInfo* nzbInfo) return true; } - for (FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; BString<1024> loFileName = fileInfo->GetFilename(); for (char* p = loFileName; *p; p++) *p = tolower(*p); // convert string to lowercase @@ -1105,9 +1081,8 @@ bool QueueEditor::MergeGroups(ItemList* itemList) EditItem* destItem = itemList->front(); - for (ItemList::iterator it = itemList->begin() + 1; it != itemList->end(); it++) + for (EditItem* item : *itemList) { - EditItem* item = *it; if (item->m_nzbInfo != destItem->m_nzbInfo) { debug("merge %s to %s", item->m_nzbInfo->GetFilename(), destItem->m_nzbInfo->GetFilename()); @@ -1132,9 +1107,8 @@ bool QueueEditor::SplitGroup(ItemList* itemList, const char* name) FileList fileList(false); - for (ItemList::iterator it = itemList->begin(); it != itemList->end(); it++) + for (EditItem* item : *itemList) { - EditItem* item = *it; fileList.push_back(item->m_fileInfo); delete item; } @@ -1163,9 +1137,8 @@ void QueueEditor::ReorderFiles(ItemList* itemList) uint32 insertPos = 0; // now can reorder - for (ItemList::iterator it = itemList->begin(); it != itemList->end(); it++) + for (EditItem* item : *itemList) { - EditItem* item = *it; FileInfo* fileInfo = item->m_fileInfo; // move file item diff --git a/daemon/queue/Scanner.cpp b/daemon/queue/Scanner.cpp index 311ed85b..a7f5addc 100644 --- a/daemon/queue/Scanner.cpp +++ b/daemon/queue/Scanner.cpp @@ -291,9 +291,8 @@ void Scanner::ProcessIncomingFile(const char* directory, const char* baseFilenam NzbInfo* urlInfo = nullptr; int nzbId = 0; - for (QueueList::iterator it = m_queueList.begin(); it != m_queueList.end(); it++) + for (QueueData& queueData1 : m_queueList) { - QueueData& queueData1 = *it; if (FileSystem::SameFilename(queueData1.GetFilename(), fullFilename)) { queueData = &queueData1; @@ -393,9 +392,8 @@ void Scanner::InitPPParameters(const char* category, NzbParameterList* parameter if (reset) { - for (ScriptConfig::Scripts::iterator it = g_ScriptConfig->GetScripts()->begin(); it != g_ScriptConfig->GetScripts()->end(); it++) + for (ScriptConfig::Script& script : *g_ScriptConfig->GetScripts()) { - ScriptConfig::Script& script = *it; parameters->SetParameter(BString<1024>("%s:", script.GetName()), nullptr); } } @@ -464,9 +462,8 @@ bool Scanner::AddFileToQueue(const char* filename, const char* nzbName, const ch nzbInfo->GetParameters()->CopyFrom(parameters); - for (::FileList::iterator it = nzbInfo->GetFileList()->begin(); it != nzbInfo->GetFileList()->end(); it++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it; fileInfo->SetPaused(addPaused); } diff --git a/daemon/queue/UrlCoordinator.cpp b/daemon/queue/UrlCoordinator.cpp index c6b2b773..56348cb9 100644 --- a/daemon/queue/UrlCoordinator.cpp +++ b/daemon/queue/UrlCoordinator.cpp @@ -85,9 +85,9 @@ UrlCoordinator::~UrlCoordinator() g_Log->UnregisterDebuggable(this); debug("Deleting UrlDownloaders"); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (UrlDownloader* urlDownloader : m_activeDownloads) { - delete *it; + delete urlDownloader; } m_activeDownloads.clear(); @@ -161,9 +161,9 @@ void UrlCoordinator::Stop() debug("Stopping UrlDownloads"); DownloadQueue::Lock(); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (UrlDownloader* urlDownloader : m_activeDownloads) { - (*it)->Stop(); + urlDownloader->Stop(); } DownloadQueue::Unlock(); debug("UrlDownloads are notified"); @@ -215,9 +215,8 @@ void UrlCoordinator::LogDebugInfo() DownloadQueue::Lock(); info(" Active Downloads: %i", (int)m_activeDownloads.size()); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (UrlDownloader* urlDownloader : m_activeDownloads) { - UrlDownloader* urlDownloader = *it; urlDownloader->LogDebugInfo(); } DownloadQueue::Unlock(); @@ -249,9 +248,8 @@ NzbInfo* UrlCoordinator::GetNextUrl(DownloadQueue* downloadQueue) NzbInfo* nzbInfo = nullptr; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo1 : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo1 = *it; if (nzbInfo1->GetKind() == NzbInfo::nkUrl && nzbInfo1->GetUrlStatus() == NzbInfo::lsNone && nzbInfo1->GetDeleteStatus() == NzbInfo::dsNone && @@ -428,9 +426,8 @@ bool UrlCoordinator::DeleteQueueEntry(DownloadQueue* downloadQueue, NzbInfo* nzb nzbInfo->SetDeleting(true); nzbInfo->SetAvoidHistory(avoidHistory); - for (ActiveDownloads::iterator it = m_activeDownloads.begin(); it != m_activeDownloads.end(); it++) + for (UrlDownloader* urlDownloader : m_activeDownloads) { - UrlDownloader* urlDownloader = *it; if (urlDownloader->GetNzbInfo() == nzbInfo) { urlDownloader->Stop(); diff --git a/daemon/remote/BinRpc.cpp b/daemon/remote/BinRpc.cpp index a52c5cf9..22686fee 100644 --- a/daemon/remote/BinRpc.cpp +++ b/daemon/remote/BinRpc.cpp @@ -504,9 +504,8 @@ void ListBinCommand::Execute() int nrNzbEntries = downloadQueue->GetQueue()->size(); int nrPPPEntries = 0; bufsize += nrNzbEntries * sizeof(SNzbListResponseNzbEntry); - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; bufsize += strlen(nzbInfo->GetFilename()) + 1; bufsize += strlen(nzbInfo->GetName()) + 1; bufsize += strlen(nzbInfo->GetDestDir()) + 1; @@ -516,9 +515,8 @@ void ListBinCommand::Execute() bufsize += bufsize % 4 > 0 ? 4 - bufsize % 4 : 0; // calculate required buffer size for pp-parameters - for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) + for (NzbParameter& nzbParameter : *nzbInfo->GetParameters()) { - NzbParameter& nzbParameter = *it; bufsize += sizeof(SNzbListResponsePPPEntry); bufsize += strlen(nzbParameter.GetName()) + 1; bufsize += strlen(nzbParameter.GetValue()) + 1; @@ -530,12 +528,10 @@ void ListBinCommand::Execute() // calculate required buffer size for files int nrFileEntries = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; nrFileEntries++; bufsize += sizeof(SNzbListResponseFileEntry); bufsize += strlen(fileInfo->GetSubject()) + 1; @@ -549,10 +545,8 @@ void ListBinCommand::Execute() char* bufptr = buf; // write nzb entries - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - SNzbListResponseNzbEntry* listAnswer = (SNzbListResponseNzbEntry*) bufptr; uint32 sizeHi, sizeLo, remainingSizeHi, remainingSizeLo, pausedSizeHi, pausedSizeLo; @@ -598,13 +592,12 @@ void ListBinCommand::Execute() } // write ppp entries - int nzbIndex = 1; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++, nzbIndex++) + int nzbIndex = 0; + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) + nzbIndex++; + for (NzbParameter& nzbParameter : *nzbInfo->GetParameters()) { - NzbParameter& nzbParameter = *it; SNzbListResponsePPPEntry* listAnswer = (SNzbListResponsePPPEntry*) bufptr; listAnswer->m_nzbIndex = htonl(nzbIndex); listAnswer->m_nameLen = htonl(strlen(nzbParameter.GetName()) + 1); @@ -625,13 +618,10 @@ void ListBinCommand::Execute() } // write file entries - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; - uint32 sizeHi, sizeLo; SNzbListResponseFileEntry* listAnswer = (SNzbListResponseFileEntry*) bufptr; listAnswer->m_id = htonl(fileInfo->GetId()); @@ -694,9 +684,8 @@ void ListBinCommand::Execute() { DownloadQueue *downloadQueue = DownloadQueue::Lock(); int postJobCount = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; postJobCount += nzbInfo->GetPostInfo() ? 1 : 0; } int64 remainingSize; @@ -939,9 +928,8 @@ void PostQueueBinCommand::Execute() // calculate required buffer size int NrEntries = 0; - for (NzbList::iterator it = nzbList->begin(); it != nzbList->end(); it++) + for (NzbInfo* nzbInfo : *nzbList) { - NzbInfo* nzbInfo = *it; PostInfo* postInfo = nzbInfo->GetPostInfo(); if (!postInfo) { @@ -962,9 +950,8 @@ void PostQueueBinCommand::Execute() buf = (char*) malloc(bufsize); char* bufptr = buf; - for (NzbList::iterator it = nzbList->begin(); it != nzbList->end(); it++) + for (NzbInfo* nzbInfo : *nzbList) { - NzbInfo* nzbInfo = *it; PostInfo* postInfo = nzbInfo->GetPostInfo(); if (!postInfo) { @@ -1098,18 +1085,16 @@ void HistoryBinCommand::Execute() // calculate required buffer size for nzbs int nrEntries = 0; - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetKind() != HistoryInfo::hkDup || showHidden) { nrEntries++; } } bufsize += nrEntries * sizeof(SNzbHistoryResponseEntry); - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetKind() != HistoryInfo::hkDup || showHidden) { bufsize += strlen(historyInfo->GetName()) + 1; @@ -1122,9 +1107,8 @@ void HistoryBinCommand::Execute() char* bufptr = buf; // write nzb entries - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; if (historyInfo->GetKind() != HistoryInfo::hkDup || showHidden) { SNzbHistoryResponseEntry* listAnswer = (SNzbHistoryResponseEntry*) bufptr; diff --git a/daemon/remote/RemoteClient.cpp b/daemon/remote/RemoteClient.cpp index 6d135807..5e40c931 100644 --- a/daemon/remote/RemoteClient.cpp +++ b/daemon/remote/RemoteClient.cpp @@ -379,13 +379,10 @@ bool RemoteClient::RequestServerList(bool files, bool groups, const char* patter int matches = 0; int nrFileEntries = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; - nrFileEntries++; BString<100> completed; @@ -466,10 +463,8 @@ bool RemoteClient::RequestServerList(bool files, bool groups, const char* patter int matches = 0; int nrFileEntries = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - nrFileEntries += nzbInfo->GetFileList()->size(); int64 unpausedRemainingSize = nzbInfo->GetRemainingSize() - nzbInfo->GetPausedSize(); @@ -503,10 +498,9 @@ bool RemoteClient::RequestServerList(bool files, bool groups, const char* patter } BString<1024> parameters; - for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) + for (NzbParameter& nzbParameter : *nzbInfo->GetParameters()) { parameters.Append(parameters.Empty() ? " (" : ", "); - NzbParameter& nzbParameter = *it; parameters.AppendFmt("%s=%s", nzbParameter.GetName(), nzbParameter.GetValue()); } if (!parameters.Empty()) @@ -817,9 +811,8 @@ bool RemoteClient::RequestServerEditQueue(DownloadQueue::EEditAction action, int int nameLength = 0; if (nameList && nameList->size() > 0) { - for (NameList::iterator it = nameList->begin(); it != nameList->end(); it++) + for (CString& name : *nameList) { - const char *name = *it; nameLength += strlen(name) + 1; nameCount++; } @@ -861,9 +854,8 @@ bool RemoteClient::RequestServerEditQueue(DownloadQueue::EEditAction action, int if (nameCount > 0) { char *names = trailingData + textLen + idLength; - for (NameList::iterator it = nameList->begin(); it != nameList->end(); it++) + for (CString& name : *nameList) { - const char *name = *it; int len = strlen(name); strncpy(names, name, len + 1); names += len + 1; diff --git a/daemon/remote/XmlRpc.cpp b/daemon/remote/XmlRpc.cpp index 3eea3523..8321e065 100644 --- a/daemon/remote/XmlRpc.cpp +++ b/daemon/remote/XmlRpc.cpp @@ -1309,9 +1309,8 @@ void StatusXmlCommand::Execute() DownloadQueue* downloadQueue = DownloadQueue::Lock(); int postJobCount = 0; int urlCount = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; postJobCount += nzbInfo->GetPostInfo() ? 1 : 0; urlCount += nzbInfo->GetKind() == NzbInfo::nkUrl ? 1 : 0; } @@ -1368,10 +1367,8 @@ void StatusXmlCommand::Execute() BoolToStr(feedActive), queuedScripts); int index = 0; - for (Servers::iterator it = g_ServerPool->GetServers()->begin(); it != g_ServerPool->GetServers()->end(); it++) + for (NewsServer* server : *g_ServerPool->GetServers()) { - NewsServer* server = *it; - AppendCondResponse(",\n", IsJson() && index++ > 0); AppendFmtResponse(IsJson() ? JSON_NEWSSERVER_ITEM : XML_NEWSSERVER_ITEM, server->GetId(), BoolToStr(server->GetActive())); @@ -1536,13 +1533,10 @@ void ListFilesXmlCommand::Execute() int index = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - for (FileList::iterator it2 = nzbInfo->GetFileList()->begin(); it2 != nzbInfo->GetFileList()->end(); it2++) + for (FileInfo* fileInfo : *nzbInfo->GetFileList()) { - FileInfo* fileInfo = *it2; - if ((nzbId > 0 && nzbId == fileInfo->GetNzbInfo()->GetId()) || (nzbId == 0 && (idStart == 0 || (idStart <= fileInfo->GetId() && fileInfo->GetId() <= idEnd)))) { @@ -1769,10 +1763,8 @@ void NzbInfoXmlCommand::AppendNzbInfoFields(NzbInfo* nzbInfo) // Post-processing parameters int paramIndex = 0; - for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) + for (NzbParameter& parameter : *nzbInfo->GetParameters()) { - NzbParameter& parameter = *it; - AppendCondResponse(",\n", IsJson() && paramIndex++ > 0); AppendFmtResponse(IsJson() ? JSON_PARAMETER_ITEM : XML_PARAMETER_ITEM, *EncodeStr(parameter.GetName()), *EncodeStr(parameter.GetValue())); @@ -1782,10 +1774,8 @@ void NzbInfoXmlCommand::AppendNzbInfoFields(NzbInfo* nzbInfo) // Script statuses int scriptIndex = 0; - for (ScriptStatusList::iterator it = nzbInfo->GetScriptStatuses()->begin(); it != nzbInfo->GetScriptStatuses()->end(); it++) + for (ScriptStatus& scriptStatus : *nzbInfo->GetScriptStatuses()) { - ScriptStatus& scriptStatus = *it; - AppendCondResponse(",\n", IsJson() && scriptIndex++ > 0); AppendFmtResponse(IsJson() ? JSON_SCRIPT_ITEM : XML_SCRIPT_ITEM, *EncodeStr(scriptStatus.GetName()), *EncodeStr(scriptStatusName[scriptStatus.GetStatus()])); @@ -1795,10 +1785,8 @@ void NzbInfoXmlCommand::AppendNzbInfoFields(NzbInfo* nzbInfo) // Server stats int statIndex = 0; - for (ServerStatList::iterator it = nzbInfo->GetCurrentServerStats()->begin(); it != nzbInfo->GetCurrentServerStats()->end(); it++) + for (ServerStat& serverStat : *nzbInfo->GetCurrentServerStats()) { - ServerStat& serverStat = *it; - AppendCondResponse(",\n", IsJson() && statIndex++ > 0); AppendFmtResponse(IsJson() ? JSON_STAT_ITEM : XML_STAT_ITEM, serverStat.GetServerId(), serverStat.GetSuccessArticles(), serverStat.GetFailedArticles()); @@ -1961,10 +1949,8 @@ void ListGroupsXmlCommand::Execute() DownloadQueue* downloadQueue = DownloadQueue::Lock(); - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - uint32 remainingSizeLo, remainingSizeHi, remainingSizeMB; uint32 pausedSizeLo, pausedSizeHi, pausedSizeMB; Util::SplitInt64(nzbInfo->GetRemainingSize(), &remainingSizeHi, &remainingSizeLo); @@ -2345,9 +2331,8 @@ void PostQueueXmlCommand::Execute() int index = 0; - for (NzbList::iterator it = nzbList->begin(); it != nzbList->end(); it++) + for (NzbInfo* nzbInfo : *nzbList) { - NzbInfo* nzbInfo = *it; PostInfo* postInfo = nzbInfo->GetPostInfo(); if (!postInfo) { @@ -2518,10 +2503,8 @@ void HistoryXmlCommand::Execute() int index = 0; - for (HistoryList::iterator it = downloadQueue->GetHistory()->begin(); it != downloadQueue->GetHistory()->end(); it++) + for (HistoryInfo* historyInfo : *downloadQueue->GetHistory()) { - HistoryInfo* historyInfo = *it; - if (historyInfo->GetKind() == HistoryInfo::hkDup && !dup) { continue; @@ -2620,10 +2603,8 @@ void UrlQueueXmlCommand::Execute() int index = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; - if (nzbInfo->GetKind() == NzbInfo::nkUrl) { AppendCondResponse(",\n", IsJson() && index++ > 0); @@ -2659,10 +2640,8 @@ void ConfigXmlCommand::Execute() Options::OptEntries* optEntries = g_Options->LockOptEntries(); - for (Options::OptEntries::iterator it = optEntries->begin(); it != optEntries->end(); it++) + for (Options::OptEntry& optEntry : *optEntries) { - Options::OptEntry& optEntry = *it; - CString xmlValue = EncodeStr(m_userAccess == XmlRpcProcessor::uaRestricted && optEntry.Restricted() ? "***" : optEntry.GetValue()); @@ -2703,10 +2682,8 @@ void LoadConfigXmlCommand::Execute() int index = 0; - for (Options::OptEntries::iterator it = optEntries->begin(); it != optEntries->end(); it++) + for (Options::OptEntry& optEntry: *optEntries) { - Options::OptEntry& optEntry = *it; - CString xmlValue = EncodeStr(m_userAccess == XmlRpcProcessor::uaRestricted && optEntry.Restricted() ? "***" : optEntry.GetValue()); @@ -2793,10 +2770,8 @@ void ConfigTemplatesXmlCommand::Execute() int index = 0; - for (ScriptConfig::ConfigTemplates::iterator it = configTemplates->begin(); it != configTemplates->end(); it++) + for (ScriptConfig::ConfigTemplate& configTemplate : *configTemplates) { - ScriptConfig::ConfigTemplate& configTemplate = *it; - AppendCondResponse(",\n", IsJson() && index++ > 0); AppendFmtResponse(IsJson() ? JSON_CONFIG_ITEM : XML_CONFIG_ITEM, *EncodeStr(configTemplate.GetScript()->GetName()), @@ -2945,10 +2920,8 @@ void ViewFeedXmlCommand::Execute() AppendResponse(IsJson() ? "[\n" : "\n"); int index = 0; - for (FeedItemInfos::iterator it = feedItemInfos->begin(); it != feedItemInfos->end(); it++) + for (FeedItemInfo& feedItemInfo : *feedItemInfos) { - FeedItemInfo& feedItemInfo = *it; - if (includeNonMatching || feedItemInfo.GetMatchStatus() == FeedItemInfo::msAccepted) { uint32 sizeHi, sizeLo; @@ -3015,9 +2988,8 @@ void EditServerXmlCommand::Execute() return; } - for (Servers::iterator it = g_ServerPool->GetServers()->begin(); it != g_ServerPool->GetServers()->end(); it++) + for (NewsServer* server : *g_ServerPool->GetServers()) { - NewsServer* server = *it; if (server->GetId() == id) { server->SetActive(active); @@ -3246,10 +3218,8 @@ void ServerVolumesXmlCommand::Execute() int index = 0; - for (ServerVolumes::iterator it = serverVolumes->begin(); it != serverVolumes->end(); it++, index++) + for (ServerVolume& serverVolume : *serverVolumes) { - ServerVolume& serverVolume = *it; - uint32 totalSizeHi, totalSizeLo, totalSizeMB; Util::SplitInt64(serverVolume.GetTotalBytes(), &totalSizeHi, &totalSizeLo); totalSizeMB = (int)(serverVolume.GetTotalBytes() / 1024 / 1024); @@ -3277,9 +3247,8 @@ void ServerVolumesXmlCommand::Execute() AppendFmtResponse(IsJson() ? JSON_BYTES_ARRAY_START : XML_BYTES_ARRAY_START, arrayName); int index2 = 0; - for (ServerVolume::VolumeArray::iterator it2 = volumeArray->begin(); it2 != volumeArray->end(); it2++) + for (int64 bytes : *volumeArray) { - int64 bytes = *it2; uint32 sizeHi, sizeLo, sizeMB; Util::SplitInt64(bytes, &sizeHi, &sizeLo); sizeMB = (int)(bytes / 1024 / 1024); @@ -3293,6 +3262,7 @@ void ServerVolumesXmlCommand::Execute() AppendCondResponse(",\n", IsJson() && i < 3); } AppendResponse(IsJson() ? JSON_VOLUME_ITEM_END : XML_VOLUME_ITEM_END); + index++; } g_StatMeter->UnlockServerVolumes(); @@ -3325,14 +3295,14 @@ void ResetServerVolumeXmlCommand::Execute() bool ok = false; ServerVolumes* serverVolumes = g_StatMeter->LockServerVolumes(); int index = 0; - for (ServerVolumes::iterator it = serverVolumes->begin(); it != serverVolumes->end(); it++, index++) + for (ServerVolume& serverVolume : *serverVolumes) { - ServerVolume& serverVolume = *it; if (index == serverId || serverId == -1) { serverVolume.ResetCustom(); ok = true; } + index++; } g_StatMeter->UnlockServerVolumes(); diff --git a/daemon/util/Log.cpp b/daemon/util/Log.cpp index a6ccb468..8c2cb9ca 100644 --- a/daemon/util/Log.cpp +++ b/daemon/util/Log.cpp @@ -65,9 +65,8 @@ void Log::LogDebugInfo() info("--------------------------------------------"); m_debugMutex.Lock(); - for (Debuggables::iterator it = m_debuggables.begin(); it != m_debuggables.end(); it++) + for (Debuggable* debuggable : m_debuggables) { - Debuggable* debuggable = *it; debuggable->LogDebugInfo(); } m_debugMutex.Unlock(); diff --git a/daemon/util/Observer.cpp b/daemon/util/Observer.cpp index dce1e9f7..189d7172 100644 --- a/daemon/util/Observer.cpp +++ b/daemon/util/Observer.cpp @@ -46,9 +46,8 @@ void Subject::Notify(void* aspect) { debug("Notifying observers"); - for (std::list::iterator it = m_observers.begin(); it != m_observers.end(); it++) + for (Observer* observer : m_observers) { - Observer* Observer = *it; - Observer->Update(this, aspect); + observer->Update(this, aspect); } } diff --git a/daemon/util/Script.cpp b/daemon/util/Script.cpp index e46263e7..1f1fd98b 100644 --- a/daemon/util/Script.cpp +++ b/daemon/util/Script.cpp @@ -120,17 +120,15 @@ void EnvironmentStrings::Append(CString&& envstr) wchar_t* EnvironmentStrings::GetStrings() { int size = 1; - for (Strings::iterator it = m_strings.begin(); it != m_strings.end(); it++) + for (CString& var : m_strings) { - char* var = *it; size += strlen(var) + 1; } wchar_t* strings = (wchar_t*)malloc(size * 2); wchar_t* ptr = strings; - for (Strings::iterator it = m_strings.begin(); it != m_strings.end(); it++) + for (CString& var : m_strings) { - char* var = *it; WString wstr(var); wcscpy(ptr, wstr); ptr += wstr.Length() + 1; @@ -150,9 +148,8 @@ char** EnvironmentStrings::GetStrings() { char** strings = (char**)malloc((m_strings.size() + 1) * sizeof(char*)); char** ptr = strings; - for (Strings::iterator it = m_strings.begin(); it != m_strings.end(); it++) + for (CString& var : m_strings) { - char* var = *it; *ptr = var; ptr++; } @@ -234,10 +231,8 @@ void ScriptController::PrepareEnvOptions(const char* stripPrefix) Options::OptEntries* optEntries = g_Options->LockOptEntries(); - for (Options::OptEntries::iterator it = optEntries->begin(); it != optEntries->end(); it++) + for (Options::OptEntry& optEntry : *optEntries) { - Options::OptEntry& optEntry = *it; - if (stripPrefix && !strncmp(optEntry.GetName(), stripPrefix, prefixLen) && (int)strlen(optEntry.GetName()) > prefixLen) { @@ -679,9 +674,8 @@ void ScriptController::Terminate() void ScriptController::TerminateAll() { m_runningMutex.Lock(); - for (RunningScripts::iterator it = m_runningScripts.begin(); it != m_runningScripts.end(); it++) + for (ScriptController* script : m_runningScripts) { - ScriptController* script = *it; if (script->m_processId && !script->m_detached) { script->Terminate(); diff --git a/daemon/util/Service.cpp b/daemon/util/Service.cpp index d2c1b4a6..722bced3 100644 --- a/daemon/util/Service.cpp +++ b/daemon/util/Service.cpp @@ -57,9 +57,8 @@ void ServiceCoordinator::Run() while (!IsStopped()) { - for (ServiceList::iterator it = m_services.begin(); it != m_services.end(); it++) + for (Service* service : m_services) { - Service* service = *it; if (curTick >= service->m_lastTick + service->ServiceInterval() || // interval expired curTick == 0 || // first start curTick + 10000 < service->m_lastTick) // int overflow diff --git a/daemon/windows/WinConsole.cpp b/daemon/windows/WinConsole.cpp index 6d2434bd..248b3694 100644 --- a/daemon/windows/WinConsole.cpp +++ b/daemon/windows/WinConsole.cpp @@ -789,9 +789,8 @@ void WinConsole::UpdateTrayIcon() DownloadQueue *downloadQueue = DownloadQueue::Lock(); int postJobCount = 0; int urlCount = 0; - for (NzbList::iterator it = downloadQueue->GetQueue()->begin(); it != downloadQueue->GetQueue()->end(); it++) + for (NzbInfo* nzbInfo : *downloadQueue->GetQueue()) { - NzbInfo* nzbInfo = *it; postJobCount += nzbInfo->GetPostInfo() ? 1 : 0; urlCount += nzbInfo->GetKind() == NzbInfo::nkUrl ? 1 : 0; } @@ -828,10 +827,8 @@ void WinConsole::UpdateTrayIcon() void WinConsole::BuildMenu() { int index = 0; - for (Options::Categories::iterator it = g_Options->GetCategories()->begin(); it != g_Options->GetCategories()->end(); it++, index++) + for (Options::Category& category : *g_Options->GetCategories()) { - Options::Category& category = *it; - BString<1024> caption("Category %i: %s", index + 1, category.GetName()); MENUITEMINFO item; @@ -843,6 +840,8 @@ void WinConsole::BuildMenu() item.wID = ID_SHOW_DESTDIR + 1000 + index; item.dwTypeData = caption; InsertMenuItem(GetSubMenu(m_menu, 1), 2 + index, TRUE, &item); + + index++; } /*