Audacity  3.0.3
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

 EnumSettingBase (const SettingBase &key, EnumValueSymbols symbols, long defaultSymbol, std::vector< int > intValues, const wxString &oldKey={})
 
- Public Member Functions inherited from ChoiceSetting
 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
 

Private Attributes

std::vector< int > mIntValues
 
const wxString mOldKey
 

Additional Inherited Members

- Protected Attributes inherited from ChoiceSetting
const wxString mKey
 
const EnumValueSymbols mSymbols
 
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 316 of file Prefs.h.

Constructor & Destructor Documentation

◆ EnumSettingBase()

EnumSettingBase::EnumSettingBase ( const SettingBase key,
EnumValueSymbols  symbols,
long  defaultSymbol,
std::vector< int >  intValues,
const wxString &  oldKey = {} 
)

Definition at line 329 of file Prefs.cpp.

337  : ChoiceSetting{ key, std::move( symbols ), defaultSymbol }
338  , mIntValues{ std::move( intValues ) }
339  , mOldKey{ oldKey }
340 {
341  auto size = mSymbols.size();
342  if( mIntValues.size() != size ) {
343  wxASSERT( false );
344  mIntValues.resize( size );
345  }
346 }

References key.

Member Function Documentation

◆ FindInt()

size_t EnumSettingBase::FindInt ( int  code) const
protected

Definition at line 379 of file Prefs.cpp.

380 {
381  const auto start = mIntValues.begin();
382  return size_t(
383  std::find( start, mIntValues.end(), code )
384  - start );
385 }

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

388 {
389  int intValue = 0;
390  if ( !mOldKey.empty() &&
391  gPrefs->Read(mOldKey, &intValue, 0) ) {
392  // Make the migration, only once and persistently.
393  // Do not DELETE the old key -- let that be read if user downgrades
394  // Audacity. But further changes will be stored only to the NEW key
395  // and won't be seen then.
396  auto index = (long) FindInt( intValue );
397  if ( index >= (long)mSymbols.size() )
398  index = mDefaultSymbol;
399  if ( index >= 0 && index < (long)mSymbols.size() ) {
400  value = mSymbols[index].Internal();
401  Write(value);
402  gPrefs->Flush();
403  }
404  }
405 }

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

357 {
358  auto index = Find( Read() );
359 
360  wxASSERT( index < mIntValues.size() );
361  return mIntValues[ index ];
362 }

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

365 {
366  wxString defaultString;
367  auto index0 = FindInt( defaultValue );
368  if ( index0 < mSymbols.size() )
369  defaultString = mSymbols[ index0 ].Internal();
370  else
371  wxASSERT( false );
372 
373  auto index = Find( ReadWithDefault( defaultString ) );
374 
375  wxASSERT( index < mSymbols.size() );
376  return mIntValues[ index ];
377 }

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

408 {
409  auto index = FindInt( code );
410  if ( index >= mSymbols.size() )
411  return false;
412  return Write( mSymbols[index].Internal() );
413 }

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

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

◆ mOldKey

const wxString EnumSettingBase::mOldKey
private

Definition at line 345 of file Prefs.h.

Referenced by Migrate().


The documentation for this class was generated from the following files:
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
EnumSettingBase::mIntValues
std::vector< int > mIntValues
Definition: Prefs.h:344
ChoiceSetting::Find
size_t Find(const wxString &value) const
Definition: Prefs.cpp:305
ChoiceSetting::Write
bool Write(const wxString &value)
Definition: Prefs.cpp:318
ChoiceSetting
Definition: Prefs.h:267
EnumSettingBase::mOldKey
const wxString mOldKey
Definition: Prefs.h:345
ChoiceSetting::mDefaultSymbol
long mDefaultSymbol
Definition: Prefs.h:309
ChoiceSetting::ReadWithDefault
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:288
ChoiceSetting::Read
wxString Read() const
Definition: Prefs.cpp:282
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
EnumSettingBase::FindInt
size_t FindInt(int code) const
Definition: Prefs.cpp:379
ExceptionType::Internal
@ Internal
Indicates internal failure from Audacity.
ChoiceSetting::mSymbols
const EnumValueSymbols mSymbols
Definition: Prefs.h:304