Audacity  2.2.2
Shuttle.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Shuttle.h
6 
7  James Crook
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_SHUTTLE__
12 #define __AUDACITY_SHUTTLE__
13 
15 #include "../include/audacity/IdentInterface.h"
16 
18 class WrappedType;
19 
20 class Shuttle /* not final */ {
21  public:
22  // constructors and destructors
23  Shuttle();
24  virtual ~Shuttle() {}
25 
26  public:
28  wxString mValueString;
29  // Even though virtual, mostly the transfer functions won't change
30  // for special kinds of archive.
31  virtual bool TransferBool( const wxString & Name, bool & bValue, const bool & bDefault );
32  virtual bool TransferFloat( const wxString & Name, float & fValue, const float &fDefault );
33  virtual bool TransferDouble( const wxString & Name, double & dValue, const double &dDefault );
34  virtual bool TransferInt( const wxString & Name, int & iValue, const int &iDefault );
35  virtual bool TransferInt( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
36  virtual bool TransferLongLong( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
37  virtual bool TransferString( const wxString & Name, wxString & strValue, const wxString &strDefault );
38  virtual bool TransferEnum( const wxString & Name, int & iValue,
39  const int nChoices, const wxString * pFirstStr);
40  virtual bool TransferWrappedType( const wxString & Name, WrappedType & W );
41  // We expect the ExchangeWithMaster function to change from one type of
42  // archive to another.
43  virtual bool ExchangeWithMaster(const wxString & Name);
44 };
45 
46 class ShuttleCli final : public Shuttle
47 {
48 public:
49  wxString mParams;
50  ShuttleCli(){ mParams = wxT("") ;}
51  virtual ~ShuttleCli() {}
52  bool ExchangeWithMaster(const wxString & Name) override;
53 };
54 
55 class CommandParameters;
56 /**************************************************************************/
60 class ShuttleParams : public Shuttle
61 {
62 public:
63  wxString mParams;
66  ShuttleParams(){ mParams = wxT("") ;mpEap=NULL;pOptionalFlag=NULL;}
67  virtual ~ShuttleParams() {}
68  bool ExchangeWithMaster(const wxString & Name) override;
69  bool ShouldSet();
70  virtual ShuttleParams & Optional( bool & WXUNUSED(var) ){ pOptionalFlag = NULL;return *this;};
71  virtual ShuttleParams & OptionalY( bool & var ){ return Optional( var );};
72  virtual ShuttleParams & OptionalN( bool & var ){ return Optional( var );};
73  virtual void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false );
74  virtual void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
75  virtual void Define( int & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
76  virtual void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl=1.0f );
77  virtual void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl=1.0f );
78  virtual void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl=1.0f );
79  virtual void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin="", const wxString vmax="", const wxString vscl="" );
80  virtual void DefineEnum( int &var, const wxChar * key, const int vdefault,
81  const IdentInterfaceSymbol strings[], size_t nStrings );
82 };
83 
84 /**************************************************************************/
88 {
89 public:
90  ShuttleParams & Optional( bool & var ) override;
91  void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
92  void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
93  void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
94  void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
95  void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
96  void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl ) override;
97  void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) override;
98  void DefineEnum( int &var, const wxChar * key, const int vdefault,
99  const IdentInterfaceSymbol strings[], size_t nStrings ) override;
100 };
101 
102 /**************************************************************************/
106 {
107 public:
108  ShuttleSetAutomation(){ bWrite = false; bOK = false;};
109  bool bOK;
110  bool bWrite;
111  ShuttleParams & Optional( bool & var ) override;
112  bool CouldGet(const wxString &key);
113  void SetForValidating( CommandParameters * pEap){ mpEap=pEap; bOK=true;bWrite=false;};
114  void SetForWriting(CommandParameters * pEap){ mpEap=pEap;bOK=true;bWrite=true;};
115  void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
116  void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
117  void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
118  void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
119  void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
120  void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl ) override;
121  void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) override;
122  void DefineEnum( int &var, const wxChar * key, const int vdefault,
123  const IdentInterfaceSymbol strings[], size_t nStrings ) override;
124 };
125 
126 /**************************************************************************/
130 {
131 public:
133  wxString Result;
134  bool IsOptional();
135  ShuttleParams & Optional( bool & var ) override;
136  void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
137  void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
138  void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
139  void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
140  void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
141  void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl ) override;
142  void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) override;
143  void DefineEnum( int &var, const wxChar * key, const int vdefault,
144  const IdentInterfaceSymbol strings[], size_t nStrings ) override;
145 };
146 
147 
148 /**************************************************************************/
152 {
153 public:
154  wxString Result;
155  virtual ShuttleParams & Optional( bool & var )override{ var = true; pOptionalFlag = NULL;return *this;};
156  virtual ShuttleParams & OptionalY( bool & var )override{ var = true; pOptionalFlag = NULL;return *this;};
157  virtual ShuttleParams & OptionalN( bool & var )override{ var = false;pOptionalFlag = NULL;return *this;};
158 
159  void Define( bool & var, const wxChar * WXUNUSED(key), const bool vdefault,
160  const bool WXUNUSED(vmin), const bool WXUNUSED(vmax), const bool WXUNUSED(vscl) )
161  override { var = vdefault;};
162  void Define( int & var, const wxChar * WXUNUSED(key), const int vdefault,
163  const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl) )
164  override { var = vdefault;};
165  void Define( size_t & var, const wxChar * WXUNUSED(key), const int vdefault,
166  const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl) )
167  override{ var = vdefault;};
168  void Define( float & var, const wxChar * WXUNUSED(key), const float vdefault,
169  const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl) )
170  override { var = vdefault;};
171  void Define( double & var, const wxChar * WXUNUSED(key), const float vdefault,
172  const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl) )
173  override { var = vdefault;};
174  void Define( double & var, const wxChar * WXUNUSED(key), const double vdefault,
175  const double WXUNUSED(vmin), const double WXUNUSED(vmax), const double WXUNUSED(vscl) )
176  override { var = vdefault;};
177  void Define( wxString &var, const wxChar * WXUNUSED(key), const wxString vdefault,
178  const wxString WXUNUSED(vmin), const wxString WXUNUSED(vmax), const wxString WXUNUSED(vscl) )
179  override { var = vdefault;};
180  void DefineEnum( int &var, const wxChar * WXUNUSED(key), const int vdefault,
181  const IdentInterfaceSymbol WXUNUSED(strings) [], size_t WXUNUSED( nStrings ) )
182  override { var = vdefault;};
183 };
184 
185 
186 
187 
188 
189 
190 #define SHUTTLE_PARAM( var, name ) \
191  Define( var, KEY_ ## name, DEF_ ## name, MIN_ ## name, MAX_ ## name, SCL_ ## name )
192 
193 #define SHUTTLE_ENUM_PARAM( var, name, strings, nStrings ) \
194  DefineEnum( var, KEY_ ## name, DEF_ ## name, strings, nStrings )
195 
196 #endif
wxString Result
Definition: Shuttle.h:154
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:72
void SetForWriting(CommandParameters *pEap)
Definition: Shuttle.h:114
void DefineEnum(int &var, const wxChar *key, const int vdefault, const IdentInterfaceSymbol strings[], size_t nStrings) override
Definition: Shuttle.cpp:516
virtual bool TransferEnum(const wxString &Name, int &iValue, const int nChoices, const wxString *pFirstStr)
Definition: Shuttle.cpp:182
void DefineEnum(int &var, const wxChar *key, const int vdefault, const IdentInterfaceSymbol strings[], size_t nStrings) override
Definition: Shuttle.cpp:406
void Define(double &var, const wxChar *WXUNUSED(key), const double vdefault, const double WXUNUSED(vmin), const double WXUNUSED(vmax), const double WXUNUSED(vscl)) override
Definition: Shuttle.h:174
wxString mParams
Definition: Shuttle.h:63
Moves data from one place to another, converting it as required.
Definition: Shuttle.h:20
void Define(size_t &var, const wxChar *WXUNUSED(key), const int vdefault, const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl)) override
Definition: Shuttle.h:165
void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl) override
Definition: Shuttle.cpp:434
virtual bool TransferInt(const wxString &Name, int &iValue, const int &iDefault)
Definition: Shuttle.cpp:138
CommandMessageTargetDecorator is a CommandOutputTarget that forwards its work on to another one...
Shuttle that gets parameter values into a string.
Definition: Shuttle.h:87
virtual ~ShuttleParams()
Definition: Shuttle.h:67
wxString mParams
Definition: Shuttle.h:49
Derived from Shuttle, this class exchanges string parameters with a binary representation.
Definition: Shuttle.h:46
ShuttleCli()
Definition: Shuttle.h:50
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:60
void Define(double &var, const wxChar *WXUNUSED(key), const float vdefault, const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl)) override
Definition: Shuttle.h:171
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:260
virtual ShuttleParams & OptionalY(bool &var) override
Definition: Shuttle.h:156
Shuttle that retrieves a JSON format definition of a command's parameters.
Definition: Shuttle.h:129
void DefineEnum(int &var, const wxChar *WXUNUSED(key), const int vdefault, const IdentInterfaceSymbol WXUNUSED(strings)[], size_t WXUNUSED(nStrings)) override
Definition: Shuttle.h:180
void Define(int &var, const wxChar *WXUNUSED(key), const int vdefault, const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl)) override
Definition: Shuttle.h:162
virtual ShuttleParams & Optional(bool &var) override
Definition: Shuttle.h:155
virtual ~ShuttleCli()
Definition: Shuttle.h:51
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
bool CouldGet(const wxString &key)
Definition: Shuttle.cpp:424
virtual void DefineEnum(int &var, const wxChar *key, const int vdefault, const IdentInterfaceSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:346
virtual bool TransferBool(const wxString &Name, bool &bValue, const bool &bDefault)
Definition: Shuttle.cpp:80
virtual bool TransferString(const wxString &Name, wxString &strValue, const wxString &strDefault)
Definition: Shuttle.cpp:223
void Define(wxString &var, const wxChar *WXUNUSED(key), const wxString vdefault, const wxString WXUNUSED(vmin), const wxString WXUNUSED(vmax), const wxString WXUNUSED(vscl)) override
Definition: Shuttle.h:177
void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl) override
Definition: Shuttle.cpp:544
ShuttleParams & Optional(bool &var) override
Definition: Shuttle.cpp:357
Shuttle that sets parameters to their default values.
Definition: Shuttle.h:151
CommandParameters * mpEap
Definition: Shuttle.h:65
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
virtual ShuttleParams & Optional(bool &WXUNUSED(var))
Definition: Shuttle.h:70
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:339
bool ShouldSet()
Definition: Shuttle.cpp:331
virtual bool TransferFloat(const wxString &Name, float &fValue, const float &fDefault)
Definition: Shuttle.cpp:99
bool * pOptionalFlag
Definition: Shuttle.h:64
bool ExchangeWithMaster(const wxString &Name) override
Definition: Shuttle.cpp:311
ShuttleParams & Optional(bool &var) override
Definition: Shuttle.cpp:414
void Define(float &var, const wxChar *WXUNUSED(key), const float vdefault, const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl)) override
Definition: Shuttle.h:168
virtual bool TransferWrappedType(const wxString &Name, WrappedType &W)
Definition: Shuttle.cpp:242
Interface for objects that can receive (string) messages from a command.
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
ShuttleParams & Optional(bool &var) override
Definition: Shuttle.cpp:534
bool mbStoreInClient
Definition: Shuttle.h:27
virtual ShuttleParams & OptionalN(bool &var) override
Definition: Shuttle.h:157
virtual bool TransferLongLong(const wxString &Name, wxLongLong_t &iValue, const wxLongLong_t &iDefault)
Definition: Shuttle.cpp:162
Shuttle that sets parameters to a value (from a string)
Definition: Shuttle.h:105
ShuttleParams()
Definition: Shuttle.h:66
virtual bool TransferDouble(const wxString &Name, double &dValue, const double &dDefault)
Definition: Shuttle.cpp:118
void Define(bool &var, const wxChar *WXUNUSED(key), const bool vdefault, const bool WXUNUSED(vmin), const bool WXUNUSED(vmax), const bool WXUNUSED(vscl)) override
Definition: Shuttle.h:159
virtual ~Shuttle()
Definition: Shuttle.h:24
void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl) override
Definition: Shuttle.cpp:362
wxString mValueString
Definition: Shuttle.h:28
bool ExchangeWithMaster(const wxString &Name) override
Definition: Shuttle.cpp:271
void DefineEnum(int &var, const wxChar *key, const int vdefault, const IdentInterfaceSymbol strings[], size_t nStrings) override
Definition: Shuttle.cpp:631
ShuttleGetDefinition(CommandMessageTarget &target)
Definition: Shuttle.cpp:539
void SetForValidating(CommandParameters *pEap)
Definition: Shuttle.h:113
Used in type conversions, this wrapper for ints, strings, doubles and enums provides conversions betw...
Definition: WrappedType.h:31
Shuttle()
Definition: Shuttle.cpp:76