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

Constructor & Destructor Documentation

◆ SettingScope() [1/2]

SettingScope::SettingScope ( )

Definition at line 241 of file Prefs.cpp.

242{
243 sScopes.push_back(this);
244}
std::vector< SettingScope * > sScopes
Definition: Prefs.cpp:238

References anonymous_namespace{Prefs.cpp}::sScopes.

◆ ~SettingScope()

SettingScope::~SettingScope ( )
noexcept

Definition at line 246 of file Prefs.cpp.

247{
248 // Settings can be scoped only on stack
249 // so it should be safe to assume that sScopes.top() == this;
250 assert(!sScopes.empty() && sScopes.back() == this);
251
252 if (sScopes.empty() || sScopes.back() != this)
253 return;
254
255 if (!mCommitted)
256 for (auto pSetting : mPending)
257 pSetting->Rollback();
258
259 sScopes.pop_back();
260}
bool mCommitted
Definition: Prefs.h:133
std::set< TransactionalSettingBase * > mPending
Definition: Prefs.h:132

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

264{
265 if ( sScopes.empty() || sScopes.back()->mCommitted )
266 return NotAdded;
267
268 const bool inserted = sScopes.back()->mPending.insert(&setting).second;
269
270 if (inserted)
271 {
272 setting.EnterTransaction(sScopes.size());
273
274 // We need to introduce this setting into all
275 // previous scopes that do not yet contain it.
276 for (auto it = sScopes.rbegin() + 1; it != sScopes.rend(); ++it)
277 {
278 if ((*it)->mPending.find(&setting) != (*it)->mPending.end())
279 break;
280
281 (*it)->mPending.insert(&setting);
282 }
283 }
284
285 return inserted ? Added : PreviouslyAdded;
286}
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 133 of file Prefs.h.

◆ mPending

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

Definition at line 132 of file Prefs.h.


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