Audacity  3.0.3
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  {}

References eWrappedString.

◆ WrappedType() [2/5]

WrappedType::WrappedType ( int &  InInt)
inlineexplicit

Definition at line 37 of file WrappedType.h.

38  : eWrappedType{ eWrappedInt }, mpInt{ &InInt }
39  {}

References eWrappedInt.

◆ WrappedType() [3/5]

WrappedType::WrappedType ( double &  InDouble)
inlineexplicit

Definition at line 40 of file WrappedType.h.

41  : eWrappedType{ eWrappedDouble }, mpDouble{ &InDouble }
42  {}

References eWrappedDouble.

◆ WrappedType() [4/5]

WrappedType::WrappedType ( bool &  InBool)
inlineexplicit

Definition at line 43 of file WrappedType.h.

44  : eWrappedType{ eWrappedBool }, mpBool{ &InBool }
45  {}

References eWrappedBool.

◆ WrappedType() [5/5]

WrappedType::WrappedType ( )
inlineexplicit

Definition at line 46 of file WrappedType.h.

48  {}

References eWrappedNotSet.

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 {
37  return eWrappedType == eWrappedString;
38 }

References eWrappedString, and eWrappedType.

Referenced by ShuttleGuiBase::TieRadioButton().

Here is the caller graph for this function:

◆ ReadAsBool()

bool WrappedType::ReadAsBool ( )

Definition at line 124 of file WrappedType.cpp.

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

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

99 {
100  switch( eWrappedType )
101  {
102  case eWrappedString:
104  break;
105  case eWrappedInt:
106  return (double)*mpInt;
107  break;
108  case eWrappedDouble:
109  return * mpDouble;
110  break;
111  case eWrappedBool:
112  return (* mpBool)? 1.0 : 0.0;
113  break;
114  case eWrappedEnum:
115  wxASSERT( false );
116  break;
117  default:
118  wxASSERT( false );
119  break;
120  }
121  return -1.0f;//Compiler pacifier
122 }

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  break;
78  }
79  case eWrappedInt:
80  return *mpInt;
81  break;
82  case eWrappedDouble:
83  return (int)*mpDouble;
84  break;
85  case eWrappedBool:
86  return (* mpBool) ? 1 : 0;
87  break;
88  case eWrappedEnum:
89  wxASSERT( false );
90  break;
91  default:
92  wxASSERT( false );
93  break;
94  }
95  return -1;//Compiler pacifier
96 }

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(), ShuttleGuiBase::TieRadioButton(), and Shuttle::TransferWrappedType().

Here is the caller graph for this function:

◆ WriteToAsBool()

void WrappedType::WriteToAsBool ( const bool  InBool)

Definition at line 233 of file WrappedType.cpp.

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

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

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

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

◆ WriteToAsInt()

void WrappedType::WriteToAsInt ( const int  InInt)

Definition at line 181 of file WrappedType.cpp.

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

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

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

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

Referenced by ShuttleGuiBase::DoTieNumericTextBox(), ShuttleGuiBase::DoTieTextBox(), ShuttleGuiBase::TieRadioButton(), and Shuttle::TransferWrappedType().

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:
WrappedType::mpDouble
double *const mpDouble
Definition: WrappedType.h:67
eWrappedEnum
@ eWrappedEnum
Definition: WrappedType.h:24
eWrappedNotSet
@ eWrappedNotSet
Definition: WrappedType.h:19
eWrappedInt
@ eWrappedInt
Definition: WrappedType.h:21
WrappedType::mpStr
wxString *const mpStr
Definition: WrappedType.h:65
eWrappedDouble
@ eWrappedDouble
Definition: WrappedType.h:22
eWrappedString
@ eWrappedString
Definition: WrappedType.h:20
WrappedType::mpBool
bool *const mpBool
Definition: WrappedType.h:68
eWrappedBool
@ eWrappedBool
Definition: WrappedType.h:23
WrappedType::mpInt
int *const mpInt
Definition: WrappedType.h:66
WrappedType::eWrappedType
const teWrappedType eWrappedType
Definition: WrappedType.h:64
Internat::CompatibleToDouble
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:134