Audacity 3.2.0
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
EnumSettingBase Class Reference

#include <Prefs.h>

Inheritance diagram for EnumSettingBase:
[legend]
Collaboration diagram for EnumSettingBase:
[legend]

Public Member Functions

template<typename Key >
 EnumSettingBase (Key &&key, EnumValueSymbols symbols, long defaultSymbol, std::vector< int > intValues, const wxString &oldKey={})
 
- Public Member Functions inherited from ChoiceSetting
 ChoiceSetting (const SettingPath &, EnumValueSymbols, long=-1)=delete
 
 ChoiceSetting (TransactionalSettingBase &key, EnumValueSymbols symbols, long defaultSymbol=-1)
 
 ChoiceSetting (const SettingBase &key, EnumValueSymbols symbols, long defaultSymbol=-1)
 
const wxString & Key () const
 
const EnumValueSymbolDefault () const
 
const EnumValueSymbolsGetSymbols () const
 
wxString Read () const
 
wxString ReadWithDefault (const wxString &) const
 
bool Write (const wxString &value)
 
void SetDefault (long value)
 

Protected Member Functions

int ReadInt () const
 
int ReadIntWithDefault (int defaultValue) const
 
bool WriteInt (int code)
 
size_t FindInt (int code) const
 
void Migrate (wxString &) override
 
- Protected Member Functions inherited from ChoiceSetting
size_t Find (const wxString &value) const
 
virtual void Migrate (wxString &)
 

Private Attributes

std::vector< int > mIntValues
 
const wxString mOldKey
 

Additional Inherited Members

- Protected Attributes inherited from ChoiceSetting
const wxString mKey
 
const EnumValueSymbols mSymbols
 
TransactionalSettingBase *const mpOtherSettings {}
 
bool mMigrated { false }
 
long mDefaultSymbol
 

Detailed Description

Extends ChoiceSetting with a corresponding table of integer codes (generally not equal to their table positions), and optionally an old preference key path that stored integer codes, to be migrated into one that stores internal string values instead

Definition at line 466 of file Prefs.h.

Constructor & Destructor Documentation

◆ EnumSettingBase()

template<typename Key >
EnumSettingBase::EnumSettingBase ( Key &&  key,
EnumValueSymbols  symbols,
long  defaultSymbol,
std::vector< int >  intValues,
const wxString &  oldKey = {} 
)
inline
Precondition
intValues.size() == symbols.size()

Definition at line 470 of file Prefs.h.

476 {}
477 ) : ChoiceSetting{ std::forward<Key>(key), move(symbols), defaultSymbol }
478 , mIntValues{ move(intValues) }
479 , mOldKey{ oldKey }
480 {
481 assert (mIntValues.size() == mSymbols.size());
482 }
static const AudacityProject::AttachedObjects::RegisteredFactory key
const EnumValueSymbols mSymbols
Definition: Prefs.h:453
const wxString mOldKey
Definition: Prefs.h:501
std::vector< int > mIntValues
Definition: Prefs.h:500

Member Function Documentation

◆ FindInt()

size_t EnumSettingBase::FindInt ( int  code) const
protected

Definition at line 433 of file Prefs.cpp.

434{
435 const auto start = mIntValues.begin();
436 return size_t(
437 std::find( start, mIntValues.end(), code )
438 - start );
439}

References mIntValues.

Referenced by Migrate(), ReadIntWithDefault(), and WriteInt().

Here is the caller graph for this function:

◆ Migrate()

void EnumSettingBase::Migrate ( wxString &  value)
overrideprotectedvirtual

Reimplemented from ChoiceSetting.

Definition at line 441 of file Prefs.cpp.

442{
443 int intValue = 0;
444 if ( !mOldKey.empty() &&
445 gPrefs->Read(mOldKey, &intValue, 0) ) {
446 // Make the migration, only once and persistently.
447 // Do not DELETE the old key -- let that be read if user downgrades
448 // Audacity. But further changes will be stored only to the NEW key
449 // and won't be seen then.
450 auto index = (long) FindInt( intValue );
451 if ( index >= (long)mSymbols.size() )
452 index = mDefaultSymbol;
453 if ( index >= 0 && index < (long)mSymbols.size() ) {
454 value = mSymbols[index].Internal();
455 Write(value);
456 gPrefs->Flush();
457 }
458 }
459}
FileConfig * gPrefs
Definition: Prefs.cpp:70
bool Write(const wxString &value)
Definition: Prefs.cpp:390
long mDefaultSymbol
Definition: Prefs.h:459
size_t FindInt(int code) const
Definition: Prefs.cpp:433
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143

References FindInt(), FileConfig::Flush(), gPrefs, ChoiceSetting::mDefaultSymbol, mOldKey, ChoiceSetting::mSymbols, and ChoiceSetting::Write().

Here is the call graph for this function:

◆ ReadInt()

int EnumSettingBase::ReadInt ( ) const
protected

Definition at line 410 of file Prefs.cpp.

411{
412 auto index = Find( Read() );
413
414 wxASSERT( index < mIntValues.size() );
415 return mIntValues[ index ];
416}
wxString Read() const
Definition: Prefs.cpp:354
size_t Find(const wxString &value) const
Definition: Prefs.cpp:377

References ChoiceSetting::Find(), mIntValues, and ChoiceSetting::Read().

Here is the call graph for this function:

◆ ReadIntWithDefault()

int EnumSettingBase::ReadIntWithDefault ( int  defaultValue) const
protected

Definition at line 418 of file Prefs.cpp.

419{
420 wxString defaultString;
421 auto index0 = FindInt( defaultValue );
422 if ( index0 < mSymbols.size() )
423 defaultString = mSymbols[ index0 ].Internal();
424 else
425 wxASSERT( false );
426
427 auto index = Find( ReadWithDefault( defaultString ) );
428
429 wxASSERT( index < mSymbols.size() );
430 return mIntValues[ index ];
431}
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:360

References ChoiceSetting::Find(), FindInt(), mIntValues, ChoiceSetting::mSymbols, and ChoiceSetting::ReadWithDefault().

Here is the call graph for this function:

◆ WriteInt()

bool EnumSettingBase::WriteInt ( int  code)
protected

Definition at line 461 of file Prefs.cpp.

462{
463 auto index = FindInt( code );
464 if ( index >= mSymbols.size() )
465 return false;
466 return Write( mSymbols[index].Internal() );
467}
@ Internal
Indicates internal failure from Audacity.

References FindInt(), Internal, ChoiceSetting::mSymbols, and ChoiceSetting::Write().

Here is the call graph for this function:

Member Data Documentation

◆ mIntValues

std::vector<int> EnumSettingBase::mIntValues
private

Definition at line 500 of file Prefs.h.

Referenced by FindInt(), ReadInt(), and ReadIntWithDefault().

◆ mOldKey

const wxString EnumSettingBase::mOldKey
private

Definition at line 501 of file Prefs.h.

Referenced by Migrate().


The documentation for this class was generated from the following files: