1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-24 16:20:05 +02:00

Move the recent const_casts elsewhere

This commit is contained in:
Paul Licameli 2016-02-29 19:54:21 -05:00
parent 4173bb1a37
commit 7aee5d09d8
3 changed files with 13 additions and 13 deletions

View File

@ -837,22 +837,19 @@ void TrackList::AddToHead(Track * t)
ResizedEvent(n);
}
void TrackList::Replace(const Track * t, const Track * with, bool deletetrack)
void TrackList::Replace(Track * t, Track * with, bool deletetrack)
{
Track *const mutableT = const_cast<Track*>(t);
Track *const mutableWith = const_cast<Track*>(with);
if (mutableT && with) {
if (t && with) {
TrackListNode *node =
const_cast<TrackListNode *>(mutableT->GetNode());
const_cast<TrackListNode *>(t->GetNode());
mutableT->SetOwner(NULL, NULL);
t->SetOwner(NULL, NULL);
if (deletetrack) {
delete t;
}
node->t = mutableWith;
mutableWith->SetOwner(this, node);
node->t = with;
with->SetOwner(this, node);
RecalcPositions(node);
UpdatedEvent(node);
ResizedEvent(node);

View File

@ -385,8 +385,7 @@ class AUDACITY_DLL_API TrackList final : public wxEvtHandler
void AddToHead(Track * t);
/// Replace first track with second track
/// Non-const function of TrackList, but it can take pointers to const tracks
void Replace(const Track * t, const Track * with, bool deletetrack = false);
void Replace(Track * t, Track * with, bool deletetrack = false);
/// Remove this Track or all children of this TrackList.
void Remove(Track * t, bool deletetrack = false);

View File

@ -2184,7 +2184,9 @@ Effect::ModifiedAnalysisTrack::ModifiedAnalysisTrack
if (!name.empty())
mpTrack->SetName(name);
pEffect->mTracks->Replace(mpOrigTrack, mpTrack, false);
// mpOrigTrack came from mTracks which we own but expose as const to subclasses
// So it's okay that we cast it back to const
pEffect->mTracks->Replace(const_cast<LabelTrack*>(mpOrigTrack), mpTrack, false);
}
Effect::ModifiedAnalysisTrack::ModifiedAnalysisTrack(ModifiedAnalysisTrack &&that)
@ -2204,7 +2206,9 @@ Effect::ModifiedAnalysisTrack::~ModifiedAnalysisTrack()
{
if (mpEffect) {
// not committed -- DELETE the label track
mpEffect->mTracks->Replace(mpTrack, mpOrigTrack, true);
// mpOrigTrack came from mTracks which we own but expose as const to subclasses
// So it's okay that we cast it back to const
mpEffect->mTracks->Replace(mpTrack, const_cast<LabelTrack*>(mpOrigTrack), true);
}
}