Audacity 3.2.0
SettingsVisitor.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 SettingsVisitor.h
6
7 James Crook
8
9**********************************************************************/
10#ifndef __AUDACITY_SETTINGS_VISITOR__
11#define __AUDACITY_SETTINGS_VISITOR__
12
13#include <type_traits>
14
16
18class WrappedType;
19
20template<
21 typename Structure,
22 typename Member,
23 typename Type,
24 typename Value = Type
26 Member Structure::*const mem{};
27 const wxChar *const key{};
28 const Type def{};
29 const Type min{};
30 const Type max{};
31 const Type scale{};
32};
33
34// Deduction guides
35// Type of def chooses the parameter type; others just need to be convertible
36template<typename Structure, typename Member,
37 typename Type, typename... Args>
38EffectParameter(Member Structure::*const mem,
39 const wxChar *key, const Type &def, Args...)
41// Deduce string type from string literal
42template<typename Structure, typename Member,
43 typename Char, size_t N, typename... Args>
44EffectParameter(Member Structure::*const mem,
45 const wxChar *key, const Char (&def)[N], Args...)
47
48template<typename Structure, typename Member>
49struct EnumParameter : EffectParameter<Structure, Member, int>
50{
51 constexpr EnumParameter(Member Structure::*const mem,
52 const wxChar *key, int def, int min, int max, int scale,
53 const EnumValueSymbol *symbols_, size_t nSymbols_ )
54 : EffectParameter<Structure, Member, int>{
55 mem, key, def, min, max, scale }
56 , symbols{ symbols_ }
57 , nSymbols{ nSymbols_ }
58 {}
59
61 const size_t nSymbols;
62};
63
64// Deduction guide
65template<typename Structure, typename Member, typename... Args>
66EnumParameter(Member Structure::*const mem, Args...)
68
70/**************************************************************************/
77template<bool Const>
78class SettingsVisitorBase /* not final */
79{
80public:
81 // By-value argument for const visitor, otherwise reference
82 template<typename T> using Ref = std::conditional_t<Const, const T&, T&>;
83 // const-reference argument for const visitor, otherwise reference
84 template<typename T> using Arg = std::conditional_t<Const, T, T&>;
85
86 wxString mParams;
87 std::conditional_t<Const, const bool, bool> *pOptionalFlag{};
89
92
93 bool ShouldSet();
97 virtual void Define( Arg<bool> var, const wxChar * key, bool vdefault,
98 bool vmin = false, bool vmax = false, bool vscl = false );
99 virtual void Define( Arg<size_t> var, const wxChar * key, int vdefault,
100 int vmin = 0, int vmax = 100000, int vscl = 1 );
101 virtual void Define( Arg<int> var, const wxChar * key, int vdefault,
102 int vmin = 0, int vmax = 100000, int vscl = 1 );
103 virtual void Define( Arg<float> var, const wxChar * key, float vdefault,
104 float vmin, float vmax, float vscl = 1.0f );
105 virtual void Define( Arg<double> var, const wxChar * key, float vdefault,
106 float vmin, float vmax, float vscl = 1.0f );
107 virtual void Define( Arg<double> var, const wxChar * key, double vdefault,
108 double vmin, double vmax, double vscl = 1.0f );
109 virtual void Define( Ref<wxString> var, const wxChar * key,
110 wxString vdefault,
111 wxString vmin = {}, wxString vmax = {},
112 wxString vscl = {} );
113 virtual void DefineEnum( Arg<int> var, const wxChar * key, int vdefault,
114 const EnumValueSymbol strings[], size_t nStrings );
115};
116
117extern template class COMPONENTS_API SettingsVisitorBase<false>;
118extern template class COMPONENTS_API SettingsVisitorBase<true>;
119
122
123#endif
static const AudacityProject::AttachedObjects::RegisteredFactory key
EnumParameter(Member Structure::*const mem, Args...) -> EnumParameter< Structure, Member >
EffectParameter(Member Structure::*const mem, const wxChar *key, const Type &def, Args...) -> EffectParameter< Structure, Member, Type >
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
virtual void Define(Arg< bool > var, const wxChar *key, bool vdefault, bool vmin=false, bool vmax=false, bool vscl=false)
virtual SettingsVisitorBase & OptionalY(Ref< bool > var)
std::conditional_t< Const, T, T & > Arg
CommandParameters * mpEap
std::conditional_t< Const, const bool, bool > * pOptionalFlag
virtual ~SettingsVisitorBase()
virtual SettingsVisitorBase & Optional(Ref< bool > var)
virtual void DefineEnum(Arg< int > var, const wxChar *key, int vdefault, const EnumValueSymbol strings[], size_t nStrings)
std::conditional_t< Const, const T &, T & > Ref
virtual SettingsVisitorBase & OptionalN(Ref< bool > var)
Used in type conversions, this wrapper for ints, strings, doubles and enums provides conversions betw...
Definition: WrappedType.h:28
const wxChar *const key
Identifier in configuration file.
const Type scale
Scaling factor, for slider control.
Member Structure::*const mem
Member holding the parameter.
const Type def
Default value.
const Type min
Minimum value.
const Type max
Maximum value.
constexpr EnumParameter(Member Structure::*const mem, const wxChar *key, int def, int min, int max, int scale, const EnumValueSymbol *symbols_, size_t nSymbols_)
const size_t nSymbols
const EnumValueSymbol *const symbols