Audacity  3.2.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Setting< T > Class Template Reference

Class template adds default value, read, and write methods to CachingSetingBase. More...

#include <Prefs.h>

Inheritance diagram for Setting< T >:
[legend]
Collaboration diagram for Setting< T >:
[legend]

Public Types

using DefaultValueFunction = std::function< T() >
 

Public Member Functions

 Setting (const SettingBase &path, const T &defaultValue)
 Usual overload supplies a default value. More...
 
 Setting (const SettingBase &path, DefaultValueFunction function)
 This overload causes recomputation of the default each time it is needed. More...
 
const T & GetDefault () const
 
bool Read (T *pVar) const
 overload of Read returning a boolean that is true if the value was previously defined *‍/ More...
 
bool ReadWithDefault (T *pVar, const T &defaultValue) const
 overload of ReadWithDefault returning a boolean that is true if the value was previously defined *‍/ More...
 
Read () const
 overload of Read, always returning a value More...
 
ReadWithDefault (const T &defaultValue) const
 new direct use is discouraged but it may be needed in legacy code More...
 
bool Write (const T &value)
 Write value to config and return true if successful. More...
 
bool Reset ()
 Reset to the default value. More...
 
- Public Member Functions inherited from CachingSettingBase< T >
 CachingSettingBase (const SettingBase &path)
 
- Public Member Functions inherited from SettingBase
 SettingBase (const char *path)
 
 SettingBase (const wxChar *path)
 
 SettingBase (const wxString &path)
 
wxConfigBase * GetConfig () const
 
const wxString & GetPath () const
 
bool Delete ()
 Delete the key if present, and return true iff it was. More...
 

Protected Member Functions

bool DoWrite ()
 Write cached value to config and return true if successful. More...
 
- Protected Member Functions inherited from CachingSettingBase< T >
 CachingSettingBase (const CachingSettingBase &)=default
 
- Protected Member Functions inherited from SettingBase
 SettingBase (const SettingBase &)=default
 

Protected Attributes

mDefaultValue {}
 
const DefaultValueFunction mFunction
 
- Protected Attributes inherited from CachingSettingBase< T >
mCurrentValue {}
 
bool mValid {false}
 
- Protected Attributes inherited from SettingBase
const RegistryPath mPath
 

Detailed Description

template<typename T>
class Setting< T >

Class template adds default value, read, and write methods to CachingSetingBase.

Definition at line 99 of file Prefs.h.

Member Typedef Documentation

◆ DefaultValueFunction

template<typename T >
using Setting< T >::DefaultValueFunction = std::function< T() >

Definition at line 104 of file Prefs.h.

Constructor & Destructor Documentation

◆ Setting() [1/2]

template<typename T >
Setting< T >::Setting ( const SettingBase path,
const T &  defaultValue 
)
inline

Usual overload supplies a default value.

Definition at line 107 of file Prefs.h.

108  : CachingSettingBase< T >{ path }
109  , mDefaultValue{ defaultValue }
110  {}

◆ Setting() [2/2]

template<typename T >
Setting< T >::Setting ( const SettingBase path,
DefaultValueFunction  function 
)
inline

This overload causes recomputation of the default each time it is needed.

Definition at line 113 of file Prefs.h.

114  : CachingSettingBase< T >{ path }
115  , mFunction{ function }
116  {}

Member Function Documentation

◆ DoWrite()

template<typename T >
bool Setting< T >::DoWrite ( )
inlineprotected

Write cached value to config and return true if successful.

(But the config object is not flushed)

Definition at line 190 of file Prefs.h.

191  {
192  const auto config = this->GetConfig();
193  return this->mValid =
194  config ? config->Write( this->mPath, this->mCurrentValue ) : false;
195  }

Referenced by Setting< bool >::Write().

Here is the caller graph for this function:

◆ GetDefault()

template<typename T >
const T& Setting< T >::GetDefault ( ) const
inline

◆ Read() [1/2]

template<typename T >
T Setting< T >::Read ( ) const
inline

overload of Read, always returning a value

The value is the default stored in this in case the key is known to be absent from the config; but it returns type T's default value if there was failure to read the config

Definition at line 153 of file Prefs.h.

154  {
155  return ReadWithDefault( GetDefault() );
156  }

◆ Read() [2/2]

template<typename T >
bool Setting< T >::Read ( T *  pVar) const
inline

overload of Read returning a boolean that is true if the value was previously defined *‍/

Definition at line 127 of file Prefs.h.

128  {
129  return ReadWithDefault( pVar, GetDefault() );
130  }

Referenced by AudioIO::AudioIO(), DeviceToolBar::ChangeDevice(), DeviceToolBar::ChangeHost(), ProjectAudioManager::ChooseExistingRecordingTracks(), RecordingPrefs::Commit(), ConfirmSave(), ProjectAudioManager::DoRecord(), SpectrumVZoomHandle::DoZoom(), FFmpegStartup(), DeviceToolBar::FillHostDevices(), DeviceToolBar::FillInputChannels(), AudioIOBase::GetDeviceInfo(), ProjectManager::GetEstimatedRecordingMinsLeftOnDisk(), GetMIDIDeviceInfo(), AudioIOBase::getPlayDevIndex(), AudioIOBase::getRecordDevIndex(), FFmpegFunctions::GetSearchPaths(), AudioIOBase::GetSupportedCaptureRates(), AudioIOBase::HandleDeviceChange(), SpectrogramSettings::Globals::LoadPrefs(), SpectrogramSettings::LoadPrefs(), WaveformSettings::LoadPrefs(), SpectrogramSettings::ColorSchemeEnumSetting::Migrate(), App::OnInit(), FrequencyPlotDialog::OnReplot(), UpdateManager::OnTimer(), FFmpegImportPlugin::Open(), FrequencyPlotDialog::Populate(), DevicePrefs::Populate(), QualityPrefs::Populate(), FFmpegNotFoundDialog::PopulateOrExchange(), SoundActivatedRecordDialog::PopulateOrExchange(), RecordingPrefs::PopulateOrExchange(), ProjectRate::ProjectRate(), ThemeBase::ReadImageCache(), Journal::RecordEnabled(), ResetPreferences(), SafeAVFormatPathUpdater::SafeAVFormatPathUpdater(), FrequencyPlotDialog::Show(), UpdateManager::Start(), AudioIO::StartMonitoring(), AudioIO::StartPortAudioStream(), anonymous_namespace{MIDIPlay.h}::MIDIPlay::StartPortMidiStream(), AudioIO::StartStream(), AudioIO::StopStream(), UpdatePopupDialog::UpdatePopupDialog(), ViewInfo::UpdatePrefs(), ZoomInfo::UpdatePrefs(), AdornedRulerPanel::UpdatePrefs(), SpectrogramSettings::UpdatePrefs(), WaveformSettings::UpdatePrefs(), DeviceToolBar::UpdatePrefs(), TrackArtist::UpdatePrefs(), and MeterPanel::UpdatePrefs().

◆ ReadWithDefault() [1/2]

template<typename T >
T Setting< T >::ReadWithDefault ( const T &  defaultValue) const
inline

new direct use is discouraged but it may be needed in legacy code

Use the given default in case the preference is not defined, which may not be the default-default stored in this object.

Definition at line 161 of file Prefs.h.

162  {
163  const auto config = this->GetConfig();
164  return config
165  ? ( this->mValid = true, this->mCurrentValue =
166  config->ReadObject( this->mPath, defaultValue ) )
167  : T{};
168  }

◆ ReadWithDefault() [2/2]

template<typename T >
bool Setting< T >::ReadWithDefault ( T *  pVar,
const T &  defaultValue 
) const
inline

overload of ReadWithDefault returning a boolean that is true if the value was previously defined *‍/

Definition at line 133 of file Prefs.h.

134  {
135  if ( pVar )
136  *pVar = defaultValue;
137  if ( pVar && this->mValid ) {
138  *pVar = this->mCurrentValue;
139  return true;
140  }
141  const auto config = this->GetConfig();
142  if ( pVar && config ) {
143  if ((this->mValid = config->Read( this->mPath, &this->mCurrentValue )))
144  *pVar = this->mCurrentValue;
145  return this->mValid;
146  }
147  return (this->mValid = false);
148  }

Referenced by Effect::Effect(), WaveTrack::GetDefaultAudioTrackNamePreference(), AudioIOBase::GetSupportedCaptureRates(), Setting< bool >::Read(), and DeviceToolBar::UpdatePrefs().

Here is the caller graph for this function:

◆ Reset()

template<typename T >
bool Setting< T >::Reset ( )
inline

Reset to the default value.

Definition at line 182 of file Prefs.h.

183  {
184  return Write( GetDefault() );
185  }

Referenced by DevicePrefs::Commit(), RecordingPrefs::Commit(), and DeviceToolBar::SetDevices().

Here is the caller graph for this function:

◆ Write()

template<typename T >
bool Setting< T >::Write ( const T &  value)
inline

Member Data Documentation

◆ mDefaultValue

template<typename T >
T Setting< T >::mDefaultValue {}
mutableprotected

Definition at line 197 of file Prefs.h.

Referenced by Setting< bool >::GetDefault().

◆ mFunction

template<typename T >
const DefaultValueFunction Setting< T >::mFunction
protected

Definition at line 198 of file Prefs.h.

Referenced by Setting< bool >::GetDefault().


The documentation for this class was generated from the following file:
Setting::DoWrite
bool DoWrite()
Write cached value to config and return true if successful.
Definition: Prefs.h:190
Setting::Write
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:171
SettingBase::mPath
const RegistryPath mPath
Definition: Prefs.h:81
Setting::GetDefault
const T & GetDefault() const
Definition: Prefs.h:119
Setting::ReadWithDefault
bool ReadWithDefault(T *pVar, const T &defaultValue) const
overload of ReadWithDefault returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:133
CachingSettingBase::mCurrentValue
T mCurrentValue
Definition: Prefs.h:93
Setting::mDefaultValue
T mDefaultValue
Definition: Prefs.h:197
Setting::mFunction
const DefaultValueFunction mFunction
Definition: Prefs.h:198
CachingSettingBase::mValid
bool mValid
Definition: Prefs.h:94
SettingBase::GetConfig
wxConfigBase * GetConfig() const
Definition: Prefs.cpp:444
CachingSettingBase
Class template adds an in-memory cache of a value to SettingBase.
Definition: Prefs.h:87