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 473 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 477 of file Prefs.h.

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

Member Function Documentation

◆ FindInt()

size_t EnumSettingBase::FindInt ( int  code) const
protected

Definition at line 467 of file Prefs.cpp.

468{
469 const auto start = mIntValues.begin();
470 return size_t(
471 std::find( start, mIntValues.end(), code )
472 - start );
473}

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.

Reimplemented in SpectrogramSettings::ColorSchemeEnumSetting.

Definition at line 475 of file Prefs.cpp.

476{
477 int intValue = 0;
478 if ( !mOldKey.empty() &&
479 gPrefs->Read(mOldKey, &intValue, 0) ) {
480 // Make the migration, only once and persistently.
481 // Do not DELETE the old key -- let that be read if user downgrades
482 // Audacity. But further changes will be stored only to the NEW key
483 // and won't be seen then.
484 auto index = (long) FindInt( intValue );
485 if ( index >= (long)mSymbols.size() )
486 index = mDefaultSymbol;
487 if ( index >= 0 && index < (long)mSymbols.size() ) {
488 value = mSymbols[index].Internal();
489 Write(value);
490 gPrefs->Flush();
491 }
492 }
493}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
bool Write(const wxString &value)
Definition: Prefs.cpp:424
long mDefaultSymbol
Definition: Prefs.h:466
size_t FindInt(int code) const
Definition: Prefs.cpp:467
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 444 of file Prefs.cpp.

445{
446 auto index = Find( Read() );
447
448 wxASSERT( index < mIntValues.size() );
449 return mIntValues[ index ];
450}
wxString Read() const
Definition: Prefs.cpp:388
size_t Find(const wxString &value) const
Definition: Prefs.cpp:411

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

453{
454 wxString defaultString;
455 auto index0 = FindInt( defaultValue );
456 if ( index0 < mSymbols.size() )
457 defaultString = mSymbols[ index0 ].Internal();
458 else
459 wxASSERT( false );
460
461 auto index = Find( ReadWithDefault( defaultString ) );
462
463 wxASSERT( index < mSymbols.size() );
464 return mIntValues[ index ];
465}
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:394

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

503{
504 auto index = FindInt( code );
505 if ( index >= mSymbols.size() )
506 return false;
507 return Write( mSymbols[index].Internal() );
508}
@ 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 507 of file Prefs.h.

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

◆ mOldKey

const wxString EnumSettingBase::mOldKey
private

Definition at line 508 of file Prefs.h.

Referenced by Migrate().


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