From a5e0b66d1f09f7d28140f7747ee9488adf9d98b7 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 26 Feb 2019 13:40:42 -0500 Subject: [PATCH] WrappedType is immutable (though it points to something mutable) --- src/ShuttleGui.cpp | 17 ++++++++--------- src/ShuttleGui.h | 2 +- src/WrappedType.cpp | 9 --------- src/WrappedType.h | 36 ++++++++++++++++++++---------------- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/ShuttleGui.cpp b/src/ShuttleGui.cpp index 8144470d4..ee9aee284 100644 --- a/src/ShuttleGui.cpp +++ b/src/ShuttleGui.cpp @@ -1440,7 +1440,7 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy mpWind = pRadioButton = safenew wxRadioButton(GetParent(), miId, Prompt, wxDefaultPosition, wxDefaultSize, (mRadioCount==1)?wxRB_GROUP:0); - pRadioButton->SetValue(WrappedRef.ValuesMatch( mRadioValue )); + pRadioButton->SetValue(WrappedRef.ValuesMatch( *mRadioValue )); pRadioButton->SetName(wxStripMenuCodes(Prompt)); UpdateSizers(); } @@ -1454,7 +1454,7 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy wxASSERT( pRadioButton ); if( pRadioButton->GetValue() ) { - mRadioValue.WriteToAsWrappedType( WrappedRef ); + mRadioValue->WriteToAsWrappedType( WrappedRef ); } } break; @@ -1470,11 +1470,11 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy /// Versions for specific types must do that initialisation. void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName ) { - wxASSERT( mRadioValue.eWrappedType != eWrappedNotSet ); + wxASSERT( mRadioValue && mRadioValue->eWrappedType != eWrappedNotSet ); mSettingName = SettingName; mRadioCount = 0; if( mShuttleMode == eIsCreating ) - DoDataShuttle( SettingName, mRadioValue ); + DoDataShuttle( SettingName, *mRadioValue ); } /// Call this after any TieRadioButton calls. @@ -1482,9 +1482,8 @@ void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName ) void ShuttleGuiBase::EndRadioButtonGroup() { if( mShuttleMode == eIsGettingFromDialog ) - DoDataShuttle( mSettingName, mRadioValue ); - mRadioValue.Init();// Clear it out... - mSettingName = wxT(""); + DoDataShuttle( mSettingName, *mRadioValue ); + mRadioValue.reset();// Clear it out... mRadioCount = -1; // So we detect a problem. } @@ -1984,7 +1983,7 @@ void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName, const { // Configure the generic type mechanism to use OUR integer. mRadioValueInt = iDefaultValue; - mRadioValue.SetTo( mRadioValueInt ); + mRadioValue.create( mRadioValueInt ); // Now actually start the radio button group. StartRadioButtonGroup( SettingName ); } @@ -1995,7 +1994,7 @@ void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName, const { // Configure the generic type mechanism to use OUR string. mRadioValueString = DefaultValue; - mRadioValue.SetTo( mRadioValueString ); + mRadioValue.create( mRadioValueString ); // Now actually start the radio button group. StartRadioButtonGroup( SettingName ); } diff --git a/src/ShuttleGui.h b/src/ShuttleGui.h index a123480da..ca6185309 100644 --- a/src/ShuttleGui.h +++ b/src/ShuttleGui.h @@ -335,7 +335,7 @@ protected: wxString mSettingName; /// The setting controlled by a group. int mRadioCount; /// The index of this radio item. -1 for none. - WrappedType mRadioValue; /// The wrapped value associated with the active radio button. + Maybe mRadioValue; /// The wrapped value associated with the active radio button. wxString mRadioValueString; /// Unwrapped string value. int mRadioValueInt; /// Unwrapped integer value. diff --git a/src/WrappedType.cpp b/src/WrappedType.cpp index 768cfd12f..3356573c2 100644 --- a/src/WrappedType.cpp +++ b/src/WrappedType.cpp @@ -66,15 +66,6 @@ bool WrappedType::ValuesMatch( const WrappedType & W ) return false; } -void WrappedType::Init() -{ - eWrappedType = eWrappedNotSet; - mpStr = NULL; - mpInt = NULL; - mpDouble = NULL; - mpBool = NULL; -} - void WrappedType::WriteToAsWrappedType( const WrappedType & W ) { wxASSERT( W.eWrappedType == eWrappedType ); diff --git a/src/WrappedType.h b/src/WrappedType.h index adf462860..a64f6c1cf 100644 --- a/src/WrappedType.h +++ b/src/WrappedType.h @@ -31,16 +31,21 @@ class AUDACITY_DLL_API WrappedType { public: - WrappedType( wxString & InStr ){ SetTo(InStr); }; - WrappedType( int & InInt ){ SetTo(InInt); }; - WrappedType( double & InDouble ){SetTo(InDouble);}; - WrappedType( bool & InBool ){ SetTo(InBool); }; - WrappedType(){ Init();} - - void SetTo( wxString & InStr ){ Init();mpStr=&InStr; eWrappedType = eWrappedString;} - void SetTo( int & InInt ){ Init();mpInt=&InInt; eWrappedType = eWrappedInt;}; - void SetTo( double & InDouble ){Init();mpDouble=&InDouble; eWrappedType = eWrappedDouble;}; - void SetTo( bool & InBool ){ Init();mpBool=&InBool; eWrappedType = eWrappedBool;}; + explicit WrappedType( wxString & InStr ) + : eWrappedType{ eWrappedString }, mpStr{ &InStr } + {} + explicit WrappedType( int & InInt ) + : eWrappedType{ eWrappedInt }, mpInt{ &InInt } + {} + explicit WrappedType( double & InDouble ) + : eWrappedType{ eWrappedDouble }, mpDouble{ &InDouble } + {} + explicit WrappedType( bool & InBool ) + : eWrappedType{ eWrappedBool }, mpBool{ &InBool } + {} + explicit WrappedType() + : eWrappedType{ eWrappedNotSet } + {} bool IsString(); @@ -58,13 +63,12 @@ public: void WriteToAsWrappedType( const WrappedType & W ); public : - void Init(); - teWrappedType eWrappedType; - wxString * mpStr; - int * mpInt; - double * mpDouble; - bool * mpBool; + const teWrappedType eWrappedType; + wxString *const mpStr {}; + int *const mpInt {}; + double *const mpDouble {}; + bool *const mpBool {}; };