Audacity  2.2.2
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 ()
 
void SetTo (wxString &InStr)
 
void SetTo (int &InInt)
 
void SetTo (double &InDouble)
 
void SetTo (bool &InBool)
 
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)
 
bool ValuesMatch (const WrappedType &W)
 
void WriteToAsWrappedType (const WrappedType &W)
 
void Init ()
 

Public Attributes

teWrappedType eWrappedType
 
wxString * mpStr
 
int * mpInt
 
double * mpDouble
 
bool * 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 31 of file WrappedType.h.

Constructor & Destructor Documentation

WrappedType::WrappedType ( wxString &  InStr)
inline

Definition at line 35 of file WrappedType.h.

35 { SetTo(InStr); };
void SetTo(wxString &InStr)
Definition: WrappedType.h:41
WrappedType::WrappedType ( int &  InInt)
inline

Definition at line 36 of file WrappedType.h.

36 { SetTo(InInt); };
void SetTo(wxString &InStr)
Definition: WrappedType.h:41
WrappedType::WrappedType ( double &  InDouble)
inline

Definition at line 37 of file WrappedType.h.

37 {SetTo(InDouble);};
void SetTo(wxString &InStr)
Definition: WrappedType.h:41
WrappedType::WrappedType ( bool &  InBool)
inline

Definition at line 38 of file WrappedType.h.

38 { SetTo(InBool); };
void SetTo(wxString &InStr)
Definition: WrappedType.h:41
WrappedType::WrappedType ( )
inline

Definition at line 39 of file WrappedType.h.

39 { Init();}

Member Function Documentation

void WrappedType::Init ( )

Definition at line 69 of file WrappedType.cpp.

References eWrappedNotSet, eWrappedType, mpBool, mpDouble, mpInt, and mpStr.

Referenced by ShuttleGuiBase::EndRadioButtonGroup().

70 {
72  mpStr = NULL;
73  mpInt = NULL;
74  mpDouble = NULL;
75  mpBool = NULL;
76 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
bool * mpBool
Definition: WrappedType.h:68
bool WrappedType::IsString ( )
Returns
true iff the wrapped type is a string.

Definition at line 34 of file WrappedType.cpp.

References eWrappedString, and eWrappedType.

Referenced by ShuttleGuiBase::TieChoice().

35 {
36  return eWrappedType == eWrappedString;
37 }
teWrappedType eWrappedType
Definition: WrappedType.h:64
bool WrappedType::ReadAsBool ( )

Definition at line 188 of file WrappedType.cpp.

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

Referenced by ShuttleGuiBase::TieCheckBox(), and ShuttleGuiBase::TieCheckBoxOnRight().

189 {
190  switch( eWrappedType )
191  {
192  case eWrappedString:
193  return mpStr->IsSameAs( wxT("true"), false ); // case free comparison.
194  break;
195  case eWrappedInt:
196  return *mpInt != 0;
197  break;
198  case eWrappedDouble:
199  wxASSERT( false );// DANGEROUS USE OF WrappedType. Can't rely on equality.
200  return * mpDouble != 0.0f; // this is what the code would be...
201  break;
202  case eWrappedBool:
203  return * mpBool;
204  break;
205  case eWrappedEnum:
206  wxASSERT( false );
207  break;
208  default:
209  wxASSERT( false );
210  break;
211  }
212  return false;//Compiler pacifier
213 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
bool * mpBool
Definition: WrappedType.h:68
double WrappedType::ReadAsDouble ( )

Definition at line 162 of file WrappedType.cpp.

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

163 {
164  switch( eWrappedType )
165  {
166  case eWrappedString:
168  break;
169  case eWrappedInt:
170  return (double)*mpInt;
171  break;
172  case eWrappedDouble:
173  return * mpDouble;
174  break;
175  case eWrappedBool:
176  return (* mpBool)? 1.0 : 0.0;
177  break;
178  case eWrappedEnum:
179  wxASSERT( false );
180  break;
181  default:
182  wxASSERT( false );
183  break;
184  }
185  return -1.0f;//Compiler pacifier
186 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:122
bool * mpBool
Definition: WrappedType.h:68
int WrappedType::ReadAsInt ( )

Definition at line 132 of file WrappedType.cpp.

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

Referenced by ShuttleGuiBase::TieChoice(), ShuttleGuiBase::TieSlider(), and ShuttleGuiBase::TieSpinCtrl().

133 {
134  switch( eWrappedType )
135  {
136  case eWrappedString:
137  {
138  long l;
139  mpStr->ToLong(&l);
140  return (int) l;
141  break;
142  }
143  case eWrappedInt:
144  return *mpInt;
145  break;
146  case eWrappedDouble:
147  return (int)*mpDouble;
148  break;
149  case eWrappedBool:
150  return (* mpBool) ? 1 : 0;
151  break;
152  case eWrappedEnum:
153  wxASSERT( false );
154  break;
155  default:
156  wxASSERT( false );
157  break;
158  }
159  return -1;//Compiler pacifier
160 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
bool * mpBool
Definition: WrappedType.h:68
wxString WrappedType::ReadAsString ( )

Definition at line 106 of file WrappedType.cpp.

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

Referenced by ShuttleGuiBase::TieCheckBox(), ShuttleGuiBase::TieCheckBoxOnRight(), ShuttleGuiBase::TieChoice(), ShuttleGuiBase::TieNumericTextBox(), ShuttleGuiBase::TieTextBox(), and Shuttle::TransferWrappedType().

107 {
108  switch( eWrappedType )
109  {
110  case eWrappedString:
111  return *mpStr;
112  break;
113  case eWrappedInt:
114  return wxString::Format(wxT("%i"),*mpInt );
115  break;
116  case eWrappedDouble:
117  return wxString::Format(wxT("%g"),*mpDouble );
118  break;
119  case eWrappedBool:
120  return (* mpBool) ? wxT("true") : wxT("false" );
121  break;
122  case eWrappedEnum:
123  wxASSERT( false );
124  break;
125  default:
126  wxASSERT( false );
127  break;
128  }
129  return wxT("ERROR"); //Compiler pacifier
130 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
bool * mpBool
Definition: WrappedType.h:68
void WrappedType::SetTo ( wxString &  InStr)
inline

Definition at line 41 of file WrappedType.h.

References eWrappedString.

Referenced by ShuttleGuiBase::StartRadioButtonGroup().

41 { Init();mpStr=&InStr; eWrappedType = eWrappedString;}
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
void WrappedType::SetTo ( int &  InInt)
inline

Definition at line 42 of file WrappedType.h.

References eWrappedInt.

42 { Init();mpInt=&InInt; eWrappedType = eWrappedInt;};
int * mpInt
Definition: WrappedType.h:66
teWrappedType eWrappedType
Definition: WrappedType.h:64
void WrappedType::SetTo ( double &  InDouble)
inline

Definition at line 43 of file WrappedType.h.

References eWrappedDouble.

43 {Init();mpDouble=&InDouble; eWrappedType = eWrappedDouble;};
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
void WrappedType::SetTo ( bool &  InBool)
inline

Definition at line 44 of file WrappedType.h.

References eWrappedBool.

44 { Init();mpBool=&InBool; eWrappedType = eWrappedBool;};
teWrappedType eWrappedType
Definition: WrappedType.h:64
bool * mpBool
Definition: WrappedType.h:68
bool WrappedType::ValuesMatch ( const WrappedType W)
Parameters
WWrapped type to compare
Returns
true iff types and values are the same.

Definition at line 41 of file WrappedType.cpp.

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

Referenced by ShuttleGuiBase::TieRadioButton().

42 {
43  if( W.eWrappedType != eWrappedType )
44  return false;
45  switch( eWrappedType )
46  {
47  case eWrappedString:
48  return *W.mpStr == *mpStr;
49  break;
50  case eWrappedInt:
51  return *W.mpInt == *mpInt;
52  break;
53  case eWrappedDouble:
54  return *W.mpDouble == *mpDouble;
55  break;
56  case eWrappedBool:
57  return *W.mpBool == *mpBool;
58  break;
59  case eWrappedEnum:
60  wxASSERT( false );
61  break;
62  default:
63  wxASSERT( false );
64  break;
65  }
66  return false;
67 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
bool * mpBool
Definition: WrappedType.h:68
void WrappedType::WriteToAsBool ( const bool  InBool)

Definition at line 297 of file WrappedType.cpp.

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

Referenced by ShuttleGuiBase::TieCheckBox(), and ShuttleGuiBase::TieCheckBoxOnRight().

298 {
299  switch( eWrappedType )
300  {
301  case eWrappedString:
302  *mpStr = InBool ? wxT("true") : wxT("false" );
303  break;
304  case eWrappedInt:
305  *mpInt = InBool ? 1 : 0;
306  break;
307  case eWrappedDouble:
308  *mpDouble = InBool ? 1.0 : 0.0;
309  break;
310  case eWrappedBool:
311  *mpBool = InBool;
312  break;
313  case eWrappedEnum:
314  wxASSERT( false );
315  break;
316  default:
317  wxASSERT( false );
318  break;
319  }
320 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
bool * mpBool
Definition: WrappedType.h:68
void WrappedType::WriteToAsDouble ( const double  InDouble)

Definition at line 270 of file WrappedType.cpp.

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

271 {
272  switch( eWrappedType )
273  {
274  case eWrappedString:
275  *mpStr = wxString::Format( wxT("%g"), InDouble );
276  break;
277  case eWrappedInt:
278  *mpInt = (int)InDouble;
279  break;
280  case eWrappedDouble:
281  *mpDouble = InDouble;
282  break;
283  case eWrappedBool:
284  wxASSERT( false );
285  * mpBool = InDouble != 0.0;
286  break;
287  case eWrappedEnum:
288  wxASSERT( false );
289  break;
290  default:
291  wxASSERT( false );
292  break;
293  }
294 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
bool * mpBool
Definition: WrappedType.h:68
void WrappedType::WriteToAsInt ( const int  InInt)

Definition at line 245 of file WrappedType.cpp.

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

Referenced by ShuttleGuiBase::TieChoice(), ShuttleGuiBase::TieSlider(), and ShuttleGuiBase::TieSpinCtrl().

246 {
247  switch( eWrappedType )
248  {
249  case eWrappedString:
250  *mpStr = wxString::Format( wxT("%i"), InInt );
251  break;
252  case eWrappedInt:
253  *mpInt = InInt;
254  break;
255  case eWrappedDouble:
256  *mpDouble = (double)InInt;
257  break;
258  case eWrappedBool:
259  * mpBool = (InInt !=0);
260  break;
261  case eWrappedEnum:
262  wxASSERT( false );
263  break;
264  default:
265  wxASSERT( false );
266  break;
267  }
268 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
bool * mpBool
Definition: WrappedType.h:68
void WrappedType::WriteToAsString ( const wxString &  InStr)

Definition at line 216 of file WrappedType.cpp.

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

Referenced by ShuttleGuiBase::TieChoice(), ShuttleGuiBase::TieNumericTextBox(), ShuttleGuiBase::TieTextBox(), and Shuttle::TransferWrappedType().

217 {
218  switch( eWrappedType )
219  {
220  case eWrappedString:
221  *mpStr = InStr;
222  break;
223  case eWrappedInt:
224  {
225  long l;
226  InStr.ToLong(&l);
227  *mpInt = (int) l;
228  break;
229  }
230  case eWrappedDouble:
232  break;
233  case eWrappedBool:
234  *mpBool = InStr.IsSameAs( wxT("true"), false ); // case free comparison.;
235  break;
236  case eWrappedEnum:
237  wxASSERT( false );
238  break;
239  default:
240  wxASSERT( false );
241  break;
242  }
243 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:122
bool * mpBool
Definition: WrappedType.h:68
void WrappedType::WriteToAsWrappedType ( const WrappedType W)

Definition at line 78 of file WrappedType.cpp.

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

Referenced by ShuttleGuiBase::TieRadioButton().

79 {
80  wxASSERT( W.eWrappedType == eWrappedType );
81  switch( eWrappedType )
82  {
83  case eWrappedString:
84  *mpStr = *W.mpStr;
85  break;
86  case eWrappedInt:
87  *mpInt = *W.mpInt;
88  break;
89  case eWrappedDouble:
90  *mpDouble = *W.mpDouble;
91  break;
92  case eWrappedBool:
93  *mpBool = *W.mpBool;
94  break;
95  case eWrappedEnum:
96  wxASSERT( false );
97  break;
98  default:
99  wxASSERT( false );
100  break;
101  }
102 }
int * mpInt
Definition: WrappedType.h:66
wxString * mpStr
Definition: WrappedType.h:65
teWrappedType eWrappedType
Definition: WrappedType.h:64
double * mpDouble
Definition: WrappedType.h:67
bool * mpBool
Definition: WrappedType.h:68

Member Data Documentation

teWrappedType WrappedType::eWrappedType
bool* WrappedType::mpBool
double* WrappedType::mpDouble
int* WrappedType::mpInt
wxString* WrappedType::mpStr

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