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

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

References anonymous_namespace{Prefs.cpp}::sScopes.

◆ ~SettingScope()

SettingScope::~SettingScope ( )
noexcept

Definition at line 245 of file Prefs.cpp.

246{
247 // Settings can be scoped only on stack
248 // so it should be safe to assume that sScopes.top() == this;
249 assert(!sScopes.empty() && sScopes.back() == this);
250
251 if (sScopes.empty() || sScopes.back() != this)
252 return;
253
254 if (!mCommitted)
255 for (auto pSetting : mPending)
256 pSetting->Rollback();
257
258 sScopes.pop_back();
259}
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 262 of file Prefs.cpp.

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