Audacity 3.2.0
WrappedType.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 WrappedType.cpp
4
5 James Crook
6 (C) Audacity Developers, 2007
7
8 wxWidgets license. See Licensing.txt
9
10**********************************************************************//**********************************************************************/
27
28
29#include "WrappedType.h"
30
31#include <wx/wxprec.h>
32#include "Internat.h"
33
36{
38}
39
40
41
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}
67
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}
93
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}
119
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}
146
147
148void WrappedType::WriteToAsString( const wxString & InStr)
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}
176
177void WrappedType::WriteToAsInt( const int InInt)
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}
201
202void WrappedType::WriteToAsDouble( const double InDouble)
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}
227
228
229void WrappedType::WriteToAsBool( const bool InBool)
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}
253
wxT("CloseDown"))
@ eWrappedDouble
Definition: WrappedType.h:22
@ eWrappedEnum
Definition: WrappedType.h:24
@ eWrappedInt
Definition: WrappedType.h:21
@ eWrappedBool
Definition: WrappedType.h:23
@ eWrappedString
Definition: WrappedType.h:20
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:133
bool ReadAsBool()
bool IsString()
Definition: WrappedType.cpp:35
void WriteToAsInt(const int InInt)
bool *const mpBool
Definition: WrappedType.h:68
double ReadAsDouble()
Definition: WrappedType.cpp:94
int ReadAsInt()
Definition: WrappedType.cpp:68
void WriteToAsDouble(const double InDouble)
void WriteToAsBool(const bool InBool)
int *const mpInt
Definition: WrappedType.h:66
void WriteToAsString(const wxString &InStr)
wxString *const mpStr
Definition: WrappedType.h:65
double *const mpDouble
Definition: WrappedType.h:67
const teWrappedType eWrappedType
Definition: WrappedType.h:64
wxString ReadAsString()
Definition: WrappedType.cpp:42