diff --git a/daemon/extension/NzbScript.cpp b/daemon/extension/NzbScript.cpp index 896732e7..9c6708bf 100644 --- a/daemon/extension/NzbScript.cpp +++ b/daemon/extension/NzbScript.cpp @@ -40,16 +40,16 @@ void NzbScriptController::PrepareEnvParameters(NzbParameterList* parameters, con for (NzbParameterList::iterator it = parameters->begin(); it != parameters->end(); it++) { - NzbParameter* parameter = *it; - const char* value = parameter->GetValue(); + NzbParameter& parameter = *it; + const char* value = parameter.GetValue(); - if (stripPrefix && !strncmp(parameter->GetName(), stripPrefix, prefixLen) && (int)strlen(parameter->GetName()) > prefixLen) + if (stripPrefix && !strncmp(parameter.GetName(), stripPrefix, prefixLen) && (int)strlen(parameter.GetName()) > prefixLen) { - SetEnvVarSpecial("NZBPR", parameter->GetName() + prefixLen, value); + SetEnvVarSpecial("NZBPR", parameter.GetName() + prefixLen, value); } else if (!stripPrefix) { - SetEnvVarSpecial("NZBPR", parameter->GetName(), value); + SetEnvVarSpecial("NZBPR", parameter.GetName(), value); } } } diff --git a/daemon/extension/PostScript.cpp b/daemon/extension/PostScript.cpp index 2c3c92d0..827517e4 100644 --- a/daemon/extension/PostScript.cpp +++ b/daemon/extension/PostScript.cpp @@ -55,10 +55,10 @@ void PostScriptController::Run() DownloadQueue::Lock(); for (NzbParameterList::iterator it = m_postInfo->GetNzbInfo()->GetParameters()->begin(); it != m_postInfo->GetNzbInfo()->GetParameters()->end(); it++) { - NzbParameter* parameter = *it; - const char* varname = parameter->GetName(); + 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"))) + (!strcasecmp(parameter.GetValue(), "yes") || !strcasecmp(parameter.GetValue(), "on") || !strcasecmp(parameter.GetValue(), "1"))) { CString scriptName(varname); scriptName[strlen(scriptName)-1] = '\0'; // remove trailing ':' @@ -66,7 +66,7 @@ void PostScriptController::Run() scriptCommaList.Append(","); } } - m_postInfo->GetNzbInfo()->GetScriptStatuses()->Clear(); + m_postInfo->GetNzbInfo()->GetScriptStatuses()->clear(); DownloadQueue::Unlock(); ExecuteScriptList(scriptCommaList); @@ -111,7 +111,7 @@ void PostScriptController::ExecuteScript(ScriptConfig::Script* script) // the locking is needed for accessing the members of NZBInfo DownloadQueue::Lock(); - m_postInfo->GetNzbInfo()->GetScriptStatuses()->Add(script->GetName(), status); + m_postInfo->GetNzbInfo()->GetScriptStatuses()->emplace_back(script->GetName(), status); DownloadQueue::Unlock(); } @@ -173,13 +173,13 @@ void PostScriptController::PrepareParams(const char* scriptName) for (ServerStatList::iterator it = m_postInfo->GetNzbInfo()->GetServerStats()->begin(); it != m_postInfo->GetNzbInfo()->GetServerStats()->end(); it++) { - ServerStat* serverStat = *it; + ServerStat& serverStat = *it; - SetIntEnvVar(BString<1024>("NZBPP_SERVER%i_SUCCESSARTICLES", serverStat->GetServerId()), - serverStat->GetSuccessArticles()); + SetIntEnvVar(BString<1024>("NZBPP_SERVER%i_SUCCESSARTICLES", serverStat.GetServerId()), + serverStat.GetSuccessArticles()); - SetIntEnvVar(BString<1024>("NZBPP_SERVER%i_FAILEDARTICLES", serverStat->GetServerId()), - serverStat->GetFailedArticles()); + SetIntEnvVar(BString<1024>("NZBPP_SERVER%i_FAILEDARTICLES", serverStat.GetServerId()), + serverStat.GetFailedArticles()); } PrepareEnvScript(m_postInfo->GetNzbInfo()->GetParameters(), scriptName); diff --git a/daemon/extension/QueueScript.cpp b/daemon/extension/QueueScript.cpp index 1aaeb4bb..b3fe1f17 100644 --- a/daemon/extension/QueueScript.cpp +++ b/daemon/extension/QueueScript.cpp @@ -322,12 +322,12 @@ void QueueScriptCoordinator::EnqueueScript(NzbInfo* nzbInfo, EEvent event) { for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) { - NzbParameter* parameter = *it; - const char* varname = parameter->GetName(); + 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"))) + (!strcasecmp(parameter.GetValue(), "yes") || + !strcasecmp(parameter.GetValue(), "on") || + !strcasecmp(parameter.GetValue(), "1"))) { BString<1024> scriptName = varname; scriptName[strlen(scriptName)-1] = '\0'; // remove trailing ':' diff --git a/daemon/nntp/ArticleWriter.cpp b/daemon/nntp/ArticleWriter.cpp index 471ba8cb..7b40f6ba 100644 --- a/daemon/nntp/ArticleWriter.cpp +++ b/daemon/nntp/ArticleWriter.cpp @@ -568,8 +568,8 @@ void ArticleWriter::CompleteFileParts() // the locking is needed for accessing the members of NZBInfo DownloadQueue::Lock(); - m_fileInfo->GetNzbInfo()->GetCompletedFiles()->push_back(new CompletedFile( - m_fileInfo->GetId(), FileSystem::BaseFileName(ofn), fileStatus, crc)); + m_fileInfo->GetNzbInfo()->GetCompletedFiles()->emplace_back( + m_fileInfo->GetId(), FileSystem::BaseFileName(ofn), fileStatus, crc); if (strcmp(m_fileInfo->GetNzbInfo()->GetDestDir(), nzbDestDir)) { // destination directory was changed during completion, need to move the file @@ -700,18 +700,18 @@ bool ArticleWriter::MoveCompletedFiles(NzbInfo* nzbInfo, const char* oldDestDir) } // move already downloaded files to new destination - for (CompletedFiles::iterator it = nzbInfo->GetCompletedFiles()->begin(); it != nzbInfo->GetCompletedFiles()->end(); it++) + for (CompletedFileList::iterator it = nzbInfo->GetCompletedFiles()->begin(); it != nzbInfo->GetCompletedFiles()->end(); it++) { - CompletedFile* completedFile = *it; + 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()); + 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()); // check if file was not moved already if (strcmp(oldFileName, newFileName)) { // prevent overwriting of existing files - newFileName = FileSystem::MakeUniqueFilename(nzbInfo->GetDestDir(), completedFile->GetFileName()); + newFileName = FileSystem::MakeUniqueFilename(nzbInfo->GetDestDir(), completedFile.GetFileName()); detail("Moving file %s to %s", *oldFileName, *newFileName); if (!FileSystem::MoveFile(oldFileName, newFileName)) diff --git a/daemon/postprocess/ParCoordinator.cpp b/daemon/postprocess/ParCoordinator.cpp index d43bd566..01c3186f 100644 --- a/daemon/postprocess/ParCoordinator.cpp +++ b/daemon/postprocess/ParCoordinator.cpp @@ -78,12 +78,12 @@ ParChecker::EFileStatus ParCoordinator::PostParChecker::FindFileCrc(const char* { CompletedFile* completedFile = nullptr; - for (CompletedFiles::iterator it = m_postInfo->GetNzbInfo()->GetCompletedFiles()->begin(); it != m_postInfo->GetNzbInfo()->GetCompletedFiles()->end(); it++) + for (CompletedFileList::iterator it = m_postInfo->GetNzbInfo()->GetCompletedFiles()->begin(); it != m_postInfo->GetNzbInfo()->GetCompletedFiles()->end(); it++) { - CompletedFile* completedFile2 = *it; - if (!strcasecmp(completedFile2->GetFileName(), filename)) + CompletedFile& completedFile2 = *it; + if (!strcasecmp(completedFile2.GetFileName(), filename)) { - completedFile = completedFile2; + completedFile = &completedFile2; break; } } @@ -215,12 +215,12 @@ void ParCoordinator::PostParRenamer::RegisterParredFile(const char* filename) */ void ParCoordinator::PostParRenamer::RegisterRenamedFile(const char* oldFilename, const char* newFileName) { - for (CompletedFiles::iterator it = m_postInfo->GetNzbInfo()->GetCompletedFiles()->begin(); it != m_postInfo->GetNzbInfo()->GetCompletedFiles()->end(); it++) + for (CompletedFileList::iterator it = m_postInfo->GetNzbInfo()->GetCompletedFiles()->begin(); it != m_postInfo->GetNzbInfo()->GetCompletedFiles()->end(); it++) { - CompletedFile* completedFile = *it; - if (!strcasecmp(completedFile->GetFileName(), oldFilename)) + CompletedFile& completedFile = *it; + if (!strcasecmp(completedFile.GetFileName(), oldFilename)) { - completedFile->SetFileName(newFileName); + completedFile.SetFileName(newFileName); break; } } diff --git a/daemon/postprocess/PrePostProcessor.cpp b/daemon/postprocess/PrePostProcessor.cpp index 6e64dd0a..9bdf6625 100644 --- a/daemon/postprocess/PrePostProcessor.cpp +++ b/daemon/postprocess/PrePostProcessor.cpp @@ -312,13 +312,13 @@ void PrePostProcessor::DeleteCleanup(NzbInfo* nzbInfo) nzbInfo->GetDeleteStatus() == NzbInfo::dsDupe) { // download was cancelled, deleting already downloaded files from disk - for (CompletedFiles::reverse_iterator it = nzbInfo->GetCompletedFiles()->rbegin(); it != nzbInfo->GetCompletedFiles()->rend(); it++) + for (CompletedFileList::reverse_iterator it = nzbInfo->GetCompletedFiles()->rbegin(); it != nzbInfo->GetCompletedFiles()->rend(); it++) { - CompletedFile* completedFile = *it; - BString<1024> fullFileName("%s%c%s", nzbInfo->GetDestDir(), (int)PATH_SEPARATOR, completedFile->GetFileName()); + CompletedFile& completedFile = *it; + BString<1024> fullFileName("%s%c%s", nzbInfo->GetDestDir(), (int)PATH_SEPARATOR, completedFile.GetFileName()); if (FileSystem::FileExists(fullFileName)) { - detail("Deleting file %s", completedFile->GetFileName()); + detail("Deleting file %s", completedFile.GetFileName()); FileSystem::DeleteFile(fullFileName); } } @@ -368,7 +368,7 @@ void PrePostProcessor::CheckPostQueue() postInfo->GetNzbInfo()->SetParStatus(NzbInfo::psNone); postInfo->SetRequestParCheck(false); postInfo->SetStage(PostInfo::ptQueued); - postInfo->GetNzbInfo()->GetScriptStatuses()->Clear(); + postInfo->GetNzbInfo()->GetScriptStatuses()->clear(); DeletePostThread(postInfo); } else if (postInfo->GetRequestParCheck() && postInfo->GetNzbInfo()->GetParStatus() <= NzbInfo::psSkipped && @@ -663,7 +663,7 @@ void PrePostProcessor::JobCompleted(DownloadQueue* downloadQueue, PostInfo* post if (nzbInfo->GetUnpackCleanedUpDisk()) { - nzbInfo->ClearCompletedFiles(); + nzbInfo->GetCompletedFiles()->clear(); } NzbCompleted(downloadQueue, nzbInfo, false); diff --git a/daemon/queue/DiskState.cpp b/daemon/queue/DiskState.cpp index 0658bcf5..4c728a71 100644 --- a/daemon/queue/DiskState.cpp +++ b/daemon/queue/DiskState.cpp @@ -465,25 +465,25 @@ void DiskState::SaveNzbInfo(NzbInfo* nzbInfo, DiskFile& outfile) nzbInfo->GetParSec(), nzbInfo->GetRepairSec(), nzbInfo->GetUnpackSec()); outfile.Print("%i\n", (int)nzbInfo->GetCompletedFiles()->size()); - for (CompletedFiles::iterator it = nzbInfo->GetCompletedFiles()->begin(); it != nzbInfo->GetCompletedFiles()->end(); it++) + for (CompletedFileList::iterator it = nzbInfo->GetCompletedFiles()->begin(); it != nzbInfo->GetCompletedFiles()->end(); it++) { - CompletedFile* completedFile = *it; - outfile.Print("%i,%i,%u,%s\n", completedFile->GetId(), (int)completedFile->GetStatus(), - completedFile->GetCrc(), completedFile->GetFileName()); + 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++) { - NzbParameter* parameter = *it; - outfile.Print("%s=%s\n", parameter->GetName(), parameter->GetValue()); + 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++) { - ScriptStatus* scriptStatus = *it; - outfile.Print("%i,%s\n", scriptStatus->GetStatus(), scriptStatus->GetName()); + ScriptStatus& scriptStatus = *it; + outfile.Print("%i,%s\n", scriptStatus.GetStatus(), scriptStatus.GetName()); } SaveServerStats(nzbInfo->GetServerStats(), outfile); @@ -621,7 +621,7 @@ bool DiskState::LoadNzbInfo(NzbInfo* nzbInfo, Servers* servers, DiskFile& infile int scriptStatus; if (fscanf(infile, "%i\n", &scriptStatus) != 1) goto error; if (scriptStatus > 1) scriptStatus--; - nzbInfo->GetScriptStatuses()->Add("SCRIPT", (ScriptStatus::EStatus)scriptStatus); + nzbInfo->GetScriptStatuses()->emplace_back("SCRIPT", (ScriptStatus::EStatus)scriptStatus); } if (formatVersion >= 18) @@ -677,7 +677,7 @@ bool DiskState::LoadNzbInfo(NzbInfo* nzbInfo, Servers* servers, DiskFile& infile if (formatVersion < 23) { if (scriptStatus > 1) scriptStatus--; - nzbInfo->GetScriptStatuses()->Add("SCRIPT", (ScriptStatus::EStatus)scriptStatus); + nzbInfo->GetScriptStatuses()->emplace_back("SCRIPT", (ScriptStatus::EStatus)scriptStatus); } } @@ -889,7 +889,7 @@ bool DiskState::LoadNzbInfo(NzbInfo* nzbInfo, Servers* servers, DiskFile& infile } } - nzbInfo->GetCompletedFiles()->push_back(new CompletedFile(id, fileName, (CompletedFile::EStatus)status, crc)); + nzbInfo->GetCompletedFiles()->emplace_back(id, fileName, (CompletedFile::EStatus)status, crc); } } @@ -927,7 +927,7 @@ bool DiskState::LoadNzbInfo(NzbInfo* nzbInfo, Servers* servers, DiskFile& infile scriptName++; int status = atoi(buf); if (status > 1 && formatVersion < 25) status--; - nzbInfo->GetScriptStatuses()->Add(scriptName, (ScriptStatus::EStatus)status); + nzbInfo->GetScriptStatuses()->emplace_back(scriptName, (ScriptStatus::EStatus)status); } } } @@ -1076,8 +1076,8 @@ void DiskState::SaveServerStats(ServerStatList* serverStatList, DiskFile& outfil outfile.Print("%i\n", (int)serverStatList->size()); for (ServerStatList::iterator it = serverStatList->begin(); it != serverStatList->end(); it++) { - ServerStat* serverStat = *it; - outfile.Print("%i,%i,%i\n", serverStat->GetServerId(), serverStat->GetSuccessArticles(), serverStat->GetFailedArticles()); + ServerStat& serverStat = *it; + outfile.Print("%i,%i,%i\n", serverStat.GetServerId(), serverStat.GetSuccessArticles(), serverStat.GetFailedArticles()); } } @@ -1436,18 +1436,18 @@ void DiskState::DiscardFiles(NzbInfo* nzbInfo) BString<1024> filename; - for (CompletedFiles::iterator it = nzbInfo->GetCompletedFiles()->begin(); it != nzbInfo->GetCompletedFiles()->end(); it++) + for (CompletedFileList::iterator it = nzbInfo->GetCompletedFiles()->begin(); it != nzbInfo->GetCompletedFiles()->end(); it++) { - CompletedFile* completedFile = *it; - if (completedFile->GetStatus() != CompletedFile::cfSuccess && completedFile->GetId() > 0) + CompletedFile& completedFile = *it; + if (completedFile.GetStatus() != CompletedFile::cfSuccess && completedFile.GetId() > 0) { - filename.Format("%s%i", g_Options->GetQueueDir(), completedFile->GetId()); + filename.Format("%s%i", g_Options->GetQueueDir(), completedFile.GetId()); FileSystem::DeleteFile(filename); - filename.Format("%s%is", g_Options->GetQueueDir(), completedFile->GetId()); + filename.Format("%s%is", g_Options->GetQueueDir(), completedFile.GetId()); FileSystem::DeleteFile(filename); - filename.Format("%s%ic", g_Options->GetQueueDir(), completedFile->GetId()); + filename.Format("%s%ic", g_Options->GetQueueDir(), completedFile.GetId()); FileSystem::DeleteFile(filename); } } diff --git a/daemon/queue/DownloadInfo.cpp b/daemon/queue/DownloadInfo.cpp index 7d2c6759..238a07d8 100644 --- a/daemon/queue/DownloadInfo.cpp +++ b/daemon/queue/DownloadInfo.cpp @@ -39,20 +39,6 @@ int NzbInfo::m_idMax = 0; DownloadQueue* DownloadQueue::g_DownloadQueue = nullptr; bool DownloadQueue::g_Loaded = false; -NzbParameterList::~NzbParameterList() -{ - Clear(); -} - -void NzbParameterList::Clear() -{ - for (iterator it = begin(); it != end(); it++) - { - delete *it; - } - clear(); -} - void NzbParameterList::SetParameter(const char* name, const char* value) { NzbParameter* parameter = nullptr; @@ -60,16 +46,15 @@ void NzbParameterList::SetParameter(const char* name, const char* value) for (iterator it = begin(); it != end(); it++) { - NzbParameter* lookupParameter = *it; - if (!strcmp(lookupParameter->GetName(), name)) + NzbParameter& lookupParameter = *it; + if (!strcmp(lookupParameter.GetName(), name)) { if (deleteObj) { - delete lookupParameter; erase(it); return; } - parameter = lookupParameter; + parameter = &lookupParameter; break; } } @@ -79,24 +64,25 @@ void NzbParameterList::SetParameter(const char* name, const char* value) return; } - if (!parameter) + if (parameter) { - parameter = new NzbParameter(name); - push_back(parameter); + parameter->SetValue(value); + } + else + { + emplace_back(name, value); } - - parameter->SetValue(value); } NzbParameter* NzbParameterList::Find(const char* name, bool caseSensitive) { for (iterator it = begin(); it != end(); it++) { - NzbParameter* parameter = *it; - if ((caseSensitive && !strcmp(parameter->GetName(), name)) || - (!caseSensitive && !strcasecmp(parameter->GetName(), name))) + NzbParameter& parameter = *it; + if ((caseSensitive && !strcmp(parameter.GetName(), name)) || + (!caseSensitive && !strcasecmp(parameter.GetName(), name))) { - return parameter; + return ¶meter; } } @@ -107,43 +93,24 @@ void NzbParameterList::CopyFrom(NzbParameterList* sourceParameters) { for (iterator it = sourceParameters->begin(); it != sourceParameters->end(); it++) { - NzbParameter* parameter = *it; - SetParameter(parameter->GetName(), parameter->GetValue()); + NzbParameter& parameter = *it; + SetParameter(parameter.GetName(), parameter.GetValue()); } } -ScriptStatusList::~ScriptStatusList() -{ - Clear(); -} - -void ScriptStatusList::Clear() -{ - for (iterator it = begin(); it != end(); it++) - { - delete *it; - } - clear(); -} - -void ScriptStatusList::Add(const char* scriptName, ScriptStatus::EStatus status) -{ - push_back(new ScriptStatus(scriptName, status)); -} - ScriptStatus::EStatus ScriptStatusList::CalcTotalStatus() { ScriptStatus::EStatus status = ScriptStatus::srNone; for (iterator it = begin(); it != end(); it++) { - ScriptStatus* scriptStatus = *it; + ScriptStatus& scriptStatus = *it; // Failure-Status overrides Success-Status - if ((scriptStatus->GetStatus() == ScriptStatus::srSuccess && status == ScriptStatus::srNone) || - (scriptStatus->GetStatus() == ScriptStatus::srFailure)) + if ((scriptStatus.GetStatus() == ScriptStatus::srSuccess && status == ScriptStatus::srNone) || + (scriptStatus.GetStatus() == ScriptStatus::srFailure)) { - status = scriptStatus->GetStatus(); + status = scriptStatus.GetStatus(); } } @@ -151,45 +118,23 @@ ScriptStatus::EStatus ScriptStatusList::CalcTotalStatus() } -ServerStat::ServerStat(int serverId) -{ - m_serverId = serverId; - m_successArticles = 0; - m_failedArticles = 0; -} - - -ServerStatList::~ServerStatList() -{ - Clear(); -} - -void ServerStatList::Clear() -{ - for (iterator it = begin(); it != end(); it++) - { - delete *it; - } - clear(); -} - void ServerStatList::StatOp(int serverId, int successArticles, int failedArticles, EStatOperation statOperation) { ServerStat* serverStat = nullptr; for (iterator it = begin(); it != end(); it++) { - ServerStat* serverStat1 = *it; - if (serverStat1->GetServerId() == serverId) + ServerStat& serverStat1 = *it; + if (serverStat1.GetServerId() == serverId) { - serverStat = serverStat1; + serverStat = &serverStat1; break; } } if (!serverStat) { - serverStat = new ServerStat(serverId); - push_back(serverStat); + emplace_back(serverId); + serverStat = &back(); } switch (statOperation) @@ -215,8 +160,8 @@ void ServerStatList::ListOp(ServerStatList* serverStats, EStatOperation statOper { for (iterator it = serverStats->begin(); it != serverStats->end(); it++) { - ServerStat* serverStat = *it; - StatOp(serverStat->GetServerId(), serverStat->GetSuccessArticles(), serverStat->GetFailedArticles(), statOperation); + ServerStat& serverStat = *it; + StatOp(serverStat.GetServerId(), serverStat.GetSuccessArticles(), serverStat.GetFailedArticles(), statOperation); } } @@ -305,9 +250,6 @@ NzbInfo::~NzbInfo() debug("Destroying NZBInfo"); delete m_postInfo; - - ClearCompletedFiles(); - m_fileList.Clear(); } @@ -338,15 +280,6 @@ int NzbInfo::GenerateId() return ++m_idGen; } -void NzbInfo::ClearCompletedFiles() -{ - for (CompletedFiles::iterator it = m_completedFiles.begin(); it != m_completedFiles.end(); it++) - { - delete *it; - } - m_completedFiles.clear(); -} - void NzbInfo::SetUrl(const char* url) { m_url = url; diff --git a/daemon/queue/DownloadInfo.h b/daemon/queue/DownloadInfo.h index c0b3e265..d0f529a4 100644 --- a/daemon/queue/DownloadInfo.h +++ b/daemon/queue/DownloadInfo.h @@ -40,11 +40,11 @@ class ServerStat { private: int m_serverId; - int m_successArticles; - int m_failedArticles; + int m_successArticles = 0; + int m_failedArticles = 0; public: - ServerStat(int serverId); + ServerStat(int serverId) : m_serverId(serverId) {} int GetServerId() { return m_serverId; } int GetSuccessArticles() { return m_successArticles; } void SetSuccessArticles(int successArticles) { m_successArticles = successArticles; } @@ -52,7 +52,7 @@ public: void SetFailedArticles(int failedArticles) { m_failedArticles = failedArticles; } }; -typedef std::vector ServerStatListBase; +typedef std::vector ServerStatListBase; class ServerStatList : public ServerStatListBase { @@ -65,10 +65,8 @@ public: }; public: - ~ServerStatList(); void StatOp(int serverId, int successArticles, int failedArticles, EStatOperation statOperation); void ListOp(ServerStatList* serverStats, EStatOperation statOperation); - void Clear(); }; class ArticleInfo @@ -264,7 +262,7 @@ public: uint32 GetCrc() { return m_crc; } }; -typedef std::deque CompletedFiles; +typedef std::deque CompletedFileList; class NzbParameter { @@ -277,20 +275,19 @@ private: friend class NzbParameterList; public: - NzbParameter(const char* name) : m_name(name) {} + NzbParameter(const char* name, const char* value) : + m_name(name), m_value(value) {} const char* GetName() { return m_name; } const char* GetValue() { return m_value; } }; -typedef std::deque NzbParameterListBase; +typedef std::deque NzbParameterListBase; class NzbParameterList : public NzbParameterListBase { public: - ~NzbParameterList(); void SetParameter(const char* name, const char* value); NzbParameter* Find(const char* name, bool caseSensitive); - void Clear(); void CopyFrom(NzbParameterList* sourceParameters); }; @@ -311,20 +308,17 @@ private: friend class ScriptStatusList; public: - ScriptStatus(const char* name, EStatus status) - : m_name(name), m_status(status) {} + ScriptStatus(const char* name, EStatus status) : + m_name(name), m_status(status) {} const char* GetName() { return m_name; } EStatus GetStatus() { return m_status; } }; -typedef std::deque ScriptStatusListBase; +typedef std::deque ScriptStatusListBase; class ScriptStatusList : public ScriptStatusListBase { public: - ~ScriptStatusList(); - void Add(const char* scriptName, ScriptStatus::EStatus status); - void Clear(); ScriptStatus::EStatus CalcTotalStatus(); }; @@ -455,7 +449,7 @@ private: time_t m_minTime; time_t m_maxTime; int m_priority; - CompletedFiles m_completedFiles; + CompletedFileList m_completedFiles; ERenameStatus m_renameStatus; EParStatus m_parStatus; EUnpackStatus m_unpackStatus; @@ -585,8 +579,7 @@ public: void SetMaxTime(time_t maxTime) { m_maxTime = maxTime; } void BuildDestDirName(); CString BuildFinalDirName(); - CompletedFiles* GetCompletedFiles() { return &m_completedFiles; } - void ClearCompletedFiles(); + CompletedFileList* GetCompletedFiles() { return &m_completedFiles; } ERenameStatus GetRenameStatus() { return m_renameStatus; } void SetRenameStatus(ERenameStatus renameStatus) { m_renameStatus = renameStatus; } EParStatus GetParStatus() { return m_parStatus; } diff --git a/daemon/queue/HistoryCoordinator.cpp b/daemon/queue/HistoryCoordinator.cpp index 5a691974..561ab610 100644 --- a/daemon/queue/HistoryCoordinator.cpp +++ b/daemon/queue/HistoryCoordinator.cpp @@ -419,7 +419,7 @@ void HistoryCoordinator::HistoryReturn(DownloadQueue* downloadQueue, HistoryList nzbInfo->SetDeleteStatus(NzbInfo::dsNone); nzbInfo->SetDeletePaused(false); nzbInfo->SetMarkStatus(NzbInfo::ksNone); - nzbInfo->GetScriptStatuses()->Clear(); + nzbInfo->GetScriptStatuses()->clear(); nzbInfo->SetParkedFileCount(0); if (nzbInfo->GetMoveStatus() == NzbInfo::msFailure) { @@ -528,9 +528,9 @@ void HistoryCoordinator::HistoryRedownload(DownloadQueue* downloadQueue, History nzbInfo->SetRepairSec(0); nzbInfo->SetUnpackSec(0); nzbInfo->SetExtraParBlocks(0); - nzbInfo->ClearCompletedFiles(); - nzbInfo->GetServerStats()->Clear(); - nzbInfo->GetCurrentServerStats()->Clear(); + nzbInfo->GetCompletedFiles()->clear(); + nzbInfo->GetServerStats()->clear(); + nzbInfo->GetCurrentServerStats()->clear(); nzbInfo->CopyFileList(nzbFile->GetNzbInfo()); diff --git a/daemon/queue/QueueCoordinator.cpp b/daemon/queue/QueueCoordinator.cpp index 021d7103..852aa972 100644 --- a/daemon/queue/QueueCoordinator.cpp +++ b/daemon/queue/QueueCoordinator.cpp @@ -159,12 +159,12 @@ void QueueCoordinator::Load() } } - for (CompletedFiles::iterator it2 = nzbInfo->GetCompletedFiles()->begin(); it2 != nzbInfo->GetCompletedFiles()->end(); it2++) + for (CompletedFileList::iterator it2 = nzbInfo->GetCompletedFiles()->begin(); it2 != nzbInfo->GetCompletedFiles()->end(); it2++) { - CompletedFile* completedFile = *it2; - if (completedFile->GetStatus() != CompletedFile::cfSuccess && completedFile->GetId() > 0) + CompletedFile& completedFile = *it2; + if (completedFile.GetStatus() != CompletedFile::cfSuccess && completedFile.GetId() > 0) { - FileInfo* fileInfo = new FileInfo(completedFile->GetId()); + FileInfo* fileInfo = new FileInfo(completedFile.GetId()); if (g_DiskState->LoadFileState(fileInfo, g_ServerPool->GetServers(), false)) { g_DiskState->SaveFileState(fileInfo, true); @@ -1110,10 +1110,10 @@ bool QueueCoordinator::MergeQueueEntries(DownloadQueue* downloadQueue, NzbInfo* destNzbInfo->GetDownloadStartTime() : srcNzbInfo->GetDownloadStartTime()); // reattach completed file items to new NZBInfo-object - for (CompletedFiles::iterator it = srcNzbInfo->GetCompletedFiles()->begin(); it != srcNzbInfo->GetCompletedFiles()->end(); it++) + for (CompletedFileList::iterator it = srcNzbInfo->GetCompletedFiles()->begin(); it != srcNzbInfo->GetCompletedFiles()->end(); it++) { - CompletedFile* completedFile = *it; - destNzbInfo->GetCompletedFiles()->push_back(completedFile); + CompletedFile& completedFile = *it; + destNzbInfo->GetCompletedFiles()->push_back(std::move(completedFile)); } srcNzbInfo->GetCompletedFiles()->clear(); diff --git a/daemon/remote/BinRpc.cpp b/daemon/remote/BinRpc.cpp index cc366fc0..a52c5cf9 100644 --- a/daemon/remote/BinRpc.cpp +++ b/daemon/remote/BinRpc.cpp @@ -518,10 +518,10 @@ void ListBinCommand::Execute() // calculate required buffer size for pp-parameters for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) { - NzbParameter* nzbParameter = *it; + NzbParameter& nzbParameter = *it; bufsize += sizeof(SNzbListResponsePPPEntry); - bufsize += strlen(nzbParameter->GetName()) + 1; - bufsize += strlen(nzbParameter->GetValue()) + 1; + bufsize += strlen(nzbParameter.GetName()) + 1; + bufsize += strlen(nzbParameter.GetValue()) + 1; // align struct to 4-bytes, needed by ARM-processor (and may be others) bufsize += bufsize % 4 > 0 ? 4 - bufsize % 4 : 0; nrPPPEntries++; @@ -604,15 +604,15 @@ void ListBinCommand::Execute() NzbInfo* nzbInfo = *it; for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) { - NzbParameter* nzbParameter = *it; + NzbParameter& nzbParameter = *it; SNzbListResponsePPPEntry* listAnswer = (SNzbListResponsePPPEntry*) bufptr; - listAnswer->m_nzbIndex = htonl(nzbIndex); - listAnswer->m_nameLen = htonl(strlen(nzbParameter->GetName()) + 1); - listAnswer->m_valueLen = htonl(strlen(nzbParameter->GetValue()) + 1); + listAnswer->m_nzbIndex = htonl(nzbIndex); + listAnswer->m_nameLen = htonl(strlen(nzbParameter.GetName()) + 1); + listAnswer->m_valueLen = htonl(strlen(nzbParameter.GetValue()) + 1); bufptr += sizeof(SNzbListResponsePPPEntry); - strcpy(bufptr, nzbParameter->GetName()); + strcpy(bufptr, nzbParameter.GetName()); bufptr += ntohl(listAnswer->m_nameLen); - strcpy(bufptr, nzbParameter->GetValue()); + strcpy(bufptr, nzbParameter.GetValue()); bufptr += ntohl(listAnswer->m_valueLen); // align struct to 4-bytes, needed by ARM-processor (and may be others) if ((size_t)bufptr % 4 > 0) diff --git a/daemon/remote/RemoteClient.cpp b/daemon/remote/RemoteClient.cpp index 15f6ad8b..6d135807 100644 --- a/daemon/remote/RemoteClient.cpp +++ b/daemon/remote/RemoteClient.cpp @@ -506,8 +506,8 @@ bool RemoteClient::RequestServerList(bool files, bool groups, const char* patter for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) { parameters.Append(parameters.Empty() ? " (" : ", "); - NzbParameter* nzbParameter = *it; - parameters.AppendFmt("%s=%s", nzbParameter->GetName(), nzbParameter->GetValue()); + NzbParameter& nzbParameter = *it; + parameters.AppendFmt("%s=%s", nzbParameter.GetName(), nzbParameter.GetValue()); } if (!parameters.Empty()) { diff --git a/daemon/remote/XmlRpc.cpp b/daemon/remote/XmlRpc.cpp index db38a2d4..3eea3523 100644 --- a/daemon/remote/XmlRpc.cpp +++ b/daemon/remote/XmlRpc.cpp @@ -1771,11 +1771,11 @@ void NzbInfoXmlCommand::AppendNzbInfoFields(NzbInfo* nzbInfo) int paramIndex = 0; for (NzbParameterList::iterator it = nzbInfo->GetParameters()->begin(); it != nzbInfo->GetParameters()->end(); it++) { - NzbParameter* parameter = *it; + NzbParameter& parameter = *it; AppendCondResponse(",\n", IsJson() && paramIndex++ > 0); AppendFmtResponse(IsJson() ? JSON_PARAMETER_ITEM : XML_PARAMETER_ITEM, - *EncodeStr(parameter->GetName()), *EncodeStr(parameter->GetValue())); + *EncodeStr(parameter.GetName()), *EncodeStr(parameter.GetValue())); } AppendResponse(IsJson() ? JSON_NZB_ITEM_SCRIPT_START : XML_NZB_ITEM_SCRIPT_START); @@ -1784,11 +1784,11 @@ void NzbInfoXmlCommand::AppendNzbInfoFields(NzbInfo* nzbInfo) int scriptIndex = 0; for (ScriptStatusList::iterator it = nzbInfo->GetScriptStatuses()->begin(); it != nzbInfo->GetScriptStatuses()->end(); it++) { - ScriptStatus* scriptStatus = *it; + ScriptStatus& scriptStatus = *it; AppendCondResponse(",\n", IsJson() && scriptIndex++ > 0); AppendFmtResponse(IsJson() ? JSON_SCRIPT_ITEM : XML_SCRIPT_ITEM, - *EncodeStr(scriptStatus->GetName()), *EncodeStr(scriptStatusName[scriptStatus->GetStatus()])); + *EncodeStr(scriptStatus.GetName()), *EncodeStr(scriptStatusName[scriptStatus.GetStatus()])); } AppendResponse(IsJson() ? JSON_NZB_ITEM_STATS_START : XML_NZB_ITEM_STATS_START); @@ -1797,11 +1797,11 @@ void NzbInfoXmlCommand::AppendNzbInfoFields(NzbInfo* nzbInfo) int statIndex = 0; for (ServerStatList::iterator it = nzbInfo->GetCurrentServerStats()->begin(); it != nzbInfo->GetCurrentServerStats()->end(); it++) { - ServerStat* serverStat = *it; + ServerStat& serverStat = *it; AppendCondResponse(",\n", IsJson() && statIndex++ > 0); AppendFmtResponse(IsJson() ? JSON_STAT_ITEM : XML_STAT_ITEM, - serverStat->GetServerId(), serverStat->GetSuccessArticles(), serverStat->GetFailedArticles()); + serverStat.GetServerId(), serverStat.GetSuccessArticles(), serverStat.GetFailedArticles()); } AppendResponse(IsJson() ? JSON_NZB_ITEM_END : XML_NZB_ITEM_END);