1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-25 07:43:54 +02:00

WrappedType is immutable (though it points to something mutable)

This commit is contained in:
Paul Licameli
2019-02-26 13:40:42 -05:00
parent 459582ce00
commit a5e0b66d1f
4 changed files with 29 additions and 35 deletions

View File

@@ -1440,7 +1440,7 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy
mpWind = pRadioButton = safenew wxRadioButton(GetParent(), miId, Prompt, mpWind = pRadioButton = safenew wxRadioButton(GetParent(), miId, Prompt,
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
(mRadioCount==1)?wxRB_GROUP:0); (mRadioCount==1)?wxRB_GROUP:0);
pRadioButton->SetValue(WrappedRef.ValuesMatch( mRadioValue )); pRadioButton->SetValue(WrappedRef.ValuesMatch( *mRadioValue ));
pRadioButton->SetName(wxStripMenuCodes(Prompt)); pRadioButton->SetName(wxStripMenuCodes(Prompt));
UpdateSizers(); UpdateSizers();
} }
@@ -1454,7 +1454,7 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy
wxASSERT( pRadioButton ); wxASSERT( pRadioButton );
if( pRadioButton->GetValue() ) if( pRadioButton->GetValue() )
{ {
mRadioValue.WriteToAsWrappedType( WrappedRef ); mRadioValue->WriteToAsWrappedType( WrappedRef );
} }
} }
break; break;
@@ -1470,11 +1470,11 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy
/// Versions for specific types must do that initialisation. /// Versions for specific types must do that initialisation.
void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName ) void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName )
{ {
wxASSERT( mRadioValue.eWrappedType != eWrappedNotSet ); wxASSERT( mRadioValue && mRadioValue->eWrappedType != eWrappedNotSet );
mSettingName = SettingName; mSettingName = SettingName;
mRadioCount = 0; mRadioCount = 0;
if( mShuttleMode == eIsCreating ) if( mShuttleMode == eIsCreating )
DoDataShuttle( SettingName, mRadioValue ); DoDataShuttle( SettingName, *mRadioValue );
} }
/// Call this after any TieRadioButton calls. /// Call this after any TieRadioButton calls.
@@ -1482,9 +1482,8 @@ void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName )
void ShuttleGuiBase::EndRadioButtonGroup() void ShuttleGuiBase::EndRadioButtonGroup()
{ {
if( mShuttleMode == eIsGettingFromDialog ) if( mShuttleMode == eIsGettingFromDialog )
DoDataShuttle( mSettingName, mRadioValue ); DoDataShuttle( mSettingName, *mRadioValue );
mRadioValue.Init();// Clear it out... mRadioValue.reset();// Clear it out...
mSettingName = wxT("");
mRadioCount = -1; // So we detect a problem. 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. // Configure the generic type mechanism to use OUR integer.
mRadioValueInt = iDefaultValue; mRadioValueInt = iDefaultValue;
mRadioValue.SetTo( mRadioValueInt ); mRadioValue.create( mRadioValueInt );
// Now actually start the radio button group. // Now actually start the radio button group.
StartRadioButtonGroup( SettingName ); StartRadioButtonGroup( SettingName );
} }
@@ -1995,7 +1994,7 @@ void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName, const
{ {
// Configure the generic type mechanism to use OUR string. // Configure the generic type mechanism to use OUR string.
mRadioValueString = DefaultValue; mRadioValueString = DefaultValue;
mRadioValue.SetTo( mRadioValueString ); mRadioValue.create( mRadioValueString );
// Now actually start the radio button group. // Now actually start the radio button group.
StartRadioButtonGroup( SettingName ); StartRadioButtonGroup( SettingName );
} }

View File

@@ -335,7 +335,7 @@ protected:
wxString mSettingName; /// The setting controlled by a group. wxString mSettingName; /// The setting controlled by a group.
int mRadioCount; /// The index of this radio item. -1 for none. int mRadioCount; /// The index of this radio item. -1 for none.
WrappedType mRadioValue; /// The wrapped value associated with the active radio button. Maybe<WrappedType> mRadioValue; /// The wrapped value associated with the active radio button.
wxString mRadioValueString; /// Unwrapped string value. wxString mRadioValueString; /// Unwrapped string value.
int mRadioValueInt; /// Unwrapped integer value. int mRadioValueInt; /// Unwrapped integer value.

View File

@@ -66,15 +66,6 @@ bool WrappedType::ValuesMatch( const WrappedType & W )
return false; return false;
} }
void WrappedType::Init()
{
eWrappedType = eWrappedNotSet;
mpStr = NULL;
mpInt = NULL;
mpDouble = NULL;
mpBool = NULL;
}
void WrappedType::WriteToAsWrappedType( const WrappedType & W ) void WrappedType::WriteToAsWrappedType( const WrappedType & W )
{ {
wxASSERT( W.eWrappedType == eWrappedType ); wxASSERT( W.eWrappedType == eWrappedType );

View File

@@ -31,16 +31,21 @@ class AUDACITY_DLL_API WrappedType
{ {
public: public:
WrappedType( wxString & InStr ){ SetTo(InStr); }; explicit WrappedType( wxString & InStr )
WrappedType( int & InInt ){ SetTo(InInt); }; : eWrappedType{ eWrappedString }, mpStr{ &InStr }
WrappedType( double & InDouble ){SetTo(InDouble);}; {}
WrappedType( bool & InBool ){ SetTo(InBool); }; explicit WrappedType( int & InInt )
WrappedType(){ Init();} : eWrappedType{ eWrappedInt }, mpInt{ &InInt }
{}
void SetTo( wxString & InStr ){ Init();mpStr=&InStr; eWrappedType = eWrappedString;} explicit WrappedType( double & InDouble )
void SetTo( int & InInt ){ Init();mpInt=&InInt; eWrappedType = eWrappedInt;}; : eWrappedType{ eWrappedDouble }, mpDouble{ &InDouble }
void SetTo( double & InDouble ){Init();mpDouble=&InDouble; eWrappedType = eWrappedDouble;}; {}
void SetTo( bool & InBool ){ Init();mpBool=&InBool; eWrappedType = eWrappedBool;}; explicit WrappedType( bool & InBool )
: eWrappedType{ eWrappedBool }, mpBool{ &InBool }
{}
explicit WrappedType()
: eWrappedType{ eWrappedNotSet }
{}
bool IsString(); bool IsString();
@@ -58,13 +63,12 @@ public:
void WriteToAsWrappedType( const WrappedType & W ); void WriteToAsWrappedType( const WrappedType & W );
public : public :
void Init();
teWrappedType eWrappedType; const teWrappedType eWrappedType;
wxString * mpStr; wxString *const mpStr {};
int * mpInt; int *const mpInt {};
double * mpDouble; double *const mpDouble {};
bool * mpBool; bool *const mpBool {};
}; };