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 471 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 475 of file Prefs.h.

481 {}
482 ) : ChoiceSetting{ std::forward<Key>(key), move(symbols), defaultSymbol }
483 , mIntValues{ move(intValues) }
484 , mOldKey{ oldKey }
485 {
486 assert (mIntValues.size() == mSymbols.size());
487 }
static const AudacityProject::AttachedObjects::RegisteredFactory key
const EnumValueSymbols mSymbols
Definition: Prefs.h:458
const wxString mOldKey
Definition: Prefs.h:506
std::vector< int > mIntValues
Definition: Prefs.h:505

Member Function Documentation

◆ FindInt()

size_t EnumSettingBase::FindInt ( int  code) const
protected

Definition at line 448 of file Prefs.cpp.

449{
450 const auto start = mIntValues.begin();
451 return size_t(
452 std::find( start, mIntValues.end(), code )
453 - start );
454}

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 456 of file Prefs.cpp.

457{
458 int intValue = 0;
459 if ( !mOldKey.empty() &&
460 gPrefs->Read(mOldKey, &intValue, 0) ) {
461 // Make the migration, only once and persistently.
462 // Do not DELETE the old key -- let that be read if user downgrades
463 // Audacity. But further changes will be stored only to the NEW key
464 // and won't be seen then.
465 auto index = (long) FindInt( intValue );
466 if ( index >= (long)mSymbols.size() )
467 index = mDefaultSymbol;
468 if ( index >= 0 && index < (long)mSymbols.size() ) {
469 value = mSymbols[index].Internal();
470 Write(value);
471 gPrefs->Flush();
472 }
473 }
474}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
bool Write(const wxString &value)
Definition: Prefs.cpp:405
long mDefaultSymbol
Definition: Prefs.h:464
size_t FindInt(int code) const
Definition: Prefs.cpp:448
virtual bool Flush() noexcept=0
virtual bool Read(const wxString &key, bool *value) const =0

References FindInt(), audacity::BasicSettings::Flush(), gPrefs, ChoiceSetting::mDefaultSymbol, mOldKey, ChoiceSetting::mSymbols, audacity::BasicSettings::Read(), and ChoiceSetting::Write().

Here is the call graph for this function:

◆ ReadInt()

int EnumSettingBase::ReadInt ( ) const
protected

Definition at line 425 of file Prefs.cpp.

426{
427 auto index = Find( Read() );
428
429 wxASSERT( index < mIntValues.size() );
430 return mIntValues[ index ];
431}
wxString Read() const
Definition: Prefs.cpp:369
size_t Find(const wxString &value) const
Definition: Prefs.cpp:392

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 433 of file Prefs.cpp.

434{
435 wxString defaultString;
436 auto index0 = FindInt( defaultValue );
437 if ( index0 < mSymbols.size() )
438 defaultString = mSymbols[ index0 ].Internal();
439 else
440 wxASSERT( false );
441
442 auto index = Find( ReadWithDefault( defaultString ) );
443
444 wxASSERT( index < mSymbols.size() );
445 return mIntValues[ index ];
446}
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:375

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 476 of file Prefs.cpp.

477{
478 auto index = FindInt( code );
479 if ( index >= mSymbols.size() )
480 return false;
481 return Write( mSymbols[index].Internal() );
482}
@ 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 505 of file Prefs.h.

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

◆ mOldKey

const wxString EnumSettingBase::mOldKey
private

Definition at line 506 of file Prefs.h.

Referenced by Migrate().


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