Audacity 3.2.0
Public Member Functions | List of all members
SettingTransaction Class Referencefinal

Extend SettingScope with Commit() which flushes updates in a batch. More...

#include <Prefs.h>

Inheritance diagram for SettingTransaction:
[legend]
Collaboration diagram for SettingTransaction:
[legend]

Public Member Functions

bool Commit ()
 
- Public Member Functions inherited from SettingScope
 SettingScope ()
 
 ~SettingScope () noexcept
 
 SettingScope (const SettingScope &)=delete
 
SettingScopeoperator= (const SettingScope &)=delete
 

Additional Inherited Members

- Public Types inherited from SettingScope
enum  AddResult { NotAdded , Added , PreviouslyAdded }
 
- Static Public Member Functions inherited from SettingScope
static AddResult Add (TransactionalSettingBase &setting)
 
- Protected Attributes inherited from SettingScope
std::set< TransactionalSettingBase * > mPending
 
bool mCommitted = false
 

Detailed Description

Extend SettingScope with Commit() which flushes updates in a batch.

Construct one; then write to some Setting objects; then Commit() before destruction to keep the changes, or else the destructor rolls them back.

Flushes preferences on successful commit.

Nesting of SettingTransaction is not supported. No copy or move.

Definition at line 148 of file Prefs.h.

Member Function Documentation

◆ Commit()

bool SettingTransaction::Commit ( )
Returns
true if successful

It is unlikely to return false, but in that case an unflushed, partial write of changes to the config file may have happened

Definition at line 322 of file Prefs.cpp.

323{
324 if (sScopes.empty() || sScopes.back() != this)
325 return false;
326
327 if ( !mCommitted ) {
328 for ( auto pSetting : mPending )
329 if ( !pSetting->Commit() )
330 return false;
331
332 if (sScopes.size() > 1 || gPrefs->Flush())
333 {
334 mPending.clear();
335 mCommitted = true;
336 return true;
337 }
338 }
339
340 return false;
341}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
bool mCommitted
Definition: Prefs.h:138
std::set< TransactionalSettingBase * > mPending
Definition: Prefs.h:137
virtual bool Flush() noexcept=0
std::vector< SettingScope * > sScopes
Definition: Prefs.cpp:272

References audacity::BasicSettings::Flush(), gPrefs, and anonymous_namespace{Prefs.cpp}::sScopes.

Referenced by FindFFmpegLibs().

Here is the call graph for this function:
Here is the caller graph for this function:

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