1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-05 14:18:53 +02:00

Hide the use of new in factory functions for BlockFiles

This commit is contained in:
Paul Licameli 2016-08-13 12:59:19 -04:00
parent 2ede67be96
commit e7b4d935a5
10 changed files with 66 additions and 64 deletions

View File

@ -48,6 +48,13 @@ class BlockFile;
// to do: use shared_ptr instead
using BlockFilePtr = BlockFile *;
// to do: make this a synonym for make_shared
template< typename Result, typename... Args >
inline Result *make_blockfile (Args && ... args)
{
return new Result( std::forward< Args > ( args )... );
}
class PROFILE_DLL_API BlockFile /* not final, abstract */ {
public:

View File

@ -871,11 +871,10 @@ BlockFilePtr DirManager::NewSimpleBlockFile(
wxFileNameWrapper filePath{ MakeBlockFileName() };
const wxString fileName{ filePath.GetName() };
BlockFile *newBlockFile =
new SimpleBlockFile(std::move(filePath), sampleData, sampleLen, format,
allowDeferredWrite);
auto newBlockFile = make_blockfile<SimpleBlockFile>
(std::move(filePath), sampleData, sampleLen, format, allowDeferredWrite);
mBlockFileHash[fileName]=newBlockFile;
mBlockFileHash[fileName] = newBlockFile;
return newBlockFile;
}
@ -887,10 +886,9 @@ BlockFilePtr DirManager::NewAliasBlockFile(
wxFileNameWrapper filePath{ MakeBlockFileName() };
const wxString fileName = filePath.GetName();
BlockFile *newBlockFile =
new PCMAliasBlockFile(std::move(filePath),
wxFileNameWrapper{aliasedFile},
aliasStart, aliasLen, aliasChannel);
auto newBlockFile = make_blockfile<PCMAliasBlockFile>
(std::move(filePath), wxFileNameWrapper{aliasedFile},
aliasStart, aliasLen, aliasChannel);
mBlockFileHash[fileName]=newBlockFile;
aliasList.Add(aliasedFile);
@ -905,9 +903,9 @@ BlockFilePtr DirManager::NewODAliasBlockFile(
wxFileNameWrapper filePath{ MakeBlockFileName() };
const wxString fileName{ filePath.GetName() };
BlockFile *newBlockFile =
new ODPCMAliasBlockFile(std::move(filePath),
wxFileNameWrapper{aliasedFile}, aliasStart, aliasLen, aliasChannel);
auto newBlockFile = make_blockfile<ODPCMAliasBlockFile>
(std::move(filePath), wxFileNameWrapper{aliasedFile},
aliasStart, aliasLen, aliasChannel);
mBlockFileHash[fileName]=newBlockFile;
aliasList.Add(aliasedFile);
@ -922,9 +920,9 @@ BlockFilePtr DirManager::NewODDecodeBlockFile(
wxFileNameWrapper filePath{ MakeBlockFileName() };
const wxString fileName{ filePath.GetName() };
BlockFile *newBlockFile =
new ODDecodeBlockFile(std::move(filePath),
wxFileNameWrapper{aliasedFile}, aliasStart, aliasLen, aliasChannel, decodeType);
auto newBlockFile = make_blockfile<ODDecodeBlockFile>
(std::move(filePath), wxFileNameWrapper{ aliasedFile },
aliasStart, aliasLen, aliasChannel, decodeType);
mBlockFileHash[fileName]=newBlockFile;
aliasList.Add(aliasedFile); //OD TODO: check to see if we need to remove this when done decoding.

View File

@ -678,7 +678,7 @@ bool Sequence::InsertSilence(sampleCount s0, sampleCount len)
BlockFilePtr silentFile {};
if (len >= idealSamples)
silentFile = new SilentBlockFile(idealSamples);
silentFile = make_blockfile<SilentBlockFile>(idealSamples);
while (len >= idealSamples) {
sTrack.mBlock.push_back(SeqBlock(silentFile, pos));
mDirManager->Ref(silentFile);
@ -689,7 +689,8 @@ bool Sequence::InsertSilence(sampleCount s0, sampleCount len)
if (silentFile)
mDirManager->Deref(silentFile);
if (len) {
sTrack.mBlock.push_back(SeqBlock(new SilentBlockFile(len), pos));
sTrack.mBlock.push_back(SeqBlock(
make_blockfile<SilentBlockFile>(len), pos));
pos += len;
}
@ -971,7 +972,7 @@ void Sequence::HandleXMLEndTag(const wxChar *tag)
Internat::ToString(((wxLongLong)mMaxSamples).ToDouble(), 0).c_str());
len = mMaxSamples;
}
block.f = new SilentBlockFile(len);
block.f = make_blockfile<SilentBlockFile>(len);
wxLogWarning(
wxT("Gap detected in project file. Replacing missing block file with silence."));
mErrorOpening = true;
@ -1233,7 +1234,7 @@ bool Sequence::Set(samplePtr buffer, sampleFormat format,
blen == fileLength) {
mDirManager->Deref(block.f);
block.f = new SilentBlockFile(blen);
block.f = make_blockfile<SilentBlockFile>(blen);
}
else {
// Odd partial blocks of silence at start or end.

View File

@ -53,12 +53,10 @@ LegacyAliasBlockFile::~LegacyAliasBlockFile()
/// @param newFileName The filename to copy the summary data to.
BlockFilePtr LegacyAliasBlockFile::Copy(wxFileNameWrapper &&newFileName)
{
BlockFile *newBlockFile =
new LegacyAliasBlockFile(std::move(newFileName),
wxFileNameWrapper{mAliasedFileName}, mAliasStart,
mLen, mAliasChannel,
mSummaryInfo.totalSummaryBytes,
mSummaryInfo.fields < 3);
auto newBlockFile = make_blockfile<LegacyAliasBlockFile>
(std::move(newFileName), wxFileNameWrapper{ mAliasedFileName },
mAliasStart, mLen, mAliasChannel,
mSummaryInfo.totalSummaryBytes, mSummaryInfo.fields < 3);
return newBlockFile;
}
@ -133,9 +131,9 @@ BlockFilePtr LegacyAliasBlockFile::BuildFromXML(const wxString &projDir, const w
}
}
return new LegacyAliasBlockFile(std::move(summaryFileName), std::move(aliasFileName),
aliasStart, aliasLen, aliasChannel,
summaryLen, noRMS);
return make_blockfile<LegacyAliasBlockFile>
(std::move(summaryFileName), std::move(aliasFileName),
aliasStart, aliasLen, aliasChannel, summaryLen, noRMS);
}
// regenerates the summary info, doesn't deal with missing alias files

View File

@ -328,7 +328,8 @@ BlockFilePtr LegacyBlockFile::BuildFromXML(const wxString &projDir, const wxChar
}
}
return new LegacyBlockFile(std::move(fileName), format, summaryLen, len, noRMS);
return make_blockfile<LegacyBlockFile>
(std::move(fileName), format, summaryLen, len, noRMS);
}
/// Create a copy of this BlockFile, but using a different disk file.
@ -336,11 +337,10 @@ BlockFilePtr LegacyBlockFile::BuildFromXML(const wxString &projDir, const wxChar
/// @param newFileName The name of the NEW file to use.
BlockFilePtr LegacyBlockFile::Copy(wxFileNameWrapper &&newFileName)
{
return new LegacyBlockFile(std::move(newFileName),
mFormat,
mSummaryInfo.totalSummaryBytes,
mLen,
mSummaryInfo.fields < 3);
return make_blockfile<LegacyBlockFile>
(std::move(newFileName),
mFormat, mSummaryInfo.totalSummaryBytes,
mLen, mSummaryInfo.fields < 3);
}
wxLongLong LegacyBlockFile::GetSpaceUsage() const

View File

@ -172,10 +172,10 @@ BlockFilePtr ODDecodeBlockFile::Copy(wxFileNameWrapper &&newFileName)
else
{
//Summary File might exist in this case, but it probably (99.999% of the time) won't.
newBlockFile = new ODDecodeBlockFile(std::move(newFileName),
wxFileNameWrapper{mAudioFileName}, mAliasStart,
mLen, mAliasChannel, mType,
mMin, mMax, mRMS,IsSummaryAvailable());
newBlockFile = make_blockfile<ODDecodeBlockFile>
(std::move(newFileName), wxFileNameWrapper{mAudioFileName},
mAliasStart, mLen, mAliasChannel, mType,
mMin, mMax, mRMS, IsSummaryAvailable());
//The client code will need to schedule this blockfile for OD decoding if it is going to a NEW track.
//It can do this by checking for IsDataAvailable()==false.
}
@ -274,10 +274,9 @@ BlockFilePtr ODDecodeBlockFile::BuildFromXML(DirManager &dm, const wxChar **attr
}
}
return new ODDecodeBlockFile(std::move(summaryFileName), std::move(audioFileName),
aliasStart, aliasLen, aliasChannel,decodeType,
0,0,0, false);
return make_blockfile<ODDecodeBlockFile>
(std::move(summaryFileName), std::move(audioFileName),
aliasStart, aliasLen, aliasChannel, decodeType, 0, 0, 0, false);
}

View File

@ -228,19 +228,18 @@ BlockFilePtr ODPCMAliasBlockFile::Copy(wxFileNameWrapper &&newFileName)
//PCMAliasBlockFile is to lock on exit, and this will cause orphaned blockfiles..
if(IsSummaryAvailable() && mHasBeenSaved)
{
newBlockFile = new PCMAliasBlockFile(std::move(newFileName),
wxFileNameWrapper{mAliasedFileName}, mAliasStart,
mLen, mAliasChannel,
mMin, mMax, mRMS);
newBlockFile = make_blockfile<PCMAliasBlockFile>
(std::move(newFileName), wxFileNameWrapper{mAliasedFileName},
mAliasStart, mLen, mAliasChannel, mMin, mMax, mRMS);
}
else
{
//Summary File might exist in this case, but it might not.
newBlockFile = new ODPCMAliasBlockFile(std::move(newFileName),
wxFileNameWrapper{mAliasedFileName}, mAliasStart,
mLen, mAliasChannel,
mMin, mMax, mRMS,IsSummaryAvailable());
newBlockFile = make_blockfile<ODPCMAliasBlockFile>
(std::move(newFileName), wxFileNameWrapper{mAliasedFileName},
mAliasStart, mLen, mAliasChannel, mMin, mMax, mRMS,
IsSummaryAvailable());
//The client code will need to schedule this blockfile for OD summarizing if it is going to a NEW track.
}
@ -339,9 +338,9 @@ BlockFilePtr ODPCMAliasBlockFile::BuildFromXML(DirManager &dm, const wxChar **at
}
}
return new ODPCMAliasBlockFile(std::move(summaryFileName), std::move(aliasFileName),
aliasStart, aliasLen, aliasChannel,
0,0,0, false);
return make_blockfile<ODPCMAliasBlockFile>
(std::move(summaryFileName), std::move(aliasFileName),
aliasStart, aliasLen, aliasChannel, 0, 0, 0, false);
}

View File

@ -152,10 +152,9 @@ int PCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
/// @param newFileName The filename to copy the summary data to.
BlockFilePtr PCMAliasBlockFile::Copy(wxFileNameWrapper &&newFileName)
{
BlockFile *newBlockFile = new PCMAliasBlockFile(std::move(newFileName),
wxFileNameWrapper{mAliasedFileName}, mAliasStart,
mLen, mAliasChannel,
mMin, mMax, mRMS);
auto newBlockFile = make_blockfile<PCMAliasBlockFile>
(std::move(newFileName), wxFileNameWrapper{mAliasedFileName},
mAliasStart, mLen, mAliasChannel, mMin, mMax, mRMS);
return newBlockFile;
}
@ -249,9 +248,9 @@ BlockFilePtr PCMAliasBlockFile::BuildFromXML(DirManager &dm, const wxChar **attr
}
}
return new PCMAliasBlockFile(std::move(summaryFileName), std::move(aliasFileName),
aliasStart, aliasLen, aliasChannel,
min, max, rms);
return make_blockfile<PCMAliasBlockFile>
(std::move(summaryFileName), std::move(aliasFileName),
aliasStart, aliasLen, aliasChannel, min, max, rms);
}
void PCMAliasBlockFile::Recover(void)

View File

@ -71,13 +71,13 @@ BlockFilePtr SilentBlockFile::BuildFromXML(DirManager & WXUNUSED(dm), const wxCh
len = nValue;
}
return new SilentBlockFile(len);
return make_blockfile<SilentBlockFile>(len);
}
/// Create a copy of this BlockFile
BlockFilePtr SilentBlockFile::Copy(wxFileNameWrapper &&)
{
BlockFile *newBlockFile = new SilentBlockFile(mLen);
auto newBlockFile = make_blockfile<SilentBlockFile>(mLen);
return newBlockFile;
}

View File

@ -532,7 +532,8 @@ BlockFilePtr SimpleBlockFile::BuildFromXML(DirManager &dm, const wxChar **attrs)
}
}
return new SimpleBlockFile(std::move(fileName), len, min, max, rms);
return make_blockfile<SimpleBlockFile>
(std::move(fileName), len, min, max, rms);
}
/// Create a copy of this BlockFile, but using a different disk file.
@ -540,8 +541,8 @@ BlockFilePtr SimpleBlockFile::BuildFromXML(DirManager &dm, const wxChar **attrs)
/// @param newFileName The name of the NEW file to use.
BlockFilePtr SimpleBlockFile::Copy(wxFileNameWrapper &&newFileName)
{
BlockFile *newBlockFile = new SimpleBlockFile(std::move(newFileName), mLen,
mMin, mMax, mRMS);
auto newBlockFile = make_blockfile<SimpleBlockFile>
(std::move(newFileName), mLen, mMin, mMax, mRMS);
return newBlockFile;
}