Audacity 3.2.0
|
Class template to generate global variables. More...
#include <GlobalVariable.h>
Classes | |
struct | dummy |
struct | Initializer |
Can guarantee that the global variable's lifetime encloses those of other objects of static duration. More... | |
class | Scope |
RAII guard for temporary installation of a value; movable. More... | |
Public Types | |
using | variable_type = GlobalVariable |
using | stored_type = Type |
using | mutable_type = std::remove_const_t< Type > |
Static Public Member Functions | |
static stored_type & | Get () |
Get the installed value. More... | |
static auto | Set (std::conditional_t< ScopedOnly, dummy, mutable_type > replacement) -> std::conditional_t< ScopedOnly, void, mutable_type > |
Move in a new value, move out and return the previous. More... | |
Private Member Functions | |
GlobalVariable ()=delete | |
Use static functions only. Don't directly construct this. More... | |
Static Private Member Functions | |
static mutable_type & | Instance () |
Generate the static variable. More... | |
static mutable_type | Assign (mutable_type &&replacement) |
Class template to generate global variables.
The variable is constructed when first used, regardless of the static initialization sequence of translation units.
Tag | distinguishes GlobalVariables with the same Type; often a "CRTP" argument |
Type | must be non-reference, and default-constructible if there is no initializer function; if const-qualified, that means Get() gives non-mutating access, but Set() and Scope{...} are still possible if Type is movable |
initializer | initial value, or a function that computes initial value |
ScopedOnly | if true, then enforce RAII for changes of the variable (do not generate Set() or Scope::Commit()) |
Definition at line 35 of file GlobalVariable.h.
using GlobalVariable< Tag, Type, initializer, ScopedOnly >::mutable_type = std::remove_const_t<Type> |
Definition at line 40 of file GlobalVariable.h.
using GlobalVariable< Tag, Type, initializer, ScopedOnly >::stored_type = Type |
Definition at line 39 of file GlobalVariable.h.
using GlobalVariable< Tag, Type, initializer, ScopedOnly >::variable_type = GlobalVariable |
Definition at line 38 of file GlobalVariable.h.
|
privatedelete |
Use static functions only. Don't directly construct this.
|
inlinestaticprivate |
Definition at line 143 of file GlobalVariable.h.
References GlobalVariable< Tag, Type, initializer, ScopedOnly >::Instance().
Referenced by GlobalVariable< Tag, Type, initializer, ScopedOnly >::Get(), GlobalVariable< Tag, Type, initializer, ScopedOnly >::Set(), and GlobalVariable< Tag, Type, initializer, ScopedOnly >::Scope::~Scope().
|
inlinestatic |
Get the installed value.
Definition at line 43 of file GlobalVariable.h.
References GlobalVariable< Tag, Type, initializer, ScopedOnly >::Assign(), and GlobalVariable< Tag, Type, initializer, ScopedOnly >::Instance().
|
inlinestaticprivate |
Generate the static variable.
Definition at line 124 of file GlobalVariable.h.
References Journal::Events::anonymous_namespace{JournalEvents.cpp}::initializer.
Referenced by GlobalVariable< Tag, Type, initializer, ScopedOnly >::Assign(), GlobalVariable< Tag, Type, initializer, ScopedOnly >::Get(), and GlobalVariable< Tag, Type, initializer, ScopedOnly >::Initializer::Initializer().
|
inlinestatic |
Move in a new value, move out and return the previous.
Calls won't compile if ScopedOnly is true, though the function can still be generated at compile time. (std::enable_if_t doesn't work here)
Definition at line 54 of file GlobalVariable.h.
References GlobalVariable< Tag, Type, initializer, ScopedOnly >::Assign().