Audacity  3.0.3
ShuttleGetDefinition.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ShuttleGetDefinition.cpp
6 
7  Paul Licameli split this out of Shuttle.cpp
8 
9 **********************************************************************/
10 
11 #include "ShuttleGetDefinition.h"
13 
15  bool result = pOptionalFlag !=NULL;
16  pOptionalFlag = NULL;
17  return result;
18 }
19 
20 // Definition distinguishes optional from not.
22  pOptionalFlag = &var;
23  return *this;
24 };
25 
27 {
28 }
29 
30 // JSON definitions.
31 void ShuttleGetDefinition::Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl )
32 {
33  StartStruct();
34  AddItem( wxString(key), "key" );
35  AddItem( "bool", "type" );
36  if( IsOptional() )
37  AddItem( "unchanged", "default" );
38  else
39  AddItem( vdefault ? "True" : "False", "default" );
40  EndStruct();
41 }
42 
43 void ShuttleGetDefinition::Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl )
44 {
45  StartStruct();
46  AddItem( wxString(key), "key" );
47  AddItem( "int", "type" );
48  if( IsOptional() )
49  AddItem( "unchanged", "default" );
50  else
51  AddItem( (double)vdefault, "default" );
52  EndStruct();
53 }
54 
55 void ShuttleGetDefinition::Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl )
56 {
57  StartStruct();
58  AddItem( wxString(key), "key" );
59  AddItem( "size_t", "type" );
60  if( IsOptional() )
61  AddItem( "unchanged", "default" );
62  else
63  AddItem( (double)vdefault, "default" );
64  EndStruct();
65 
66 }
67 
68 void ShuttleGetDefinition::Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
69 {
70  StartStruct();
71  AddItem( wxString(key), "key" );
72  AddItem( "float", "type" );
73  if( IsOptional() )
74  AddItem( "unchanged", "default" );
75  else
76  AddItem( (double)vdefault, "default" );
77  EndStruct();
78 }
79 
80 void ShuttleGetDefinition::Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
81 {
82  StartStruct();
83  AddItem( wxString(key), "key" );
84  AddItem( "float", "type" );
85  if( IsOptional() )
86  AddItem( "unchanged", "default" );
87  else
88  AddItem( (double)vdefault, "default" );
89  EndStruct();
90 }
91 
92 void ShuttleGetDefinition::Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl )
93 {
94  StartStruct();
95  AddItem( wxString(key), "key" );
96  AddItem( "double", "type" );
97  if( IsOptional() )
98  AddItem( "unchanged", "default" );
99  else
100  AddItem( (double)vdefault, "default" );
101  EndStruct();
102 }
103 
104 
105 void ShuttleGetDefinition::Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl )
106 {
107  StartStruct();
108  AddItem( wxString(key), "key" );
109  AddItem( "string", "type" );
110  if( IsOptional() )
111  AddItem( "unchanged", "default" );
112  else
113  AddItem( vdefault, "default" );
114  EndStruct();
115 }
116 
117 
119  const wxChar * key, const int vdefault,
120  const EnumValueSymbol strings[], size_t nStrings )
121 {
122  StartStruct();
123  AddItem( wxString(key), "key" );
124  AddItem( "enum", "type" );
125  if( IsOptional() )
126  AddItem( "unchanged", "default" );
127  else
128  AddItem( strings[vdefault].Internal(), "default" );
129  StartField( "enum" );
130  StartArray();
131  for( size_t i = 0; i < nStrings; i++ )
132  AddItem( strings[i].Internal() );
133  EndArray();
134  EndField();
135  EndStruct();
136 }
CommandMessageTargetDecorator::StartField
void StartField(const wxString &name={}) override
Definition: CommandTargets.h:110
ShuttleGetDefinition::Define
void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl) override
Definition: ShuttleGetDefinition.cpp:31
CommandMessageTargetDecorator::EndStruct
void EndStruct() override
Definition: CommandTargets.h:103
ShuttleGetDefinition.h
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
ComponentInterfaceSymbol.h
CommandMessageTargetDecorator::AddItem
void AddItem(const wxString &value, const wxString &name={}) override
Definition: CommandTargets.h:104
CommandMessageTarget
Interface for objects that can receive (string) messages from a command.
Definition: CommandTargets.h:75
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
CommandMessageTargetDecorator::EndField
void EndField() override
Definition: CommandTargets.h:112
CommandMessageTargetDecorator
CommandMessageTargetDecorator is a CommandOutputTarget that forwards its work on to another one....
Definition: CommandTargets.h:95
ShuttleGetDefinition::Optional
ShuttleParams & Optional(bool &var) override
Definition: ShuttleGetDefinition.cpp:21
CommandMessageTargetDecorator::EndArray
void EndArray() override
Definition: CommandTargets.h:101
ShuttleGetDefinition::ShuttleGetDefinition
ShuttleGetDefinition(CommandMessageTarget &target)
Definition: ShuttleGetDefinition.cpp:26
ShuttleGetDefinition::DefineEnum
void DefineEnum(int &var, const wxChar *key, const int vdefault, const EnumValueSymbol strings[], size_t nStrings) override
Definition: ShuttleGetDefinition.cpp:118
CommandMessageTargetDecorator::StartArray
void StartArray() override
Definition: CommandTargets.h:100
CommandMessageTargetDecorator::StartStruct
void StartStruct() override
Definition: CommandTargets.h:102
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
ExceptionType::Internal
@ Internal
Indicates internal failure from Audacity.
ShuttleGetDefinition::IsOptional
bool IsOptional()
Definition: ShuttleGetDefinition.cpp:14
ShuttleParams::pOptionalFlag
bool * pOptionalFlag
Definition: Shuttle.h:65