Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
WrappedType Class Reference

Used in type conversions, this wrapper for ints, strings, doubles and enums provides conversions between all the types. Functions that work on wrapped types can quickly be reused to work on any of these types. This cuts out a lot of repetitive code. More...

#include <WrappedType.h>

Public Member Functions

 WrappedType (wxString &InStr)
 
 WrappedType (int &InInt)
 
 WrappedType (double &InDouble)
 
 WrappedType (bool &InBool)
 
 WrappedType ()
 
bool IsString ()
 
wxString ReadAsString ()
 
int ReadAsInt ()
 
double ReadAsDouble ()
 
bool ReadAsBool ()
 
void WriteToAsString (const wxString &InStr)
 
void WriteToAsInt (const int InInt)
 
void WriteToAsDouble (const double InDouble)
 
void WriteToAsBool (const bool InBool)
 

Public Attributes

const teWrappedType eWrappedType
 
wxString *const mpStr {}
 
int *const mpInt {}
 
double *const mpDouble {}
 
bool *const mpBool {}
 

Detailed Description

Used in type conversions, this wrapper for ints, strings, doubles and enums provides conversions between all the types. Functions that work on wrapped types can quickly be reused to work on any of these types. This cuts out a lot of repetitive code.

JKC: This class grows in size with the square of the number of types it supports. It has to do all conversions between all pairs, so try to re-use existing types if you can.

It's probable that not all the cases are actually used in practice. The most heavily used will be conversions to <-> from string.

Definition at line 27 of file WrappedType.h.

Constructor & Destructor Documentation

◆ WrappedType() [1/5]

WrappedType::WrappedType ( wxString &  InStr)
inlineexplicit

Definition at line 31 of file WrappedType.h.

32 : eWrappedType{ eWrappedString }, mpStr{ &InStr }
33 {}
@ eWrappedString
Definition: WrappedType.h:18
wxString *const mpStr
Definition: WrappedType.h:62
const teWrappedType eWrappedType
Definition: WrappedType.h:61

◆ WrappedType() [2/5]

WrappedType::WrappedType ( int &  InInt)
inlineexplicit

Definition at line 34 of file WrappedType.h.

35 : eWrappedType{ eWrappedInt }, mpInt{ &InInt }
36 {}
@ eWrappedInt
Definition: WrappedType.h:19
int *const mpInt
Definition: WrappedType.h:63

◆ WrappedType() [3/5]

WrappedType::WrappedType ( double &  InDouble)
inlineexplicit

Definition at line 37 of file WrappedType.h.

38 : eWrappedType{ eWrappedDouble }, mpDouble{ &InDouble }
39 {}
@ eWrappedDouble
Definition: WrappedType.h:20
double *const mpDouble
Definition: WrappedType.h:64

◆ WrappedType() [4/5]

WrappedType::WrappedType ( bool &  InBool)
inlineexplicit

Definition at line 40 of file WrappedType.h.

41 : eWrappedType{ eWrappedBool }, mpBool{ &InBool }
42 {}
@ eWrappedBool
Definition: WrappedType.h:21
bool *const mpBool
Definition: WrappedType.h:65

◆ WrappedType() [5/5]

WrappedType::WrappedType ( )
inlineexplicit

Definition at line 43 of file WrappedType.h.

45 {}
@ eWrappedNotSet
Definition: WrappedType.h:17

Member Function Documentation

◆ IsString()

bool WrappedType::IsString ( )
Returns
true iff the wrapped type is a string.

Definition at line 34 of file WrappedType.cpp.

35{
37}

References eWrappedString, and eWrappedType.

Referenced by ShuttleGuiBase::TieRadioButton().

Here is the caller graph for this function:

◆ ReadAsBool()

bool WrappedType::ReadAsBool ( )

Definition at line 119 of file WrappedType.cpp.

120{
121 switch( eWrappedType )
122 {
123 case eWrappedString:
124 return mpStr->IsSameAs( wxT("true"), false ); // case free comparison.
125 break;
126 case eWrappedInt:
127 return *mpInt != 0;
128 break;
129 case eWrappedDouble:
130 wxASSERT( false );// DANGEROUS USE OF WrappedType. Can't rely on equality.
131 return * mpDouble != 0.0f; // this is what the code would be...
132 break;
133 case eWrappedBool:
134 return * mpBool;
135 break;
136 case eWrappedEnum:
137 wxASSERT( false );
138 break;
139 default:
140 wxASSERT( false );
141 break;
142 }
143 return false;//Compiler pacifier
144}
wxT("CloseDown"))
@ eWrappedEnum
Definition: WrappedType.h:22

References eWrappedBool, eWrappedDouble, eWrappedEnum, eWrappedInt, eWrappedString, eWrappedType, mpBool, mpDouble, mpInt, mpStr, and wxT().

Referenced by ShuttleGuiBase::DoTieCheckBox(), and ShuttleGuiBase::DoTieCheckBoxOnRight().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadAsDouble()

double WrappedType::ReadAsDouble ( )

Definition at line 93 of file WrappedType.cpp.

94{
95 switch( eWrappedType )
96 {
97 case eWrappedString:
99 break;
100 case eWrappedInt:
101 return (double)*mpInt;
102 break;
103 case eWrappedDouble:
104 return * mpDouble;
105 break;
106 case eWrappedBool:
107 return (* mpBool)? 1.0 : 0.0;
108 break;
109 case eWrappedEnum:
110 wxASSERT( false );
111 break;
112 default:
113 wxASSERT( false );
114 break;
115 }
116 return -1.0f;//Compiler pacifier
117}
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:109

References Internat::CompatibleToDouble(), eWrappedBool, eWrappedDouble, eWrappedEnum, eWrappedInt, eWrappedString, eWrappedType, mpBool, mpDouble, mpInt, and mpStr.

Referenced by ShuttleGuiBase::DoTieSpinControl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadAsInt()

int WrappedType::ReadAsInt ( )

Definition at line 67 of file WrappedType.cpp.

68{
69 switch( eWrappedType )
70 {
71 case eWrappedString:
72 {
73 long l;
74 mpStr->ToLong(&l);
75 return (int) l;
76 }
77 case eWrappedInt:
78 return *mpInt;
79 case eWrappedDouble:
80 return (int)*mpDouble;
81 case eWrappedBool:
82 return (* mpBool) ? 1 : 0;
83 case eWrappedEnum:
84 wxASSERT( false );
85 break;
86 default:
87 wxASSERT( false );
88 break;
89 }
90 return -1;//Compiler pacifier
91}

References eWrappedBool, eWrappedDouble, eWrappedEnum, eWrappedInt, eWrappedString, eWrappedType, mpBool, mpDouble, mpInt, and mpStr.

Referenced by ShuttleGuiBase::DoTieSlider(), and ShuttleGuiBase::DoTieSpinCtrl().

Here is the caller graph for this function:

◆ ReadAsString()

wxString WrappedType::ReadAsString ( )

Definition at line 41 of file WrappedType.cpp.

42{
43 switch( eWrappedType )
44 {
45 case eWrappedString:
46 return *mpStr;
47 break;
48 case eWrappedInt:
49 return wxString::Format(wxT("%i"),*mpInt );
50 break;
51 case eWrappedDouble:
52 return wxString::Format(wxT("%.8g"),*mpDouble );
53 break;
54 case eWrappedBool:
55 return (* mpBool) ? wxT("true") : wxT("false" );
56 break;
57 case eWrappedEnum:
58 wxASSERT( false );
59 break;
60 default:
61 wxASSERT( false );
62 break;
63 }
64 return wxT("ERROR"); //Compiler pacifier
65}

References eWrappedBool, eWrappedDouble, eWrappedEnum, eWrappedInt, eWrappedString, eWrappedType, mpBool, mpDouble, mpInt, mpStr, and wxT().

Referenced by ShuttleGuiBase::DoTieCheckBox(), ShuttleGuiBase::DoTieCheckBoxOnRight(), ShuttleGuiBase::DoTieNumericTextBox(), ShuttleGuiBase::DoTieTextBox(), ShuttleGuiBase::TieCheckBoxOnRight(), and ShuttleGuiBase::TieRadioButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteToAsBool()

void WrappedType::WriteToAsBool ( const bool  InBool)

Definition at line 228 of file WrappedType.cpp.

229{
230 switch( eWrappedType )
231 {
232 case eWrappedString:
233 *mpStr = InBool ? wxT("true") : wxT("false" );
234 break;
235 case eWrappedInt:
236 *mpInt = InBool ? 1 : 0;
237 break;
238 case eWrappedDouble:
239 *mpDouble = InBool ? 1.0 : 0.0;
240 break;
241 case eWrappedBool:
242 *mpBool = InBool;
243 break;
244 case eWrappedEnum:
245 wxASSERT( false );
246 break;
247 default:
248 wxASSERT( false );
249 break;
250 }
251}

References eWrappedBool, eWrappedDouble, eWrappedEnum, eWrappedInt, eWrappedString, eWrappedType, mpBool, mpDouble, mpInt, mpStr, and wxT().

Referenced by ShuttleGuiBase::DoTieCheckBox(), and ShuttleGuiBase::DoTieCheckBoxOnRight().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteToAsDouble()

void WrappedType::WriteToAsDouble ( const double  InDouble)

Definition at line 201 of file WrappedType.cpp.

202{
203 switch( eWrappedType )
204 {
205 case eWrappedString:
206 *mpStr = wxString::Format( wxT("%.8g"), InDouble );
207 break;
208 case eWrappedInt:
209 *mpInt = (int)InDouble;
210 break;
211 case eWrappedDouble:
212 *mpDouble = InDouble;
213 break;
214 case eWrappedBool:
215 wxASSERT( false );
216 * mpBool = InDouble != 0.0;
217 break;
218 case eWrappedEnum:
219 wxASSERT( false );
220 break;
221 default:
222 wxASSERT( false );
223 break;
224 }
225}

References eWrappedBool, eWrappedDouble, eWrappedEnum, eWrappedInt, eWrappedString, eWrappedType, mpBool, mpDouble, mpInt, mpStr, and wxT().

Referenced by ShuttleGuiBase::DoTieSpinControl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteToAsInt()

void WrappedType::WriteToAsInt ( const int  InInt)

Definition at line 176 of file WrappedType.cpp.

177{
178 switch( eWrappedType )
179 {
180 case eWrappedString:
181 *mpStr = wxString::Format( wxT("%i"), InInt );
182 break;
183 case eWrappedInt:
184 *mpInt = InInt;
185 break;
186 case eWrappedDouble:
187 *mpDouble = (double)InInt;
188 break;
189 case eWrappedBool:
190 * mpBool = (InInt !=0);
191 break;
192 case eWrappedEnum:
193 wxASSERT( false );
194 break;
195 default:
196 wxASSERT( false );
197 break;
198 }
199}

References eWrappedBool, eWrappedDouble, eWrappedEnum, eWrappedInt, eWrappedString, eWrappedType, mpBool, mpDouble, mpInt, mpStr, and wxT().

Referenced by ShuttleGuiBase::DoTieSlider(), and ShuttleGuiBase::DoTieSpinCtrl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteToAsString()

void WrappedType::WriteToAsString ( const wxString &  InStr)

Definition at line 147 of file WrappedType.cpp.

148{
149 switch( eWrappedType )
150 {
151 case eWrappedString:
152 *mpStr = InStr;
153 break;
154 case eWrappedInt:
155 {
156 long l;
157 InStr.ToLong(&l);
158 *mpInt = (int) l;
159 break;
160 }
161 case eWrappedDouble:
163 break;
164 case eWrappedBool:
165 *mpBool = InStr.IsSameAs( wxT("true"), false ); // case free comparison.;
166 break;
167 case eWrappedEnum:
168 wxASSERT( false );
169 break;
170 default:
171 wxASSERT( false );
172 break;
173 }
174}

References Internat::CompatibleToDouble(), eWrappedBool, eWrappedDouble, eWrappedEnum, eWrappedInt, eWrappedString, eWrappedType, mpBool, mpDouble, mpInt, mpStr, and wxT().

Referenced by ShuttleGuiBase::DoTieNumericTextBox(), and ShuttleGuiBase::DoTieTextBox().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ eWrappedType

const teWrappedType WrappedType::eWrappedType

◆ mpBool

bool* const WrappedType::mpBool {}

◆ mpDouble

double* const WrappedType::mpDouble {}

◆ mpInt

int* const WrappedType::mpInt {}

◆ mpStr

wxString* const WrappedType::mpStr {}

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