Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope Class Reference

RAII guard for temporary installation of a value; movable. More...

#include <GlobalVariable.h>

Public Member Functions

 Scope (mutable_type value)
 
 Scope (Scope &&other)=default
 
Scopeoperator= (Scope &&other)=default
 
 ~Scope ()
 
void Commit ()
 
bool HasValue () const
 

Private Attributes

std::conditional_t< ScopedOnly, mutable_type, std::optional< mutable_type > > m_previous
 

Detailed Description

template<typename Tag, typename Type, auto initializer = nullptr, bool ScopedOnly = true>
class GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope

RAII guard for temporary installation of a value; movable.

Constructor captures previous value, installs a new value; destructor restores the previous value, unless moved-from or Committed

Not required to have stack-like lifetime. Non-nested lifetimes for distinct Scope objects is not prevented and may have surprising results.

Definition at line 70 of file GlobalVariable.h.

Constructor & Destructor Documentation

◆ Scope() [1/2]

template<typename Tag , typename Type , auto initializer = nullptr, bool ScopedOnly = true>
GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::Scope ( mutable_type  value)
inlineexplicit

Definition at line 73 of file GlobalVariable.h.

74 : m_previous{ Assign(std::move(value)) }
75 {}
std::conditional_t< ScopedOnly, mutable_type, std::optional< mutable_type > > m_previous
static mutable_type Assign(mutable_type &&replacement)

◆ Scope() [2/2]

template<typename Tag , typename Type , auto initializer = nullptr, bool ScopedOnly = true>
GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::Scope ( Scope &&  other)
default

◆ ~Scope()

template<typename Tag , typename Type , auto initializer = nullptr, bool ScopedOnly = true>
GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::~Scope ( )
inline

Definition at line 78 of file GlobalVariable.h.

79 {
80 if constexpr (ScopedOnly)
81 Assign(std::move(m_previous));
82 else if (m_previous)
83 Assign(std::move(*m_previous));
84 }

References GlobalVariable< Tag, Type, initializer, ScopedOnly >::Assign(), and GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::m_previous.

Here is the call graph for this function:

Member Function Documentation

◆ Commit()

template<typename Tag , typename Type , auto initializer = nullptr, bool ScopedOnly = true>
void GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::Commit ( )
inline

Won't compile unless ScopedOnly is false

Definition at line 86 of file GlobalVariable.h.

87 {
88 static_assert(!ScopedOnly);
89 m_previous.reset();
90 }

References GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::m_previous.

◆ HasValue()

template<typename Tag , typename Type , auto initializer = nullptr, bool ScopedOnly = true>
bool GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::HasValue ( ) const
inline

Definition at line 91 of file GlobalVariable.h.

92 {
93 if constexpr (ScopedOnly)
94 return true;
95 else
96 return m_previous.has_value();
97 }

References GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::m_previous.

◆ operator=()

template<typename Tag , typename Type , auto initializer = nullptr, bool ScopedOnly = true>
Scope & GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::operator= ( Scope &&  other)
default

Member Data Documentation

◆ m_previous

template<typename Tag , typename Type , auto initializer = nullptr, bool ScopedOnly = true>
std::conditional_t<ScopedOnly, mutable_type, std::optional<mutable_type> > GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::m_previous
private

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