Skip to content

Commit

Permalink
cppcheck: Fix "consider using std::xxx" warnings. (plugins)
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Oct 7, 2020
1 parent fef663e commit 7c56627
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 89 deletions.
24 changes: 9 additions & 15 deletions mythplugins/mytharchive/mytharchive/fileselector.cpp
Expand Up @@ -237,14 +237,9 @@ void FileSelector::OKPressed()
{
f = m_selectedList.at(x);

for (const auto *a : qAsConst(*m_archiveList))
{
if (a->filename == f)
{
tempSList.append(f);
break;
}
}
auto namematch = [f](const auto *a){ return a->filename == f; };
if (std::any_of(m_archiveList->cbegin(), m_archiveList->cend(), namematch))
tempSList.append(f);
}

for (int x = 0; x < tempSList.size(); x++)
Expand Down Expand Up @@ -349,14 +344,13 @@ void FileSelector::updateSelectedList()

for (const auto *a : qAsConst(*m_archiveList))
{
for (const auto *f : qAsConst(m_fileData))
auto samename = [a](const auto *f)
{ return f->filename == a->filename; };
auto f = std::find_if(m_fileData.cbegin(), m_fileData.cend(), samename);
if (f != m_fileData.cend())
{
if (f->filename == a->filename)
{
if (m_selectedList.indexOf(f->filename) == -1)
m_selectedList.append(f->filename);
break;
}
if (m_selectedList.indexOf((*f)->filename) == -1)
m_selectedList.append((*f)->filename);
}
}
}
Expand Down
11 changes: 2 additions & 9 deletions mythplugins/mythbrowser/mythbrowser/bookmarkmanager.cpp
Expand Up @@ -232,15 +232,8 @@ void BookmarkManager::UpdateURLList(void)

uint BookmarkManager::GetMarkedCount(void)
{
uint count = 0;

for (auto *site : qAsConst(m_siteList))
{
if (site && site->m_selected)
count++;
}

return count;
auto selected = [](auto *site){ return site && site->m_selected; };
return std::count_if(m_siteList.cbegin(), m_siteList.cend(), selected);
}

bool BookmarkManager::keyPressEvent(QKeyEvent *event)
Expand Down
31 changes: 10 additions & 21 deletions mythplugins/mythgame/mythgame/gamesettings.cpp
Expand Up @@ -29,31 +29,20 @@ const std::array<GameTypes,12> GameTypeList

QString GetGameTypeName(const QString &GameType)
{
QString result = "";

for (const auto & console : GameTypeList)
{
if (console.m_idStr == GameType) {
result = QCoreApplication::translate("(GameTypes)",
console.m_nameStr.toUtf8());
break;
}
}
return result;
auto sametype = [GameType](const auto & console)
{ return console.m_idStr == GameType; };
const auto *const con = std::find_if(GameTypeList.cbegin(), GameTypeList.cend(), sametype);
return (con != GameTypeList.cend())
? QCoreApplication::translate("(GameTypes)", con->m_nameStr.toUtf8())
: "";
}

QString GetGameTypeExtensions(const QString &GameType)
{
QString result = "";

for (const auto & console : GameTypeList)
{
if (console.m_idStr == GameType) {
result = console.m_extensions;
break;
}
}
return result;
auto sametype = [GameType](const auto & console)
{ return console.m_idStr == GameType; };
const auto *const con = std::find_if(GameTypeList.cbegin(), GameTypeList.cend(), sametype);
return (con != GameTypeList.cend()) ? con->m_extensions : "";
}

// -----------------------------------------------------------------------
Expand Down
13 changes: 6 additions & 7 deletions mythplugins/mythmusic/mythmusic/decoder.cpp
Expand Up @@ -101,11 +101,10 @@ Decoder *Decoder::create(const QString &source, AudioOutput *output, bool deleta
{
checkFactories();

for (const auto & factory : qAsConst(*factories))
{
if (factory->supports(source))
return factory->create(source, output, deletable);
}

return nullptr;
auto supported = [source](const auto & factory)
{ return factory->supports(source); };
auto f = std::find_if(factories->cbegin(), factories->cend(), supported);
return (f != factories->cend())
? (*f)->create(source, output, deletable)
: nullptr;
}
42 changes: 19 additions & 23 deletions mythplugins/mythmusic/mythmusic/playlistcontainer.cpp
Expand Up @@ -141,11 +141,11 @@ Playlist *PlaylistContainer::getPlaylist(int id)
return m_activePlaylist;
}

for (const auto & playlist : qAsConst(*m_allPlaylists))
{
if (playlist->getID() == id)
return playlist;
}
auto idmatch = [id](const auto & playlist)
{ return playlist->getID() == id; };
auto it = std::find_if(m_allPlaylists->cbegin(), m_allPlaylists->cend(), idmatch);
if (it != m_allPlaylists->cend())
return *it;

LOG(VB_GENERAL, LOG_ERR,
"getPlaylistName() called with unknown index number");
Expand All @@ -156,12 +156,11 @@ Playlist *PlaylistContainer::getPlaylist(const QString &name)
{
// return a pointer to a playlist
// by name;

for (const auto & playlist : qAsConst(*m_allPlaylists))
{
if (playlist->getName() == name)
return playlist;
}
auto namematch = [name](const auto & playlist)
{ return playlist->getName() == name; };
auto it = std::find_if(m_allPlaylists->cbegin(), m_allPlaylists->cend(), namematch);
if (it != m_allPlaylists->cend())
return *it;

LOG(VB_GENERAL, LOG_ERR, QString("getPlaylistName() called with unknown name: %1").arg(name));
return nullptr;
Expand Down Expand Up @@ -259,11 +258,11 @@ QString PlaylistContainer::getPlaylistName(int index, bool &reference)
return m_activePlaylist->getName();
}

for (const auto & playlist : qAsConst(*m_allPlaylists))
{
if (playlist->getID() == index)
return playlist->getName();
}
auto indexmatch = [index](const auto & playlist)
{ return playlist->getID() == index; };
auto it = std::find_if(m_allPlaylists->cbegin(), m_allPlaylists->cend(), indexmatch);
if (it != m_allPlaylists->cend())
return (*it)->getName();
}

LOG(VB_GENERAL, LOG_ERR, LOC +
Expand All @@ -278,13 +277,10 @@ bool PlaylistContainer::nameIsUnique(const QString& a_name, int which_id)
if (a_name == DEFAULT_PLAYLIST_NAME)
return false;

for (const auto & playlist : qAsConst(*m_allPlaylists))
{
if (playlist->getName() == a_name && playlist->getID() != which_id)
return false;
}

return true;
auto itemfound = [a_name,which_id](const auto & playlist)
{ return playlist->getName() == a_name &&
playlist->getID() != which_id; };
return std::none_of(m_allPlaylists->cbegin(), m_allPlaylists->cend(), itemfound);
}

QStringList PlaylistContainer::getPlaylistNames(void)
Expand Down
17 changes: 8 additions & 9 deletions mythplugins/mythweather/mythweather/sourceManager.cpp
Expand Up @@ -240,16 +240,15 @@ WeatherSource *SourceManager::needSourceFor(int id, const QString &loc,
}

// no matching source, make one
for (auto *si : qAsConst(m_scripts))
auto idmatch = [id](auto *si){ return si->id == id; };
auto it = std::find_if(m_scripts.cbegin(), m_scripts.cend(), idmatch);
if (it != m_scripts.cend())
{
if (si->id == id)
{
auto *ws = new WeatherSource(si);
ws->setLocale(loc);
ws->setUnits(units);
m_sources.append(ws);
return ws;
}
auto *ws = new WeatherSource(*it);
ws->setLocale(loc);
ws->setUnits(units);
m_sources.append(ws);
return ws;
}

LOG(VB_GENERAL, LOG_ERR, LOC +
Expand Down
9 changes: 4 additions & 5 deletions mythplugins/mythweather/mythweather/weatherSetup.cpp
Expand Up @@ -645,11 +645,10 @@ void ScreenSetup::customEvent(QEvent *event)
{
auto *si = dce->GetData().value<ScreenListInfo *>();

for (const auto & type : qAsConst(si->m_types))
{
if (type.m_location.isEmpty())
return;
}
if (std::any_of(si->m_types.cbegin(), si->m_types.cend(),
[](const auto & type)
{ return type.m_location.isEmpty(); } ))
return;

if (si->m_updating)
{
Expand Down

0 comments on commit 7c56627

Please sign in to comment.