Use unique_ptr instead of auto_ptr where available (and define a macro to pick which one to use); fix a few other remaining warnings.

This commit is contained in:
Brian Cox 2017-03-22 20:00:08 -07:00
parent 4cb15a741a
commit 5c1cfe4702
17 changed files with 55 additions and 33 deletions

View File

@ -1016,7 +1016,7 @@ cDoubleIconvConverter::Convert(
// //
size_t nBufBytes = nChars * MB_LEN_MAX; size_t nBufBytes = nChars * MB_LEN_MAX;
ntmbs_t pszBuffer = (ntmbs_t)::operator new( nBufBytes + 1 ); ntmbs_t pszBuffer = (ntmbs_t)::operator new( nBufBytes + 1 );
std::auto_ptr<mbchar_t> pBuf( pszBuffer ); TW_UNIQUE_PTR<mbchar_t> pBuf( pszBuffer );
// //
// do first conversion // do first conversion
@ -1074,7 +1074,7 @@ cDoubleIconvConverter::Convert(
// //
size_t nBufBytes = nBytes * MB_LEN_MAX; size_t nBufBytes = nBytes * MB_LEN_MAX;
ntmbs_t pszBuffer = (ntmbs_t)::operator new( nBufBytes + 1 ); ntmbs_t pszBuffer = (ntmbs_t)::operator new( nBufBytes + 1 );
std::auto_ptr<mbchar_t> pBuf( pszBuffer ); TW_UNIQUE_PTR<mbchar_t> pBuf( pszBuffer );
// //
// do first conversion // do first conversion

View File

@ -207,6 +207,7 @@ char *getenv(); /* get variable from environment */
* on some systems, this is a library function, so define STRDUP * on some systems, this is a library function, so define STRDUP
* if it is on yours * if it is on yours
*/ */
#if 0
#ifdef STRDUP #ifdef STRDUP
# ifndef __STDC__ # ifndef __STDC__
char *strdup(); char *strdup();
@ -230,7 +231,7 @@ char *getenv(); /* get variable from environment */
return(p); return(p);
} }
#endif #endif
#endif //0
/* /*
* allocate space for an array of pointers, OR * allocate space for an array of pointers, OR

View File

@ -135,9 +135,6 @@ void cRefCountObj::AddRef() const
void cRefCountObj::Release() const void cRefCountObj::Release() const
{ {
if (this == 0)
return;
if (--mRefCount == 0) if (--mRefCount == 0)
{ {
Delete(); Delete();

View File

@ -187,5 +187,16 @@ inline int64 SWAPBYTES64(int64 i)
#endif //WORDS_BIGENDIAN #endif //WORDS_BIGENDIAN
////////////////////////////////////////////
#if __cplusplus >= 201103L
# define TW_UNIQUE_PTR std::unique_ptr
#else
# define TW_UNIQUE_PTR std::auto_ptr
#endif
#endif // __TYPES_H #endif // __TYPES_H

View File

@ -5,6 +5,12 @@
#include "queue.h" #include "queue.h"
#include <memory> #include <memory>
#if __cplusplus >= 201103L
# define TW_UNIQUE_PTR std::unique_ptr
#else
# define TW_UNIQUE_PTR std::auto_ptr
#endif
Filter::Filter(BufferedTransformation *outQ) Filter::Filter(BufferedTransformation *outQ)
: outQueue(outQ ? outQ : new ByteQueue) : outQueue(outQ ? outQ : new ByteQueue)
{ {
@ -17,7 +23,7 @@ Filter::Filter(const Filter &source)
void Filter::Detach(BufferedTransformation *newOut) void Filter::Detach(BufferedTransformation *newOut)
{ {
std::auto_ptr<BufferedTransformation> out(newOut ? newOut : new ByteQueue); TW_UNIQUE_PTR<BufferedTransformation> out(newOut ? newOut : new ByteQueue);
outQueue->Close(); outQueue->Close();
outQueue->TransferTo(*out); outQueue->TransferTo(*out);
outQueue.reset(out.release()); outQueue.reset(out.release());

View File

@ -5,6 +5,12 @@
#include "queue.h" #include "queue.h"
#include <memory> #include <memory>
#if __cplusplus >= 201103L
# define TW_UNIQUE_PTR std::unique_ptr
#else
# define TW_UNIQUE_PTR std::auto_ptr
#endif
Fork::Fork(int n, BufferedTransformation *const *givenOutPorts) Fork::Fork(int n, BufferedTransformation *const *givenOutPorts)
: numberOfPorts(n), outPorts(n) : numberOfPorts(n), outPorts(n)
{ {
@ -21,7 +27,7 @@ void Fork::SelectOutPort(int portNumber)
void Fork::Detach(BufferedTransformation *newOut) void Fork::Detach(BufferedTransformation *newOut)
{ {
std::auto_ptr<BufferedTransformation> out(newOut ? newOut : new ByteQueue); TW_UNIQUE_PTR<BufferedTransformation> out(newOut ? newOut : new ByteQueue);
outPorts[currentPort]->Close(); outPorts[currentPort]->Close();
outPorts[currentPort]->TransferTo(*out); outPorts[currentPort]->TransferTo(*out);
outPorts[currentPort].reset(out.release()); outPorts[currentPort].reset(out.release());

View File

@ -100,7 +100,7 @@ static void util_ProcessDir( cDbDataSourceIter dbIter, iFCODataSourceIter* pIter
{ {
dbIter.AddChildArray(); dbIter.AddChildArray();
} }
std::auto_ptr<iFCODataSourceIter> pCopy( pIter->CreateCopy() ); TW_UNIQUE_PTR<iFCODataSourceIter> pCopy( pIter->CreateCopy() );
util_ProcessDir( dbIter, pCopy.get(), pSpec, pPC, pPD ); util_ProcessDir( dbIter, pCopy.get(), pSpec, pPC, pPD );
// //
// if no files were added, remove the child array... // if no files were added, remove the child array...
@ -122,7 +122,7 @@ void cGenerateDb::Execute( const cFCOSpecList& specList, cHierDatabase& db, iFCO
{ {
// TODO -- assert the db is empty or clear it out myself! // TODO -- assert the db is empty or clear it out myself!
std::auto_ptr<iFCODataSourceIter> pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); TW_UNIQUE_PTR<iFCODataSourceIter> pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter());
// //
// set up the database's iterator... // set up the database's iterator...
@ -139,7 +139,7 @@ void cGenerateDb::Execute( const cFCOSpecList& specList, cHierDatabase& db, iFCO
// //
// this is the object that will calculate all of the properties of the fcos. // this is the object that will calculate all of the properties of the fcos.
// //
std::auto_ptr<iFCOPropCalc> pPC(iTWFactory::GetInstance()->CreatePropCalc()); TW_UNIQUE_PTR<iFCOPropCalc> pPC(iTWFactory::GetInstance()->CreatePropCalc());
pPC->SetErrorBucket( pBucket ); pPC->SetErrorBucket( pBucket );
if( flags & FLAG_ERASE_FOOTPRINTS_GD ) if( flags & FLAG_ERASE_FOOTPRINTS_GD )
{ {
@ -193,7 +193,7 @@ void cGenerateDb::Execute( const cFCOSpecList& specList, cHierDatabase& db, iFCO
{ {
dbIter.AddChildArray(); dbIter.AddChildArray();
} }
std::auto_ptr<iFCODataSourceIter> pCopy( pDSIter->CreateCopy() ); TW_UNIQUE_PTR<iFCODataSourceIter> pCopy( pDSIter->CreateCopy() );
util_ProcessDir( dbIter, pCopy.get(), specIter.Spec(), pPC.get(), pPD ); util_ProcessDir( dbIter, pCopy.get(), specIter.Spec(), pPC.get(), pPD );
// //
// if no files were added, remove the child array... // if no files were added, remove the child array...

View File

@ -90,7 +90,7 @@ void cIntegrityCheck::ProcessAddedFCO( cDbDataSourceIter dbIter, iFCODataSourceI
// to done... // to done...
// //
while( ! dbIter.Done() ) dbIter.Next(); while( ! dbIter.Done() ) dbIter.Next();
std::auto_ptr<iFCODataSourceIter> pCopy( pIter->CreateCopy() ); TW_UNIQUE_PTR<iFCODataSourceIter> pCopy( pIter->CreateCopy() );
ProcessDir( dbIter, pCopy.get() ); ProcessDir( dbIter, pCopy.get() );
} }
} }
@ -231,7 +231,7 @@ void cIntegrityCheck::ProcessChangedFCO( cDbDataSourceIter dbIter, iFCODataSourc
{ {
if( pIter->CanDescend() || dbIter.CanDescend() ) if( pIter->CanDescend() || dbIter.CanDescend() )
{ {
std::auto_ptr<iFCODataSourceIter> pCopy( pIter->CreateCopy() ); TW_UNIQUE_PTR<iFCODataSourceIter> pCopy( pIter->CreateCopy() );
ProcessDir( dbIter, pCopy.get() ); ProcessDir( dbIter, pCopy.get() );
} }
} }
@ -453,7 +453,7 @@ void cIntegrityCheck::Execute( uint32 flags )
mFlags = flags; mFlags = flags;
// create the data source iterator // create the data source iterator
// //
std::auto_ptr<iFCODataSourceIter> pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); TW_UNIQUE_PTR<iFCODataSourceIter> pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter());
// //
// set up the database's iterator... // set up the database's iterator...
// I assume the current genre is correct... // I assume the current genre is correct...
@ -560,7 +560,7 @@ void cIntegrityCheck::ExecuteOnObjectList( const std::list<cFCOName>& fcoNames,
// //
// create the data source iterator // create the data source iterator
// //
std::auto_ptr<iFCODataSourceIter> pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); TW_UNIQUE_PTR<iFCODataSourceIter> pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter());
// //
// set up the database's iterator... // set up the database's iterator...
// I assume the current genre is correct... // I assume the current genre is correct...

View File

@ -44,7 +44,7 @@
#include "core/errorbucketimpl.h" #include "core/errorbucketimpl.h"
#include "core/usernotifystdout.h" #include "core/usernotifystdout.h"
#include "core/timebomb.h" #include "core/timebomb.h"
#include <memory> // for auto_ptr #include <memory> // for auto_ptr / unique_ptr
#include <iostream> #include <iostream>
#include <exception> #include <exception>
@ -133,7 +133,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] )
// first, get the right mode... // first, get the right mode...
std::auto_ptr<iTWMode> pMode(cTWCmdLine::GetMode(argc, argv)); TW_UNIQUE_PTR<iTWMode> pMode(cTWCmdLine::GetMode(argc, argv));
if(! pMode.get()) if(! pMode.get())
{ {
// no valid mode passed; GetMode will display an appropriate string (include usage statement) // no valid mode passed; GetMode will display an appropriate string (include usage statement)

View File

@ -1129,7 +1129,7 @@ int cTWModeIC::Execute(cErrorQueue* pQueue)
if( ! dbIter.Done() ) if( ! dbIter.Done() )
{ {
cGenreSwitcher::GetInstance()->SelectGenre( (cGenre::Genre)dbIter.GetGenre() ); cGenreSwitcher::GetInstance()->SelectGenre( (cGenre::Genre)dbIter.GetGenre() );
std::auto_ptr<iParserGenreUtil> pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); TW_UNIQUE_PTR<iParserGenreUtil> pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil());
// //
// I have to turn this into a list of cFCONames // I have to turn this into a list of cFCONames
// //

View File

@ -531,7 +531,7 @@ static bool EmailReportTo(const TSTRING &toAddress, const cFCOReportHeader& head
const cTWModeCommon *modeCommon, const cTWModeCommon *modeCommon,
const bool bForceFullReport) const bool bForceFullReport)
{ {
std::auto_ptr<cMailMessage> reportMail; TW_UNIQUE_PTR<cMailMessage> reportMail;
// allocate the right kind of emailer object based on what came out of the config file. // allocate the right kind of emailer object based on what came out of the config file.
switch (modeCommon->mMailMethod) switch (modeCommon->mMailMethod)
@ -540,10 +540,10 @@ static bool EmailReportTo(const TSTRING &toAddress, const cFCOReportHeader& head
ASSERT(false); ASSERT(false);
return false; return false;
case cMailMessage::MAIL_BY_SMTP: case cMailMessage::MAIL_BY_SMTP:
reportMail = std::auto_ptr<cMailMessage>(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); reportMail = TW_UNIQUE_PTR<cMailMessage>(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort));
break; break;
case cMailMessage::MAIL_BY_PIPE: case cMailMessage::MAIL_BY_PIPE:
reportMail = std::auto_ptr<cMailMessage>(new cPipedMailMessage(modeCommon->mMailProgram)); reportMail = TW_UNIQUE_PTR<cMailMessage>(new cPipedMailMessage(modeCommon->mMailProgram));
break; break;
} }
@ -685,7 +685,7 @@ bool cTWCmdLineUtil::EmailReport(const cFCOReportHeader& header, const cFCORepor
bool cTWCmdLineUtil::SendEmailTestMessage(const TSTRING &mAddress, const cTWModeCommon *modeCommon) bool cTWCmdLineUtil::SendEmailTestMessage(const TSTRING &mAddress, const cTWModeCommon *modeCommon)
{ {
std::auto_ptr<cMailMessage> reportMail; TW_UNIQUE_PTR<cMailMessage> reportMail;
// allocate the right kind of emailer object based on what came out of the config file. // allocate the right kind of emailer object based on what came out of the config file.
switch (modeCommon->mMailMethod) switch (modeCommon->mMailMethod)
@ -694,10 +694,10 @@ bool cTWCmdLineUtil::SendEmailTestMessage(const TSTRING &mAddress, const cTWMode
ASSERT(false); ASSERT(false);
return false; return false;
case cMailMessage::MAIL_BY_SMTP: case cMailMessage::MAIL_BY_SMTP:
reportMail = std::auto_ptr<cMailMessage>(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); reportMail = TW_UNIQUE_PTR<cMailMessage>(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort));
break; break;
case cMailMessage::MAIL_BY_PIPE: case cMailMessage::MAIL_BY_PIPE:
reportMail = std::auto_ptr<cMailMessage>(new cPipedMailMessage(modeCommon->mMailProgram)); reportMail = TW_UNIQUE_PTR<cMailMessage>(new cPipedMailMessage(modeCommon->mMailProgram));
break; break;
} }

View File

@ -1247,7 +1247,7 @@ void cTWUtil::ParseObjectList( cTWUtil::GenreObjList& listOut, const cTWUtil::Ob
// //
if( g == cGenre::GENRE_INVALID ) if( g == cGenre::GENRE_INVALID )
{ {
std::auto_ptr<iParserGenreUtil> pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); TW_UNIQUE_PTR<iParserGenreUtil> pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil());
if( ! pParseUtil->IsAbsolutePath( *i ) ) if( ! pParseUtil->IsAbsolutePath( *i ) )
throw eTWUnknownSectionName( *i ); throw eTWUnknownSectionName( *i );
} }
@ -1310,7 +1310,7 @@ void cTWUtil::ParseObjectList( cTWUtil::GenreObjList& listOut, const cTWUtil::Ob
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
cFCOName cTWUtil::ParseObjectName( const TSTRING& fcoName ) cFCOName cTWUtil::ParseObjectName( const TSTRING& fcoName )
{ {
std::auto_ptr<iParserGenreUtil> pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); TW_UNIQUE_PTR<iParserGenreUtil> pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil());
cFCOName name( iTWFactory::GetInstance()->GetNameInfo() ); cFCOName name( iTWFactory::GetInstance()->GetNameInfo() );
// //
// make sure the fco name is a full path... // make sure the fco name is a full path...

View File

@ -94,7 +94,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] )
// first, get the right mode... // first, get the right mode...
std::auto_ptr<iTWAMode> pMode(cTWAdminCmdLine::GetMode(argc, argv)); TW_UNIQUE_PTR<iTWAMode> pMode(cTWAdminCmdLine::GetMode(argc, argv));
if(! pMode.get()) if(! pMode.get())
{ {
// no valid mode passed; GetMode will display an appropriate string (include usage statement) // no valid mode passed; GetMode will display an appropriate string (include usage statement)

View File

@ -128,7 +128,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ] )
} }
// Next, set the mode... exit with error if now valid mode specified. // Next, set the mode... exit with error if now valid mode specified.
std::auto_ptr<iTWMode> pMode(cTWPrintCmdLine::GetMode(argc, argv)); TW_UNIQUE_PTR<iTWMode> pMode(cTWPrintCmdLine::GetMode(argc, argv));
if(! pMode.get()) if(! pMode.get())
{ {
// no valid mode passed; GetMode will display an appropriate string (include usage statement) // no valid mode passed; GetMode will display an appropriate string (include usage statement)

View File

@ -182,9 +182,10 @@ char NonZeroChar( char ch )
} }
// mbchar_t to dbchar_t // mbchar_t to dbchar_t
//TestMbToDb in codeconvert_t.cpp seems to hit an infinite loop or runs verrrry long; ifdef'd"
void TestMbToDb() void TestMbToDb()
{ {
TCERR << "TODO: TestMbToDb in codeconvert_t.cpp seems to hit an infinite loop or runs verrrry long; ifdef'd" << std::endl; TCERR << "\nTODO: TestMbToDb in codeconvert_t.cpp is flaky & needs to be fixed/replaced; currently disabled." << std::endl;
#if 0 #if 0
std::string s; std::string s;
s.resize( 0x10000 * 2 ); // two bytes for each combination s.resize( 0x10000 * 2 ); // two bytes for each combination

View File

@ -39,7 +39,7 @@ class cRefCountTestObj : public cRefCountObj
public: public:
cRefCountTestObj(); cRefCountTestObj();
virtual void Release(); virtual void Release() const;
void AddChild(cRefCountTestObj* pChild); void AddChild(cRefCountTestObj* pChild);
@ -74,7 +74,7 @@ void cRefCountTestObj::AddChild(cRefCountTestObj* pChild)
mChildren.push_back(pChild); mChildren.push_back(pChild);
} }
void cRefCountTestObj::Release() void cRefCountTestObj::Release() const
{ {
cRefCountObj::Release(); cRefCountObj::Release();
} }

View File

@ -68,7 +68,7 @@ void TestUnixFSServices()
d.TraceDebug("name: %d entries\n", v.size()); d.TraceDebug("name: %d entries\n", v.size());
std::vector <TSTRING>::iterator p; std::vector <TSTRING>::iterator p;
int n = 0; size_t n = 0;
for (p = v.begin(); p != v.end(); p++) { for (p = v.begin(); p != v.end(); p++) {
d.TraceDetail(" %s\n", p->c_str()); d.TraceDetail(" %s\n", p->c_str());
n++; n++;