Skip to content

Commit

Permalink
Merge pull request #16573 from Rechi/modernize/readability-redundant-…
Browse files Browse the repository at this point in the history
…smartptr-get

[modernize] readability-redundant-smartptr-get
  • Loading branch information
Rechi committed Sep 5, 2019
2 parents 8b45479 + 25cc1cd commit df4baf4
Show file tree
Hide file tree
Showing 35 changed files with 894 additions and 503 deletions.
2 changes: 1 addition & 1 deletion xbmc/cdrip/CDDARipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool CCDDARipper::RipCD()
CFileItemPtr pItem = vecItems[i];
CMusicInfoTagLoaderFactory factory;
std::unique_ptr<IMusicInfoTagLoader> pLoader (factory.CreateLoader(*pItem));
if (NULL != pLoader.get())
if (nullptr != pLoader)
{
pLoader->Load(pItem->GetPath(), *pItem->GetMusicInfoTag()); // get tag from file
if (!pItem->GetMusicInfoTag()->Loaded())
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxVobsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool CDVDDemuxVobsub::Open(const std::string& filename, int source, const std::s
item.SetMimeType("video/x-vobsub");
item.SetContentLookup(false);
m_Input = CDVDFactoryInputStream::CreateInputStream(NULL, item);
if(!m_Input.get() || !m_Input->Open())
if (!m_Input || !m_Input->Open())
return false;

m_Demuxer.reset(new CDVDDemuxFFmpeg());
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/DVDFileInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool CDVDFileInfo::GetFileDuration(const std::string &path, int& duration)
return false;

demux.reset(CDVDFactoryDemuxer::CreateDemuxer(input, true));
if (!demux.get())
if (!demux)
return false;

duration = demux->GetStreamLength();
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/VideoPlayer/DVDStreamInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ bool CDVDStreamInfo::Equal(const CDVDStreamInfo& right, bool withextradata)
// SUBTITLE

// Crypto
if ((cryptoSession.get() == nullptr) != (right.cryptoSession.get() == nullptr))
if ((cryptoSession == nullptr) != (right.cryptoSession == nullptr))
return false;

if (cryptoSession && !(*cryptoSession.get() == *right.cryptoSession.get()))
if (cryptoSession && !(*cryptoSession == *right.cryptoSession))
return false;

return true;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/Process/ProcessInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ CVideoSettings CProcessInfo::GetVideoSettings()
CVideoSettingsLocked& CProcessInfo::UpdateVideoSettings()
{
CSingleLock lock(m_settingsSection);
return *m_videoSettingsLocked.get();
return *m_videoSettingsLocked;
}

void CProcessInfo::SetVideoSettings(CVideoSettings &settings)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/paplayer/VideoPlayerCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool VideoPlayerCodec::Init(const CFileItem &file, unsigned int filecache)
CDVDStreamInfo hint(*pStream, true);

CAEStreamInfo::DataType ptStreamTye = GetPassthroughStreamType(hint.codec, hint.samplerate);
m_pAudioCodec = CDVDFactoryCodec::CreateAudioCodec(hint, *m_processInfo.get(), true, true, ptStreamTye);
m_pAudioCodec = CDVDFactoryCodec::CreateAudioCodec(hint, *m_processInfo, true, true, ptStreamTye);
if (!m_pAudioCodec)
{
CLog::Log(LOGERROR, "%s: Could not create audio codec", __FUNCTION__);
Expand Down
40 changes: 25 additions & 15 deletions xbmc/dbwrappers/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ std::string CDatabase::PrepareSQL(std::string strStmt, ...) const
{
std::string strResult = "";

if (NULL != m_pDB.get())
if (nullptr != m_pDB)
{
va_list args;
va_start(args, strStmt);
Expand All @@ -263,7 +263,7 @@ std::string CDatabase::GetSingleValue(const std::string &query, std::unique_ptr<
std::string ret;
try
{
if (!m_pDB.get() || !ds.get())
if (!m_pDB || !ds)
return ret;

if (ds->query(query) && ds->num_rows() > 0)
Expand Down Expand Up @@ -336,8 +336,10 @@ bool CDatabase::ExecuteQuery(const std::string &strQuery)

try
{
if (NULL == m_pDB.get()) return bReturn;
if (NULL == m_pDS.get()) return bReturn;
if (nullptr == m_pDB)
return bReturn;
if (nullptr == m_pDS)
return bReturn;
m_pDS->exec(strQuery);
bReturn = true;
}
Expand All @@ -356,8 +358,10 @@ bool CDatabase::ResultQuery(const std::string &strQuery)

try
{
if (NULL == m_pDB.get()) return bReturn;
if (NULL == m_pDS.get()) return bReturn;
if (nullptr == m_pDB)
return bReturn;
if (nullptr == m_pDS)
return bReturn;

std::string strPreparedQuery = PrepareSQL(strQuery.c_str());

Expand All @@ -379,8 +383,10 @@ bool CDatabase::QueueInsertQuery(const std::string &strQuery)

if (!m_bMultiWrite)
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS2.get()) return false;
if (nullptr == m_pDB)
return false;
if (nullptr == m_pDS2)
return false;

m_bMultiWrite = true;
m_pDS2->insert();
Expand Down Expand Up @@ -596,8 +602,10 @@ void CDatabase::Close()
m_openCount = 0;
m_multipleExecute = false;

if (NULL == m_pDB.get() ) return ;
if (NULL != m_pDS.get()) m_pDS->close();
if (nullptr == m_pDB)
return;
if (nullptr != m_pDS)
m_pDS->close();
m_pDB->disconnect();
m_pDB.reset();
m_pDS.reset();
Expand All @@ -611,8 +619,10 @@ bool CDatabase::Compress(bool bForce /* =true */)

try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
if (nullptr == m_pDB)
return false;
if (nullptr == m_pDS)
return false;
if (!bForce)
{
m_pDS->query("select iCompressCount from version");
Expand Down Expand Up @@ -649,7 +659,7 @@ void CDatabase::BeginTransaction()
{
try
{
if (NULL != m_pDB.get())
if (nullptr != m_pDB)
m_pDB->start_transaction();
}
catch (...)
Expand All @@ -662,7 +672,7 @@ bool CDatabase::CommitTransaction()
{
try
{
if (NULL != m_pDB.get())
if (nullptr != m_pDB)
m_pDB->commit_transaction();
}
catch (...)
Expand All @@ -677,7 +687,7 @@ void CDatabase::RollbackTransaction()
{
try
{
if (NULL != m_pDB.get())
if (nullptr != m_pDB)
m_pDB->rollback_transaction();
}
catch (...)
Expand Down
12 changes: 6 additions & 6 deletions xbmc/filesystem/Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool CDirectory::GetDirectory(const CURL& url, std::shared_ptr<IDirectory> pDire
try
{
CURL realURL = URIUtils::SubstitutePath(url);
if (!pDirectory.get())
if (!pDirectory)
return false;

// check our cache for this path
Expand Down Expand Up @@ -323,7 +323,7 @@ bool CDirectory::Create(const CURL& url)
CPasswordManager::GetInstance().AuthenticateURL(realURL);

std::unique_ptr<IDirectory> pDirectory(CDirectoryFactory::Create(realURL));
if (pDirectory.get())
if (pDirectory)
if(pDirectory->Create(realURL))
return true;
}
Expand Down Expand Up @@ -362,7 +362,7 @@ bool CDirectory::Exists(const CURL& url, bool bUseCache /* = true */)
CPasswordManager::GetInstance().AuthenticateURL(realURL);

std::unique_ptr<IDirectory> pDirectory(CDirectoryFactory::Create(realURL));
if (pDirectory.get())
if (pDirectory)
return pDirectory->Exists(realURL);
}
XBMCCOMMONS_HANDLE_UNCHECKED
Expand Down Expand Up @@ -395,7 +395,7 @@ bool CDirectory::Remove(const CURL& url)
CPasswordManager::GetInstance().AuthenticateURL(authUrl);

std::unique_ptr<IDirectory> pDirectory(CDirectoryFactory::Create(realURL));
if (pDirectory.get())
if (pDirectory)
if(pDirectory->Remove(authUrl))
{
g_directoryCache.ClearFile(realURL.Get());
Expand All @@ -421,7 +421,7 @@ bool CDirectory::RemoveRecursive(const CURL& url)
CPasswordManager::GetInstance().AuthenticateURL(authUrl);

std::unique_ptr<IDirectory> pDirectory(CDirectoryFactory::Create(realURL));
if (pDirectory.get())
if (pDirectory)
if(pDirectory->RemoveRecursive(authUrl))
{
g_directoryCache.ClearFile(realURL.Get());
Expand All @@ -447,7 +447,7 @@ void CDirectory::FilterFileDirectories(CFileItemList &items, const std::string &
if (!pItem->m_bIsFolder && pItem->IsFileFolder(mode))
{
std::unique_ptr<IFileDirectory> pDirectory(CFileDirectoryFactory::Create(pItem->GetURL(),pItem.get(),mask));
if (pDirectory.get())
if (pDirectory)
pItem->m_bIsFolder = true;
else
if (pItem->m_bIsFolder)
Expand Down
20 changes: 10 additions & 10 deletions xbmc/filesystem/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ bool CFile::Open(const CURL& file, const unsigned int flags)
m_pFile = pRedirectEx->m_pNewFileImp;
delete pRedirectEx;

if (pNewUrl.get())
if (pNewUrl)
{
CURL newAuthUrl(*pNewUrl);
if (CPasswordManager::GetInstance().IsURLSupported(newAuthUrl) && newAuthUrl.GetUserName().empty())
Expand Down Expand Up @@ -439,7 +439,7 @@ bool CFile::Exists(const CURL& file, bool bUseCache /* = true */)
}

std::unique_ptr<IFile> pFile(CFileFactory::CreateLoader(url));
if (!pFile.get())
if (!pFile)
return false;

return pFile->Exists(authUrl);
Expand All @@ -456,9 +456,9 @@ bool CFile::Exists(const CURL& file, bool bUseCache /* = true */)
std::unique_ptr<CURL> pNewUrl(pRedirectEx->m_pNewUrl);
delete pRedirectEx;

if (pImp.get())
if (pImp)
{
if (pNewUrl.get())
if (pNewUrl)
{
if (bUseCache)
{
Expand Down Expand Up @@ -523,7 +523,7 @@ int CFile::Stat(const CURL& file, struct __stat64* buffer)
try
{
std::unique_ptr<IFile> pFile(CFileFactory::CreateLoader(url));
if (!pFile.get())
if (!pFile)
return -1;
return pFile->Stat(authUrl, buffer);
}
Expand All @@ -539,9 +539,9 @@ int CFile::Stat(const CURL& file, struct __stat64* buffer)
std::unique_ptr<CURL> pNewUrl(pRedirectEx->m_pNewUrl);
delete pRedirectEx;

if (pNewUrl.get())
if (pNewUrl)
{
if (pImp.get())
if (pImp)
{
CURL newAuthUrl = *pNewUrl;
if (CPasswordManager::GetInstance().IsURLSupported(newAuthUrl) && newAuthUrl.GetUserName().empty())
Expand Down Expand Up @@ -869,7 +869,7 @@ bool CFile::Delete(const CURL& file)
CPasswordManager::GetInstance().AuthenticateURL(authUrl);

std::unique_ptr<IFile> pFile(CFileFactory::CreateLoader(url));
if (!pFile.get())
if (!pFile)
return false;

if(pFile->Delete(authUrl))
Expand Down Expand Up @@ -910,7 +910,7 @@ bool CFile::Rename(const CURL& file, const CURL& newFile)
CPasswordManager::GetInstance().AuthenticateURL(authUrlNew);

std::unique_ptr<IFile> pFile(CFileFactory::CreateLoader(url));
if (!pFile.get())
if (!pFile)
return false;

if(pFile->Rename(authUrl, authUrlNew))
Expand Down Expand Up @@ -945,7 +945,7 @@ bool CFile::SetHidden(const CURL& file, bool hidden)
CPasswordManager::GetInstance().AuthenticateURL(authUrl);

std::unique_ptr<IFile> pFile(CFileFactory::CreateLoader(url));
if (!pFile.get())
if (!pFile)
return false;

return pFile->SetHidden(authUrl, hidden);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/filesystem/FileCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void CFileCache::Process()

// create our read buffer
std::unique_ptr<char[]> buffer(new char[m_chunkSize]);
if (buffer.get() == NULL)
if (buffer == nullptr)
{
CLog::Log(LOGERROR, "%s - failed to allocate read buffer", __FUNCTION__);
return;
Expand Down
14 changes: 7 additions & 7 deletions xbmc/filesystem/MusicDatabaseDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool CMusicDatabaseDirectory::GetDirectory(const CURL& url, CFileItemList &items

std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));

if (!pNode.get())
if (!pNode)
return false;

bool bResult = pNode->GetChilds(items);
Expand All @@ -59,7 +59,7 @@ NODE_TYPE CMusicDatabaseDirectory::GetDirectoryChildType(const std::string& strP
std::string path = CLegacyPathTranslation::TranslateMusicDbPath(strPath);
std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));

if (!pNode.get())
if (!pNode)
return NODE_TYPE_NONE;

return pNode->GetChildType();
Expand All @@ -70,7 +70,7 @@ NODE_TYPE CMusicDatabaseDirectory::GetDirectoryType(const std::string& strPath)
std::string path = CLegacyPathTranslation::TranslateMusicDbPath(strPath);
std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));

if (!pNode.get())
if (!pNode)
return NODE_TYPE_NONE;

return pNode->GetType();
Expand All @@ -81,7 +81,7 @@ NODE_TYPE CMusicDatabaseDirectory::GetDirectoryParentType(const std::string& str
std::string path = CLegacyPathTranslation::TranslateMusicDbPath(strPath);
std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));

if (!pNode.get())
if (!pNode)
return NODE_TYPE_NONE;

CDirectoryNode* pParentNode=pNode->GetParent();
Expand Down Expand Up @@ -124,7 +124,7 @@ bool CMusicDatabaseDirectory::GetLabel(const std::string& strDirectory, std::str

std::string path = CLegacyPathTranslation::TranslateMusicDbPath(strDirectory);
std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
if (!pNode.get())
if (!pNode)
return false;

// first see if there's any filter criteria
Expand Down Expand Up @@ -237,7 +237,7 @@ bool CMusicDatabaseDirectory::Exists(const CURL& url)
std::string path = CLegacyPathTranslation::TranslateMusicDbPath(url);
std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));

if (!pNode.get())
if (!pNode)
return false;

if (pNode->GetChildType() == MUSICDATABASEDIRECTORY::NODE_TYPE_NONE)
Expand All @@ -250,7 +250,7 @@ bool CMusicDatabaseDirectory::CanCache(const std::string& strPath)
{
std::string path = CLegacyPathTranslation::TranslateMusicDbPath(strPath);
std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
if (!pNode.get())
if (!pNode)
return false;
return pNode->CanCache();
}
Expand Down
4 changes: 2 additions & 2 deletions xbmc/filesystem/MusicDatabaseDirectory/DirectoryNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void CDirectoryNode::GetDatabaseInfo(const std::string& strPath, CQueryParams& p
{
std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(strPath));

if (!pNode.get())
if (!pNode)
return;

pNode->CollectQueryParams(params);
Expand Down Expand Up @@ -250,7 +250,7 @@ bool CDirectoryNode::GetChilds(CFileItemList& items)
std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::CreateNode(GetChildType(), "", this));

bool bSuccess=false;
if (pNode.get())
if (pNode)
{
pNode->m_options = m_options;
bSuccess=pNode->GetContent(items);
Expand Down

0 comments on commit df4baf4

Please sign in to comment.