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#include "WrappedType.h"
29
30#include <wx/wxprec.h>
31#include "Internat.h"
32
35{
37}
38
39
40
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}
66
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}
92
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}
118
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}
145
146
147void WrappedType::WriteToAsString( const wxString & InStr)
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}
175
176void WrappedType::WriteToAsInt( const int InInt)
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}
200
201void WrappedType::WriteToAsDouble( const double InDouble)
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}
226
227
228void WrappedType::WriteToAsBool( const bool InBool)
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}
252
wxT("CloseDown"))
@ eWrappedDouble
Definition: WrappedType.h:20
@ eWrappedEnum
Definition: WrappedType.h:22
@ eWrappedInt
Definition: WrappedType.h:19
@ eWrappedBool
Definition: WrappedType.h:21
@ eWrappedString
Definition: WrappedType.h:18
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:109
bool ReadAsBool()
bool IsString()
Definition: WrappedType.cpp:34
void WriteToAsInt(const int InInt)
bool *const mpBool
Definition: WrappedType.h:65
double ReadAsDouble()
Definition: WrappedType.cpp:93
int ReadAsInt()
Definition: WrappedType.cpp:67
void WriteToAsDouble(const double InDouble)
void WriteToAsBool(const bool InBool)
int *const mpInt
Definition: WrappedType.h:63
void WriteToAsString(const wxString &InStr)
wxString *const mpStr
Definition: WrappedType.h:62
double *const mpDouble
Definition: WrappedType.h:64
const teWrappedType eWrappedType
Definition: WrappedType.h:61
wxString ReadAsString()
Definition: WrappedType.cpp:41