Audacity  3.0.3
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 100 of file Prefs.h.

Member Typedef Documentation

◆ DefaultValueFunction

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

Definition at line 105 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 108 of file Prefs.h.

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

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

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

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

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

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

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

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

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

Referenced by DeviceToolBar::ChangeDevice(), DeviceToolBar::ChangeHost(), ProjectAudioManager::ChooseExistingRecordingTracks(), RecordingPrefs::Commit(), ProjectAudioManager::DoRecord(), FFmpegStartup(), DeviceToolBar::FillHostDevices(), DeviceToolBar::FillInputChannels(), AudioIOBase::GetDeviceInfo(), ProjectManager::GetEstimatedRecordingMinsLeftOnDisk(), GetMIDIDeviceInfo(), AudioIOBase::getPlayDevIndex(), AudioIOBase::getRecordDevIndex(), FFmpegFunctions::GetSearchPaths(), AudioIOBase::GetSupportedCaptureRates(), AudioIOBase::HandleDeviceChange(), WaveformSettings::LoadPrefs(), FrequencyPlotDialog::OnReplot(), UpdateManager::OnTimer(), FFmpegImportPlugin::Open(), FrequencyPlotDialog::Populate(), DevicePrefs::Populate(), QualityPrefs::Populate(), FFmpegNotFoundDialog::PopulateOrExchange(), SoundActivatedRecordDialog::PopulateOrExchange(), RecordingPrefs::PopulateOrExchange(), Journal::RecordEnabled(), ResetPreferences(), 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(), WaveformSettings::UpdatePrefs(), DeviceToolBar::UpdatePrefs(), TrackArtist::UpdatePrefs(), and MeterPanel::UpdatePrefs().

Here is the caller graph for this function:

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

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

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

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

Referenced by Effect::Effect(), 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 183 of file Prefs.h.

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

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

Write value to config and return true if successful.

Definition at line 172 of file Prefs.h.

173  {
174  const auto config = this->GetConfig();
175  if ( config ) {
176  this->mCurrentValue = value;
177  return DoWrite();
178  }
179  return false;
180  }

Referenced by DeviceToolBar::ChangeHost(), DevicePrefs::Commit(), QualityPrefs::Commit(), anonymous_namespace{FileMenus.cpp}::DoImport(), DeviceToolBar::FillHostDevices(), DeviceToolBar::FillInputChannels(), FindFFmpegLibs(), AudioIO::Init(), LoadFFmpeg(), DeviceToolBar::OnChoice(), UpdatePopupDialog::OnDontShow(), FFmpegNotFoundDialog::OnOk(), FFmpegImportPlugin::Open(), Setting< bool >::Reset(), DeviceToolBar::SetDevices(), Journal::SetRecordEnabled(), and UpdateManager::Start().

Here is the caller graph for this function:

Member Data Documentation

◆ mDefaultValue

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

Definition at line 198 of file Prefs.h.

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

◆ mFunction

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

Definition at line 199 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:191
Setting::Write
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:172
SettingBase::mPath
const RegistryPath mPath
Definition: Prefs.h:82
Setting::GetDefault
const T & GetDefault() const
Definition: Prefs.h:120
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:134
CachingSettingBase::mCurrentValue
T mCurrentValue
Definition: Prefs.h:94
Setting::mDefaultValue
T mDefaultValue
Definition: Prefs.h:198
Setting::mFunction
const DefaultValueFunction mFunction
Definition: Prefs.h:199
CachingSettingBase::mValid
bool mValid
Definition: Prefs.h:95
SettingBase::GetConfig
wxConfigBase * GetConfig() const
Definition: Prefs.cpp:449
CachingSettingBase
Class template adds an in-memory cache of a value to SettingBase.
Definition: Prefs.h:88