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 30 of file WrappedType.h.

Constructor & Destructor Documentation

◆ WrappedType() [1/5]

WrappedType::WrappedType ( wxString &  InStr)
inlineexplicit

Definition at line 34 of file WrappedType.h.

35 : eWrappedType{ eWrappedString }, mpStr{ &InStr }
36 {}
@ eWrappedString
Definition: WrappedType.h:20
wxString *const mpStr
Definition: WrappedType.h:65
const teWrappedType eWrappedType
Definition: WrappedType.h:64

◆ WrappedType() [2/5]

WrappedType::WrappedType ( int &  InInt)
inlineexplicit

Definition at line 37 of file WrappedType.h.

38 : eWrappedType{ eWrappedInt }, mpInt{ &InInt }
39 {}
@ eWrappedInt
Definition: WrappedType.h:21
int *const mpInt
Definition: WrappedType.h:66

◆ WrappedType() [3/5]

WrappedType::WrappedType ( double &  InDouble)
inlineexplicit

Definition at line 40 of file WrappedType.h.

41 : eWrappedType{ eWrappedDouble }, mpDouble{ &InDouble }
42 {}
@ eWrappedDouble
Definition: WrappedType.h:22
double *const mpDouble
Definition: WrappedType.h:67

◆ WrappedType() [4/5]

WrappedType::WrappedType ( bool &  InBool)
inlineexplicit

Definition at line 43 of file WrappedType.h.

44 : eWrappedType{ eWrappedBool }, mpBool{ &InBool }
45 {}
@ eWrappedBool
Definition: WrappedType.h:23
bool *const mpBool
Definition: WrappedType.h:68

◆ WrappedType() [5/5]

WrappedType::WrappedType ( )
inlineexplicit

Definition at line 46 of file WrappedType.h.

48 {}
@ eWrappedNotSet
Definition: WrappedType.h:19

Member Function Documentation

◆ IsString()

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

Definition at line 35 of file WrappedType.cpp.

36{
38}

References eWrappedString, and eWrappedType.

Referenced by ShuttleGuiBase::TieRadioButton().

Here is the caller graph for this function:

◆ ReadAsBool()

bool WrappedType::ReadAsBool ( )

Definition at line 120 of file WrappedType.cpp.

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

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

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

Here is the caller graph for this function:

◆ ReadAsDouble()

double WrappedType::ReadAsDouble ( )

Definition at line 94 of file WrappedType.cpp.

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

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

Here is the call graph for this function:

◆ ReadAsInt()

int WrappedType::ReadAsInt ( )

Definition at line 68 of file WrappedType.cpp.

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

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 42 of file WrappedType.cpp.

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

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

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

Here is the caller graph for this function:

◆ WriteToAsBool()

void WrappedType::WriteToAsBool ( const bool  InBool)

Definition at line 229 of file WrappedType.cpp.

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

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

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

Here is the caller graph for this function:

◆ WriteToAsDouble()

void WrappedType::WriteToAsDouble ( const double  InDouble)

Definition at line 202 of file WrappedType.cpp.

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

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

◆ WriteToAsInt()

void WrappedType::WriteToAsInt ( const int  InInt)

Definition at line 177 of file WrappedType.cpp.

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

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:

◆ WriteToAsString()

void WrappedType::WriteToAsString ( const wxString &  InStr)

Definition at line 148 of file WrappedType.cpp.

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

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

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: