Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
SettingScope Class Reference

Makes temporary changes to preferences, then rolls them back at destruction. More...

#include <Prefs.h>

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

Public Types

enum  AddResult { NotAdded , Added , PreviouslyAdded }
 

Public Member Functions

 SettingScope ()
 
 ~SettingScope () noexcept
 
 SettingScope (const SettingScope &)=delete
 
SettingScopeoperator= (const SettingScope &)=delete
 

Static Public Member Functions

static AddResult Add (TransactionalSettingBase &setting)
 

Protected Attributes

std::set< TransactionalSettingBase * > mPending
 
bool mCommitted = false
 

Detailed Description

Makes temporary changes to preferences, then rolls them back at destruction.

No copy or move.

Definition at line 119 of file Prefs.h.

Member Enumeration Documentation

◆ AddResult

Returns
NotAdded if there is no pending (and uncommitted) scope; PreviouslyAdded if there is one, but the given setting object was already added since it began; else Added
Enumerator
NotAdded 
Added 
PreviouslyAdded 

Definition at line 133 of file Prefs.h.

Constructor & Destructor Documentation

◆ SettingScope() [1/2]

SettingScope::SettingScope ( )

Definition at line 275 of file Prefs.cpp.

276{
277 sScopes.push_back(this);
278}
std::vector< SettingScope * > sScopes
Definition: Prefs.cpp:272

References anonymous_namespace{Prefs.cpp}::sScopes.

◆ ~SettingScope()

SettingScope::~SettingScope ( )
noexcept

Definition at line 280 of file Prefs.cpp.

281{
282 // Settings can be scoped only on stack
283 // so it should be safe to assume that sScopes.top() == this;
284 assert(!sScopes.empty() && sScopes.back() == this);
285
286 if (sScopes.empty() || sScopes.back() != this)
287 return;
288
289 if (!mCommitted)
290 for (auto pSetting : mPending)
291 pSetting->Rollback();
292
293 sScopes.pop_back();
294}
bool mCommitted
Definition: Prefs.h:138
std::set< TransactionalSettingBase * > mPending
Definition: Prefs.h:137

References anonymous_namespace{Prefs.cpp}::sScopes.

◆ SettingScope() [2/2]

SettingScope::SettingScope ( const SettingScope )
delete

Member Function Documentation

◆ Add()

auto SettingScope::Add ( TransactionalSettingBase setting)
static

Definition at line 297 of file Prefs.cpp.

298{
299 if ( sScopes.empty() || sScopes.back()->mCommitted )
300 return NotAdded;
301
302 const bool inserted = sScopes.back()->mPending.insert(&setting).second;
303
304 if (inserted)
305 {
306 setting.EnterTransaction(sScopes.size());
307
308 // We need to introduce this setting into all
309 // previous scopes that do not yet contain it.
310 for (auto it = sScopes.rbegin() + 1; it != sScopes.rend(); ++it)
311 {
312 if ((*it)->mPending.find(&setting) != (*it)->mPending.end())
313 break;
314
315 (*it)->mPending.insert(&setting);
316 }
317 }
318
319 return inserted ? Added : PreviouslyAdded;
320}
virtual void EnterTransaction(size_t depth)=0

References anonymous_namespace{Prefs.cpp}::sScopes.

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

Here is the caller graph for this function:

◆ operator=()

SettingScope & SettingScope::operator= ( const SettingScope )
delete

Member Data Documentation

◆ mCommitted

bool SettingScope::mCommitted = false
protected

Definition at line 138 of file Prefs.h.

◆ mPending

std::set< TransactionalSettingBase * > SettingScope::mPending
protected

Definition at line 137 of file Prefs.h.


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