Review uses of safenew...

... add comments and assertions, and use make_unique instead where possible
This commit is contained in:
Paul Licameli 2016-08-13 23:16:05 -04:00
parent 84a6456788
commit 32f24eabb2
13 changed files with 24 additions and 6 deletions

View File

@ -934,6 +934,7 @@ MixerBoard::MixerBoard(AudacityProject* pProject,
this->LoadMusicalInstruments(); // Set up mMusicalInstruments.
mProject = pProject;
wxASSERT(pProject); // to justify safenew
mScrolledWindow =
safenew MixerBoardScrolledWindow(
pProject, // AudacityProject* project,

View File

@ -169,7 +169,8 @@ scroll information. It also has some status flags.
#include "../images/AudacityLogoAlpha.xpm"
std::unique_ptr<TrackList> AudacityProject::msClipboard{ safenew TrackList() };
std::unique_ptr<TrackList> AudacityProject::msClipboard
{ std::make_unique<TrackList>() };
double AudacityProject::msClipT0 = 0.0;
double AudacityProject::msClipT1 = 0.0;
AudacityProject *AudacityProject::msClipProject = NULL;
@ -829,7 +830,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
mSelectionFormat(gPrefs->Read(wxT("/SelectionFormat"), wxT(""))),
mFrequencySelectionFormatName(gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT(""))),
mBandwidthSelectionFormatName(gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT(""))),
mUndoManager(safenew UndoManager),
mUndoManager(std::make_unique<UndoManager>()),
mViewInfo(0.0, 1.0, ZoomInfo::GetDefaultZoom())
{
// Note that the first field of the status bar is a dummy, and it's width is set

View File

@ -143,6 +143,7 @@ void SplashDialog::Show2( wxWindow * pParent )
if( pSelf == NULL )
{
// pParent owns it
wxASSERT(pParent);
pSelf = safenew SplashDialog( pParent );
}
pSelf->mpHtml->SetPage(HelpText( wxT("welcome") ));

View File

@ -778,6 +778,7 @@ TimerRecordPathCtrl * TimerRecordDialog::NewPathControl(wxWindow *wParent, const
const wxString &sCaption, const wxString &sValue)
{
TimerRecordPathCtrl * pTextCtrl;
wxASSERT(wParent); // to justify safenew
pTextCtrl = safenew TimerRecordPathCtrl(wParent, iID, sValue);
pTextCtrl->SetName(sCaption);
return pTextCtrl;

View File

@ -2125,7 +2125,7 @@ Effect::AddedAnalysisTrack::~AddedAnalysisTrack()
auto Effect::AddAnalysisTrack(const wxString &name) -> std::shared_ptr<AddedAnalysisTrack>
{
return std::shared_ptr<AddedAnalysisTrack>
{ safenew AddedAnalysisTrack{ this, name } };
{ safenew AddedAnalysisTrack{ this, name } };
}
Effect::ModifiedAnalysisTrack::ModifiedAnalysisTrack

View File

@ -113,6 +113,7 @@ void MeterToolBar::ReCreateButtons()
void MeterToolBar::Populate()
{
wxASSERT(mProject); // to justify safenew
Add((mSizer = safenew wxGridBagSizer()), 1, wxEXPAND);
if( mWhichMeters & kWithRecordMeter ){

View File

@ -758,6 +758,7 @@ AButton * ToolBar::MakeButton(wxWindow *parent,
wxImagePtr down2 (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1));
wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff));
wxASSERT(parent); // to justify safenew
AButton * button =
safenew AButton(parent, id, placement, size, *up2, *hilite2, *down2,
*disable2, processdownevents);

View File

@ -181,6 +181,7 @@ class ToolBar /* not final */ : public wxPanelWrapper
int border = 0,
wxObject *userData = NULL);
// Takes ownership of sizer
void Add(wxSizer *sizer,
int proportion = 0,
int flag = 0,

View File

@ -363,6 +363,7 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
mLeft = std::make_unique<wxRegion>( 3, &pt[0] );
// Create the indicator frame
// parent is null but FramePtr ensures destruction
mIndicator = FramePtr{ safenew wxFrame( NULL,
wxID_ANY,
wxEmptyString,
@ -410,6 +411,8 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
mBotDock = safenew ToolDock( this, mParent, BotDockID );
// Create all of the toolbars
// All have the project as parent window
wxASSERT(parent);
mBars[ ToolsBarID ] = ToolBar::Holder{ safenew ToolsToolBar() };
mBars[ TransportBarID ] = ToolBar::Holder{ safenew ControlToolBar() };
mBars[ RecordMeterBarID ] = ToolBar::Holder{ safenew MeterToolBar( parent, RecordMeterBarID ) };
@ -583,6 +586,7 @@ void ToolManager::Reset()
// Maybe construct a NEW floater
// this happens if we have just been bounced out of a dock.
if( floater == NULL ) {
wxASSERT(mParent);
floater = safenew ToolFrame( mParent, this, bar, wxPoint(-1,-1) );
bar->Reparent( floater );
}
@ -761,6 +765,7 @@ void ToolManager::ReadConfig()
bar->Create( mTopDock );
// Construct a NEW floater
wxASSERT(mParent);
ToolFrame *f = safenew ToolFrame( mParent, this, bar, wxPoint( x, y ) );
// Set the width and height
@ -1327,6 +1332,7 @@ void ToolManager::OnGrabber( GrabberEvent & event )
mDragBar->SetPositioned();
// Construct a NEW floater
wxASSERT(mParent);
mDragWindow = safenew ToolFrame( mParent, this, mDragBar, mp );
// Make sure the ferry is visible

View File

@ -14,7 +14,7 @@ BackedPanel::BackedPanel(wxWindow * parent, wxWindowID id,
const wxSize & size,
long style)
: wxPanelWrapper(parent, id, pos, size, style)
, mBacking{ safenew wxBitmap(1, 1) }
, mBacking{ std::make_unique<wxBitmap>(1, 1) }
{
// Preinit the backing DC and bitmap so routines that require it will
// not cause a crash if they run before the panel is fully initialized.
@ -52,7 +52,7 @@ void BackedPanel::ResizeBacking()
mBackingDC.SelectObject(wxNullBitmap);
wxSize sz = GetClientSize();
mBacking.reset(safenew wxBitmap);
mBacking = std::make_unique<wxBitmap>();
mBacking->Create(sz.x, sz.y); //, *dc);
mBackingDC.SelectObject(*mBacking);
}

View File

@ -184,6 +184,7 @@ void ShowModelessErrorDialog(wxWindow *parent,
const wxString &helpURL,
const bool Close)
{
wxASSERT(parent);
ErrorDialog *dlog = safenew ErrorDialog(parent, dlogTitle, message, helpURL, Close, false);
dlog->CentreOnParent();
dlog->Show();
@ -199,6 +200,7 @@ void ShowAliasMissingDialog(AudacityProject *parent,
const wxString &helpURL,
const bool Close)
{
wxASSERT(parent); // to justify safenew
ErrorDialog *dlog = safenew AliasedFileMissingDialog(parent, dlogTitle, message, helpURL, Close, false);
// Don't center because in many cases (effect, export, etc) there will be a progress bar in the center that blocks this.
// instead put it just above or on the top of the project.

View File

@ -100,6 +100,7 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent,
{
LinkingHtmlWindow *html;
wxASSERT(pParent); // to justify safenew
auto pFrame = safenew wxFrame {
pParent, wxID_ANY, Title, wxDefaultPosition, wxDefaultSize,
#if defined(__WXMAC__)
@ -195,6 +196,7 @@ void HelpSystem::ShowHelpDialog(wxWindow *parent,
const wxString &remoteURL,
bool bModal)
{
wxASSERT(parent); // to justify safenew
AudacityProject * pProj = GetActiveProject();
wxString HelpMode = wxT("Local");
@ -341,6 +343,7 @@ void HelpSystem::ShowHelpDialog(wxWindow *parent,
wxLogMessage(wxT("webHelpPage %s, localHelpPage %s"),
webHelpPage.c_str(), localHelpPage.c_str());
wxASSERT(parent); // to justify safenew
HelpSystem::ShowHelpDialog(
parent,
localHelpPage,

View File

@ -124,7 +124,7 @@ void LinkingHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
wxFileName( FileNames::HtmlHelpDir(), href.Mid( 10 ) + wxT(".htm") ).GetFullPath();
if( wxFileExists( FileName ) )
{
HelpSystem::ShowHelpDialog(NULL, FileName, wxT(""));
HelpSystem::ShowHelpDialog(this, FileName, wxT(""));
return;
}
else