aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Sommerfeld <kai.sommerfeld@gmx.com>2022-04-28 23:14:49 +0200
committerGitHub <noreply@github.com>2022-04-28 23:14:49 +0200
commit9f699af44bde1b8b3448c3d4162fbb089974d38e (patch)
tree460da71e178fb807949e6141b909fd33365807be
parent7ac3adb28de8da792ec8e49c8de34c4e9400fb39 (diff)
parent789cc04811e3e2b7e659a0d393850c94b5795ecb (diff)
Merge pull request #21315 from ksooo/pvr-cppcheck
[PVR] Fix CPPCheck warnings
-rw-r--r--xbmc/pvr/PVRCachedImages.cpp15
-rw-r--r--xbmc/pvr/PVRContextMenus.cpp50
-rw-r--r--xbmc/pvr/PVRDatabase.cpp2
-rw-r--r--xbmc/pvr/PVRDatabase.h2
-rw-r--r--xbmc/pvr/PVRManager.cpp19
-rw-r--r--xbmc/pvr/PVRPlaybackState.cpp11
-rw-r--r--xbmc/pvr/PVRStreamProperties.cpp32
-rw-r--r--xbmc/pvr/PVRThumbLoader.cpp2
-rw-r--r--xbmc/pvr/PVRThumbLoader.h2
-rw-r--r--xbmc/pvr/addons/PVRClient.cpp8
-rw-r--r--xbmc/pvr/addons/PVRClients.cpp85
-rw-r--r--xbmc/pvr/channels/PVRChannelGroup.cpp81
-rw-r--r--xbmc/pvr/channels/PVRChannelGroupInternal.cpp12
-rw-r--r--xbmc/pvr/channels/PVRChannelGroups.cpp112
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRChannelManager.cpp59
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRChannelManager.h26
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRClientPriorities.cpp6
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRGroupManager.cpp20
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRGroupManager.h20
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp12
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.h12
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp6
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.h6
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRRecordingSettings.cpp7
-rw-r--r--xbmc/pvr/dialogs/GUIDialogPVRTimerSettings.cpp92
-rw-r--r--xbmc/pvr/epg/EpgContainer.cpp33
-rw-r--r--xbmc/pvr/epg/EpgDatabase.cpp2
-rw-r--r--xbmc/pvr/epg/EpgInfoTag.cpp3
-rw-r--r--xbmc/pvr/epg/EpgSearchFilter.h2
-rw-r--r--xbmc/pvr/epg/EpgTagsCache.cpp19
-rw-r--r--xbmc/pvr/epg/EpgTagsContainer.cpp47
-rw-r--r--xbmc/pvr/guilib/GUIEPGGridContainer.cpp3
-rw-r--r--xbmc/pvr/guilib/GUIEPGGridContainerModel.cpp42
-rw-r--r--xbmc/pvr/guilib/PVRGUIActions.cpp55
-rw-r--r--xbmc/pvr/guilib/PVRGUIActions.h2
-rw-r--r--xbmc/pvr/providers/PVRProviders.cpp74
-rw-r--r--xbmc/pvr/recordings/PVRRecordings.cpp20
-rw-r--r--xbmc/pvr/timers/PVRTimerType.cpp45
-rw-r--r--xbmc/pvr/timers/PVRTimers.cpp267
-rw-r--r--xbmc/pvr/windows/GUIWindowPVRGuide.cpp4
-rw-r--r--xbmc/pvr/windows/GUIWindowPVRGuide.h6
41 files changed, 602 insertions, 721 deletions
diff --git a/xbmc/pvr/PVRCachedImages.cpp b/xbmc/pvr/PVRCachedImages.cpp
index 3333e3deb7..ea17fd769f 100644
--- a/xbmc/pvr/PVRCachedImages.cpp
+++ b/xbmc/pvr/PVRCachedImages.cpp
@@ -16,6 +16,8 @@
#include "utils/Variant.h"
#include "utils/log.h"
+#include <algorithm>
+
using namespace PVR;
int CPVRCachedImages::Cleanup(const std::vector<PVRImagePattern>& urlPatterns,
@@ -70,17 +72,8 @@ int CPVRCachedImages::Cleanup(const std::vector<PVRImagePattern>& urlPatterns,
// Unwrap the image:// URL returned from texture db.
const std::string textureURL = UnwrapImageURL(items[i]["url"].asString());
- bool bFound = false;
- for (const auto& url : urlsToCheck)
- {
- if (url == textureURL)
- {
- bFound = true;
- break; // next item
- }
- }
-
- if (!bFound)
+ if (std::none_of(urlsToCheck.cbegin(), urlsToCheck.cend(),
+ [&textureURL](const std::string& url) { return url == textureURL; }))
{
CLog::LogFC(LOGDEBUG, LOGPVR, "Removing stale cached image: '{}'", textureURL);
CServiceBroker::GetTextureCache()->ClearCachedImage(items[i]["textureid"].asInteger());
diff --git a/xbmc/pvr/PVRContextMenus.cpp b/xbmc/pvr/PVRContextMenus.cpp
index 5bb3edad74..f5e38f057b 100644
--- a/xbmc/pvr/PVRContextMenus.cpp
+++ b/xbmc/pvr/PVRContextMenus.cpp
@@ -78,7 +78,7 @@ namespace PVR
class PVRClientMenuHook : public IContextMenuItem
{
public:
- PVRClientMenuHook(const CPVRClientMenuHook& hook) : m_hook(hook) {};
+ explicit PVRClientMenuHook(const CPVRClientMenuHook& hook) : m_hook(hook) {}
std::string GetLabel(const CFileItem& item) const override;
bool IsVisible(const CFileItem& item) const override;
@@ -704,31 +704,31 @@ namespace PVR
}
CPVRContextMenuManager::CPVRContextMenuManager()
+ : m_items({
+ std::make_shared<CONTEXTMENUITEM::PlayEpgTag>(19190), /* Play programme */
+ std::make_shared<CONTEXTMENUITEM::PlayRecording>(19687), /* Play recording */
+ std::make_shared<CONTEXTMENUITEM::ShowInformation>(),
+ std::make_shared<CONTEXTMENUITEM::ShowChannelGuide>(19686), /* Channel guide */
+ std::make_shared<CONTEXTMENUITEM::FindSimilar>(19003), /* Find similar */
+ std::make_shared<CONTEXTMENUITEM::ToggleTimerState>(),
+ std::make_shared<CONTEXTMENUITEM::AddTimerRule>(19061), /* Add timer */
+ std::make_shared<CONTEXTMENUITEM::EditTimerRule>(),
+ std::make_shared<CONTEXTMENUITEM::DeleteTimerRule>(19295), /* Delete timer rule */
+ std::make_shared<CONTEXTMENUITEM::EditTimer>(),
+ std::make_shared<CONTEXTMENUITEM::DeleteTimer>(),
+ std::make_shared<CONTEXTMENUITEM::StartRecording>(264), /* Record */
+ std::make_shared<CONTEXTMENUITEM::StopRecording>(19059), /* Stop recording */
+ std::make_shared<CONTEXTMENUITEM::EditRecording>(21450), /* Edit */
+ std::make_shared<CONTEXTMENUITEM::DeleteRecording>(),
+ std::make_shared<CONTEXTMENUITEM::UndeleteRecording>(19290), /* Undelete */
+ std::make_shared<CONTEXTMENUITEM::DeleteWatchedRecordings>(19327), /* Delete watched */
+ std::make_shared<CONTEXTMENUITEM::AddReminder>(826), /* Set reminder */
+ std::make_shared<CONTEXTMENUITEM::ExecuteSearch>(137), /* Search */
+ std::make_shared<CONTEXTMENUITEM::EditSearch>(21450), /* Edit */
+ std::make_shared<CONTEXTMENUITEM::RenameSearch>(118), /* Rename */
+ std::make_shared<CONTEXTMENUITEM::DeleteSearch>(117), /* Delete */
+ })
{
- m_items = {
- std::make_shared<CONTEXTMENUITEM::PlayEpgTag>(19190), /* Play programme */
- std::make_shared<CONTEXTMENUITEM::PlayRecording>(19687), /* Play recording */
- std::make_shared<CONTEXTMENUITEM::ShowInformation>(),
- std::make_shared<CONTEXTMENUITEM::ShowChannelGuide>(19686), /* Channel guide */
- std::make_shared<CONTEXTMENUITEM::FindSimilar>(19003), /* Find similar */
- std::make_shared<CONTEXTMENUITEM::ToggleTimerState>(),
- std::make_shared<CONTEXTMENUITEM::AddTimerRule>(19061), /* Add timer */
- std::make_shared<CONTEXTMENUITEM::EditTimerRule>(),
- std::make_shared<CONTEXTMENUITEM::DeleteTimerRule>(19295), /* Delete timer rule */
- std::make_shared<CONTEXTMENUITEM::EditTimer>(),
- std::make_shared<CONTEXTMENUITEM::DeleteTimer>(),
- std::make_shared<CONTEXTMENUITEM::StartRecording>(264), /* Record */
- std::make_shared<CONTEXTMENUITEM::StopRecording>(19059), /* Stop recording */
- std::make_shared<CONTEXTMENUITEM::EditRecording>(21450), /* Edit */
- std::make_shared<CONTEXTMENUITEM::DeleteRecording>(),
- std::make_shared<CONTEXTMENUITEM::UndeleteRecording>(19290), /* Undelete */
- std::make_shared<CONTEXTMENUITEM::DeleteWatchedRecordings>(19327), /* Delete watched */
- std::make_shared<CONTEXTMENUITEM::AddReminder>(826), /* Set reminder */
- std::make_shared<CONTEXTMENUITEM::ExecuteSearch>(137), /* Search */
- std::make_shared<CONTEXTMENUITEM::EditSearch>(21450), /* Edit */
- std::make_shared<CONTEXTMENUITEM::RenameSearch>(118), /* Rename */
- std::make_shared<CONTEXTMENUITEM::DeleteSearch>(117), /* Delete */
- };
}
void CPVRContextMenuManager::AddMenuHook(const CPVRClientMenuHook& hook)
diff --git a/xbmc/pvr/PVRDatabase.cpp b/xbmc/pvr/PVRDatabase.cpp
index af7480af8b..8ad293b672 100644
--- a/xbmc/pvr/PVRDatabase.cpp
+++ b/xbmc/pvr/PVRDatabase.cpp
@@ -736,7 +736,7 @@ std::vector<std::shared_ptr<CPVRChannelGroupMember>> CPVRDatabase::Get(
return results;
}
-bool CPVRDatabase::PersistChannels(CPVRChannelGroup& group)
+bool CPVRDatabase::PersistChannels(const CPVRChannelGroup& group)
{
/* invalid group id */
if (group.GroupID() < 0)
diff --git a/xbmc/pvr/PVRDatabase.h b/xbmc/pvr/PVRDatabase.h
index 6e11837b35..e9a1950122 100644
--- a/xbmc/pvr/PVRDatabase.h
+++ b/xbmc/pvr/PVRDatabase.h
@@ -305,7 +305,7 @@ namespace PVR
bool PersistGroupMembers(const CPVRChannelGroup& group);
- bool PersistChannels(CPVRChannelGroup& group);
+ bool PersistChannels(const CPVRChannelGroup& group);
bool RemoveChannelsFromGroup(const CPVRChannelGroup& group);
diff --git a/xbmc/pvr/PVRManager.cpp b/xbmc/pvr/PVRManager.cpp
index f7464b6fc6..33a64db48d 100644
--- a/xbmc/pvr/PVRManager.cpp
+++ b/xbmc/pvr/PVRManager.cpp
@@ -39,6 +39,7 @@
#include "utils/URIUtils.h"
#include "utils/log.h"
+#include <algorithm>
#include <memory>
#include <mutex>
#include <string>
@@ -150,13 +151,11 @@ void CPVRManagerJobQueue::AppendJob(CPVRJob* job)
std::unique_lock<CCriticalSection> lock(m_critSection);
// check for another pending job of given type...
- for (CPVRJob* updateJob : m_pendingUpdates)
+ if (std::any_of(m_pendingUpdates.cbegin(), m_pendingUpdates.cend(),
+ [job](CPVRJob* updateJob) { return updateJob->GetType() == job->GetType(); }))
{
- if (updateJob->GetType() == job->GetType())
- {
- delete job;
- return;
- }
+ delete job;
+ return;
}
m_pendingUpdates.push_back(job);
@@ -608,10 +607,10 @@ bool CPVRManager::SetWakeupCommand()
const std::string strWakeupCommand(m_settings.GetStringValue(CSettings::SETTING_PVRPOWERMANAGEMENT_SETWAKEUPCMD));
if (!strWakeupCommand.empty() && m_timers)
{
- time_t iWakeupTime;
const CDateTime nextEvent = m_timers->GetNextEventTime();
if (nextEvent.IsValid())
{
+ time_t iWakeupTime;
nextEvent.GetAsTime(iWakeupTime);
std::string strExecCommand = StringUtils::Format("{} {}", strWakeupCommand, iWakeupTime);
@@ -717,10 +716,10 @@ bool CPVRManager::UpdateComponents(std::vector<std::shared_ptr<CPVRClient>>& kno
continue;
}
- if (knownClients.empty() || std::find_if(knownClients.cbegin(), knownClients.cend(),
+ if (knownClients.empty() || std::none_of(knownClients.cbegin(), knownClients.cend(),
[&entry](const std::shared_ptr<CPVRClient>& client) {
- return entry.first == client->GetID();
- }) == knownClients.cend())
+ return client->GetID() == entry.first;
+ }))
{
knownClients.emplace_back(entry.second);
newClients.emplace_back(entry.second);
diff --git a/xbmc/pvr/PVRPlaybackState.cpp b/xbmc/pvr/PVRPlaybackState.cpp
index c91722793b..9f00c50315 100644
--- a/xbmc/pvr/PVRPlaybackState.cpp
+++ b/xbmc/pvr/PVRPlaybackState.cpp
@@ -29,6 +29,7 @@
#include "threads/Timer.h"
#include "utils/log.h"
+#include <algorithm>
#include <mutex>
using namespace PVR;
@@ -461,11 +462,11 @@ std::shared_ptr<CPVRChannelGroup> GetFirstNonDeletedAndNonHiddenChannelGroup(boo
{
const std::vector<std::shared_ptr<CPVRChannelGroup>> members =
groups->GetMembers(true); // exclude hidden
- for (const auto& group : members)
- {
- if (!group->IsDeleted())
- return group;
- }
+
+ const auto it = std::find_if(members.cbegin(), members.cend(),
+ [](const auto& group) { return !group->IsDeleted(); });
+ if (it != members.cend())
+ return (*it);
}
CLog::LogFC(LOGERROR, LOGPVR, "Failed to obtain any non-deleted and non-hidden group");
diff --git a/xbmc/pvr/PVRStreamProperties.cpp b/xbmc/pvr/PVRStreamProperties.cpp
index 2cd0e1416e..272b33aa25 100644
--- a/xbmc/pvr/PVRStreamProperties.cpp
+++ b/xbmc/pvr/PVRStreamProperties.cpp
@@ -11,34 +11,30 @@
#include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_general.h"
#include "utils/StringUtils.h"
+#include <algorithm>
+
using namespace PVR;
std::string CPVRStreamProperties::GetStreamURL() const
{
- for (const auto& prop : *this)
- {
- if (prop.first == PVR_STREAM_PROPERTY_STREAMURL)
- return prop.second;
- }
- return {};
+ const auto it = std::find_if(cbegin(), cend(), [](const auto& prop) {
+ return prop.first == PVR_STREAM_PROPERTY_STREAMURL;
+ });
+ return it != cend() ? (*it).second : std::string();
}
std::string CPVRStreamProperties::GetStreamMimeType() const
{
- for (const auto& prop : *this)
- {
- if (prop.first == PVR_STREAM_PROPERTY_MIMETYPE)
- return prop.second;
- }
- return {};
+ const auto it = std::find_if(cbegin(), cend(), [](const auto& prop) {
+ return prop.first == PVR_STREAM_PROPERTY_MIMETYPE;
+ });
+ return it != cend() ? (*it).second : std::string();
}
bool CPVRStreamProperties::EPGPlaybackAsLive() const
{
- for (const auto& prop : *this)
- {
- if (prop.first == PVR_STREAM_PROPERTY_EPGPLAYBACKASLIVE)
- return StringUtils::EqualsNoCase(prop.second, "true");
- }
- return false;
+ const auto it = std::find_if(cbegin(), cend(), [](const auto& prop) {
+ return prop.first == PVR_STREAM_PROPERTY_EPGPLAYBACKASLIVE;
+ });
+ return it != cend() ? StringUtils::EqualsNoCase((*it).second, "true") : false;
}
diff --git a/xbmc/pvr/PVRThumbLoader.cpp b/xbmc/pvr/PVRThumbLoader.cpp
index 0564ce4de0..4b3544c7c0 100644
--- a/xbmc/pvr/PVRThumbLoader.cpp
+++ b/xbmc/pvr/PVRThumbLoader.cpp
@@ -69,7 +69,7 @@ void CPVRThumbLoader::ClearCachedImage(CFileItem& item)
}
}
-void CPVRThumbLoader::ClearCachedImages(CFileItemList& items)
+void CPVRThumbLoader::ClearCachedImages(const CFileItemList& items)
{
for (auto& item : items)
ClearCachedImage(*item);
diff --git a/xbmc/pvr/PVRThumbLoader.h b/xbmc/pvr/PVRThumbLoader.h
index 4a8dcb4fda..33e1bd44e2 100644
--- a/xbmc/pvr/PVRThumbLoader.h
+++ b/xbmc/pvr/PVRThumbLoader.h
@@ -26,7 +26,7 @@ public:
bool LoadItemLookup(CFileItem* item) override;
void ClearCachedImage(CFileItem& item);
- void ClearCachedImages(CFileItemList& items);
+ void ClearCachedImages(const CFileItemList& items);
protected:
void OnLoaderFinish() override;
diff --git a/xbmc/pvr/addons/PVRClient.cpp b/xbmc/pvr/addons/PVRClient.cpp
index 07f4d6cf8c..41d14b777d 100644
--- a/xbmc/pvr/addons/PVRClient.cpp
+++ b/xbmc/pvr/addons/PVRClient.cpp
@@ -42,6 +42,8 @@
#include "utils/StringUtils.h"
#include "utils/log.h"
+#include <algorithm>
+#include <iterator>
#include <map>
#include <memory>
#include <mutex>
@@ -1926,7 +1928,7 @@ void CPVRClient::cb_recording_notification(void* kodiInstance,
std::string strLine2;
if (strName)
strLine2 = strName;
- else if (strFileName)
+ else
strLine2 = strFileName;
// display a notification for 5 seconds
@@ -2196,8 +2198,8 @@ void CPVRClientCapabilities::InitRecordingsLifetimeValues()
void CPVRClientCapabilities::GetRecordingsLifetimeValues(
std::vector<std::pair<std::string, int>>& list) const
{
- for (const auto& lifetime : m_recordingsLifetimeValues)
- list.push_back(lifetime);
+ std::copy(m_recordingsLifetimeValues.cbegin(), m_recordingsLifetimeValues.cend(),
+ std::back_inserter(list));
}
} // namespace PVR
diff --git a/xbmc/pvr/addons/PVRClients.cpp b/xbmc/pvr/addons/PVRClients.cpp
index 8bbbd52f9e..50044fe4ad 100644
--- a/xbmc/pvr/addons/PVRClients.cpp
+++ b/xbmc/pvr/addons/PVRClients.cpp
@@ -20,6 +20,7 @@
#include "utils/JobManager.h"
#include "utils/log.h"
+#include <algorithm>
#include <functional>
#include <memory>
#include <mutex>
@@ -290,41 +291,23 @@ bool CPVRClients::GetClient(int iClientId, std::shared_ptr<CPVRClient>& addon) c
int CPVRClients::GetClientId(const std::string& strId) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& entry : m_clientMap)
- {
- if (entry.second->ID() == strId)
- {
- return entry.first;
- }
- }
-
- return -1;
+ const auto it = std::find_if(m_clientMap.cbegin(), m_clientMap.cend(),
+ [&strId](const auto& entry) { return entry.second->ID() == strId; });
+ return it != m_clientMap.cend() ? (*it).first : -1;
}
int CPVRClients::CreatedClientAmount() const
{
- int iReturn = 0;
-
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& client : m_clientMap)
- {
- if (client.second->ReadyToUse())
- ++iReturn;
- }
-
- return iReturn;
+ return std::count_if(m_clientMap.cbegin(), m_clientMap.cend(),
+ [](const auto& client) { return client.second->ReadyToUse(); });
}
bool CPVRClients::HasCreatedClients() const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& client : m_clientMap)
- {
- if (client.second->ReadyToUse())
- return true;
- }
-
- return false;
+ return std::any_of(m_clientMap.cbegin(), m_clientMap.cend(),
+ [](const auto& client) { return client.second->ReadyToUse(); });
}
bool CPVRClients::IsKnownClient(const std::string& id) const
@@ -342,12 +325,9 @@ bool CPVRClients::IsCreatedClient(int iClientId) const
bool CPVRClients::IsCreatedClient(const std::string& id) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& client : m_clientMap)
- {
- if (client.second->ID() == id)
- return client.second->ReadyToUse();
- }
- return false;
+ const auto it = std::find_if(m_clientMap.cbegin(), m_clientMap.cend(),
+ [&id](const auto& client) { return client.second->ID() == id; });
+ return it != m_clientMap.cend() ? (*it).second->ReadyToUse() : false;
}
bool CPVRClients::GetCreatedClient(int iClientId, std::shared_ptr<CPVRClient>& addon) const
@@ -409,13 +389,9 @@ std::vector<CVariant> CPVRClients::GetClientProviderInfos() const
int CPVRClients::GetFirstCreatedClientID()
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& client : m_clientMap)
- {
- if (client.second->ReadyToUse())
- return client.second->GetID();
- }
-
- return -1;
+ const auto it = std::find_if(m_clientMap.cbegin(), m_clientMap.cend(),
+ [](const auto& client) { return client.second->ReadyToUse(); });
+ return it != m_clientMap.cend() ? (*it).second->GetID() : -1;
}
PVR_ERROR CPVRClients::GetCallableClients(CPVRClientMap& clientsReady,
@@ -447,21 +423,16 @@ PVR_ERROR CPVRClients::GetCallableClients(CPVRClientMap& clientsReady,
int CPVRClients::EnabledClientAmount() const
{
- int iReturn = 0;
-
CPVRClientMap clientMap;
{
std::unique_lock<CCriticalSection> lock(m_critSection);
clientMap = m_clientMap;
}
- for (const auto& client : clientMap)
- {
- if (!CServiceBroker::GetAddonMgr().IsAddonDisabled(client.second->ID()))
- ++iReturn;
- }
-
- return iReturn;
+ ADDON::CAddonMgr& addonMgr = CServiceBroker::GetAddonMgr();
+ return std::count_if(clientMap.cbegin(), clientMap.cend(), [&addonMgr](const auto& client) {
+ return !addonMgr.IsAddonDisabled(client.second->ID());
+ });
}
bool CPVRClients::IsEnabledClient(int clientId) const
@@ -513,13 +484,8 @@ std::vector<CVariant> CPVRClients::GetEnabledClientInfos() const
bool CPVRClients::HasIgnoredClients() const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& client : m_clientMap)
- {
- if (client.second->IgnoreClient())
- return true;
- }
-
- return false;
+ return std::any_of(m_clientMap.cbegin(), m_clientMap.cend(),
+ [](const auto& client) { return client.second->IgnoreClient(); });
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -909,10 +875,8 @@ PVR_ERROR CPVRClients::ForClients(const char* strFunctionName,
for (const auto& entry : m_clientMap)
{
if (entry.second->ReadyToUse() && !entry.second->IgnoreClient() &&
- std::find_if(clients.cbegin(), clients.cend(),
- [&entry](const std::shared_ptr<CPVRClient>& client) {
- return entry.first == client->GetID();
- }) != clients.cend())
+ std::any_of(clients.cbegin(), clients.cend(),
+ [&entry](const auto& client) { return client->GetID() == entry.first; }))
{
// Allow ready to use clients that shall be called
continue;
@@ -924,9 +888,8 @@ PVR_ERROR CPVRClients::ForClients(const char* strFunctionName,
for (const auto& client : clients)
{
- if (std::find_if(failedClients.cbegin(), failedClients.cend(), [&client](int failedClientId) {
- return client->GetID() == failedClientId;
- }) == failedClients.cend())
+ if (std::none_of(failedClients.cbegin(), failedClients.cend(),
+ [&client](int failedClientId) { return failedClientId == client->GetID(); }))
{
PVR_ERROR currentError = function(client);
diff --git a/xbmc/pvr/channels/PVRChannelGroup.cpp b/xbmc/pvr/channels/PVRChannelGroup.cpp
index 86df6ef1fb..fc8d319e4b 100644
--- a/xbmc/pvr/channels/PVRChannelGroup.cpp
+++ b/xbmc/pvr/channels/PVRChannelGroup.cpp
@@ -27,8 +27,10 @@
#include "utils/log.h"
#include <algorithm>
+#include <iterator>
#include <memory>
#include <mutex>
+#include <numeric>
#include <string>
#include <utility>
#include <vector>
@@ -163,23 +165,18 @@ void CPVRChannelGroup::SetPath(const CPVRChannelsPath& path)
bool CPVRChannelGroup::SetChannelNumber(const std::shared_ptr<CPVRChannel>& channel, const CPVRChannelNumber& channelNumber)
{
- bool bReturn(false);
std::unique_lock<CCriticalSection> lock(m_critSection);
+ const auto it =
+ std::find_if(m_sortedMembers.cbegin(), m_sortedMembers.cend(),
+ [&channel](const auto& member) { return *member->Channel() == *channel; });
- for (auto& member : m_sortedMembers)
+ if (it != m_sortedMembers.cend() && (*it)->ChannelNumber() != channelNumber)
{
- if (*member->Channel() == *channel)
- {
- if (member->ChannelNumber() != channelNumber)
- {
- bReturn = true;
- member->SetChannelNumber(channelNumber);
- }
- break;
- }
+ (*it)->SetChannelNumber(channelNumber);
+ return true;
}
- return bReturn;
+ return false;
}
/********** sort methods **********/
@@ -287,14 +284,11 @@ std::shared_ptr<CPVRChannel> CPVRChannelGroup::GetByUniqueID(int iUniqueChannelI
std::shared_ptr<CPVRChannel> CPVRChannelGroup::GetByChannelID(int iChannelID) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
-
- for (const auto& memberPair : m_members)
- {
- if (memberPair.second->Channel()->ChannelID() == iChannelID)
- return memberPair.second->Channel();
- }
-
- return {};
+ const auto it =
+ std::find_if(m_members.cbegin(), m_members.cend(), [iChannelID](const auto& member) {
+ return member.second->Channel()->ChannelID() == iChannelID;
+ });
+ return it != m_members.cend() ? (*it).second->Channel() : std::shared_ptr<CPVRChannel>();
}
std::shared_ptr<CPVRChannelGroupMember> CPVRChannelGroup::GetLastPlayedChannelGroupMember(
@@ -483,7 +477,7 @@ int CPVRChannelGroup::LoadFromDatabase(const std::vector<std::shared_ptr<CPVRCli
std::vector<std::shared_ptr<CPVRChannelGroupMember>> membersToDelete;
if (!results.empty())
{
- const std::shared_ptr<CPVRClients> clients = CServiceBroker::GetPVRManager().Clients();
+ const std::shared_ptr<CPVRClients> allClients = CServiceBroker::GetPVRManager().Clients();
std::unique_lock<CCriticalSection> lock(m_critSection);
for (const auto& member : results)
@@ -492,7 +486,7 @@ int CPVRChannelGroup::LoadFromDatabase(const std::vector<std::shared_ptr<CPVRCli
if (member->ClientID() > 0 && member->ChannelUID() > 0 && member->IsRadio() == IsRadio())
{
// Ignore data from unknown/disabled clients
- if (clients->IsEnabledClient(member->ClientID()))
+ if (allClients->IsEnabledClient(member->ClientID()))
{
m_sortedMembers.emplace_back(member);
m_members.emplace(std::make_pair(member->ClientID(), member->ChannelUID()), member);
@@ -605,15 +599,10 @@ bool CPVRChannelGroup::UpdateFromClient(const std::shared_ptr<CPVRChannelGroupMe
bool CPVRChannelGroup::AddAndUpdateGroupMembers(
const std::vector<std::shared_ptr<CPVRChannelGroupMember>>& groupMembers)
{
- bool bChanged = false;
-
- // go through the group member list and check for updated or new members
- for (const auto& groupMember : groupMembers)
- {
- bChanged |= UpdateFromClient(groupMember);
- }
-
- return bChanged;
+ return std::accumulate(groupMembers.cbegin(), groupMembers.cend(), false,
+ [this](bool changed, const auto& groupMember) {
+ return UpdateFromClient(groupMember) ? true : changed;
+ });
}
bool CPVRChannelGroup::HasValidDataForClient(int iClientId) const
@@ -760,12 +749,13 @@ bool CPVRChannelGroup::AppendToGroup(const std::shared_ptr<CPVRChannel>& channel
if (allGroupMember)
{
- unsigned int channelNumberMax = 0;
- for (const auto& member : m_sortedMembers)
- {
- if (member->ChannelNumber().GetChannelNumber() > channelNumberMax)
- channelNumberMax = member->ChannelNumber().GetChannelNumber();
- }
+ unsigned int channelNumberMax =
+ std::accumulate(m_sortedMembers.cbegin(), m_sortedMembers.cend(), 0,
+ [](unsigned int last, const auto& member) {
+ return (member->ChannelNumber().GetChannelNumber() > last)
+ ? member->ChannelNumber().GetChannelNumber()
+ : last;
+ });
const auto newMember = std::make_shared<CPVRChannelGroupMember>(GroupID(), GroupName(),
allGroupMember->Channel());
@@ -896,14 +886,8 @@ bool CPVRChannelGroup::Renumber(RenumberMode mode /* = NORMAL */)
bool CPVRChannelGroup::HasNewChannels() const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
-
- for (const auto& memberPair : m_members)
- {
- if (memberPair.second->Channel()->ChannelID() <= 0)
- return true;
- }
-
- return false;
+ return std::any_of(m_members.cbegin(), m_members.cend(),
+ [](const auto& member) { return member.second->Channel()->ChannelID() <= 0; });
}
bool CPVRChannelGroup::HasChanges() const
@@ -1167,10 +1151,9 @@ int CPVRChannelGroup::CleanupCachedImages()
std::vector<std::string> urlsToCheck;
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& groupMember : m_members)
- {
- urlsToCheck.emplace_back(groupMember.second->Channel()->ClientIconPath());
- }
+ std::transform(
+ m_members.cbegin(), m_members.cend(), std::back_inserter(urlsToCheck),
+ [](const auto& groupMember) { return groupMember.second->Channel()->ClientIconPath(); });
}
const std::string owner =
diff --git a/xbmc/pvr/channels/PVRChannelGroupInternal.cpp b/xbmc/pvr/channels/PVRChannelGroupInternal.cpp
index d6634adff6..d2e0b4c5bf 100644
--- a/xbmc/pvr/channels/PVRChannelGroupInternal.cpp
+++ b/xbmc/pvr/channels/PVRChannelGroupInternal.cpp
@@ -20,6 +20,8 @@
#include "utils/Variant.h"
#include "utils/log.h"
+#include <algorithm>
+#include <iterator>
#include <mutex>
#include <string>
#include <utility>
@@ -114,12 +116,10 @@ bool CPVRChannelGroupInternal::UpdateFromClients(
// create group members for the channels
std::vector<std::shared_ptr<CPVRChannelGroupMember>> groupMembers;
- groupMembers.reserve(channels.size());
- for (const auto& channel : channels)
- {
- groupMembers.emplace_back(
- std::make_shared<CPVRChannelGroupMember>(GroupID(), GroupName(), channel));
- }
+ std::transform(channels.cbegin(), channels.cend(), std::back_inserter(groupMembers),
+ [this](const auto& channel) {
+ return std::make_shared<CPVRChannelGroupMember>(GroupID(), GroupName(), channel);
+ });
return UpdateGroupEntries(groupMembers);
}
diff --git a/xbmc/pvr/channels/PVRChannelGroups.cpp b/xbmc/pvr/channels/PVRChannelGroups.cpp
index 849cc0a0d8..88c4e914bf 100644
--- a/xbmc/pvr/channels/PVRChannelGroups.cpp
+++ b/xbmc/pvr/channels/PVRChannelGroups.cpp
@@ -26,8 +26,10 @@
#include <algorithm>
#include <chrono>
+#include <iterator>
#include <memory>
#include <mutex>
+#include <numeric>
#include <string>
#include <vector>
@@ -112,14 +114,13 @@ void CPVRChannelGroups::SortGroups()
std::unique_lock<CCriticalSection> lock(m_critSection);
// check if one of the group holds a valid sort position
- std::vector<std::shared_ptr<CPVRChannelGroup>>::iterator it = std::find_if(m_groups.begin(), m_groups.end(), [](const std::shared_ptr<CPVRChannelGroup>& group) {
- return (group->GetPosition() > 0);
- });
+ const auto it = std::find_if(m_groups.cbegin(), m_groups.cend(),
+ [](const auto& group) { return (group->GetPosition() > 0); });
// sort by position if we found a valid sort position
- if (it != m_groups.end())
+ if (it != m_groups.cend())
{
- std::sort(m_groups.begin(), m_groups.end(), [](const std::shared_ptr<CPVRChannelGroup>& group1, const std::shared_ptr<CPVRChannelGroup>& group2) {
+ std::sort(m_groups.begin(), m_groups.end(), [](const auto& group1, const auto& group2) {
return group1->GetPosition() < group2->GetPosition();
});
}
@@ -143,14 +144,10 @@ std::shared_ptr<CPVRChannelGroupMember> CPVRChannelGroups::GetChannelGroupMember
std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetById(int iGroupId) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (std::vector<std::shared_ptr<CPVRChannelGroup>>::const_iterator it = m_groups.begin(); it != m_groups.end(); ++it)
- {
- if ((*it)->GroupID() == iGroupId)
- return *it;
- }
-
- std::shared_ptr<CPVRChannelGroup> empty;
- return empty;
+ const auto it = std::find_if(m_groups.cbegin(), m_groups.cend(), [iGroupId](const auto& group) {
+ return group->GroupID() == iGroupId;
+ });
+ return (it != m_groups.cend()) ? (*it) : std::shared_ptr<CPVRChannelGroup>();
}
std::vector<std::shared_ptr<CPVRChannelGroup>> CPVRChannelGroups::GetGroupsByChannel(const std::shared_ptr<CPVRChannel>& channel, bool bExcludeHidden /* = false */) const
@@ -158,11 +155,10 @@ std::vector<std::shared_ptr<CPVRChannelGroup>> CPVRChannelGroups::GetGroupsByCha
std::vector<std::shared_ptr<CPVRChannelGroup>> groups;
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const std::shared_ptr<CPVRChannelGroup>& group : m_groups)
- {
- if ((!bExcludeHidden || !group->IsHidden()) && group->IsGroupMember(channel))
- groups.push_back(group);
- }
+ std::copy_if(m_groups.cbegin(), m_groups.cend(), std::back_inserter(groups),
+ [bExcludeHidden, &channel](const auto& group) {
+ return (!bExcludeHidden || !group->IsHidden()) && group->IsGroupMember(channel);
+ });
return groups;
}
@@ -172,11 +168,10 @@ std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetGroupByPath(const std::s
if (path.IsChannelGroup())
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& group : m_groups)
- {
- if (group->GetPath() == path)
- return group;
- }
+ const auto it = std::find_if(m_groups.cbegin(), m_groups.cend(),
+ [&path](const auto& group) { return group->GetPath() == path; });
+ if (it != m_groups.cend())
+ return (*it);
}
return {};
}
@@ -184,14 +179,10 @@ std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetGroupByPath(const std::s
std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetByName(const std::string& strName) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (std::vector<std::shared_ptr<CPVRChannelGroup>>::const_iterator it = m_groups.begin(); it != m_groups.end(); ++it)
- {
- if ((*it)->GroupName() == strName)
- return *it;
- }
-
- std::shared_ptr<CPVRChannelGroup> empty;
- return empty;
+ const auto it = std::find_if(m_groups.cbegin(), m_groups.cend(), [&strName](const auto& group) {
+ return group->GroupName() == strName;
+ });
+ return (it != m_groups.cend()) ? (*it) : std::shared_ptr<CPVRChannelGroup>();
}
bool CPVRChannelGroups::HasValidDataForAllClients() const
@@ -242,7 +233,7 @@ bool CPVRChannelGroups::UpdateFromClients(const std::vector<std::shared_ptr<CPVR
bReturn = false;
}
- if (group->Size() - iMemberCount > 0)
+ if ((group->Size() - iMemberCount) > 0)
{
CLog::LogFC(LOGDEBUG, LOGPVR, "{} channel group members added from clients to group '{}'",
static_cast<int>(group->Size() - iMemberCount), group->GroupName());
@@ -286,12 +277,10 @@ bool CPVRChannelGroups::UpdateFromClients(const std::vector<std::shared_ptr<CPVR
bool CPVRChannelGroups::UpdateChannelNumbersFromAllChannelsGroup()
{
std::unique_lock<CCriticalSection> lock(m_critSection);
-
- bool bChanged = false;
- for (auto& group : m_groups)
- bChanged |= group->UpdateChannelNumbersFromAllChannelsGroup();
-
- return bChanged;
+ return std::accumulate(
+ m_groups.cbegin(), m_groups.cend(), false, [](bool changed, const auto& group) {
+ return group->UpdateChannelNumbersFromAllChannelsGroup() ? true : changed;
+ });
}
std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::CreateChannelGroup(
@@ -359,14 +348,12 @@ bool CPVRChannelGroups::LoadFromDatabase(const std::vector<std::shared_ptr<CPVRC
bool CPVRChannelGroups::PersistAll()
{
- bool bReturn(true);
CLog::LogFC(LOGDEBUG, LOGPVR, "Persisting all channel group changes");
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (std::vector<std::shared_ptr<CPVRChannelGroup>>::iterator it = m_groups.begin(); it != m_groups.end(); ++it)
- bReturn &= (*it)->Persist();
-
- return bReturn;
+ return std::accumulate(
+ m_groups.cbegin(), m_groups.cend(), true,
+ [](bool success, const auto& group) { return !group->Persist() ? false : success; });
}
std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetGroupAll() const
@@ -421,17 +408,14 @@ GroupMemberPair CPVRChannelGroups::GetLastAndPreviousToLastPlayedChannelGroupMem
std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetLastOpenedGroup() const
{
- std::shared_ptr<CPVRChannelGroup> lastOpenedGroup;
-
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& group : m_groups)
- {
- if (group->LastOpened() > 0 &&
- (!lastOpenedGroup || group->LastOpened() > lastOpenedGroup->LastOpened()))
- lastOpenedGroup = group;
- }
-
- return lastOpenedGroup;
+ return std::accumulate(
+ m_groups.cbegin(), m_groups.cend(), std::shared_ptr<CPVRChannelGroup>{},
+ [](std::shared_ptr<CPVRChannelGroup> last, const std::shared_ptr<CPVRChannelGroup>& group) {
+ return group->LastOpened() > 0 && (!last || group->LastOpened() > last->LastOpened())
+ ? group
+ : last;
+ });
}
std::vector<std::shared_ptr<CPVRChannelGroup>> CPVRChannelGroups::GetMembers(bool bExcludeHidden /* = false */) const
@@ -439,19 +423,17 @@ std::vector<std::shared_ptr<CPVRChannelGroup>> CPVRChannelGroups::GetMembers(boo
std::vector<std::shared_ptr<CPVRChannelGroup>> groups;
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const std::shared_ptr<CPVRChannelGroup>& group : m_groups)
- {
- if (!bExcludeHidden || !group->IsHidden())
- groups.push_back(group);
- }
+ std::copy_if(
+ m_groups.cbegin(), m_groups.cend(), std::back_inserter(groups),
+ [bExcludeHidden](const auto& group) { return (!bExcludeHidden || !group->IsHidden()); });
return groups;
}
std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetPreviousGroup(const CPVRChannelGroup& group) const
{
- bool bReturnNext(false);
-
{
+ bool bReturnNext = false;
+
std::unique_lock<CCriticalSection> lock(m_critSection);
for (std::vector<std::shared_ptr<CPVRChannelGroup>>::const_reverse_iterator it = m_groups.rbegin(); it != m_groups.rend(); ++it)
{
@@ -478,9 +460,9 @@ std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetPreviousGroup(const CPVR
std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetNextGroup(const CPVRChannelGroup& group) const
{
- bool bReturnNext(false);
-
{
+ bool bReturnNext = false;
+
std::unique_lock<CCriticalSection> lock(m_critSection);
for (std::vector<std::shared_ptr<CPVRChannelGroup>>::const_iterator it = m_groups.begin(); it != m_groups.end(); ++it)
{
@@ -606,10 +588,8 @@ int CPVRChannelGroups::CleanupCachedImages()
std::vector<std::string> urlsToCheck;
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& group : m_groups)
- {
- urlsToCheck.emplace_back(group->GetPath());
- }
+ std::transform(m_groups.cbegin(), m_groups.cend(), std::back_inserter(urlsToCheck),
+ [](const auto& group) { return group->GetPath(); });
}
// kodi-generated thumbnail (see CPVRThumbLoader)
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRChannelManager.cpp b/xbmc/pvr/dialogs/GUIDialogPVRChannelManager.cpp
index bef8947135..cc392fa0ad 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRChannelManager.cpp
+++ b/xbmc/pvr/dialogs/GUIDialogPVRChannelManager.cpp
@@ -41,6 +41,7 @@
#include "utils/StringUtils.h"
#include "utils/Variant.h"
+#include <algorithm>
#include <memory>
#include <string>
#include <utility>
@@ -240,7 +241,7 @@ void CGUIDialogPVRChannelManager::Open(const std::shared_ptr<CFileItem>& initial
CGUIDialog::Open();
}
-bool CGUIDialogPVRChannelManager::OnClickListChannels(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickListChannels(const CGUIMessage& message)
{
if (!m_bMovingMode)
{
@@ -274,26 +275,26 @@ bool CGUIDialogPVRChannelManager::OnClickListChannels(CGUIMessage& message)
return false;
}
-bool CGUIDialogPVRChannelManager::OnClickButtonOK(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonOK()
{
SaveList();
Close();
return true;
}
-bool CGUIDialogPVRChannelManager::OnClickButtonApply(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonApply()
{
SaveList();
return true;
}
-bool CGUIDialogPVRChannelManager::OnClickButtonCancel(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonCancel()
{
Close();
return true;
}
-bool CGUIDialogPVRChannelManager::OnClickButtonRadioTV(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonRadioTV()
{
PromptAndSaveList();
@@ -306,7 +307,7 @@ bool CGUIDialogPVRChannelManager::OnClickButtonRadioTV(CGUIMessage& message)
return true;
}
-bool CGUIDialogPVRChannelManager::OnClickButtonRadioActive(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonRadioActive()
{
CGUIMessage msg(GUI_MSG_IS_SELECTED, GetID(), RADIOBUTTON_ACTIVE);
if (OnMessage(msg))
@@ -329,7 +330,7 @@ bool CGUIDialogPVRChannelManager::OnClickButtonRadioActive(CGUIMessage& message)
return false;
}
-bool CGUIDialogPVRChannelManager::OnClickButtonRadioParentalLocked(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonRadioParentalLocked()
{
CGUIMessage msg(GUI_MSG_IS_SELECTED, GetID(), RADIOBUTTON_PARENTAL_LOCK);
if (!OnMessage(msg))
@@ -359,7 +360,7 @@ bool CGUIDialogPVRChannelManager::OnClickButtonRadioParentalLocked(CGUIMessage&
return false;
}
-bool CGUIDialogPVRChannelManager::OnClickButtonEditName(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonEditName()
{
CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), EDIT_NAME);
if (OnMessage(msg))
@@ -379,7 +380,7 @@ bool CGUIDialogPVRChannelManager::OnClickButtonEditName(CGUIMessage& message)
return false;
}
-bool CGUIDialogPVRChannelManager::OnClickButtonChannelLogo(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonChannelLogo()
{
CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
if (!pItem)
@@ -445,7 +446,7 @@ bool CGUIDialogPVRChannelManager::OnClickButtonChannelLogo(CGUIMessage& message)
return true;
}
-bool CGUIDialogPVRChannelManager::OnClickButtonUseEPG(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonUseEPG()
{
CGUIMessage msg(GUI_MSG_IS_SELECTED, GetID(), RADIOBUTTON_USEEPG);
if (OnMessage(msg))
@@ -466,7 +467,7 @@ bool CGUIDialogPVRChannelManager::OnClickButtonUseEPG(CGUIMessage& message)
return false;
}
-bool CGUIDialogPVRChannelManager::OnClickEPGSourceSpin(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickEPGSourceSpin()
{
//! @todo Add EPG scraper support
return true;
@@ -486,7 +487,7 @@ bool CGUIDialogPVRChannelManager::OnClickEPGSourceSpin(CGUIMessage& message)
// }
}
-bool CGUIDialogPVRChannelManager::OnClickButtonGroupManager(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnClickButtonGroupManager()
{
PromptAndSaveList();
@@ -588,7 +589,7 @@ bool CGUIDialogPVRChannelManager::OnClickButtonRefreshChannelLogos()
return true;
}
-bool CGUIDialogPVRChannelManager::OnMessageClick(CGUIMessage& message)
+bool CGUIDialogPVRChannelManager::OnMessageClick(const CGUIMessage& message)
{
int iControl = message.GetSenderId();
switch(iControl)
@@ -596,27 +597,27 @@ bool CGUIDialogPVRChannelManager::OnMessageClick(CGUIMessage& message)
case CONTROL_LIST_CHANNELS:
return OnClickListChannels(message);
case BUTTON_OK:
- return OnClickButtonOK(message);
+ return OnClickButtonOK();
case BUTTON_APPLY:
- return OnClickButtonApply(message);
+ return OnClickButtonApply();
case BUTTON_CANCEL:
- return OnClickButtonCancel(message);
+ return OnClickButtonCancel();
case BUTTON_RADIO_TV:
- return OnClickButtonRadioTV(message);
+ return OnClickButtonRadioTV();
case RADIOBUTTON_ACTIVE:
- return OnClickButtonRadioActive(message);
+ return OnClickButtonRadioActive();
case RADIOBUTTON_PARENTAL_LOCK:
- return OnClickButtonRadioParentalLocked(message);
+ return OnClickButtonRadioParentalLocked();
case EDIT_NAME:
- return OnClickButtonEditName(message);
+ return OnClickButtonEditName();
case BUTTON_CHANNEL_LOGO:
- return OnClickButtonChannelLogo(message);
+ return OnClickButtonChannelLogo();
case RADIOBUTTON_USEEPG:
- return OnClickButtonUseEPG(message);
+ return OnClickButtonUseEPG();
case SPIN_EPGSOURCE_SELECTION:
- return OnClickEPGSourceSpin(message);
+ return OnClickEPGSourceSpin();
case BUTTON_GROUP_MANAGER:
- return OnClickButtonGroupManager(message);
+ return OnClickButtonGroupManager();
case BUTTON_NEW_CHANNEL:
return OnClickButtonNewChannel();
case BUTTON_REFRESH_LOGOS:
@@ -1014,13 +1015,9 @@ void CGUIDialogPVRChannelManager::SaveList()
bool CGUIDialogPVRChannelManager::HasChangedItems() const
{
- for (const auto& item : *m_channelItems)
- {
- if (item && item->GetProperty(PROPERTY_ITEM_CHANGED).asBoolean())
- return true;
- }
-
- return false;
+ return std::any_of(m_channelItems->cbegin(), m_channelItems->cend(), [](const auto& item) {
+ return item && item->GetProperty(PROPERTY_ITEM_CHANGED).asBoolean();
+ });
}
namespace
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRChannelManager.h b/xbmc/pvr/dialogs/GUIDialogPVRChannelManager.h
index 6737e5c2eb..0716436f77 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRChannelManager.h
+++ b/xbmc/pvr/dialogs/GUIDialogPVRChannelManager.h
@@ -58,19 +58,19 @@ namespace PVR
bool OnPopupMenu(int iItem);
bool OnContextButton(int itemNumber, CONTEXT_BUTTON button);
bool OnActionMove(const CAction& action);
- bool OnMessageClick(CGUIMessage& message);
- bool OnClickListChannels(CGUIMessage& message);
- bool OnClickButtonOK(CGUIMessage& message);
- bool OnClickButtonApply(CGUIMessage& message);
- bool OnClickButtonCancel(CGUIMessage& message);
- bool OnClickButtonRadioTV(CGUIMessage& message);
- bool OnClickButtonRadioActive(CGUIMessage& message);
- bool OnClickButtonRadioParentalLocked(CGUIMessage& message);
- bool OnClickButtonEditName(CGUIMessage& message);
- bool OnClickButtonChannelLogo(CGUIMessage& message);
- bool OnClickButtonUseEPG(CGUIMessage& message);
- bool OnClickEPGSourceSpin(CGUIMessage& message);
- bool OnClickButtonGroupManager(CGUIMessage& message);
+ bool OnMessageClick(const CGUIMessage& message);
+ bool OnClickListChannels(const CGUIMessage& message);
+ bool OnClickButtonOK();
+ bool OnClickButtonApply();
+ bool OnClickButtonCancel();
+ bool OnClickButtonRadioTV();
+ bool OnClickButtonRadioActive();
+ bool OnClickButtonRadioParentalLocked();
+ bool OnClickButtonEditName();
+ bool OnClickButtonChannelLogo();
+ bool OnClickButtonUseEPG();
+ bool OnClickEPGSourceSpin();
+ bool OnClickButtonGroupManager();
bool OnClickButtonNewChannel();
bool OnClickButtonRefreshChannelLogos();
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRClientPriorities.cpp b/xbmc/pvr/dialogs/GUIDialogPVRClientPriorities.cpp
index 16e8573856..0770efbf8a 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRClientPriorities.cpp
+++ b/xbmc/pvr/dialogs/GUIDialogPVRClientPriorities.cpp
@@ -67,13 +67,11 @@ void CGUIDialogPVRClientPriorities::InitializeSettings()
return;
}
- std::shared_ptr<CSetting> setting = nullptr;
-
CServiceBroker::GetPVRManager().Clients()->GetCreatedClients(m_clients);
for (const auto& client : m_clients)
{
- setting = AddEdit(group, std::to_string(client.second->GetID()), 13205 /* Unknown */,
- SettingLevel::Basic, client.second->GetPriority());
+ AddEdit(group, std::to_string(client.second->GetID()), 13205 /* Unknown */, SettingLevel::Basic,
+ client.second->GetPriority());
}
}
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRGroupManager.cpp b/xbmc/pvr/dialogs/GUIDialogPVRGroupManager.cpp
index fac804e365..6c10a0d8fe 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRGroupManager.cpp
+++ b/xbmc/pvr/dialogs/GUIDialogPVRGroupManager.cpp
@@ -79,7 +79,7 @@ bool CGUIDialogPVRGroupManager::PersistChanges()
return CServiceBroker::GetPVRManager().ChannelGroups()->Get(m_bIsRadio)->PersistAll();
}
-bool CGUIDialogPVRGroupManager::ActionButtonOk(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonOk(const CGUIMessage& message)
{
bool bReturn = false;
unsigned int iControl = message.GetSenderId();
@@ -94,7 +94,7 @@ bool CGUIDialogPVRGroupManager::ActionButtonOk(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGroupManager::ActionButtonNewGroup(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonNewGroup(const CGUIMessage& message)
{
bool bReturn = false;
unsigned int iControl = message.GetSenderId();
@@ -123,7 +123,7 @@ bool CGUIDialogPVRGroupManager::ActionButtonNewGroup(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGroupManager::ActionButtonDeleteGroup(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonDeleteGroup(const CGUIMessage& message)
{
bool bReturn = false;
unsigned int iControl = message.GetSenderId();
@@ -159,7 +159,7 @@ bool CGUIDialogPVRGroupManager::ActionButtonDeleteGroup(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGroupManager::ActionButtonRenameGroup(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonRenameGroup(const CGUIMessage& message)
{
bool bReturn = false;
unsigned int iControl = message.GetSenderId();
@@ -186,7 +186,7 @@ bool CGUIDialogPVRGroupManager::ActionButtonRenameGroup(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGroupManager::ActionButtonUngroupedChannels(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonUngroupedChannels(const CGUIMessage& message)
{
bool bReturn = false;
unsigned int iControl = message.GetSenderId();
@@ -219,7 +219,7 @@ bool CGUIDialogPVRGroupManager::ActionButtonUngroupedChannels(CGUIMessage& messa
return bReturn;
}
-bool CGUIDialogPVRGroupManager::ActionButtonGroupMembers(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonGroupMembers(const CGUIMessage& message)
{
bool bReturn = false;
unsigned int iControl = message.GetSenderId();
@@ -245,7 +245,7 @@ bool CGUIDialogPVRGroupManager::ActionButtonGroupMembers(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGroupManager::ActionButtonChannelGroups(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonChannelGroups(const CGUIMessage& message)
{
bool bReturn = false;
unsigned int iControl = message.GetSenderId();
@@ -265,7 +265,7 @@ bool CGUIDialogPVRGroupManager::ActionButtonChannelGroups(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGroupManager::ActionButtonHideGroup(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonHideGroup(const CGUIMessage& message)
{
bool bReturn = false;
@@ -287,7 +287,7 @@ bool CGUIDialogPVRGroupManager::ActionButtonHideGroup(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGroupManager::ActionButtonToggleRadioTV(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonToggleRadioTV(const CGUIMessage& message)
{
bool bReturn = false;
@@ -302,7 +302,7 @@ bool CGUIDialogPVRGroupManager::ActionButtonToggleRadioTV(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGroupManager::ActionButtonRecreateThumbnail(CGUIMessage& message)
+bool CGUIDialogPVRGroupManager::ActionButtonRecreateThumbnail(const CGUIMessage& message)
{
bool bReturn = false;
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRGroupManager.h b/xbmc/pvr/dialogs/GUIDialogPVRGroupManager.h
index 97777d324a..7fa48f467f 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRGroupManager.h
+++ b/xbmc/pvr/dialogs/GUIDialogPVRGroupManager.h
@@ -42,16 +42,16 @@ namespace PVR
void ClearSelectedGroupsThumbnail();
void Update();
bool PersistChanges();
- bool ActionButtonOk(CGUIMessage& message);
- bool ActionButtonNewGroup(CGUIMessage& message);
- bool ActionButtonDeleteGroup(CGUIMessage& message);
- bool ActionButtonRenameGroup(CGUIMessage& message);
- bool ActionButtonUngroupedChannels(CGUIMessage& message);
- bool ActionButtonGroupMembers(CGUIMessage& message);
- bool ActionButtonChannelGroups(CGUIMessage& message);
- bool ActionButtonHideGroup(CGUIMessage& message);
- bool ActionButtonToggleRadioTV(CGUIMessage& message);
- bool ActionButtonRecreateThumbnail(CGUIMessage& message);
+ bool ActionButtonOk(const CGUIMessage& message);
+ bool ActionButtonNewGroup(const CGUIMessage& message);
+ bool ActionButtonDeleteGroup(const CGUIMessage& message);
+ bool ActionButtonRenameGroup(const CGUIMessage& message);
+ bool ActionButtonUngroupedChannels(const CGUIMessage& message);
+ bool ActionButtonGroupMembers(const CGUIMessage& message);
+ bool ActionButtonChannelGroups(const CGUIMessage& message);
+ bool ActionButtonHideGroup(const CGUIMessage& message);
+ bool ActionButtonToggleRadioTV(const CGUIMessage& message);
+ bool ActionButtonRecreateThumbnail(const CGUIMessage& message);
bool OnMessageClick(CGUIMessage& message);
bool OnActionMove(const CAction& action);
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp
index e37d4a6f34..b2e1d9d3b7 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp
+++ b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp
@@ -39,7 +39,7 @@ CGUIDialogPVRGuideInfo::CGUIDialogPVRGuideInfo()
CGUIDialogPVRGuideInfo::~CGUIDialogPVRGuideInfo() = default;
-bool CGUIDialogPVRGuideInfo::OnClickButtonOK(CGUIMessage& message)
+bool CGUIDialogPVRGuideInfo::OnClickButtonOK(const CGUIMessage& message)
{
bool bReturn = false;
@@ -52,7 +52,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonOK(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGuideInfo::OnClickButtonRecord(CGUIMessage& message)
+bool CGUIDialogPVRGuideInfo::OnClickButtonRecord(const CGUIMessage& message)
{
bool bReturn = false;
@@ -80,7 +80,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonRecord(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGuideInfo::OnClickButtonAddTimer(CGUIMessage& message)
+bool CGUIDialogPVRGuideInfo::OnClickButtonAddTimer(const CGUIMessage& message)
{
bool bReturn = false;
@@ -99,7 +99,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonAddTimer(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGuideInfo::OnClickButtonSetReminder(CGUIMessage& message)
+bool CGUIDialogPVRGuideInfo::OnClickButtonSetReminder(const CGUIMessage& message)
{
bool bReturn = false;
@@ -118,7 +118,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonSetReminder(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGuideInfo::OnClickButtonPlay(CGUIMessage& message)
+bool CGUIDialogPVRGuideInfo::OnClickButtonPlay(const CGUIMessage& message)
{
bool bReturn = false;
@@ -142,7 +142,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonPlay(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRGuideInfo::OnClickButtonFind(CGUIMessage& message)
+bool CGUIDialogPVRGuideInfo::OnClickButtonFind(const CGUIMessage& message)
{
bool bReturn = false;
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.h b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.h
index 1f38865bf0..29ade4adbf 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.h
+++ b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.h
@@ -34,12 +34,12 @@ namespace PVR
void OnInitWindow() override;
private:
- bool OnClickButtonOK(CGUIMessage& message);
- bool OnClickButtonRecord(CGUIMessage& message);
- bool OnClickButtonPlay(CGUIMessage& message);
- bool OnClickButtonFind(CGUIMessage& message);
- bool OnClickButtonAddTimer(CGUIMessage& message);
- bool OnClickButtonSetReminder(CGUIMessage& message);
+ bool OnClickButtonOK(const CGUIMessage& message);
+ bool OnClickButtonRecord(const CGUIMessage& message);
+ bool OnClickButtonPlay(const CGUIMessage& message);
+ bool OnClickButtonFind(const CGUIMessage& message);
+ bool OnClickButtonAddTimer(const CGUIMessage& message);
+ bool OnClickButtonSetReminder(const CGUIMessage& message);
std::shared_ptr<CPVREpgInfoTag> m_progItem;
};
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp b/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp
index 963f34787b..1cf4655c0b 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp
+++ b/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp
@@ -39,7 +39,7 @@ bool CGUIDialogPVRRecordingInfo::OnMessage(CGUIMessage& message)
return CGUIDialog::OnMessage(message);
}
-bool CGUIDialogPVRRecordingInfo::OnClickButtonOK(CGUIMessage& message)
+bool CGUIDialogPVRRecordingInfo::OnClickButtonOK(const CGUIMessage& message)
{
bool bReturn = false;
@@ -52,7 +52,7 @@ bool CGUIDialogPVRRecordingInfo::OnClickButtonOK(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRRecordingInfo::OnClickButtonPlay(CGUIMessage& message)
+bool CGUIDialogPVRRecordingInfo::OnClickButtonPlay(const CGUIMessage& message)
{
bool bReturn = false;
@@ -69,7 +69,7 @@ bool CGUIDialogPVRRecordingInfo::OnClickButtonPlay(CGUIMessage& message)
return bReturn;
}
-bool CGUIDialogPVRRecordingInfo::OnClickButtonFind(CGUIMessage& message)
+bool CGUIDialogPVRRecordingInfo::OnClickButtonFind(const CGUIMessage& message)
{
bool bReturn = false;
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.h b/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.h
index 7f371f91f4..76965b0d48 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.h
+++ b/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.h
@@ -28,9 +28,9 @@ namespace PVR
void SetRecording(const CFileItem* item);
private:
- bool OnClickButtonFind(CGUIMessage& message);
- bool OnClickButtonOK(CGUIMessage& message);
- bool OnClickButtonPlay(CGUIMessage& message);
+ bool OnClickButtonFind(const CGUIMessage& message);
+ bool OnClickButtonOK(const CGUIMessage& message);
+ bool OnClickButtonPlay(const CGUIMessage& message);
CFileItemPtr m_recordItem;
};
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRRecordingSettings.cpp b/xbmc/pvr/dialogs/GUIDialogPVRRecordingSettings.cpp
index 7f3d7c3fd5..19f20117db 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRRecordingSettings.cpp
+++ b/xbmc/pvr/dialogs/GUIDialogPVRRecordingSettings.cpp
@@ -22,6 +22,8 @@
#include "utils/Variant.h"
#include "utils/log.h"
+#include <algorithm>
+#include <iterator>
#include <memory>
#include <string>
#include <utility>
@@ -200,8 +202,9 @@ void CGUIDialogPVRRecordingSettings::LifetimesFiller(const SettingConstPtr& sett
{
std::vector<std::pair<std::string,int>> values;
client->GetClientCapabilities().GetRecordingsLifetimeValues(values);
- for (const auto& value : values)
- list.emplace_back(IntegerSettingOption(value.first, value.second));
+ std::transform(
+ values.cbegin(), values.cend(), std::back_inserter(list),
+ [](const auto& value) { return IntegerSettingOption(value.first, value.second); });
}
current = pThis->m_iLifetime;
diff --git a/xbmc/pvr/dialogs/GUIDialogPVRTimerSettings.cpp b/xbmc/pvr/dialogs/GUIDialogPVRTimerSettings.cpp
index 9b1f9b7fd5..9c5046d00a 100644
--- a/xbmc/pvr/dialogs/GUIDialogPVRTimerSettings.cpp
+++ b/xbmc/pvr/dialogs/GUIDialogPVRTimerSettings.cpp
@@ -32,6 +32,8 @@
#include "utils/Variant.h"
#include "utils/log.h"
+#include <algorithm>
+#include <iterator>
#include <memory>
#include <string>
#include <utility>
@@ -146,55 +148,60 @@ void CGUIDialogPVRTimerSettings::SetTimer(const std::shared_ptr<CPVRTimerInfoTag
if (m_timerInfoTag->m_iClientChannelUid == PVR_CHANNEL_INVALID_UID)
{
- bool bChannelSet(false);
if (m_timerType->SupportsAnyChannel())
{
// Select first matching "Any channel" entry.
- for (const auto& channel : m_channelEntries)
+ const auto it = std::find_if(m_channelEntries.cbegin(), m_channelEntries.cend(),
+ [this](const auto& channel) {
+ return channel.second.channelUid == PVR_CHANNEL_INVALID_UID &&
+ channel.second.clientId == m_timerInfoTag->m_iClientId;
+ });
+
+ if (it != m_channelEntries.cend())
{
- if (channel.second.channelUid == PVR_CHANNEL_INVALID_UID &&
- channel.second.clientId == m_timerInfoTag->m_iClientId)
- {
- m_channel = channel.second;
- bChannelSet = true;
- }
+ m_channel = (*it).second;
+ }
+ else
+ {
+ CLog::LogF(LOGERROR, "Unable to map PVR_CHANNEL_INVALID_UID to channel entry!");
}
}
else if (m_bIsNewTimer)
{
// Select first matching regular (not "Any channel") entry.
- for (const auto& channel : m_channelEntries)
+ const auto it = std::find_if(m_channelEntries.cbegin(), m_channelEntries.cend(),
+ [this](const auto& channel) {
+ return channel.second.channelUid != PVR_CHANNEL_INVALID_UID &&
+ channel.second.clientId == m_timerInfoTag->m_iClientId;
+ });
+
+ if (it != m_channelEntries.cend())
{
- if (channel.second.channelUid != PVR_CHANNEL_INVALID_UID &&
- channel.second.clientId == m_timerInfoTag->m_iClientId)
- {
- m_channel = channel.second;
- bChannelSet = true;
- break;
- }
+ m_channel = (*it).second;
+ }
+ else
+ {
+ CLog::LogF(LOGERROR, "Unable to map PVR_CHANNEL_INVALID_UID to channel entry!");
}
}
-
- if (!bChannelSet)
- CLog::LogF(LOGERROR, "Unable to map PVR_CHANNEL_INVALID_UID to channel entry!");
}
else
{
// Find matching channel entry
- bool bChannelSet(false);
- for (const auto& channel : m_channelEntries)
+ const auto it = std::find_if(
+ m_channelEntries.cbegin(), m_channelEntries.cend(), [this](const auto& channel) {
+ return channel.second.channelUid == m_timerInfoTag->m_iClientChannelUid &&
+ channel.second.clientId == m_timerInfoTag->m_iClientId;
+ });
+
+ if (it != m_channelEntries.cend())
{
- if ((channel.second.channelUid == m_timerInfoTag->m_iClientChannelUid) &&
- (channel.second.clientId == m_timerInfoTag->m_iClientId))
- {
- m_channel = channel.second;
- bChannelSet = true;
- break;
- }
+ m_channel = (*it).second;
}
-
- if (!bChannelSet)
+ else
+ {
CLog::LogF(LOGERROR, "Unable to map channel uid to channel entry!");
+ }
}
}
@@ -964,8 +971,9 @@ void CGUIDialogPVRTimerSettings::DupEpisodesFiller(const SettingConstPtr& settin
std::vector<std::pair<std::string,int>> values;
pThis->m_timerType->GetPreventDuplicateEpisodesValues(values);
- for (const auto& value : values)
- list.emplace_back(IntegerSettingOption(value.first, value.second));
+ std::transform(values.cbegin(), values.cend(), std::back_inserter(list), [](const auto& value) {
+ return IntegerSettingOption(value.first, value.second);
+ });
current = pThis->m_iPreventDupEpisodes;
}
@@ -1008,8 +1016,9 @@ void CGUIDialogPVRTimerSettings::PrioritiesFiller(const SettingConstPtr& setting
std::vector<std::pair<std::string,int>> values;
pThis->m_timerType->GetPriorityValues(values);
- for (const auto& value : values)
- list.emplace_back(IntegerSettingOption(value.first, value.second));
+ std::transform(values.cbegin(), values.cend(), std::back_inserter(list), [](const auto& value) {
+ return IntegerSettingOption(value.first, value.second);
+ });
current = pThis->m_iPriority;
@@ -1044,8 +1053,9 @@ void CGUIDialogPVRTimerSettings::LifetimesFiller(const SettingConstPtr& setting,
std::vector<std::pair<std::string,int>> values;
pThis->m_timerType->GetLifetimeValues(values);
- for (const auto& value : values)
- list.emplace_back(IntegerSettingOption(value.first, value.second));
+ std::transform(values.cbegin(), values.cend(), std::back_inserter(list), [](const auto& value) {
+ return IntegerSettingOption(value.first, value.second);
+ });
current = pThis->m_iLifetime;
@@ -1082,8 +1092,9 @@ void CGUIDialogPVRTimerSettings::MaxRecordingsFiller(const SettingConstPtr& sett
std::vector<std::pair<std::string,int>> values;
pThis->m_timerType->GetMaxRecordingsValues(values);
- for (const auto& value : values)
- list.emplace_back(IntegerSettingOption(value.first, value.second));
+ std::transform(values.cbegin(), values.cend(), std::back_inserter(list), [](const auto& value) {
+ return IntegerSettingOption(value.first, value.second);
+ });
current = pThis->m_iMaxRecordings;
@@ -1118,8 +1129,9 @@ void CGUIDialogPVRTimerSettings::RecordingGroupFiller(const SettingConstPtr& set
std::vector<std::pair<std::string,int>> values;
pThis->m_timerType->GetRecordingGroupValues(values);
- for (const auto& value : values)
- list.emplace_back(IntegerSettingOption(value.first, value.second));
+ std::transform(values.cbegin(), values.cend(), std::back_inserter(list), [](const auto& value) {
+ return IntegerSettingOption(value.first, value.second);
+ });
current = pThis->m_iRecordingGroup;
}
diff --git a/xbmc/pvr/epg/EpgContainer.cpp b/xbmc/pvr/epg/EpgContainer.cpp
index 0b5fb90d0b..538dceaa2c 100644
--- a/xbmc/pvr/epg/EpgContainer.cpp
+++ b/xbmc/pvr/epg/EpgContainer.cpp
@@ -24,8 +24,11 @@
#include "threads/SystemClock.h"
#include "utils/log.h"
+#include <algorithm>
+#include <iterator>
#include <memory>
#include <mutex>
+#include <numeric>
#include <utility>
#include <vector>
@@ -189,8 +192,8 @@ void CPVREpgContainer::Unload()
std::unique_lock<CCriticalSection> lock(m_critSection);
/* clear all epg tables and remove pointers to epg tables on channels */
- for (const auto& epgEntry : m_epgIdToEpgMap)
- epgs.emplace_back(epgEntry.second);
+ std::transform(m_epgIdToEpgMap.cbegin(), m_epgIdToEpgMap.cend(), std::back_inserter(epgs),
+ [](const auto& epgEntry) { return epgEntry.second; });
m_epgIdToEpgMap.clear();
m_channelUidToEpgMap.clear();
@@ -448,10 +451,8 @@ std::vector<std::shared_ptr<CPVREpg>> CPVREpgContainer::GetAllEpgs() const
std::vector<std::shared_ptr<CPVREpg>> epgs;
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& epg : m_epgIdToEpgMap)
- {
- epgs.emplace_back(epg.second);
- }
+ std::transform(m_epgIdToEpgMap.cbegin(), m_epgIdToEpgMap.cend(), std::back_inserter(epgs),
+ [](const auto& epgEntry) { return epgEntry.second; });
return epgs;
}
@@ -852,8 +853,10 @@ bool CPVREpgContainer::CheckPlayingEvents()
CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNow);
if (iNow >= iNextEpgActiveTagCheck)
{
- for (const auto& epgEntry : epgs)
- bFoundChanges = epgEntry.second->CheckPlayingEvent() || bFoundChanges;
+ bFoundChanges = std::accumulate(epgs.cbegin(), epgs.cend(), bFoundChanges,
+ [](bool found, const auto& epgEntry) {
+ return epgEntry.second->CheckPlayingEvent() ? true : found;
+ });
CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNextEpgActiveTagCheck);
iNextEpgActiveTagCheck += CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_iEpgActiveTagCheckInterval;
@@ -932,13 +935,11 @@ void CPVREpgContainer::OnSystemWake()
int CPVREpgContainer::CleanupCachedImages()
{
- int iCleanedImages = 0;
-
const std::shared_ptr<CPVREpgDatabase> database = GetEpgDatabase();
if (!database)
{
CLog::LogF(LOGERROR, "No EPG database");
- return iCleanedImages;
+ return 0;
}
// Processing can take some time. Do not block.
@@ -946,12 +947,10 @@ int CPVREpgContainer::CleanupCachedImages()
const std::map<int, std::shared_ptr<CPVREpg>> epgIdToEpgMap = m_epgIdToEpgMap;
m_critSection.unlock();
- for (const auto& epg : epgIdToEpgMap)
- {
- iCleanedImages += epg.second->CleanupCachedImages(database);
- }
-
- return iCleanedImages;
+ return std::accumulate(epgIdToEpgMap.cbegin(), epgIdToEpgMap.cend(), 0,
+ [&database](int cleanedImages, const auto& epg) {
+ return cleanedImages + epg.second->CleanupCachedImages(database);
+ });
}
std::vector<std::shared_ptr<CPVREpgSearchFilter>> CPVREpgContainer::GetSavedSearches(bool bRadio)
diff --git a/xbmc/pvr/epg/EpgDatabase.cpp b/xbmc/pvr/epg/EpgDatabase.cpp
index e0d7a4279c..ab90d478ec 100644
--- a/xbmc/pvr/epg/EpgDatabase.cpp
+++ b/xbmc/pvr/epg/EpgDatabase.cpp
@@ -520,7 +520,7 @@ namespace
class CSearchTermConverter
{
public:
- CSearchTermConverter(const std::string& strSearchTerm) { Parse(strSearchTerm); }
+ explicit CSearchTermConverter(const std::string& strSearchTerm) { Parse(strSearchTerm); }
std::string ToSQL(const std::string& strFieldName) const
{
diff --git a/xbmc/pvr/epg/EpgInfoTag.cpp b/xbmc/pvr/epg/EpgInfoTag.cpp
index 5426309637..5312f63456 100644
--- a/xbmc/pvr/epg/EpgInfoTag.cpp
+++ b/xbmc/pvr/epg/EpgInfoTag.cpp
@@ -552,10 +552,9 @@ bool CPVREpgInfoTag::Update(const CPVREpgInfoTag& tag, bool bUpdateBroadcastId /
m_iUniqueBroadcastID = tag.m_iUniqueBroadcastID;
m_iconPath = tag.m_iconPath;
m_channelData = tag.m_channelData;
- }
- if (bChanged)
UpdatePath();
+ }
return bChanged;
}
diff --git a/xbmc/pvr/epg/EpgSearchFilter.h b/xbmc/pvr/epg/EpgSearchFilter.h
index 9ceffdcc17..ea11ed0ee7 100644
--- a/xbmc/pvr/epg/EpgSearchFilter.h
+++ b/xbmc/pvr/epg/EpgSearchFilter.h
@@ -28,7 +28,7 @@ namespace PVR
* @brief ctor.
* @param bRadio the type of channels to search - if true, 'radio'. 'tv', otherwise.
*/
- CPVREpgSearchFilter(bool bRadio);
+ explicit CPVREpgSearchFilter(bool bRadio);
/*!
* @brief Clear this filter.
diff --git a/xbmc/pvr/epg/EpgTagsCache.cpp b/xbmc/pvr/epg/EpgTagsCache.cpp
index 43f6311c05..2c4d1112e2 100644
--- a/xbmc/pvr/epg/EpgTagsCache.cpp
+++ b/xbmc/pvr/epg/EpgTagsCache.cpp
@@ -16,6 +16,8 @@
#include "pvr/epg/EpgInfoTag.h"
#include "utils/log.h"
+#include <algorithm>
+
using namespace PVR;
namespace
@@ -80,15 +82,16 @@ bool CPVREpgTagsCache::Refresh()
m_nowActiveTag.reset();
m_nextStartingTag.reset();
- for (const auto& tag : m_changedTags)
+ const auto it =
+ std::find_if(m_changedTags.cbegin(), m_changedTags.cend(), [&activeTime](const auto& tag) {
+ return tag.second->StartAsUTC() <= activeTime && tag.second->EndAsUTC() > activeTime;
+ });
+
+ if (it != m_changedTags.cend())
{
- if (tag.second->StartAsUTC() <= activeTime && tag.second->EndAsUTC() > activeTime)
- {
- m_nowActiveTag = tag.second;
- m_nowActiveStart = m_nowActiveTag->StartAsUTC();
- m_nowActiveEnd = m_nowActiveTag->EndAsUTC();
- break;
- }
+ m_nowActiveTag = (*it).second;
+ m_nowActiveStart = m_nowActiveTag->StartAsUTC();
+ m_nowActiveEnd = m_nowActiveTag->EndAsUTC();
}
if (!m_nowActiveTag && m_database)
diff --git a/xbmc/pvr/epg/EpgTagsContainer.cpp b/xbmc/pvr/epg/EpgTagsContainer.cpp
index a233135ceb..83f534f9c9 100644
--- a/xbmc/pvr/epg/EpgTagsContainer.cpp
+++ b/xbmc/pvr/epg/EpgTagsContainer.cpp
@@ -14,6 +14,9 @@
#include "pvr/epg/EpgTagsCache.h"
#include "utils/log.h"
+#include <algorithm>
+#include <iterator>
+
using namespace PVR;
namespace
@@ -164,18 +167,14 @@ bool CPVREpgTagsContainer::UpdateEntries(const CPVREpgTagsContainer& tags)
tag->SetChannelData(m_channelData);
tag->SetEpgID(m_iEpgID);
- std::shared_ptr<CPVREpgInfoTag> existingTag;
- for (const auto& t : existingTags)
- {
- if (t->StartAsUTC() == tag->StartAsUTC())
- {
- existingTag = t;
- break;
- }
- }
+ const auto it =
+ std::find_if(existingTags.cbegin(), existingTags.cend(),
+ [&tag](const auto& t) { return t->StartAsUTC() == tag->StartAsUTC(); });
- if (existingTag)
+ if (it != existingTags.cend())
{
+ const std::shared_ptr<CPVREpgInfoTag> existingTag = *it;
+
existingTag->SetChannelData(m_channelData);
existingTag->SetEpgID(m_iEpgID);
@@ -370,11 +369,13 @@ std::shared_ptr<CPVREpgInfoTag> CPVREpgTagsContainer::GetTag(unsigned int iUniqu
if (iUniqueBroadcastID == EPG_TAG_INVALID_UID)
return {};
- for (const auto& tag : m_changedTags)
- {
- if (tag.second->UniqueBroadcastID() == iUniqueBroadcastID)
- return tag.second;
- }
+ const auto it = std::find_if(m_changedTags.cbegin(), m_changedTags.cend(),
+ [iUniqueBroadcastID](const auto& tag) {
+ return tag.second->UniqueBroadcastID() == iUniqueBroadcastID;
+ });
+
+ if (it != m_changedTags.cend())
+ return (*it).second;
if (m_database)
return CreateEntry(m_database->GetEpgTagByUniqueBroadcastID(m_iEpgID, iUniqueBroadcastID));
@@ -387,11 +388,13 @@ std::shared_ptr<CPVREpgInfoTag> CPVREpgTagsContainer::GetTagByDatabaseID(int iDa
if (iDatabaseID <= 0)
return {};
- for (const auto& tag : m_changedTags)
- {
- if (tag.second->DatabaseID() == iDatabaseID)
- return tag.second;
- }
+ const auto it =
+ std::find_if(m_changedTags.cbegin(), m_changedTags.cend(), [iDatabaseID](const auto& tag) {
+ return tag.second->DatabaseID() == iDatabaseID;
+ });
+
+ if (it != m_changedTags.cend())
+ return (*it).second;
if (m_database)
return CreateEntry(m_database->GetEpgTagByDatabaseID(m_iEpgID, iDatabaseID));
@@ -586,8 +589,8 @@ std::vector<std::shared_ptr<CPVREpgInfoTag>> CPVREpgTagsContainer::GetAllTags()
if (!m_changedTags.empty() && !m_database->HasTags(m_iEpgID))
{
// nothing in the db yet. take what we have in memory.
- for (const auto& tag : m_changedTags)
- tags.emplace_back(tag.second);
+ std::transform(m_changedTags.cbegin(), m_changedTags.cend(), std::back_inserter(tags),
+ [](const auto& tag) { return tag.second; });
FixOverlappingEvents(tags);
}
diff --git a/xbmc/pvr/guilib/GUIEPGGridContainer.cpp b/xbmc/pvr/guilib/GUIEPGGridContainer.cpp
index f39f11e10e..d88dc86692 100644
--- a/xbmc/pvr/guilib/GUIEPGGridContainer.cpp
+++ b/xbmc/pvr/guilib/GUIEPGGridContainer.cpp
@@ -769,10 +769,7 @@ void CGUIEPGGridContainer::UpdateItems()
return;
}
}
- }
- if (prevSelectedEpgTag)
- {
if (newChannelIndex >= m_gridModel->ChannelItemsSize() ||
newBlockIndex >= m_gridModel->GridItemsSize() ||
m_gridModel->GetGridItem(newChannelIndex, newBlockIndex)->GetEPGInfoTag() !=
diff --git a/xbmc/pvr/guilib/GUIEPGGridContainerModel.cpp b/xbmc/pvr/guilib/GUIEPGGridContainerModel.cpp
index 8eca2946ac..cc36c77cb4 100644
--- a/xbmc/pvr/guilib/GUIEPGGridContainerModel.cpp
+++ b/xbmc/pvr/guilib/GUIEPGGridContainerModel.cpp
@@ -18,7 +18,9 @@
#include "utils/Variant.h"
#include "utils/log.h"
+#include <algorithm>
#include <cmath>
+#include <iterator>
#include <memory>
#include <vector>
@@ -80,11 +82,7 @@ void CGUIEPGGridContainerModel::Initialize(const std::unique_ptr<CFileItemList>&
////////////////////////////////////////////////////////////////////////
// Create channel items
- m_channelItems.reserve(items->Size());
- for (const auto& channelItem : *items)
- {
- m_channelItems.emplace_back(channelItem);
- }
+ std::copy(items->cbegin(), items->cend(), std::back_inserter(m_channelItems));
/* check for invalid start and end time */
if (gridStart >= gridEnd)
@@ -199,14 +197,12 @@ std::shared_ptr<CFileItem> CGUIEPGGridContainerModel::GetEpgTags(EpgTagsMap::ite
}
else
{
- for (const auto& item : epgTags.tags)
- {
- if (IsEventMemberOfBlock(item->GetEPGInfoTag(), iBlock))
- {
- result = item;
- break;
- }
- }
+ const auto it =
+ std::find_if(epgTags.tags.cbegin(), epgTags.tags.cend(), [this, iBlock](const auto& item) {
+ return IsEventMemberOfBlock(item->GetEPGInfoTag(), iBlock);
+ });
+ if (it != epgTags.tags.cend())
+ result = (*it);
}
return result;
@@ -225,11 +221,6 @@ std::shared_ptr<CFileItem> CGUIEPGGridContainerModel::GetEpgTagsBefore(EpgTags&
const auto tags =
GetEPGTimeline(iChannel, GetStartTimeForBlock(iBlock), GetStartTimeForBlock(lastBlock));
- const int firstResultBlock = GetFirstEventBlock(tags.front());
- const int lastResultBlock = GetLastEventBlock(tags.back());
- if (firstResultBlock > lastResultBlock)
- return result;
-
if (epgTags.lastBlock == -1)
epgTags.lastBlock = lastBlock;
@@ -239,6 +230,11 @@ std::shared_ptr<CFileItem> CGUIEPGGridContainerModel::GetEpgTagsBefore(EpgTags&
}
else
{
+ const int firstResultBlock = GetFirstEventBlock(tags.front());
+ const int lastResultBlock = GetLastEventBlock(tags.back());
+ if (firstResultBlock > lastResultBlock)
+ return result;
+
// insert before the existing tags
epgTags.firstBlock = firstResultBlock;
@@ -288,11 +284,6 @@ std::shared_ptr<CFileItem> CGUIEPGGridContainerModel::GetEpgTagsAfter(EpgTags& e
const auto tags =
GetEPGTimeline(iChannel, GetStartTimeForBlock(firstBlock), GetStartTimeForBlock(iBlock));
- const int firstResultBlock = GetFirstEventBlock(tags.front());
- const int lastResultBlock = GetLastEventBlock(tags.back());
- if (firstResultBlock > lastResultBlock)
- return result;
-
if (epgTags.firstBlock == -1)
epgTags.firstBlock = firstBlock;
@@ -302,6 +293,11 @@ std::shared_ptr<CFileItem> CGUIEPGGridContainerModel::GetEpgTagsAfter(EpgTags& e
}
else
{
+ const int firstResultBlock = GetFirstEventBlock(tags.front());
+ const int lastResultBlock = GetLastEventBlock(tags.back());
+ if (firstResultBlock > lastResultBlock)
+ return result;
+
// append to the existing tags
epgTags.lastBlock = lastResultBlock;
diff --git a/xbmc/pvr/guilib/PVRGUIActions.cpp b/xbmc/pvr/guilib/PVRGUIActions.cpp
index 14aa395931..05ab2b160d 100644
--- a/xbmc/pvr/guilib/PVRGUIActions.cpp
+++ b/xbmc/pvr/guilib/PVRGUIActions.cpp
@@ -73,6 +73,7 @@
#include <map>
#include <memory>
#include <mutex>
+#include <numeric>
#include <string>
#include <thread>
#include <utility>
@@ -176,14 +177,15 @@ namespace PVR
items.Add(item);
}
- bool bReturn = true;
- for (const auto& itemToDelete : items)
- {
- if (itemToDelete->IsPVRRecording() &&
- (!m_bWatchedOnly || itemToDelete->GetPVRRecordingInfoTag()->GetPlayCount() > 0))
- bReturn &= itemToDelete->GetPVRRecordingInfoTag()->Delete();
- }
- return bReturn;
+ return std::accumulate(
+ items.cbegin(), items.cend(), true, [this](bool success, const auto& itemToDelete) {
+ return (itemToDelete->IsPVRRecording() &&
+ (!m_bWatchedOnly ||
+ itemToDelete->GetPVRRecordingInfoTag()->GetPlayCount() > 0) &&
+ !itemToDelete->GetPVRRecordingInfoTag()->Delete())
+ ? false
+ : success;
+ });
}
bool m_bWatchedOnly = false;
};
@@ -602,14 +604,12 @@ namespace PVR
if (m_pDlgSelect->IsConfirmed())
{
int iSelection = m_pDlgSelect->GetSelectedItem();
- for (const auto& action : m_actions)
- {
- if (action.second == iSelection)
- {
- eAction = action.first;
- break;
- }
- }
+ const auto it =
+ std::find_if(m_actions.cbegin(), m_actions.cend(),
+ [iSelection](const auto& action) { return action.second == iSelection; });
+
+ if (it != m_actions.cend())
+ eAction = (*it).first;
}
return eAction;
@@ -1239,7 +1239,7 @@ namespace PVR
void CPVRGUIActions::StartPlayback(CFileItem* item,
bool bFullscreen,
- CPVRStreamProperties* epgProps) const
+ const CPVRStreamProperties* epgProps) const
{
// Obtain dynamic playback url and properties from the respective pvr client
const std::shared_ptr<CPVRClient> client = CServiceBroker::GetPVRManager().GetClient(*item);
@@ -1624,14 +1624,12 @@ namespace PVR
if (clientId != PVR_INVALID_CLIENT_ID)
{
- for (const auto& client : possibleScanClients)
- {
- if (client->GetID() == clientId)
- {
- scanClient = client;
- break;
- }
- }
+ const auto it =
+ std::find_if(possibleScanClients.cbegin(), possibleScanClients.cend(),
+ [clientId](const auto& client) { return client->GetID() == clientId; });
+
+ if (it != possibleScanClients.cend())
+ scanClient = (*it);
if (!scanClient)
{
@@ -1706,10 +1704,9 @@ namespace PVR
std::vector<std::pair<std::shared_ptr<CPVRClient>, CPVRClientMenuHook>> settingsHooks;
for (const auto& client : clients)
{
- for (const auto& hook : client.second->GetMenuHooks()->GetSettingsHooks())
- {
- settingsHooks.emplace_back(std::make_pair(client.second, hook));
- }
+ const auto hooks = client.second->GetMenuHooks()->GetSettingsHooks();
+ std::transform(hooks.cbegin(), hooks.cend(), std::back_inserter(settingsHooks),
+ [&client](const auto& hook) { return std::make_pair(client.second, hook); });
}
if (settingsHooks.empty())
diff --git a/xbmc/pvr/guilib/PVRGUIActions.h b/xbmc/pvr/guilib/PVRGUIActions.h
index 918a49c391..5635b55ed0 100644
--- a/xbmc/pvr/guilib/PVRGUIActions.h
+++ b/xbmc/pvr/guilib/PVRGUIActions.h
@@ -580,7 +580,7 @@ namespace PVR
*/
void StartPlayback(CFileItem* item,
bool bFullscreen,
- CPVRStreamProperties* epgProps = nullptr) const;
+ const CPVRStreamProperties* epgProps = nullptr) const;
bool AllLocalBackendsIdle(std::shared_ptr<CPVRTimerInfoTag>& causingEvent) const;
bool EventOccursOnLocalBackend(const std::shared_ptr<CFileItem>& item) const;
diff --git a/xbmc/pvr/providers/PVRProviders.cpp b/xbmc/pvr/providers/PVRProviders.cpp
index 4082038e38..e4dabe6857 100644
--- a/xbmc/pvr/providers/PVRProviders.cpp
+++ b/xbmc/pvr/providers/PVRProviders.cpp
@@ -18,8 +18,10 @@
#include "settings/Settings.h"
#include "utils/log.h"
+#include <algorithm>
#include <memory>
#include <mutex>
+#include <numeric>
#include <string>
#include <vector>
@@ -47,15 +49,11 @@ std::shared_ptr<CPVRProvider> CPVRProvidersContainer::GetByClient(int iClientId,
int iUniqueId) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& provider : m_providers)
- {
- if (provider->GetClientId() == iClientId && provider->GetUniqueId() == iUniqueId)
- {
- return provider;
- }
- }
-
- return {};
+ const auto it = std::find_if(
+ m_providers.cbegin(), m_providers.cend(), [iClientId, iUniqueId](const auto& provider) {
+ return provider->GetClientId() == iClientId && provider->GetUniqueId() == iUniqueId;
+ });
+ return it != m_providers.cend() ? (*it) : std::shared_ptr<CPVRProvider>();
}
void CPVRProvidersContainer::InsertEntry(const std::shared_ptr<CPVRProvider>& newProvider,
@@ -161,10 +159,14 @@ bool CPVRProviders::UpdateDefaultEntries(const CPVRProvidersContainer& newProvid
std::unique_lock<CCriticalSection> lock(m_critSection);
// go through the provider list and check for updated or new providers
- for (const auto& newProvider : newProviders.GetProvidersList())
- {
- bChanged |= (CheckAndPersistEntry(newProvider, ProviderUpdateMode::BY_CLIENT) != nullptr);
- }
+ const auto newProviderList = newProviders.GetProvidersList();
+ bChanged = std::accumulate(
+ newProviderList.cbegin(), newProviderList.cend(), false,
+ [this](bool changed, const auto& newProvider) {
+ return (CheckAndPersistEntry(newProvider, ProviderUpdateMode::BY_CLIENT) != nullptr)
+ ? true
+ : changed;
+ });
// check for deleted providers
for (std::vector<std::shared_ptr<CPVRProvider>>::iterator it = m_providers.begin();
@@ -221,30 +223,16 @@ bool CPVRProviders::UpdateClientEntries(const CPVRProvidersContainer& newProvide
const std::shared_ptr<CPVRProvider> provider = *it;
if (!newProviders.GetByClient(provider->GetClientId(), provider->GetUniqueId()))
{
- // provider was not found
- bool bIgnoreProvider = false;
- for (const auto& failedClient : failedClients)
- {
- if (failedClient == provider->GetClientId())
- {
- bIgnoreProvider = true;
- break;
- }
- }
-
- for (const auto& disabledClient : disabledClients)
- {
- if (disabledClient == provider->GetClientId())
- {
- bIgnoreProvider = true;
- break;
- }
- }
-
- // ignore add-on providers as they are a special case
- if (provider->IsClientProvider())
- bIgnoreProvider = true;
-
+ const bool bIgnoreProvider =
+ (provider->IsClientProvider() || // ignore add-on providers as they are a special case
+ std::any_of(failedClients.cbegin(), failedClients.cend(),
+ [&provider](const auto& failedClient) {
+ return failedClient == provider->GetClientId();
+ }) ||
+ std::any_of(disabledClients.cbegin(), disabledClients.cend(),
+ [&provider](const auto& disabledClient) {
+ return disabledClient == provider->GetClientId();
+ }));
if (bIgnoreProvider)
{
++it;
@@ -352,13 +340,11 @@ bool CPVRProviders::PersistUserChanges(const std::vector<std::shared_ptr<CPVRPro
std::shared_ptr<CPVRProvider> CPVRProviders::GetById(int iProviderId) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& provider : m_providers)
- {
- if (provider->GetDatabaseId() == iProviderId)
- return provider;
- }
-
- return {};
+ const auto it =
+ std::find_if(m_providers.cbegin(), m_providers.cend(), [iProviderId](const auto& provider) {
+ return provider->GetDatabaseId() == iProviderId;
+ });
+ return it != m_providers.cend() ? (*it) : std::shared_ptr<CPVRProvider>();
}
void CPVRProviders::RemoveEntry(const std::shared_ptr<CPVRProvider>& provider)
diff --git a/xbmc/pvr/recordings/PVRRecordings.cpp b/xbmc/pvr/recordings/PVRRecordings.cpp
index 0f04abaacf..b497b13c09 100644
--- a/xbmc/pvr/recordings/PVRRecordings.cpp
+++ b/xbmc/pvr/recordings/PVRRecordings.cpp
@@ -19,6 +19,8 @@
#include "utils/log.h"
#include "video/VideoDatabase.h"
+#include <algorithm>
+#include <iterator>
#include <memory>
#include <mutex>
#include <utility>
@@ -133,10 +135,8 @@ std::vector<std::shared_ptr<CPVRRecording>> CPVRRecordings::GetAll() const
std::vector<std::shared_ptr<CPVRRecording>> recordings;
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& recordingEntry : m_recordings)
- {
- recordings.emplace_back(recordingEntry.second);
- }
+ std::transform(m_recordings.cbegin(), m_recordings.cend(), std::back_inserter(recordings),
+ [](const auto& recordingEntry) { return recordingEntry.second; });
return recordings;
}
@@ -144,13 +144,11 @@ std::vector<std::shared_ptr<CPVRRecording>> CPVRRecordings::GetAll() const
std::shared_ptr<CPVRRecording> CPVRRecordings::GetById(unsigned int iId) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (const auto& recording : m_recordings)
- {
- if (iId == recording.second->m_iRecordingId)
- return recording.second;
- }
-
- return {};
+ const auto it =
+ std::find_if(m_recordings.cbegin(), m_recordings.cend(), [iId](const auto& recording) {
+ return recording.second->m_iRecordingId == iId;
+ });
+ return it != m_recordings.cend() ? (*it).second : std::shared_ptr<CPVRRecording>();
}
std::shared_ptr<CPVRRecording> CPVRRecordings::GetByPath(const std::string& path) const
diff --git a/xbmc/pvr/timers/PVRTimerType.cpp b/xbmc/pvr/timers/PVRTimerType.cpp
index c5f393beca..db20fa10af 100644
--- a/xbmc/pvr/timers/PVRTimerType.cpp
+++ b/xbmc/pvr/timers/PVRTimerType.cpp
@@ -16,6 +16,8 @@
#include "utils/StringUtils.h"
#include "utils/log.h"
+#include <algorithm>
+#include <iterator>
#include <memory>
#include <string>
#include <utility>
@@ -117,11 +119,12 @@ const std::shared_ptr<CPVRTimerType> CPVRTimerType::GetFirstAvailableType(const
std::shared_ptr<CPVRTimerType> CPVRTimerType::CreateFromIds(unsigned int iTypeId, int iClientId)
{
const std::vector<std::shared_ptr<CPVRTimerType>> types = GetAllTypes();
- for (const auto& type : types)
- {
- if ((type->GetClientId() == iClientId) && (type->GetTypeId() == iTypeId))
- return type;
- }
+ const auto it =
+ std::find_if(types.cbegin(), types.cend(), [iClientId, iTypeId](const auto& type) {
+ return type->GetClientId() == iClientId && type->GetTypeId() == iTypeId;
+ });
+ if (it != types.cend())
+ return (*it);
if (iClientId != -1)
{
@@ -140,13 +143,14 @@ std::shared_ptr<CPVRTimerType> CPVRTimerType::CreateFromAttributes(uint64_t iMus
int iClientId)
{
const std::vector<std::shared_ptr<CPVRTimerType>> types = GetAllTypes();
- for (const auto& type : types)
- {
- if ((type->GetClientId() == iClientId) &&
- ((type->GetAttributes() & iMustHaveAttr) == iMustHaveAttr) &&
- ((type->GetAttributes() & iMustNotHaveAttr) == 0))
- return type;
- }
+ const auto it = std::find_if(types.cbegin(), types.cend(),
+ [iClientId, iMustHaveAttr, iMustNotHaveAttr](const auto& type) {
+ return type->GetClientId() == iClientId &&
+ (type->GetAttributes() & iMustHaveAttr) == iMustHaveAttr &&
+ (type->GetAttributes() & iMustNotHaveAttr) == 0;
+ });
+ if (it != types.cend())
+ return (*it);
if (iClientId != -1)
{
@@ -282,8 +286,7 @@ void CPVRTimerType::InitPriorityValues(const PVR_TIMER_TYPE& type)
void CPVRTimerType::GetPriorityValues(std::vector<std::pair<std::string, int>>& list) const
{
- for (const auto& prio : m_priorityValues)
- list.push_back(prio);
+ std::copy(m_priorityValues.cbegin(), m_priorityValues.cend(), std::back_inserter(list));
}
void CPVRTimerType::InitLifetimeValues(const PVR_TIMER_TYPE& type)
@@ -323,8 +326,7 @@ void CPVRTimerType::InitLifetimeValues(const PVR_TIMER_TYPE& type)
void CPVRTimerType::GetLifetimeValues(std::vector<std::pair<std::string, int>>& list) const
{
- for (const auto& lifetime : m_lifetimeValues)
- list.push_back(lifetime);
+ std::copy(m_lifetimeValues.cbegin(), m_lifetimeValues.cend(), std::back_inserter(list));
}
void CPVRTimerType::InitMaxRecordingsValues(const PVR_TIMER_TYPE& type)
@@ -348,8 +350,7 @@ void CPVRTimerType::InitMaxRecordingsValues(const PVR_TIMER_TYPE& type)
void CPVRTimerType::GetMaxRecordingsValues(std::vector<std::pair<std::string, int>>& list) const
{
- for (const auto& maxRecordings : m_maxRecordingsValues)
- list.push_back(maxRecordings);
+ std::copy(m_maxRecordingsValues.cbegin(), m_maxRecordingsValues.cend(), std::back_inserter(list));
}
void CPVRTimerType::InitPreventDuplicateEpisodesValues(const PVR_TIMER_TYPE& type)
@@ -385,8 +386,8 @@ void CPVRTimerType::InitPreventDuplicateEpisodesValues(const PVR_TIMER_TYPE& typ
void CPVRTimerType::GetPreventDuplicateEpisodesValues(std::vector<std::pair<std::string, int>>& list) const
{
- for (const auto& preventDupEpisodes : m_preventDupEpisodesValues)
- list.push_back(preventDupEpisodes);
+ std::copy(m_preventDupEpisodesValues.cbegin(), m_preventDupEpisodesValues.cend(),
+ std::back_inserter(list));
}
void CPVRTimerType::InitRecordingGroupValues(const PVR_TIMER_TYPE& type)
@@ -412,6 +413,6 @@ void CPVRTimerType::InitRecordingGroupValues(const PVR_TIMER_TYPE& type)
void CPVRTimerType::GetRecordingGroupValues(std::vector< std::pair<std::string, int>>& list) const
{
- for (const auto& recordingGroup : m_recordingGroupValues)
- list.push_back(recordingGroup);
+ std::copy(m_recordingGroupValues.cbegin(), m_recordingGroupValues.cend(),
+ std::back_inserter(list));
}
diff --git a/xbmc/pvr/timers/PVRTimers.cpp b/xbmc/pvr/timers/PVRTimers.cpp
index 017e50487f..719163999d 100644
--- a/xbmc/pvr/timers/PVRTimers.cpp
+++ b/xbmc/pvr/timers/PVRTimers.cpp
@@ -24,9 +24,11 @@
#include "utils/log.h"
#include <algorithm>
+#include <iterator>
#include <map>
#include <memory>
#include <mutex>
+#include <numeric>
#include <string>
#include <utility>
#include <vector>
@@ -61,16 +63,16 @@ std::shared_ptr<CPVRTimerInfoTag> CPVRTimersContainer::GetByClient(int iClientId
std::unique_lock<CCriticalSection> lock(m_critSection);
for (const auto& startDates : m_tags)
{
- for (const auto& timer : startDates.second)
- {
- if (timer->m_iClientId == iClientId && timer->m_iClientIndex == iClientIndex)
- {
- return timer;
- }
- }
+ const auto it = std::find_if(startDates.second.cbegin(), startDates.second.cend(),
+ [iClientId, iClientIndex](const auto& timer) {
+ return timer->m_iClientId == iClientId &&
+ timer->m_iClientIndex == iClientIndex;
+ });
+ if (it != startDates.second.cend())
+ return (*it);
}
- return std::shared_ptr<CPVRTimerInfoTag>();
+ return {};
}
void CPVRTimersContainer::InsertEntry(const std::shared_ptr<CPVRTimerInfoTag>& newTimer)
@@ -110,16 +112,13 @@ bool CPVRTimers::LoadFromDatabase(const std::vector<std::shared_ptr<CPVRClient>>
const std::shared_ptr<CPVRDatabase> database = CServiceBroker::GetPVRManager().GetTVDatabase();
if (database)
{
- bool bChanged = false;
-
const std::vector<std::shared_ptr<CPVRTimerInfoTag>> timers =
database->GetTimers(*this, clients);
- for (const auto& timer : timers)
- {
- bChanged |= !!UpdateEntry(timer);
- }
- if (bChanged)
+ if (std::accumulate(timers.cbegin(), timers.cend(), false,
+ [this](bool changed, const auto& timer) {
+ return (UpdateEntry(timer) != nullptr) ? true : changed;
+ }))
NotifyTimersEvent();
}
return true;
@@ -177,10 +176,12 @@ bool CPVRTimers::IsRecording() const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (MapTags::const_iterator it = m_tags.begin(); it != m_tags.end(); ++it)
- for (VecTimerInfoTag::const_iterator timerIt = it->second.begin(); timerIt != it->second.end(); ++timerIt)
- if ((*timerIt)->IsRecording())
- return true;
+ for (const auto& tagsEntry : m_tags)
+ {
+ if (std::any_of(tagsEntry.second.cbegin(), tagsEntry.second.cend(),
+ [](const auto& timersEntry) { return timersEntry->IsRecording(); }))
+ return true;
+ }
return false;
}
@@ -232,17 +233,18 @@ bool CPVRTimers::UpdateEntries(const CPVRTimersContainer& timers, const std::vec
std::unique_lock<CCriticalSection> lock(m_critSection);
/* go through the timer list and check for updated or new timers */
- for (MapTags::const_iterator it = timers.GetTags().begin(); it != timers.GetTags().end(); ++it)
+ for (const auto& tagsEntry : timers.GetTags())
{
- for (VecTimerInfoTag::const_iterator timerIt = it->second.begin(); timerIt != it->second.end(); ++timerIt)
+ for (const auto& timersEntry : tagsEntry.second)
{
/* check if this timer is present in this container */
- std::shared_ptr<CPVRTimerInfoTag> existingTimer = GetByClient((*timerIt)->m_iClientId, (*timerIt)->m_iClientIndex);
+ const std::shared_ptr<CPVRTimerInfoTag> existingTimer =
+ GetByClient(timersEntry->m_iClientId, timersEntry->m_iClientIndex);
if (existingTimer)
{
/* if it's present, update the current tag */
- bool bStateChanged(existingTimer->m_state != (*timerIt)->m_state);
- if (existingTimer->UpdateEntry(*timerIt))
+ bool bStateChanged(existingTimer->m_state != timersEntry->m_state);
+ if (existingTimer->UpdateEntry(timersEntry))
{
bChanged = true;
existingTimer->ResetChildState();
@@ -250,15 +252,15 @@ bool CPVRTimers::UpdateEntries(const CPVRTimersContainer& timers, const std::vec
if (bStateChanged)
CheckAndAppendTimerNotification(timerNotifications, existingTimer, false);
- CLog::LogFC(LOGDEBUG, LOGPVR, "Updated timer {} on client {}", (*timerIt)->m_iClientIndex,
- (*timerIt)->m_iClientId);
+ CLog::LogFC(LOGDEBUG, LOGPVR, "Updated timer {} on client {}",
+ timersEntry->m_iClientIndex, timersEntry->m_iClientId);
}
}
else
{
/* new timer */
std::shared_ptr<CPVRTimerInfoTag> newTimer = std::shared_ptr<CPVRTimerInfoTag>(new CPVRTimerInfoTag);
- newTimer->UpdateEntry(*timerIt);
+ newTimer->UpdateEntry(timersEntry);
newTimer->m_iTimerId = ++m_iLastId;
InsertEntry(newTimer);
@@ -267,8 +269,8 @@ bool CPVRTimers::UpdateEntries(const CPVRTimersContainer& timers, const std::vec
CheckAndAppendTimerNotification(timerNotifications, newTimer, false);
- CLog::LogFC(LOGDEBUG, LOGPVR, "Added timer {} on client {}", (*timerIt)->m_iClientIndex,
- (*timerIt)->m_iClientId);
+ CLog::LogFC(LOGDEBUG, LOGPVR, "Added timer {} on client {}", timersEntry->m_iClientIndex,
+ timersEntry->m_iClientId);
}
}
}
@@ -277,9 +279,9 @@ bool CPVRTimers::UpdateEntries(const CPVRTimersContainer& timers, const std::vec
VecTimerInfoTag timersToMove;
/* check for deleted timers */
- for (MapTags::iterator it = m_tags.begin(); it != m_tags.end();)
+ for (auto it = m_tags.begin(); it != m_tags.end();)
{
- for (std::vector<std::shared_ptr<CPVRTimerInfoTag>>::iterator it2 = it->second.begin(); it2 != it->second.end();)
+ for (auto it2 = it->second.begin(); it2 != it->second.end();)
{
const std::shared_ptr<CPVRTimerInfoTag> timer = *it2;
if (!timers.GetByClient(timer->m_iClientId, timer->m_iClientIndex))
@@ -288,14 +290,9 @@ bool CPVRTimers::UpdateEntries(const CPVRTimersContainer& timers, const std::vec
bool bIgnoreTimer = !timer->IsOwnedByClient();
if (!bIgnoreTimer)
{
- for (const auto& failedClient : failedClients)
- {
- if (failedClient == timer->m_iClientId)
- {
- bIgnoreTimer = true;
- break;
- }
- }
+ bIgnoreTimer = std::any_of(
+ failedClients.cbegin(), failedClients.cend(),
+ [&timer](const auto& failedClient) { return failedClient == timer->m_iClientId; });
}
if (bIgnoreTimer)
@@ -342,9 +339,9 @@ bool CPVRTimers::UpdateEntries(const CPVRTimersContainer& timers, const std::vec
}
/* reinsert timers with changed timer start */
- for (VecTimerInfoTag::const_iterator timerIt = timersToMove.begin(); timerIt != timersToMove.end(); ++timerIt)
+ for (const auto& timer : timersToMove)
{
- InsertEntry(*timerIt);
+ InsertEntry(timer);
}
/* update child information for all parent timers */
@@ -413,26 +410,22 @@ namespace
const std::shared_ptr<CPVREpg> epg = channel->GetEPG();
if (epg)
{
- std::vector<std::shared_ptr<CPVREpgInfoTag>> tags = epg->GetTags();
- for (const auto& tag : tags)
- {
- if (matcher.Matches(tag))
- matches.emplace_back(tag);
- }
+ const std::vector<std::shared_ptr<CPVREpgInfoTag>> tags = epg->GetTags();
+ std::copy_if(tags.cbegin(), tags.cend(), std::back_inserter(matches),
+ [&matcher](const auto& tag) { return matcher.Matches(tag); });
}
}
else
{
// match any channel
- const std::vector<std::shared_ptr<CPVREpg>> epgs = CServiceBroker::GetPVRManager().EpgContainer().GetAllEpgs();
+ const std::vector<std::shared_ptr<CPVREpg>> epgs =
+ CServiceBroker::GetPVRManager().EpgContainer().GetAllEpgs();
+
for (const auto& epg : epgs)
{
- std::vector<std::shared_ptr<CPVREpgInfoTag>> tags = epg->GetTags();
- for (const auto& tag : tags)
- {
- if (matcher.Matches(tag))
- matches.emplace_back(tag);
- }
+ const std::vector<std::shared_ptr<CPVREpgInfoTag>> tags = epg->GetTags();
+ std::copy_if(tags.cbegin(), tags.cend(), std::back_inserter(matches),
+ [&matcher](const auto& tag) { return matcher.Matches(tag); });
}
}
@@ -498,9 +491,9 @@ bool CPVRTimers::UpdateEntries(int iMaxNotificationDelay)
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (MapTags::iterator it = m_tags.begin(); it != m_tags.end();)
+ for (auto it = m_tags.begin(); it != m_tags.end();)
{
- for (VecTimerInfoTag::iterator it2 = it->second.begin(); it2 != it->second.end();)
+ for (auto it2 = it->second.begin(); it2 != it->second.end();)
{
std::shared_ptr<CPVRTimerInfoTag> timer = *it2;
bool bDeleteTimer = false;
@@ -586,10 +579,10 @@ bool CPVRTimers::UpdateEntries(int iMaxNotificationDelay)
if (it1 == m_tags.end())
bCreate = true;
else
- bCreate = std::find_if(it1->second.cbegin(), it1->second.cend(),
+ bCreate = std::none_of(it1->second.cbegin(), it1->second.cend(),
[&timer](const std::shared_ptr<CPVRTimerInfoTag>& tmr) {
return tmr->m_iParentClientIndex == timer->m_iClientIndex;
- }) == it1->second.cend();
+ });
if (bCreate)
{
const CDateTimeSpan duration = timer->EndAsUTC() - timer->StartAsUTC();
@@ -714,7 +707,7 @@ std::shared_ptr<CPVRTimerInfoTag> CPVRTimers::GetNextActiveTimer(const TimerKind
}
}
- return std::shared_ptr<CPVRTimerInfoTag>();
+ return {};
}
std::shared_ptr<CPVRTimerInfoTag> CPVRTimers::GetNextActiveTimer(bool bIgnoreReminders /* = true */) const
@@ -737,19 +730,13 @@ std::vector<std::shared_ptr<CPVRTimerInfoTag>> CPVRTimers::GetActiveTimers() con
std::vector<std::shared_ptr<CPVRTimerInfoTag>> tags;
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (MapTags::const_iterator it = m_tags.begin(); it != m_tags.end(); ++it)
+ for (const auto& tagsEntry : m_tags)
{
- for (VecTimerInfoTag::const_iterator timerIt = it->second.begin(); timerIt != it->second.end(); ++timerIt)
- {
- std::shared_ptr<CPVRTimerInfoTag> current = *timerIt;
- if (current->IsActive() &&
- !current->IsBroken() &&
- !current->IsReminder() &&
- !current->IsTimerRule())
- {
- tags.emplace_back(current);
- }
- }
+ std::copy_if(tagsEntry.second.cbegin(), tagsEntry.second.cend(), std::back_inserter(tags),
+ [](const auto& timersEntry) {
+ return timersEntry->IsActive() && !timersEntry->IsBroken() &&
+ !timersEntry->IsReminder() && !timersEntry->IsTimerRule();
+ });
}
return tags;
@@ -762,15 +749,12 @@ int CPVRTimers::AmountActiveTimers(const TimerKind& eKind) const
for (const auto& tagsEntry : m_tags)
{
- for (const auto& timersEntry : tagsEntry.second)
- {
- if (KindMatchesTag(eKind, timersEntry) &&
- timersEntry->IsActive() &&
- !timersEntry->IsBroken() &&
- !timersEntry->IsReminder() &&
- !timersEntry->IsTimerRule())
- ++iReturn;
- }
+ iReturn += std::count_if(tagsEntry.second.cbegin(), tagsEntry.second.cend(),
+ [this, &eKind](const auto& timersEntry) {
+ return KindMatchesTag(eKind, timersEntry) &&
+ timersEntry->IsActive() && !timersEntry->IsBroken() &&
+ !timersEntry->IsReminder() && !timersEntry->IsTimerRule();
+ });
}
return iReturn;
@@ -798,17 +782,12 @@ std::vector<std::shared_ptr<CPVRTimerInfoTag>> CPVRTimers::GetActiveRecordings(c
for (const auto& tagsEntry : m_tags)
{
- for (const auto& timersEntry : tagsEntry.second)
- {
- if (KindMatchesTag(eKind, timersEntry) &&
- timersEntry->IsRecording() &&
- !timersEntry->IsTimerRule() &&
- !timersEntry->IsBroken() &&
- !timersEntry->IsReminder())
- {
- tags.emplace_back(timersEntry);
- }
- }
+ std::copy_if(tagsEntry.second.cbegin(), tagsEntry.second.cend(), std::back_inserter(tags),
+ [this, &eKind](const auto& timersEntry) {
+ return KindMatchesTag(eKind, timersEntry) && timersEntry->IsRecording() &&
+ !timersEntry->IsTimerRule() && !timersEntry->IsBroken() &&
+ !timersEntry->IsReminder();
+ });
}
return tags;
@@ -836,15 +815,12 @@ int CPVRTimers::AmountActiveRecordings(const TimerKind& eKind) const
for (const auto& tagsEntry : m_tags)
{
- for (const auto& timersEntry : tagsEntry.second)
- {
- if (KindMatchesTag(eKind, timersEntry) &&
- timersEntry->IsRecording() &&
- !timersEntry->IsTimerRule() &&
- !timersEntry->IsBroken() &&
- !timersEntry->IsReminder())
- ++iReturn;
- }
+ iReturn += std::count_if(tagsEntry.second.cbegin(), tagsEntry.second.cend(),
+ [this, &eKind](const auto& timersEntry) {
+ return KindMatchesTag(eKind, timersEntry) &&
+ timersEntry->IsRecording() && !timersEntry->IsTimerRule() &&
+ !timersEntry->IsBroken() && !timersEntry->IsReminder();
+ });
}
return iReturn;
@@ -876,17 +852,17 @@ bool CPVRTimers::DeleteTimersOnChannel(const std::shared_ptr<CPVRChannel>& chann
for (MapTags::reverse_iterator it = m_tags.rbegin(); it != m_tags.rend(); ++it)
{
- for (VecTimerInfoTag::iterator timerIt = it->second.begin(); timerIt != it->second.end(); ++timerIt)
+ for (const auto& timersEntry : (*it).second)
{
- bool bDeleteActiveItem = !bCurrentlyActiveOnly || (*timerIt)->IsRecording();
- bool bDeleteTimerRuleItem = bDeleteTimerRules || !(*timerIt)->IsTimerRule();
- bool bChannelsMatch = (*timerIt)->HasChannel() && (*timerIt)->Channel() == channel;
+ bool bDeleteActiveItem = !bCurrentlyActiveOnly || timersEntry->IsRecording();
+ bool bDeleteTimerRuleItem = bDeleteTimerRules || !timersEntry->IsTimerRule();
+ bool bChannelsMatch = timersEntry->HasChannel() && timersEntry->Channel() == channel;
if (bDeleteActiveItem && bDeleteTimerRuleItem && bChannelsMatch)
{
- CLog::LogFC(LOGDEBUG, LOGPVR, "Deleted timer {} on client {}", (*timerIt)->m_iClientIndex,
- (*timerIt)->m_iClientId);
- bReturn = ((*timerIt)->DeleteFromClient(true) == TimerOperationResult::OK) || bReturn;
+ CLog::LogFC(LOGDEBUG, LOGPVR, "Deleted timer {} on client {}",
+ timersEntry->m_iClientIndex, timersEntry->m_iClientId);
+ bReturn = (timersEntry->DeleteFromClient(true) == TimerOperationResult::OK) || bReturn;
bChanged = true;
}
}
@@ -1121,15 +1097,15 @@ bool CPVRTimers::IsRecordingOnChannel(const CPVRChannel& channel) const
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (MapTags::const_iterator it = m_tags.begin(); it != m_tags.end(); ++it)
+ for (const auto& tagsEntry : m_tags)
{
- for (VecTimerInfoTag::const_iterator timerIt = it->second.begin(); timerIt != it->second.end(); ++timerIt)
- {
- if ((*timerIt)->IsRecording() &&
- (*timerIt)->m_iClientChannelUid == channel.UniqueID() &&
- (*timerIt)->m_iClientId == channel.ClientID())
- return true;
- }
+ if (std::any_of(tagsEntry.second.cbegin(), tagsEntry.second.cend(),
+ [&channel](const auto& timersEntry) {
+ return timersEntry->IsRecording() &&
+ timersEntry->m_iClientChannelUid == channel.UniqueID() &&
+ timersEntry->m_iClientId == channel.ClientID();
+ }))
+ return true;
}
return false;
@@ -1140,16 +1116,17 @@ std::shared_ptr<CPVRTimerInfoTag> CPVRTimers::GetActiveTimerForChannel(const std
std::unique_lock<CCriticalSection> lock(m_critSection);
for (const auto& tagsEntry : m_tags)
{
- for (const auto& timersEntry : tagsEntry.second)
- {
- if (timersEntry->IsRecording() &&
- timersEntry->m_iClientChannelUid == channel->UniqueID() &&
- timersEntry->m_iClientId == channel->ClientID())
- return timersEntry;
- }
+ const auto it = std::find_if(tagsEntry.second.cbegin(), tagsEntry.second.cend(),
+ [&channel](const auto& timersEntry) {
+ return timersEntry->IsRecording() &&
+ timersEntry->m_iClientChannelUid == channel->UniqueID() &&
+ timersEntry->m_iClientId == channel->ClientID();
+ });
+ if (it != tagsEntry.second.cend())
+ return (*it);
}
- return std::shared_ptr<CPVRTimerInfoTag>();
+ return {};
}
std::shared_ptr<CPVRTimerInfoTag> CPVRTimers::GetTimerForEpgTag(const std::shared_ptr<CPVREpgInfoTag>& epgTag) const
@@ -1184,7 +1161,7 @@ std::shared_ptr<CPVRTimerInfoTag> CPVRTimers::GetTimerForEpgTag(const std::share
}
}
- return std::shared_ptr<CPVRTimerInfoTag>();
+ return {};
}
std::shared_ptr<CPVRTimerInfoTag> CPVRTimers::GetTimerRule(const std::shared_ptr<CPVRTimerInfoTag>& timer) const
@@ -1199,15 +1176,18 @@ std::shared_ptr<CPVRTimerInfoTag> CPVRTimers::GetTimerRule(const std::shared_ptr
std::unique_lock<CCriticalSection> lock(m_critSection);
for (const auto& tagsEntry : m_tags)
{
- for (const auto& timersEntry : tagsEntry.second)
- {
- if (timersEntry->m_iClientId == iClientId && timersEntry->m_iClientIndex == iRuleId)
- return timersEntry;
- }
+ const auto it = std::find_if(tagsEntry.second.cbegin(), tagsEntry.second.cend(),
+ [iClientId, iRuleId](const auto& timersEntry) {
+ return timersEntry->m_iClientId == iClientId &&
+ timersEntry->m_iClientIndex == iRuleId;
+ });
+ if (it != tagsEntry.second.cend())
+ return (*it);
}
}
}
- return std::shared_ptr<CPVRTimerInfoTag>();
+
+ return {};
}
void CPVRTimers::Notify(const PVREvent& event)
@@ -1277,10 +1257,10 @@ CDateTime CPVRTimers::GetNextEventTime() const
void CPVRTimers::UpdateChannels()
{
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (MapTags::iterator it = m_tags.begin(); it != m_tags.end(); ++it)
+ for (const auto& tagsEntry : m_tags)
{
- for (VecTimerInfoTag::iterator timerIt = it->second.begin(); timerIt != it->second.end(); ++timerIt)
- (*timerIt)->UpdateChannel();
+ for (const auto& timersEntry : tagsEntry.second)
+ timersEntry->UpdateChannel();
}
}
@@ -1291,10 +1271,7 @@ std::vector<std::shared_ptr<CPVRTimerInfoTag>> CPVRTimers::GetAll() const
std::unique_lock<CCriticalSection> lock(m_critSection);
for (const auto& tagsEntry : m_tags)
{
- for (const auto& timer : tagsEntry.second)
- {
- timers.emplace_back(timer);
- }
+ std::copy(tagsEntry.second.cbegin(), tagsEntry.second.cend(), std::back_inserter(timers));
}
return timers;
@@ -1302,17 +1279,17 @@ std::vector<std::shared_ptr<CPVRTimerInfoTag>> CPVRTimers::GetAll() const
std::shared_ptr<CPVRTimerInfoTag> CPVRTimers::GetById(unsigned int iTimerId) const
{
- std::shared_ptr<CPVRTimerInfoTag> item;
std::unique_lock<CCriticalSection> lock(m_critSection);
- for (MapTags::const_iterator it = m_tags.begin(); !item && it != m_tags.end(); ++it)
+ for (const auto& tagsEntry : m_tags)
{
- for (VecTimerInfoTag::const_iterator timerIt = it->second.begin(); !item && timerIt != it->second.end(); ++timerIt)
- {
- if ((*timerIt)->m_iTimerId == iTimerId)
- item = *timerIt;
- }
+ const auto it = std::find_if(
+ tagsEntry.second.cbegin(), tagsEntry.second.cend(),
+ [iTimerId](const auto& timersEntry) { return timersEntry->m_iTimerId == iTimerId; });
+ if (it != tagsEntry.second.cend())
+ return (*it);
}
- return item;
+
+ return {};
}
void CPVRTimers::NotifyTimersEvent(bool bAddedOrDeleted /* = true */)
diff --git a/xbmc/pvr/windows/GUIWindowPVRGuide.cpp b/xbmc/pvr/windows/GUIWindowPVRGuide.cpp
index 4b644fea47..720e1dffb5 100644
--- a/xbmc/pvr/windows/GUIWindowPVRGuide.cpp
+++ b/xbmc/pvr/windows/GUIWindowPVRGuide.cpp
@@ -52,10 +52,8 @@ using namespace PVR;
using namespace std::chrono_literals;
CGUIWindowPVRGuideBase::CGUIWindowPVRGuideBase(bool bRadio, int id, const std::string& xmlFile)
- : CGUIWindowPVRBase(bRadio, id, xmlFile), m_bChannelSelectionRestored(false)
+ : CGUIWindowPVRBase(bRadio, id, xmlFile)
{
- m_bRefreshTimelineItems = false;
- m_bSyncRefreshTimelineItems = false;
}
CGUIWindowPVRGuideBase::~CGUIWindowPVRGuideBase()
diff --git a/xbmc/pvr/windows/GUIWindowPVRGuide.h b/xbmc/pvr/windows/GUIWindowPVRGuide.h
index 4d1133c5de..e6cbc51850 100644
--- a/xbmc/pvr/windows/GUIWindowPVRGuide.h
+++ b/xbmc/pvr/windows/GUIWindowPVRGuide.h
@@ -88,12 +88,12 @@ namespace PVR
int GetCurrentListItemIndex(const std::shared_ptr<CFileItem>& item);
std::unique_ptr<CPVRRefreshTimelineItemsThread> m_refreshTimelineItemsThread;
- std::atomic_bool m_bRefreshTimelineItems;
- std::atomic_bool m_bSyncRefreshTimelineItems;
+ std::atomic_bool m_bRefreshTimelineItems{false};
+ std::atomic_bool m_bSyncRefreshTimelineItems{false};
std::shared_ptr<CPVRChannelGroup> m_cachedChannelGroup;
- bool m_bChannelSelectionRestored;
+ bool m_bChannelSelectionRestored{false};
};
class CGUIWindowPVRTVGuide : public CGUIWindowPVRGuideBase