]>
Commit | Line | Data |
---|---|---|
341287bf JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: variant.cpp | |
3 | // Purpose: wxVariant class, container for any type | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 10/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) | |
3f4a0c5b | 9 | // Licence: wxWindows licence |
341287bf JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "variant.h" | |
68ee7c47 VZ |
14 | #pragma implementation "time.h" |
15 | #pragma implementation "date.h" | |
341287bf JS |
16 | #endif |
17 | ||
18 | // For compilers that support precompilation, includes "wx/wx.h". | |
19 | #include "wx/wxprec.h" | |
20 | ||
21 | #ifdef __BORLANDC__ | |
3f4a0c5b | 22 | #pragma hdrstop |
341287bf JS |
23 | #endif |
24 | ||
be087207 RR |
25 | #if wxUSE_STD_IOSTREAM |
26 | #if wxUSE_IOSTREAMH | |
27 | #include <fstream.h> | |
28 | #else | |
29 | #include <fstream> | |
30 | #endif | |
fbc535ff | 31 | #endif |
341287bf | 32 | |
fae05df5 | 33 | #if wxUSE_STREAMS |
75ed1d15 | 34 | #include "wx/stream.h" |
fae05df5 GL |
35 | #include "wx/txtstrm.h" |
36 | #endif | |
37 | ||
341287bf | 38 | #include "wx/string.h" |
fb42d7c3 VZ |
39 | #include "wx/tokenzr.h" |
40 | ||
341287bf JS |
41 | #include "wx/variant.h" |
42 | ||
f6bcfd97 | 43 | #if wxUSE_TIMEDATE |
cd0b1709 VZ |
44 | IMPLEMENT_DYNAMIC_CLASS(wxDate, wxObject) |
45 | IMPLEMENT_DYNAMIC_CLASS(wxTime, wxObject) | |
46 | ||
47 | wxTime::tFormat wxTime::ms_Format = wxTime::wx12h; | |
48 | wxTime::tPrecision wxTime::ms_Precision = wxTime::wxStdMinSec; | |
03e11df5 | 49 | wxChar wxTime::ms_bufTime[128]; |
f6bcfd97 | 50 | #endif |
cd0b1709 | 51 | |
341287bf JS |
52 | IMPLEMENT_ABSTRACT_CLASS(wxVariantData, wxObject) |
53 | ||
3ba055ac | 54 | wxVariant WXDLLEXPORT wxNullVariant; |
341287bf JS |
55 | |
56 | /* | |
57 | * wxVariantDataList | |
58 | */ | |
59 | ||
60 | class WXDLLEXPORT wxVariantDataList: public wxVariantData | |
61 | { | |
62 | DECLARE_DYNAMIC_CLASS(wxVariantDataList) | |
63 | public: | |
64 | wxVariantDataList() {} | |
65 | wxVariantDataList(const wxList& list); | |
66 | ~wxVariantDataList(); | |
67 | ||
68 | wxList& GetValue() const { return (wxList&) m_value; } | |
69 | void SetValue(const wxList& value) ; | |
70 | ||
71 | virtual void Copy(wxVariantData& data); | |
72 | virtual bool Eq(wxVariantData& data) const; | |
38830220 | 73 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 74 | virtual bool Write(wxSTD ostream& str) const; |
38830220 | 75 | #endif |
341287bf | 76 | virtual bool Write(wxString& str) const; |
38830220 | 77 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 78 | virtual bool Read(wxSTD istream& str); |
38830220 | 79 | #endif |
341287bf | 80 | virtual bool Read(wxString& str); |
223d09f6 | 81 | virtual wxString GetType() const { return wxT("list"); }; |
341287bf JS |
82 | |
83 | void Clear(); | |
84 | ||
85 | protected: | |
86 | wxList m_value; | |
87 | }; | |
88 | ||
89 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataList, wxVariantData) | |
90 | ||
91 | wxVariantDataList::wxVariantDataList(const wxList& list) | |
92 | { | |
93 | SetValue(list); | |
94 | } | |
95 | ||
96 | wxVariantDataList::~wxVariantDataList() | |
97 | { | |
98 | Clear(); | |
99 | } | |
100 | ||
101 | void wxVariantDataList::SetValue(const wxList& value) | |
102 | { | |
103 | Clear(); | |
b1d4dd7a | 104 | wxNode* node = value.GetFirst(); |
341287bf JS |
105 | while (node) |
106 | { | |
b1d4dd7a | 107 | wxVariant* var = (wxVariant*) node->GetData(); |
341287bf | 108 | m_value.Append(new wxVariant(*var)); |
b1d4dd7a | 109 | node = node->GetNext(); |
341287bf JS |
110 | } |
111 | } | |
112 | ||
113 | void wxVariantDataList::Clear() | |
114 | { | |
b1d4dd7a | 115 | wxNode* node = m_value.GetFirst(); |
341287bf JS |
116 | while (node) |
117 | { | |
b1d4dd7a | 118 | wxVariant* var = (wxVariant*) node->GetData(); |
341287bf | 119 | delete var; |
b1d4dd7a | 120 | node = node->GetNext(); |
341287bf JS |
121 | } |
122 | m_value.Clear(); | |
123 | } | |
124 | ||
125 | void wxVariantDataList::Copy(wxVariantData& data) | |
126 | { | |
223d09f6 | 127 | wxASSERT_MSG( (data.GetType() == wxT("list")), wxT("wxVariantDataList::Copy: Can't copy to this type of data") ); |
341287bf JS |
128 | |
129 | wxVariantDataList& listData = (wxVariantDataList&) data; | |
130 | ||
131 | listData.Clear(); | |
b1d4dd7a | 132 | wxNode* node = m_value.GetFirst(); |
341287bf JS |
133 | while (node) |
134 | { | |
b1d4dd7a | 135 | wxVariant* var = (wxVariant*) node->GetData(); |
341287bf | 136 | listData.m_value.Append(new wxVariant(*var)); |
b1d4dd7a | 137 | node = node->GetNext(); |
341287bf JS |
138 | } |
139 | } | |
140 | ||
141 | bool wxVariantDataList::Eq(wxVariantData& data) const | |
142 | { | |
223d09f6 | 143 | wxASSERT_MSG( (data.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") ); |
341287bf JS |
144 | |
145 | wxVariantDataList& listData = (wxVariantDataList&) data; | |
b1d4dd7a RL |
146 | wxNode* node1 = m_value.GetFirst(); |
147 | wxNode* node2 = listData.GetValue().GetFirst(); | |
341287bf JS |
148 | while (node1 && node2) |
149 | { | |
b1d4dd7a RL |
150 | wxVariant* var1 = (wxVariant*) node1->GetData(); |
151 | wxVariant* var2 = (wxVariant*) node2->GetData(); | |
341287bf | 152 | if ((*var1) != (*var2)) |
dc259b79 | 153 | return FALSE; |
b1d4dd7a RL |
154 | node1 = node1->GetNext(); |
155 | node2 = node2->GetNext(); | |
341287bf | 156 | } |
dc259b79 DW |
157 | if (node1 || node2) return FALSE; |
158 | return TRUE; | |
341287bf JS |
159 | } |
160 | ||
38830220 | 161 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 162 | bool wxVariantDataList::Write(wxSTD ostream& str) const |
341287bf JS |
163 | { |
164 | wxString s; | |
165 | Write(s); | |
783b6cfd | 166 | str << (const char*) s.mb_str(); |
dc259b79 | 167 | return TRUE; |
341287bf | 168 | } |
38830220 | 169 | #endif |
341287bf JS |
170 | |
171 | bool wxVariantDataList::Write(wxString& str) const | |
172 | { | |
223d09f6 | 173 | str = wxT(""); |
b1d4dd7a | 174 | wxNode* node = m_value.GetFirst(); |
341287bf JS |
175 | while (node) |
176 | { | |
b1d4dd7a RL |
177 | wxVariant* var = (wxVariant*) node->GetData(); |
178 | if (node != m_value.GetFirst()) | |
223d09f6 | 179 | str += wxT(" "); |
341287bf JS |
180 | wxString str1; |
181 | str += var->MakeString(); | |
b1d4dd7a | 182 | node = node->GetNext(); |
341287bf JS |
183 | } |
184 | ||
dc259b79 | 185 | return TRUE; |
341287bf JS |
186 | } |
187 | ||
38830220 | 188 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 189 | bool wxVariantDataList::Read(wxSTD istream& WXUNUSED(str)) |
341287bf | 190 | { |
223d09f6 | 191 | wxFAIL_MSG(wxT("Unimplemented")); |
341287bf | 192 | // TODO |
dc259b79 | 193 | return FALSE; |
341287bf | 194 | } |
38830220 | 195 | #endif |
341287bf JS |
196 | |
197 | bool wxVariantDataList::Read(wxString& WXUNUSED(str)) | |
198 | { | |
223d09f6 | 199 | wxFAIL_MSG(wxT("Unimplemented")); |
341287bf | 200 | // TODO |
dc259b79 | 201 | return FALSE; |
341287bf JS |
202 | } |
203 | ||
204 | /* | |
205 | * wxVariantDataStringList | |
206 | */ | |
207 | ||
208 | class WXDLLEXPORT wxVariantDataStringList: public wxVariantData | |
209 | { | |
210 | DECLARE_DYNAMIC_CLASS(wxVariantDataStringList) | |
211 | public: | |
212 | wxVariantDataStringList() {} | |
213 | wxVariantDataStringList(const wxStringList& list) { m_value = list; } | |
214 | ||
215 | wxStringList& GetValue() const { return (wxStringList&) m_value; } | |
216 | void SetValue(const wxStringList& value); | |
217 | ||
218 | virtual void Copy(wxVariantData& data); | |
219 | virtual bool Eq(wxVariantData& data) const; | |
38830220 | 220 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 221 | virtual bool Write(wxSTD ostream& str) const; |
38830220 | 222 | #endif |
341287bf | 223 | virtual bool Write(wxString& str) const; |
38830220 | 224 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 225 | virtual bool Read(wxSTD istream& str); |
38830220 | 226 | #endif |
341287bf | 227 | virtual bool Read(wxString& str); |
223d09f6 | 228 | virtual wxString GetType() const { return wxT("stringlist"); }; |
341287bf JS |
229 | |
230 | protected: | |
231 | wxStringList m_value; | |
232 | }; | |
233 | ||
234 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataStringList, wxVariantData) | |
235 | ||
236 | void wxVariantDataStringList::SetValue(const wxStringList& value) | |
237 | { | |
238 | m_value = value; | |
239 | } | |
240 | ||
241 | void wxVariantDataStringList::Copy(wxVariantData& data) | |
242 | { | |
223d09f6 | 243 | wxASSERT_MSG( (data.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Copy: Can't copy to this type of data") ); |
341287bf JS |
244 | |
245 | wxVariantDataStringList& listData = (wxVariantDataStringList&) data; | |
246 | ||
247 | listData.m_value = m_value ; | |
248 | } | |
249 | ||
250 | bool wxVariantDataStringList::Eq(wxVariantData& data) const | |
251 | { | |
223d09f6 | 252 | wxASSERT_MSG( (data.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") ); |
341287bf JS |
253 | |
254 | wxVariantDataStringList& listData = (wxVariantDataStringList&) data; | |
b1d4dd7a RL |
255 | wxStringList::Node *node1 = m_value.GetFirst(); |
256 | wxStringList::Node *node2 = listData.GetValue().GetFirst(); | |
341287bf JS |
257 | while (node1 && node2) |
258 | { | |
b1d4dd7a RL |
259 | wxString str1 ( node1->GetData() ); |
260 | wxString str2 ( node2->GetData() ); | |
341287bf | 261 | if (str1 != str2) |
dc259b79 | 262 | return FALSE; |
b1d4dd7a RL |
263 | node1 = node1->GetNext(); |
264 | node2 = node2->GetNext(); | |
341287bf | 265 | } |
dc259b79 DW |
266 | if (node1 || node2) return FALSE; |
267 | return TRUE; | |
341287bf JS |
268 | } |
269 | ||
38830220 | 270 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 271 | bool wxVariantDataStringList::Write(wxSTD ostream& str) const |
341287bf JS |
272 | { |
273 | wxString s; | |
274 | Write(s); | |
783b6cfd | 275 | str << (const char*) s.mb_str(); |
dc259b79 | 276 | return TRUE; |
341287bf | 277 | } |
38830220 | 278 | #endif |
341287bf JS |
279 | |
280 | bool wxVariantDataStringList::Write(wxString& str) const | |
281 | { | |
b1d4dd7a RL |
282 | str.Empty(); |
283 | wxStringList::Node *node = m_value.GetFirst(); | |
341287bf JS |
284 | while (node) |
285 | { | |
b1d4dd7a RL |
286 | wxChar* s = node->GetData(); |
287 | if (node != m_value.GetFirst()) | |
223d09f6 | 288 | str += wxT(" "); |
341287bf | 289 | str += s; |
b1d4dd7a | 290 | node = node->GetNext(); |
341287bf JS |
291 | } |
292 | ||
dc259b79 | 293 | return TRUE; |
341287bf JS |
294 | } |
295 | ||
38830220 | 296 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 297 | bool wxVariantDataStringList::Read(wxSTD istream& WXUNUSED(str)) |
341287bf | 298 | { |
223d09f6 | 299 | wxFAIL_MSG(wxT("Unimplemented")); |
341287bf | 300 | // TODO |
dc259b79 | 301 | return FALSE; |
341287bf | 302 | } |
38830220 | 303 | #endif |
341287bf JS |
304 | |
305 | bool wxVariantDataStringList::Read(wxString& WXUNUSED(str)) | |
306 | { | |
223d09f6 | 307 | wxFAIL_MSG(wxT("Unimplemented")); |
341287bf | 308 | // TODO |
dc259b79 | 309 | return FALSE; |
341287bf JS |
310 | } |
311 | ||
312 | /* | |
313 | * wxVariantDataLong | |
314 | */ | |
315 | ||
316 | class WXDLLEXPORT wxVariantDataLong: public wxVariantData | |
317 | { | |
318 | DECLARE_DYNAMIC_CLASS(wxVariantDataLong) | |
319 | public: | |
320 | wxVariantDataLong() { m_value = 0; } | |
321 | wxVariantDataLong(long value) { m_value = value; } | |
322 | ||
323 | inline long GetValue() const { return m_value; } | |
324 | inline void SetValue(long value) { m_value = value; } | |
325 | ||
326 | virtual void Copy(wxVariantData& data); | |
327 | virtual bool Eq(wxVariantData& data) const; | |
1ccbb61a VZ |
328 | |
329 | virtual bool Read(wxString& str); | |
341287bf | 330 | virtual bool Write(wxString& str) const; |
38830220 | 331 | #if wxUSE_STD_IOSTREAM |
dd107c50 VZ |
332 | virtual bool Read(wxSTD istream& str); |
333 | virtual bool Write(wxSTD ostream& str) const; | |
38830220 | 334 | #endif |
e02afc7a | 335 | #if wxUSE_STREAMS |
75ed1d15 | 336 | virtual bool Read(wxInputStream& str); |
1ccbb61a | 337 | virtual bool Write(wxOutputStream &str) const; |
e02afc7a | 338 | #endif // wxUSE_STREAMS |
1ccbb61a | 339 | |
223d09f6 | 340 | virtual wxString GetType() const { return wxT("long"); }; |
341287bf JS |
341 | |
342 | protected: | |
343 | long m_value; | |
344 | }; | |
345 | ||
346 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataLong, wxVariantData) | |
347 | ||
348 | void wxVariantDataLong::Copy(wxVariantData& data) | |
349 | { | |
223d09f6 | 350 | wxASSERT_MSG( (data.GetType() == wxT("long")), wxT("wxVariantDataLong::Copy: Can't copy to this type of data") ); |
341287bf JS |
351 | |
352 | wxVariantDataLong& otherData = (wxVariantDataLong&) data; | |
353 | ||
354 | otherData.m_value = m_value; | |
355 | } | |
356 | ||
357 | bool wxVariantDataLong::Eq(wxVariantData& data) const | |
358 | { | |
223d09f6 | 359 | wxASSERT_MSG( (data.GetType() == wxT("long")), wxT("wxVariantDataLong::Eq: argument mismatch") ); |
341287bf JS |
360 | |
361 | wxVariantDataLong& otherData = (wxVariantDataLong&) data; | |
362 | ||
363 | return (otherData.m_value == m_value); | |
364 | } | |
365 | ||
38830220 | 366 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 367 | bool wxVariantDataLong::Write(wxSTD ostream& str) const |
341287bf JS |
368 | { |
369 | wxString s; | |
370 | Write(s); | |
783b6cfd | 371 | str << (const char*) s.mb_str(); |
dc259b79 | 372 | return TRUE; |
341287bf | 373 | } |
38830220 | 374 | #endif |
341287bf JS |
375 | |
376 | bool wxVariantDataLong::Write(wxString& str) const | |
377 | { | |
223d09f6 | 378 | str.Printf(wxT("%ld"), m_value); |
dc259b79 | 379 | return TRUE; |
341287bf JS |
380 | } |
381 | ||
38830220 | 382 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 383 | bool wxVariantDataLong::Read(wxSTD istream& str) |
341287bf JS |
384 | { |
385 | str >> m_value; | |
dc259b79 | 386 | return TRUE; |
341287bf | 387 | } |
38830220 | 388 | #endif |
341287bf | 389 | |
e02afc7a | 390 | #if wxUSE_STREAMS |
1ccbb61a VZ |
391 | bool wxVariantDataLong::Write(wxOutputStream& str) const |
392 | { | |
fae05df5 GL |
393 | wxTextOutputStream s(str); |
394 | ||
479cd5de | 395 | s.Write32((size_t)m_value); |
dc259b79 | 396 | return TRUE; |
1ccbb61a VZ |
397 | } |
398 | ||
75ed1d15 GL |
399 | bool wxVariantDataLong::Read(wxInputStream& str) |
400 | { | |
fae05df5 GL |
401 | wxTextInputStream s(str); |
402 | m_value = s.Read32(); | |
dc259b79 | 403 | return TRUE; |
75ed1d15 | 404 | } |
e02afc7a | 405 | #endif // wxUSE_STREAMS |
75ed1d15 | 406 | |
341287bf JS |
407 | bool wxVariantDataLong::Read(wxString& str) |
408 | { | |
783b6cfd | 409 | m_value = wxAtol((const wxChar*) str); |
dc259b79 | 410 | return TRUE; |
341287bf JS |
411 | } |
412 | ||
413 | /* | |
414 | * wxVariantDataReal | |
415 | */ | |
416 | ||
417 | class WXDLLEXPORT wxVariantDataReal: public wxVariantData | |
418 | { | |
419 | DECLARE_DYNAMIC_CLASS(wxVariantDataReal) | |
420 | public: | |
421 | wxVariantDataReal() { m_value = 0.0; } | |
422 | wxVariantDataReal(double value) { m_value = value; } | |
423 | ||
424 | inline double GetValue() const { return m_value; } | |
425 | inline void SetValue(double value) { m_value = value; } | |
426 | ||
427 | virtual void Copy(wxVariantData& data); | |
428 | virtual bool Eq(wxVariantData& data) const; | |
1ccbb61a | 429 | virtual bool Read(wxString& str); |
38830220 | 430 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 431 | virtual bool Write(wxSTD ostream& str) const; |
38830220 | 432 | #endif |
341287bf | 433 | virtual bool Write(wxString& str) const; |
38830220 | 434 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 435 | virtual bool Read(wxSTD istream& str); |
38830220 | 436 | #endif |
e02afc7a | 437 | #if wxUSE_STREAMS |
75ed1d15 | 438 | virtual bool Read(wxInputStream& str); |
1ccbb61a | 439 | virtual bool Write(wxOutputStream &str) const; |
e02afc7a | 440 | #endif // wxUSE_STREAMS |
223d09f6 | 441 | virtual wxString GetType() const { return wxT("double"); }; |
341287bf JS |
442 | |
443 | protected: | |
444 | double m_value; | |
445 | }; | |
446 | ||
447 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataReal, wxVariantData) | |
448 | ||
449 | void wxVariantDataReal::Copy(wxVariantData& data) | |
450 | { | |
223d09f6 | 451 | wxASSERT_MSG( (data.GetType() == wxT("double")), wxT("wxVariantDataReal::Copy: Can't copy to this type of data") ); |
341287bf JS |
452 | |
453 | wxVariantDataReal& otherData = (wxVariantDataReal&) data; | |
454 | ||
455 | otherData.m_value = m_value; | |
456 | } | |
457 | ||
458 | bool wxVariantDataReal::Eq(wxVariantData& data) const | |
459 | { | |
223d09f6 | 460 | wxASSERT_MSG( (data.GetType() == wxT("double")), wxT("wxVariantDataReal::Eq: argument mismatch") ); |
341287bf JS |
461 | |
462 | wxVariantDataReal& otherData = (wxVariantDataReal&) data; | |
463 | ||
464 | return (otherData.m_value == m_value); | |
465 | } | |
466 | ||
38830220 | 467 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 468 | bool wxVariantDataReal::Write(wxSTD ostream& str) const |
341287bf JS |
469 | { |
470 | wxString s; | |
471 | Write(s); | |
783b6cfd | 472 | str << (const char*) s.mb_str(); |
dc259b79 | 473 | return TRUE; |
341287bf | 474 | } |
38830220 | 475 | #endif |
341287bf JS |
476 | |
477 | bool wxVariantDataReal::Write(wxString& str) const | |
478 | { | |
223d09f6 | 479 | str.Printf(wxT("%.4f"), m_value); |
dc259b79 | 480 | return TRUE; |
341287bf JS |
481 | } |
482 | ||
38830220 | 483 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 484 | bool wxVariantDataReal::Read(wxSTD istream& str) |
341287bf JS |
485 | { |
486 | str >> m_value; | |
dc259b79 | 487 | return TRUE; |
341287bf | 488 | } |
38830220 | 489 | #endif |
341287bf | 490 | |
e02afc7a | 491 | #if wxUSE_STREAMS |
1ccbb61a VZ |
492 | bool wxVariantDataReal::Write(wxOutputStream& str) const |
493 | { | |
fae05df5 GL |
494 | wxTextOutputStream s(str); |
495 | s.WriteDouble((double)m_value); | |
dc259b79 | 496 | return TRUE; |
1ccbb61a VZ |
497 | } |
498 | ||
75ed1d15 GL |
499 | bool wxVariantDataReal::Read(wxInputStream& str) |
500 | { | |
fae05df5 GL |
501 | wxTextInputStream s(str); |
502 | m_value = (float)s.ReadDouble(); | |
dc259b79 | 503 | return TRUE; |
75ed1d15 | 504 | } |
e02afc7a | 505 | #endif // wxUSE_STREAMS |
75ed1d15 | 506 | |
341287bf JS |
507 | bool wxVariantDataReal::Read(wxString& str) |
508 | { | |
783b6cfd | 509 | m_value = wxAtof((const wxChar*) str); |
dc259b79 | 510 | return TRUE; |
341287bf JS |
511 | } |
512 | ||
57493f9f | 513 | #ifdef HAVE_BOOL |
341287bf JS |
514 | /* |
515 | * wxVariantDataBool | |
516 | */ | |
517 | ||
518 | class WXDLLEXPORT wxVariantDataBool: public wxVariantData | |
519 | { | |
520 | DECLARE_DYNAMIC_CLASS(wxVariantDataBool) | |
521 | public: | |
522 | wxVariantDataBool() { m_value = 0; } | |
523 | wxVariantDataBool(bool value) { m_value = value; } | |
524 | ||
525 | inline bool GetValue() const { return m_value; } | |
526 | inline void SetValue(bool value) { m_value = value; } | |
527 | ||
528 | virtual void Copy(wxVariantData& data); | |
529 | virtual bool Eq(wxVariantData& data) const; | |
38830220 | 530 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 531 | virtual bool Write(wxSTD ostream& str) const; |
38830220 | 532 | #endif |
341287bf | 533 | virtual bool Write(wxString& str) const; |
1ccbb61a | 534 | virtual bool Read(wxString& str); |
38830220 | 535 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 536 | virtual bool Read(wxSTD istream& str); |
38830220 | 537 | #endif |
e02afc7a | 538 | #if wxUSE_STREAMS |
75ed1d15 | 539 | virtual bool Read(wxInputStream& str); |
1ccbb61a | 540 | virtual bool Write(wxOutputStream& str) const; |
e02afc7a | 541 | #endif // wxUSE_STREAMS |
223d09f6 | 542 | virtual wxString GetType() const { return wxT("bool"); }; |
341287bf JS |
543 | |
544 | protected: | |
545 | bool m_value; | |
546 | }; | |
547 | ||
548 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataBool, wxVariantData) | |
549 | ||
550 | void wxVariantDataBool::Copy(wxVariantData& data) | |
551 | { | |
223d09f6 | 552 | wxASSERT_MSG( (data.GetType() == wxT("bool")), wxT("wxVariantDataBool::Copy: Can't copy to this type of data") ); |
341287bf JS |
553 | |
554 | wxVariantDataBool& otherData = (wxVariantDataBool&) data; | |
555 | ||
556 | otherData.m_value = m_value; | |
557 | } | |
558 | ||
559 | bool wxVariantDataBool::Eq(wxVariantData& data) const | |
560 | { | |
223d09f6 | 561 | wxASSERT_MSG( (data.GetType() == wxT("bool")), wxT("wxVariantDataBool::Eq: argument mismatch") ); |
341287bf JS |
562 | |
563 | wxVariantDataBool& otherData = (wxVariantDataBool&) data; | |
564 | ||
565 | return (otherData.m_value == m_value); | |
566 | } | |
567 | ||
38830220 | 568 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 569 | bool wxVariantDataBool::Write(wxSTD ostream& str) const |
341287bf JS |
570 | { |
571 | wxString s; | |
572 | Write(s); | |
783b6cfd | 573 | str << (const char*) s.mb_str(); |
dc259b79 | 574 | return TRUE; |
341287bf | 575 | } |
38830220 | 576 | #endif |
341287bf JS |
577 | |
578 | bool wxVariantDataBool::Write(wxString& str) const | |
579 | { | |
223d09f6 | 580 | str.Printf(wxT("%d"), (int) m_value); |
dc259b79 | 581 | return TRUE; |
341287bf JS |
582 | } |
583 | ||
38830220 | 584 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 585 | bool wxVariantDataBool::Read(wxSTD istream& WXUNUSED(str)) |
341287bf | 586 | { |
223d09f6 | 587 | wxFAIL_MSG(wxT("Unimplemented")); |
341287bf | 588 | // str >> (long) m_value; |
dc259b79 | 589 | return FALSE; |
341287bf | 590 | } |
38830220 | 591 | #endif |
341287bf | 592 | |
e02afc7a | 593 | #if wxUSE_STREAMS |
1ccbb61a VZ |
594 | bool wxVariantDataBool::Write(wxOutputStream& str) const |
595 | { | |
fae05df5 GL |
596 | wxTextOutputStream s(str); |
597 | ||
2b004197 | 598 | s.Write8(m_value); |
dc259b79 | 599 | return TRUE; |
1ccbb61a VZ |
600 | } |
601 | ||
75ed1d15 GL |
602 | bool wxVariantDataBool::Read(wxInputStream& str) |
603 | { | |
fae05df5 GL |
604 | wxTextInputStream s(str); |
605 | ||
a1b82138 | 606 | m_value = s.Read8() != 0; |
dc259b79 | 607 | return TRUE; |
75ed1d15 | 608 | } |
e02afc7a | 609 | #endif // wxUSE_STREAMS |
75ed1d15 | 610 | |
341287bf JS |
611 | bool wxVariantDataBool::Read(wxString& str) |
612 | { | |
783b6cfd | 613 | m_value = (wxAtol((const wxChar*) str) != 0); |
dc259b79 | 614 | return TRUE; |
341287bf | 615 | } |
57493f9f | 616 | #endif // HAVE_BOOL |
341287bf JS |
617 | |
618 | /* | |
619 | * wxVariantDataChar | |
620 | */ | |
621 | ||
622 | class WXDLLEXPORT wxVariantDataChar: public wxVariantData | |
623 | { | |
624 | DECLARE_DYNAMIC_CLASS(wxVariantDataChar) | |
625 | public: | |
626 | wxVariantDataChar() { m_value = 0; } | |
627 | wxVariantDataChar(char value) { m_value = value; } | |
628 | ||
629 | inline char GetValue() const { return m_value; } | |
630 | inline void SetValue(char value) { m_value = value; } | |
631 | ||
632 | virtual void Copy(wxVariantData& data); | |
633 | virtual bool Eq(wxVariantData& data) const; | |
38830220 | 634 | #if wxUSE_STD_IOSTREAM |
dd107c50 VZ |
635 | virtual bool Read(wxSTD istream& str); |
636 | virtual bool Write(wxSTD ostream& str) const; | |
38830220 | 637 | #endif |
1ccbb61a | 638 | virtual bool Read(wxString& str); |
341287bf | 639 | virtual bool Write(wxString& str) const; |
e02afc7a | 640 | #if wxUSE_STREAMS |
75ed1d15 | 641 | virtual bool Read(wxInputStream& str); |
1ccbb61a | 642 | virtual bool Write(wxOutputStream& str) const; |
e02afc7a | 643 | #endif // wxUSE_STREAMS |
223d09f6 | 644 | virtual wxString GetType() const { return wxT("char"); }; |
341287bf JS |
645 | |
646 | protected: | |
647 | char m_value; | |
648 | }; | |
649 | ||
650 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataChar, wxVariantData) | |
651 | ||
652 | void wxVariantDataChar::Copy(wxVariantData& data) | |
653 | { | |
223d09f6 | 654 | wxASSERT_MSG( (data.GetType() == wxT("char")), wxT("wxVariantDataChar::Copy: Can't copy to this type of data") ); |
341287bf JS |
655 | |
656 | wxVariantDataChar& otherData = (wxVariantDataChar&) data; | |
657 | ||
658 | otherData.m_value = m_value; | |
659 | } | |
660 | ||
661 | bool wxVariantDataChar::Eq(wxVariantData& data) const | |
662 | { | |
223d09f6 | 663 | wxASSERT_MSG( (data.GetType() == wxT("char")), wxT("wxVariantDataChar::Eq: argument mismatch") ); |
341287bf JS |
664 | |
665 | wxVariantDataChar& otherData = (wxVariantDataChar&) data; | |
666 | ||
667 | return (otherData.m_value == m_value); | |
668 | } | |
669 | ||
38830220 | 670 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 671 | bool wxVariantDataChar::Write(wxSTD ostream& str) const |
341287bf JS |
672 | { |
673 | wxString s; | |
674 | Write(s); | |
783b6cfd | 675 | str << (const char*) s.mb_str(); |
dc259b79 | 676 | return TRUE; |
341287bf | 677 | } |
38830220 | 678 | #endif |
341287bf JS |
679 | |
680 | bool wxVariantDataChar::Write(wxString& str) const | |
681 | { | |
223d09f6 | 682 | str.Printf(wxT("%c"), m_value); |
dc259b79 | 683 | return TRUE; |
341287bf JS |
684 | } |
685 | ||
38830220 | 686 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 687 | bool wxVariantDataChar::Read(wxSTD istream& WXUNUSED(str)) |
341287bf | 688 | { |
223d09f6 | 689 | wxFAIL_MSG(wxT("Unimplemented")); |
341287bf | 690 | // str >> m_value; |
dc259b79 | 691 | return FALSE; |
341287bf | 692 | } |
38830220 | 693 | #endif |
341287bf | 694 | |
e02afc7a | 695 | #if wxUSE_STREAMS |
1ccbb61a VZ |
696 | bool wxVariantDataChar::Write(wxOutputStream& str) const |
697 | { | |
fae05df5 GL |
698 | wxTextOutputStream s(str); |
699 | ||
700 | s.Write8(m_value); | |
dc259b79 | 701 | return TRUE; |
1ccbb61a VZ |
702 | } |
703 | ||
75ed1d15 GL |
704 | bool wxVariantDataChar::Read(wxInputStream& str) |
705 | { | |
fae05df5 GL |
706 | wxTextInputStream s(str); |
707 | ||
708 | m_value = s.Read8(); | |
dc259b79 | 709 | return TRUE; |
75ed1d15 | 710 | } |
e02afc7a | 711 | #endif // wxUSE_STREAMS |
75ed1d15 | 712 | |
341287bf JS |
713 | bool wxVariantDataChar::Read(wxString& str) |
714 | { | |
715 | m_value = str[(size_t)0]; | |
dc259b79 | 716 | return TRUE; |
341287bf JS |
717 | } |
718 | ||
719 | /* | |
720 | * wxVariantDataString | |
721 | */ | |
722 | ||
62448488 JS |
723 | #if defined(__BORLANDC__) && defined(__WIN16__) |
724 | // Change name because of truncation | |
725 | #define wxVariantDataString wxVariantStringData | |
726 | #endif | |
727 | ||
341287bf JS |
728 | class WXDLLEXPORT wxVariantDataString: public wxVariantData |
729 | { | |
62448488 JS |
730 | #if defined(__BORLANDC__) && defined(__WIN16__) |
731 | DECLARE_DYNAMIC_CLASS(wxVariantStringData) | |
732 | #else | |
341287bf | 733 | DECLARE_DYNAMIC_CLASS(wxVariantDataString) |
62448488 | 734 | #endif |
341287bf JS |
735 | public: |
736 | wxVariantDataString() { } | |
737 | wxVariantDataString(const wxString& value) { m_value = value; } | |
738 | ||
739 | inline wxString GetValue() const { return m_value; } | |
740 | inline void SetValue(const wxString& value) { m_value = value; } | |
741 | ||
742 | virtual void Copy(wxVariantData& data); | |
743 | virtual bool Eq(wxVariantData& data) const; | |
38830220 | 744 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 745 | virtual bool Write(wxSTD ostream& str) const; |
38830220 | 746 | #endif |
1ccbb61a | 747 | virtual bool Read(wxString& str); |
341287bf | 748 | virtual bool Write(wxString& str) const; |
38830220 | 749 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 750 | virtual bool Read(wxSTD istream& str); |
38830220 | 751 | #endif |
e02afc7a | 752 | #if wxUSE_STREAMS |
75ed1d15 | 753 | virtual bool Read(wxInputStream& str); |
1ccbb61a | 754 | virtual bool Write(wxOutputStream& str) const; |
e02afc7a | 755 | #endif // wxUSE_STREAMS |
223d09f6 | 756 | virtual wxString GetType() const { return wxT("string"); }; |
341287bf JS |
757 | |
758 | protected: | |
759 | wxString m_value; | |
760 | }; | |
761 | ||
762 | void wxVariantDataString::Copy(wxVariantData& data) | |
763 | { | |
223d09f6 | 764 | wxASSERT_MSG( (data.GetType() == wxT("string")), wxT("wxVariantDataString::Copy: Can't copy to this type of data") ); |
341287bf JS |
765 | |
766 | wxVariantDataString& otherData = (wxVariantDataString&) data; | |
767 | ||
768 | otherData.m_value = m_value; | |
769 | } | |
770 | ||
771 | bool wxVariantDataString::Eq(wxVariantData& data) const | |
772 | { | |
223d09f6 | 773 | wxASSERT_MSG( (data.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") ); |
341287bf JS |
774 | |
775 | wxVariantDataString& otherData = (wxVariantDataString&) data; | |
776 | ||
777 | return (otherData.m_value == m_value); | |
778 | } | |
779 | ||
38830220 | 780 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 781 | bool wxVariantDataString::Write(wxSTD ostream& str) const |
341287bf | 782 | { |
783b6cfd | 783 | str << (const char*) m_value.mb_str(); |
dc259b79 | 784 | return TRUE; |
341287bf | 785 | } |
38830220 | 786 | #endif |
341287bf JS |
787 | |
788 | bool wxVariantDataString::Write(wxString& str) const | |
789 | { | |
790 | str = m_value; | |
dc259b79 | 791 | return TRUE; |
341287bf JS |
792 | } |
793 | ||
38830220 | 794 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 795 | bool wxVariantDataString::Read(wxSTD istream& str) |
341287bf JS |
796 | { |
797 | str >> m_value; | |
dc259b79 | 798 | return TRUE; |
341287bf | 799 | } |
38830220 | 800 | #endif |
341287bf | 801 | |
e02afc7a | 802 | #if wxUSE_STREAMS |
1ccbb61a VZ |
803 | bool wxVariantDataString::Write(wxOutputStream& str) const |
804 | { | |
783b6cfd | 805 | // why doesn't wxOutputStream::operator<< take "const wxString&" |
fae05df5 GL |
806 | wxTextOutputStream s(str); |
807 | s.WriteString(m_value); | |
dc259b79 | 808 | return TRUE; |
1ccbb61a VZ |
809 | } |
810 | ||
75ed1d15 GL |
811 | bool wxVariantDataString::Read(wxInputStream& str) |
812 | { | |
fae05df5 GL |
813 | wxTextInputStream s(str); |
814 | ||
815 | m_value = s.ReadString(); | |
dc259b79 | 816 | return TRUE; |
75ed1d15 | 817 | } |
e02afc7a | 818 | #endif // wxUSE_STREAMS |
75ed1d15 | 819 | |
341287bf JS |
820 | bool wxVariantDataString::Read(wxString& str) |
821 | { | |
822 | m_value = str; | |
dc259b79 | 823 | return TRUE; |
341287bf JS |
824 | } |
825 | ||
62448488 JS |
826 | #if defined(__BORLANDC__) && defined(__WIN16__) |
827 | IMPLEMENT_DYNAMIC_CLASS(wxVariantStringData, wxVariantData) | |
828 | #else | |
341287bf | 829 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString, wxVariantData) |
62448488 | 830 | #endif |
341287bf | 831 | |
a0a302dc JS |
832 | /* |
833 | * wxVariantDataTime | |
834 | */ | |
835 | ||
457e6c54 JS |
836 | // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled |
837 | #if wxUSE_TIMEDATE && !defined(__WATCOMC__) | |
a0a302dc JS |
838 | |
839 | class wxVariantDataTime: public wxVariantData | |
840 | { | |
841 | DECLARE_DYNAMIC_CLASS(wxVariantDataTime) | |
842 | public: | |
843 | wxVariantDataTime() { } | |
844 | wxVariantDataTime(const wxTime& value) { m_value = value; } | |
845 | ||
846 | inline wxTime GetValue() const { return m_value; } | |
847 | inline void SetValue(const wxTime& value) { m_value = value; } | |
848 | ||
849 | virtual void Copy(wxVariantData& data); | |
850 | virtual bool Eq(wxVariantData& data) const; | |
38830220 | 851 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 852 | virtual bool Write(wxSTD ostream& str) const; |
38830220 | 853 | #endif |
a0a302dc | 854 | virtual bool Write(wxString& str) const; |
38830220 | 855 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 856 | virtual bool Read(wxSTD istream& str); |
38830220 | 857 | #endif |
a0a302dc | 858 | virtual bool Read(wxString& str); |
223d09f6 | 859 | virtual wxString GetType() const { return wxT("time"); }; |
b1d4dd7a | 860 | virtual wxVariantData* Clone() { return new wxVariantDataTime; } |
a0a302dc JS |
861 | |
862 | protected: | |
863 | wxTime m_value; | |
864 | }; | |
865 | ||
866 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataTime, wxVariantData) | |
867 | ||
868 | void wxVariantDataTime::Copy(wxVariantData& data) | |
869 | { | |
223d09f6 | 870 | wxASSERT_MSG( (data.GetType() == wxT("time")), wxT("wxVariantDataTime::Copy: Can't copy to this type of data") ); |
a0a302dc JS |
871 | |
872 | wxVariantDataTime& otherData = (wxVariantDataTime&) data; | |
873 | ||
874 | otherData.m_value = m_value; | |
875 | } | |
876 | ||
877 | bool wxVariantDataTime::Eq(wxVariantData& data) const | |
878 | { | |
223d09f6 | 879 | wxASSERT_MSG( (data.GetType() == wxT("time")), wxT("wxVariantDataTime::Eq: argument mismatch") ); |
a0a302dc JS |
880 | |
881 | wxVariantDataTime& otherData = (wxVariantDataTime&) data; | |
882 | ||
883 | return (otherData.m_value == m_value); | |
884 | } | |
885 | ||
38830220 | 886 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 887 | bool wxVariantDataTime::Write(wxSTD ostream& str) const |
a0a302dc JS |
888 | { |
889 | wxString s; | |
890 | Write(s); | |
783b6cfd | 891 | str << (const char*) s.mb_str(); |
dc259b79 | 892 | return TRUE; |
a0a302dc | 893 | } |
38830220 | 894 | #endif |
a0a302dc JS |
895 | |
896 | bool wxVariantDataTime::Write(wxString& str) const | |
897 | { | |
783b6cfd | 898 | wxChar*s = m_value.FormatTime(); |
a0a302dc | 899 | str = s; |
dc259b79 | 900 | return TRUE; |
a0a302dc JS |
901 | } |
902 | ||
38830220 | 903 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 904 | bool wxVariantDataTime::Read(wxSTD istream& WXUNUSED(str)) |
a0a302dc JS |
905 | { |
906 | // Not implemented | |
dc259b79 | 907 | return FALSE; |
a0a302dc | 908 | } |
38830220 | 909 | #endif |
a0a302dc | 910 | |
8b53e5a2 | 911 | bool wxVariantDataTime::Read(wxString& WXUNUSED(str)) |
a0a302dc JS |
912 | { |
913 | // Not implemented | |
dc259b79 | 914 | return FALSE; |
a0a302dc JS |
915 | } |
916 | ||
917 | /* | |
918 | * wxVariantDataDate | |
919 | */ | |
920 | ||
921 | class wxVariantDataDate: public wxVariantData | |
922 | { | |
923 | DECLARE_DYNAMIC_CLASS(wxVariantDataDate) | |
924 | public: | |
925 | wxVariantDataDate() { } | |
926 | wxVariantDataDate(const wxDate& value) { m_value = value; } | |
927 | ||
928 | inline wxDate GetValue() const { return m_value; } | |
929 | inline void SetValue(const wxDate& value) { m_value = value; } | |
930 | ||
931 | virtual void Copy(wxVariantData& data); | |
932 | virtual bool Eq(wxVariantData& data) const; | |
38830220 | 933 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 934 | virtual bool Write(wxSTD ostream& str) const; |
38830220 | 935 | #endif |
a0a302dc | 936 | virtual bool Write(wxString& str) const; |
38830220 | 937 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 938 | virtual bool Read(wxSTD istream& str); |
38830220 | 939 | #endif |
a0a302dc | 940 | virtual bool Read(wxString& str); |
223d09f6 | 941 | virtual wxString GetType() const { return wxT("date"); }; |
b1d4dd7a | 942 | virtual wxVariantData* Clone() { return new wxVariantDataDate; } |
a0a302dc JS |
943 | |
944 | protected: | |
945 | wxDate m_value; | |
946 | }; | |
947 | ||
948 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDate, wxVariantData) | |
949 | ||
950 | void wxVariantDataDate::Copy(wxVariantData& data) | |
951 | { | |
223d09f6 | 952 | wxASSERT_MSG( (data.GetType() == wxT("date")), wxT("wxVariantDataDate::Copy: Can't copy to this type of data") ); |
a0a302dc JS |
953 | |
954 | wxVariantDataDate& otherData = (wxVariantDataDate&) data; | |
955 | ||
956 | otherData.m_value = m_value; | |
957 | } | |
958 | ||
959 | bool wxVariantDataDate::Eq(wxVariantData& data) const | |
960 | { | |
223d09f6 | 961 | wxASSERT_MSG( (data.GetType() == wxT("date")), wxT("wxVariantDataDate::Eq: argument mismatch") ); |
a0a302dc JS |
962 | |
963 | wxVariantDataDate& otherData = (wxVariantDataDate&) data; | |
964 | ||
965 | return (otherData.m_value == m_value); | |
966 | } | |
967 | ||
38830220 | 968 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 969 | bool wxVariantDataDate::Write(wxSTD ostream& str) const |
a0a302dc JS |
970 | { |
971 | wxString s; | |
972 | Write(s); | |
783b6cfd | 973 | str << (const char*) s.mb_str(); |
dc259b79 | 974 | return TRUE; |
a0a302dc | 975 | } |
38830220 | 976 | #endif |
a0a302dc JS |
977 | |
978 | bool wxVariantDataDate::Write(wxString& str) const | |
979 | { | |
980 | str = m_value.FormatDate(); | |
dc259b79 | 981 | return TRUE; |
a0a302dc JS |
982 | } |
983 | ||
38830220 | 984 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 985 | bool wxVariantDataDate::Read(wxSTD istream& WXUNUSED(str)) |
a0a302dc JS |
986 | { |
987 | // Not implemented | |
dc259b79 | 988 | return FALSE; |
a0a302dc | 989 | } |
38830220 | 990 | #endif |
a0a302dc | 991 | |
8b53e5a2 | 992 | bool wxVariantDataDate::Read(wxString& WXUNUSED(str)) |
a0a302dc JS |
993 | { |
994 | // Not implemented | |
dc259b79 | 995 | return FALSE; |
a0a302dc JS |
996 | } |
997 | #endif | |
998 | // wxUSE_TIMEDATE | |
999 | ||
1000 | /* | |
1001 | * wxVariantDataVoidPtr | |
1002 | */ | |
1003 | ||
1004 | class wxVariantDataVoidPtr: public wxVariantData | |
1005 | { | |
1006 | DECLARE_DYNAMIC_CLASS(wxVariantDataVoidPtr) | |
1007 | public: | |
1008 | wxVariantDataVoidPtr() { } | |
1009 | wxVariantDataVoidPtr(void* value) { m_value = value; } | |
1010 | ||
1011 | inline void* GetValue() const { return m_value; } | |
1012 | inline void SetValue(void* value) { m_value = value; } | |
1013 | ||
1014 | virtual void Copy(wxVariantData& data); | |
1015 | virtual bool Eq(wxVariantData& data) const; | |
38830220 | 1016 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 1017 | virtual bool Write(wxSTD ostream& str) const; |
38830220 | 1018 | #endif |
a0a302dc | 1019 | virtual bool Write(wxString& str) const; |
38830220 | 1020 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 1021 | virtual bool Read(wxSTD istream& str); |
38830220 | 1022 | #endif |
a0a302dc | 1023 | virtual bool Read(wxString& str); |
223d09f6 | 1024 | virtual wxString GetType() const { return wxT("void*"); }; |
b1d4dd7a | 1025 | virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; } |
a0a302dc JS |
1026 | |
1027 | protected: | |
1028 | void* m_value; | |
22f3361e VZ |
1029 | |
1030 | DECLARE_NO_COPY_CLASS(wxVariantDataVoidPtr) | |
a0a302dc JS |
1031 | }; |
1032 | ||
1033 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr, wxVariantData) | |
1034 | ||
1035 | void wxVariantDataVoidPtr::Copy(wxVariantData& data) | |
1036 | { | |
223d09f6 | 1037 | wxASSERT_MSG( (data.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Copy: Can't copy to this type of data") ); |
a0a302dc JS |
1038 | |
1039 | wxVariantDataVoidPtr& otherData = (wxVariantDataVoidPtr&) data; | |
1040 | ||
1041 | otherData.m_value = m_value; | |
1042 | } | |
1043 | ||
1044 | bool wxVariantDataVoidPtr::Eq(wxVariantData& data) const | |
1045 | { | |
223d09f6 | 1046 | wxASSERT_MSG( (data.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") ); |
a0a302dc JS |
1047 | |
1048 | wxVariantDataVoidPtr& otherData = (wxVariantDataVoidPtr&) data; | |
1049 | ||
1050 | return (otherData.m_value == m_value); | |
1051 | } | |
1052 | ||
38830220 | 1053 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 1054 | bool wxVariantDataVoidPtr::Write(wxSTD ostream& str) const |
a0a302dc JS |
1055 | { |
1056 | wxString s; | |
1057 | Write(s); | |
783b6cfd | 1058 | str << (const char*) s.mb_str(); |
dc259b79 | 1059 | return TRUE; |
a0a302dc | 1060 | } |
38830220 | 1061 | #endif |
a0a302dc JS |
1062 | |
1063 | bool wxVariantDataVoidPtr::Write(wxString& str) const | |
1064 | { | |
223d09f6 | 1065 | str.Printf(wxT("%ld"), (long) m_value); |
dc259b79 | 1066 | return TRUE; |
a0a302dc JS |
1067 | } |
1068 | ||
38830220 | 1069 | #if wxUSE_STD_IOSTREAM |
dd107c50 | 1070 | bool wxVariantDataVoidPtr::Read(wxSTD istream& WXUNUSED(str)) |
a0a302dc JS |
1071 | { |
1072 | // Not implemented | |
dc259b79 | 1073 | return FALSE; |
a0a302dc | 1074 | } |
38830220 | 1075 | #endif |
a0a302dc | 1076 | |
8b53e5a2 | 1077 | bool wxVariantDataVoidPtr::Read(wxString& WXUNUSED(str)) |
a0a302dc JS |
1078 | { |
1079 | // Not implemented | |
dc259b79 | 1080 | return FALSE; |
a0a302dc JS |
1081 | } |
1082 | ||
edca7a82 GT |
1083 | /* |
1084 | * wxVariantDataDateTime | |
1085 | */ | |
1086 | ||
e2b87f38 VZ |
1087 | #if wxUSE_DATETIME |
1088 | ||
edca7a82 GT |
1089 | class wxVariantDataDateTime: public wxVariantData |
1090 | { | |
1091 | DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime) | |
1092 | ||
1093 | public: | |
1094 | wxVariantDataDateTime() { } | |
1095 | wxVariantDataDateTime(const wxDateTime& value) { m_value = value; } | |
1096 | #if wxUSE_ODBC | |
2b004197 | 1097 | wxVariantDataDateTime(const TIME_STRUCT* valptr) |
edca7a82 | 1098 | { m_value = wxDateTime(valptr->hour, valptr->minute, valptr->second); } |
2b004197 | 1099 | wxVariantDataDateTime(const DATE_STRUCT* valptr) |
edca7a82 | 1100 | { m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1),valptr->year); } |
2b004197 | 1101 | wxVariantDataDateTime(const TIMESTAMP_STRUCT* valptr) |
edca7a82 GT |
1102 | { m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1), valptr->year, |
1103 | valptr->hour, valptr->minute, valptr->second, valptr->fraction ); } | |
1104 | #endif //ODBC | |
1105 | ||
1106 | inline wxDateTime GetValue() const { return m_value; } | |
1107 | inline void SetValue(const wxDateTime& value) { m_value = value; } | |
1108 | ||
1109 | virtual void Copy(wxVariantData& data); | |
1110 | virtual bool Eq(wxVariantData& data) const; | |
1111 | #if wxUSE_STD_IOSTREAM | |
2b004197 | 1112 | virtual bool Write(wxSTD ostream& str) const; |
edca7a82 GT |
1113 | #endif |
1114 | virtual bool Write(wxString& str) const; | |
1115 | #if wxUSE_STD_IOSTREAM | |
2b004197 | 1116 | virtual bool Read(wxSTD istream& str); |
edca7a82 GT |
1117 | #endif |
1118 | virtual bool Read(wxString& str); | |
1119 | virtual wxString GetType() const { return wxT("datetime"); }; | |
1120 | virtual wxVariantData* Clone() { return new wxVariantDataDateTime; } | |
1121 | ||
1122 | protected: | |
1123 | wxDateTime m_value; | |
1124 | }; | |
1125 | ||
1126 | ||
1127 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDateTime, wxVariantData) | |
1128 | ||
1129 | void wxVariantDataDateTime::Copy(wxVariantData& data) | |
1130 | { | |
1131 | wxASSERT_MSG( (data.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Copy: Can't copy to this type of data") ); | |
1132 | ||
1133 | wxVariantDataDateTime& otherData = (wxVariantDataDateTime&) data; | |
1134 | ||
1135 | otherData.m_value = m_value; | |
1136 | } | |
1137 | ||
1138 | ||
1139 | bool wxVariantDataDateTime::Eq(wxVariantData& data) const | |
1140 | { | |
1141 | wxASSERT_MSG( (data.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Eq: argument mismatch") ); | |
1142 | ||
1143 | wxVariantDataDateTime& otherData = (wxVariantDataDateTime&) data; | |
1144 | ||
1145 | return (otherData.m_value == m_value); | |
1146 | } | |
1147 | ||
1148 | ||
1149 | #if wxUSE_STD_IOSTREAM | |
2b004197 | 1150 | bool wxVariantDataDateTime::Write(wxSTD ostream& str) const |
edca7a82 GT |
1151 | { |
1152 | // Not implemented | |
dc259b79 | 1153 | return FALSE; |
edca7a82 GT |
1154 | } |
1155 | #endif | |
1156 | ||
1157 | ||
1158 | bool wxVariantDataDateTime::Write(wxString& str) const | |
1159 | { | |
1160 | str = m_value.Format(); | |
dc259b79 | 1161 | return TRUE; |
edca7a82 GT |
1162 | } |
1163 | ||
1164 | ||
1165 | #if wxUSE_STD_IOSTREAM | |
2b004197 | 1166 | bool wxVariantDataDateTime::Read(wxSTD istream& WXUNUSED(str)) |
edca7a82 GT |
1167 | { |
1168 | // Not implemented | |
dc259b79 | 1169 | return FALSE; |
edca7a82 GT |
1170 | } |
1171 | #endif | |
1172 | ||
1173 | ||
1174 | bool wxVariantDataDateTime::Read(wxString& str) | |
1175 | { | |
1176 | if(! m_value.ParseDateTime(str)) | |
dc259b79 DW |
1177 | return FALSE; |
1178 | return TRUE; | |
edca7a82 GT |
1179 | } |
1180 | ||
e2b87f38 VZ |
1181 | #endif // wxUSE_DATETIME |
1182 | ||
fb42d7c3 VZ |
1183 | // ---------------------------------------------------------------------------- |
1184 | // wxVariantDataArrayString | |
1185 | // ---------------------------------------------------------------------------- | |
1186 | ||
1187 | class wxVariantDataArrayString: public wxVariantData | |
1188 | { | |
1189 | public: | |
1190 | wxVariantDataArrayString() { } | |
1191 | wxVariantDataArrayString(const wxArrayString& value) { m_value = value; } | |
1192 | ||
1193 | wxArrayString GetValue() const { return m_value; } | |
1194 | void SetValue(const wxArrayString& value) { m_value = value; } | |
1195 | ||
1196 | virtual void Copy(wxVariantData& data); | |
1197 | virtual bool Eq(wxVariantData& data) const; | |
1198 | #if wxUSE_STD_IOSTREAM | |
1199 | virtual bool Write(wxSTD ostream& str) const; | |
1200 | #endif | |
1201 | virtual bool Write(wxString& str) const; | |
1202 | #if wxUSE_STD_IOSTREAM | |
1203 | virtual bool Read(wxSTD istream& str); | |
1204 | #endif | |
1205 | virtual bool Read(wxString& str); | |
1206 | virtual wxString GetType() const { return wxT("arrstring"); }; | |
1207 | virtual wxVariantData* Clone() { return new wxVariantDataArrayString; } | |
1208 | ||
1209 | protected: | |
1210 | wxArrayString m_value; | |
1211 | ||
1212 | DECLARE_DYNAMIC_CLASS(wxVariantDataArrayString) | |
1213 | }; | |
1214 | ||
1215 | IMPLEMENT_DYNAMIC_CLASS(wxVariantDataArrayString, wxVariantData) | |
1216 | ||
1217 | void wxVariantDataArrayString::Copy(wxVariantData& data) | |
1218 | { | |
1219 | wxASSERT_MSG( data.GetType() == GetType(), wxT("wxVariantDataArrayString::Copy: Can't copy to this type of data") ); | |
1220 | ||
1221 | wxVariantDataArrayString& otherData = (wxVariantDataArrayString&) data; | |
1222 | ||
1223 | otherData.m_value = m_value; | |
1224 | } | |
1225 | ||
1226 | ||
1227 | bool wxVariantDataArrayString::Eq(wxVariantData& data) const | |
1228 | { | |
1229 | wxASSERT_MSG( data.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") ); | |
1230 | ||
1231 | wxVariantDataArrayString& otherData = (wxVariantDataArrayString&) data; | |
1232 | ||
1233 | return otherData.m_value == m_value; | |
1234 | } | |
1235 | ||
1236 | ||
1237 | #if wxUSE_STD_IOSTREAM | |
1238 | bool wxVariantDataArrayString::Write(wxSTD ostream& str) const | |
1239 | { | |
1240 | // Not implemented | |
dc259b79 | 1241 | return FALSE; |
fb42d7c3 VZ |
1242 | } |
1243 | #endif | |
1244 | ||
1245 | ||
1246 | bool wxVariantDataArrayString::Write(wxString& str) const | |
1247 | { | |
1248 | size_t count = m_value.GetCount(); | |
1249 | for ( size_t n = 0; n < count; n++ ) | |
1250 | { | |
1251 | if ( n ) | |
1252 | str += _T(';'); | |
1253 | ||
1254 | str += m_value[n]; | |
1255 | } | |
1256 | ||
dc259b79 | 1257 | return TRUE; |
fb42d7c3 VZ |
1258 | } |
1259 | ||
1260 | ||
1261 | #if wxUSE_STD_IOSTREAM | |
1262 | bool wxVariantDataArrayString::Read(wxSTD istream& WXUNUSED(str)) | |
1263 | { | |
1264 | // Not implemented | |
dc259b79 | 1265 | return FALSE; |
fb42d7c3 VZ |
1266 | } |
1267 | #endif | |
1268 | ||
1269 | ||
1270 | bool wxVariantDataArrayString::Read(wxString& str) | |
1271 | { | |
1272 | wxStringTokenizer tk(str, _T(";")); | |
1273 | while ( tk.HasMoreTokens() ) | |
1274 | { | |
1275 | m_value.Add(tk.GetNextToken()); | |
1276 | } | |
1277 | ||
dc259b79 | 1278 | return TRUE; |
fb42d7c3 VZ |
1279 | } |
1280 | ||
1281 | ||
a0a302dc | 1282 | |
341287bf JS |
1283 | /* |
1284 | * wxVariant | |
1285 | */ | |
1286 | ||
1287 | IMPLEMENT_DYNAMIC_CLASS(wxVariant, wxObject) | |
1288 | ||
1289 | // Construction & destruction | |
1290 | wxVariant::wxVariant() | |
1291 | { | |
1292 | m_data = (wxVariantData*) NULL; | |
1293 | } | |
1294 | ||
a0a302dc | 1295 | wxVariant::wxVariant(double val, const wxString& name) |
341287bf JS |
1296 | { |
1297 | m_data = new wxVariantDataReal(val); | |
a0a302dc | 1298 | m_name = name; |
341287bf JS |
1299 | } |
1300 | ||
a0a302dc | 1301 | wxVariant::wxVariant(long val, const wxString& name) |
341287bf JS |
1302 | { |
1303 | m_data = new wxVariantDataLong(val); | |
a0a302dc | 1304 | m_name = name; |
341287bf JS |
1305 | } |
1306 | ||
57493f9f | 1307 | #ifdef HAVE_BOOL |
a0a302dc | 1308 | wxVariant::wxVariant(bool val, const wxString& name) |
341287bf JS |
1309 | { |
1310 | m_data = new wxVariantDataBool(val); | |
a0a302dc | 1311 | m_name = name; |
341287bf | 1312 | } |
57493f9f | 1313 | #endif |
341287bf | 1314 | |
a0a302dc | 1315 | wxVariant::wxVariant(char val, const wxString& name) |
341287bf JS |
1316 | { |
1317 | m_data = new wxVariantDataChar(val); | |
a0a302dc | 1318 | m_name = name; |
341287bf JS |
1319 | } |
1320 | ||
a0a302dc | 1321 | wxVariant::wxVariant(const wxString& val, const wxString& name) |
341287bf JS |
1322 | { |
1323 | m_data = new wxVariantDataString(val); | |
a0a302dc | 1324 | m_name = name; |
341287bf JS |
1325 | } |
1326 | ||
783b6cfd | 1327 | wxVariant::wxVariant(const wxChar* val, const wxString& name) |
341287bf JS |
1328 | { |
1329 | m_data = new wxVariantDataString(wxString(val)); | |
a0a302dc | 1330 | m_name = name; |
341287bf JS |
1331 | } |
1332 | ||
a0a302dc | 1333 | wxVariant::wxVariant(const wxStringList& val, const wxString& name) |
341287bf JS |
1334 | { |
1335 | m_data = new wxVariantDataStringList(val); | |
a0a302dc | 1336 | m_name = name; |
341287bf | 1337 | } |
341287bf | 1338 | |
a0a302dc | 1339 | wxVariant::wxVariant(const wxList& val, const wxString& name) // List of variants |
341287bf JS |
1340 | { |
1341 | m_data = new wxVariantDataList(val); | |
a0a302dc JS |
1342 | m_name = name; |
1343 | } | |
1344 | ||
457e6c54 JS |
1345 | // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled |
1346 | #if wxUSE_TIMEDATE && !defined(__WATCOMC__) | |
a0a302dc JS |
1347 | wxVariant::wxVariant(const wxTime& val, const wxString& name) // Time |
1348 | { | |
1349 | m_data = new wxVariantDataTime(val); | |
1350 | m_name = name; | |
1351 | } | |
1352 | ||
1353 | wxVariant::wxVariant(const wxDate& val, const wxString& name) // Date | |
1354 | { | |
1355 | m_data = new wxVariantDataDate(val); | |
1356 | m_name = name; | |
1357 | } | |
1358 | #endif | |
1359 | ||
1360 | wxVariant::wxVariant(void* val, const wxString& name) // Void ptr | |
1361 | { | |
1362 | m_data = new wxVariantDataVoidPtr(val); | |
1363 | m_name = name; | |
341287bf JS |
1364 | } |
1365 | ||
e2b87f38 | 1366 | #if wxUSE_DATETIME |
edca7a82 GT |
1367 | wxVariant::wxVariant(const wxDateTime& val, const wxString& name) // Date |
1368 | { | |
1369 | m_data = new wxVariantDataDateTime(val); | |
1370 | m_name = name; | |
1371 | } | |
e2b87f38 | 1372 | #endif // wxUSE_DATETIME |
edca7a82 GT |
1373 | |
1374 | #if wxUSE_ODBC | |
1375 | wxVariant::wxVariant(const TIME_STRUCT* valptr, const wxString& name) // Date | |
1376 | { | |
1377 | m_data = new wxVariantDataDateTime(valptr); | |
1378 | m_name = name; | |
1379 | } | |
1380 | ||
1381 | wxVariant::wxVariant(const TIMESTAMP_STRUCT* valptr, const wxString& name) // Date | |
1382 | { | |
1383 | m_data = new wxVariantDataDateTime(valptr); | |
1384 | m_name = name; | |
1385 | } | |
1386 | ||
1387 | wxVariant::wxVariant(const DATE_STRUCT* valptr, const wxString& name) // Date | |
1388 | { | |
1389 | m_data = new wxVariantDataDateTime(valptr); | |
1390 | m_name = name; | |
1391 | } | |
fb42d7c3 VZ |
1392 | #endif // wxUSE_ODBC |
1393 | ||
1394 | wxVariant::wxVariant(const wxArrayString& val, const wxString& name) // Strings | |
1395 | { | |
1396 | m_data = new wxVariantDataArrayString(val); | |
1397 | m_name = name; | |
1398 | } | |
edca7a82 | 1399 | |
341287bf | 1400 | wxVariant::wxVariant(const wxVariant& variant) |
d84afea9 | 1401 | : wxObject() |
341287bf JS |
1402 | { |
1403 | if (!variant.IsNull()) | |
1404 | { | |
1405 | m_data = (wxVariantData*) variant.GetData()->GetClassInfo()->CreateObject(); | |
1406 | variant.m_data->Copy(*m_data); | |
1407 | } | |
4fabb575 JS |
1408 | else |
1409 | m_data = (wxVariantData*) NULL; | |
a0a302dc | 1410 | m_name = variant.m_name; |
341287bf JS |
1411 | } |
1412 | ||
a0a302dc | 1413 | wxVariant::wxVariant(wxVariantData* data, const wxString& name) // User-defined data |
341287bf JS |
1414 | { |
1415 | m_data = data; | |
a0a302dc | 1416 | m_name = name; |
341287bf JS |
1417 | } |
1418 | ||
1419 | wxVariant::~wxVariant() | |
1420 | { | |
1421 | delete m_data; | |
1422 | } | |
1423 | ||
1424 | ||
1425 | // Make NULL (i.e. delete the data) | |
1426 | void wxVariant::MakeNull() | |
1427 | { | |
1428 | delete m_data; | |
1429 | m_data = NULL; | |
1430 | } | |
1431 | ||
1432 | // Generic operators | |
1433 | // Assignment | |
1434 | void wxVariant::operator= (const wxVariant& variant) | |
1435 | { | |
1436 | if (variant.IsNull()) | |
1437 | { | |
1438 | MakeNull(); | |
1439 | return; | |
1440 | } | |
1441 | ||
1442 | if (IsNull() || (GetType() != variant.GetType())) | |
1443 | { | |
1444 | if (m_data) | |
1445 | delete m_data; | |
1446 | m_data = (wxVariantData*) variant.GetData()->GetClassInfo()->CreateObject(); | |
1447 | } | |
3d8daa0f | 1448 | |
4fabb575 | 1449 | variant.GetData()->Copy(* GetData()); |
3d8daa0f VZ |
1450 | |
1451 | m_name = variant.m_name; | |
341287bf JS |
1452 | } |
1453 | ||
1454 | // Assignment using data, e.g. | |
1455 | // myVariant = new wxStringVariantData("hello") | |
1456 | void wxVariant::operator= (wxVariantData* variantData) | |
1457 | { | |
1458 | MakeNull(); | |
1459 | m_data = variantData; | |
1460 | } | |
1461 | ||
1462 | bool wxVariant::operator== (const wxVariant& variant) const | |
1463 | { | |
1464 | if (IsNull() || variant.IsNull()) | |
1465 | return (IsNull() == variant.IsNull()); | |
1466 | ||
1467 | return (GetData()->Eq(* variant.GetData())); | |
1468 | } | |
1469 | ||
1470 | bool wxVariant::operator!= (const wxVariant& variant) const | |
1471 | { | |
1472 | return (!(*this == variant)); | |
1473 | } | |
1474 | ||
1475 | ||
1476 | // Specific operators | |
1477 | bool wxVariant::operator== (double value) const | |
1478 | { | |
1479 | double thisValue; | |
1480 | if (!Convert(&thisValue)) | |
dc259b79 | 1481 | return FALSE; |
341287bf JS |
1482 | else |
1483 | return (value == thisValue); | |
1484 | } | |
1485 | ||
1486 | bool wxVariant::operator!= (double value) const | |
1487 | { | |
1488 | return (!((*this) == value)); | |
1489 | } | |
1490 | ||
1491 | void wxVariant::operator= (double value) | |
1492 | { | |
223d09f6 | 1493 | if (GetType() == wxT("double")) |
341287bf JS |
1494 | { |
1495 | ((wxVariantDataReal*)GetData())->SetValue(value); | |
1496 | } | |
1497 | else | |
1498 | { | |
1499 | if (m_data) | |
1500 | delete m_data; | |
1501 | m_data = new wxVariantDataReal(value); | |
1502 | } | |
1503 | } | |
1504 | ||
1505 | bool wxVariant::operator== (long value) const | |
1506 | { | |
1507 | long thisValue; | |
1508 | if (!Convert(&thisValue)) | |
dc259b79 | 1509 | return FALSE; |
341287bf JS |
1510 | else |
1511 | return (value == thisValue); | |
1512 | } | |
1513 | ||
1514 | bool wxVariant::operator!= (long value) const | |
1515 | { | |
1516 | return (!((*this) == value)); | |
1517 | } | |
1518 | ||
1519 | void wxVariant::operator= (long value) | |
1520 | { | |
223d09f6 | 1521 | if (GetType() == wxT("long")) |
341287bf JS |
1522 | { |
1523 | ((wxVariantDataLong*)GetData())->SetValue(value); | |
1524 | } | |
1525 | else | |
1526 | { | |
1527 | if (m_data) | |
1528 | delete m_data; | |
1529 | m_data = new wxVariantDataLong(value); | |
1530 | } | |
1531 | } | |
1532 | ||
1533 | bool wxVariant::operator== (char value) const | |
1534 | { | |
1535 | char thisValue; | |
1536 | if (!Convert(&thisValue)) | |
dc259b79 | 1537 | return FALSE; |
341287bf JS |
1538 | else |
1539 | return (value == thisValue); | |
1540 | } | |
1541 | ||
1542 | bool wxVariant::operator!= (char value) const | |
1543 | { | |
1544 | return (!((*this) == value)); | |
1545 | } | |
1546 | ||
1547 | void wxVariant::operator= (char value) | |
1548 | { | |
223d09f6 | 1549 | if (GetType() == wxT("char")) |
341287bf JS |
1550 | { |
1551 | ((wxVariantDataChar*)GetData())->SetValue(value); | |
1552 | } | |
1553 | else | |
1554 | { | |
1555 | if (m_data) | |
1556 | delete m_data; | |
1557 | m_data = new wxVariantDataChar(value); | |
1558 | } | |
1559 | } | |
1560 | ||
57493f9f | 1561 | #ifdef HAVE_BOOL |
341287bf JS |
1562 | bool wxVariant::operator== (bool value) const |
1563 | { | |
1564 | bool thisValue; | |
1565 | if (!Convert(&thisValue)) | |
dc259b79 | 1566 | return FALSE; |
341287bf JS |
1567 | else |
1568 | return (value == thisValue); | |
1569 | } | |
1570 | ||
1571 | bool wxVariant::operator!= (bool value) const | |
1572 | { | |
1573 | return (!((*this) == value)); | |
1574 | } | |
1575 | ||
1576 | void wxVariant::operator= (bool value) | |
1577 | { | |
223d09f6 | 1578 | if (GetType() == wxT("bool")) |
341287bf JS |
1579 | { |
1580 | ((wxVariantDataBool*)GetData())->SetValue(value); | |
1581 | } | |
1582 | else | |
1583 | { | |
1584 | if (m_data) | |
1585 | delete m_data; | |
1586 | m_data = new wxVariantDataBool(value); | |
1587 | } | |
1588 | } | |
57493f9f | 1589 | #endif // HAVE_BOOL |
341287bf JS |
1590 | |
1591 | bool wxVariant::operator== (const wxString& value) const | |
1592 | { | |
1593 | wxString thisValue; | |
1594 | if (!Convert(&thisValue)) | |
dc259b79 | 1595 | return FALSE; |
f6bcfd97 BP |
1596 | |
1597 | return value == thisValue; | |
341287bf JS |
1598 | } |
1599 | ||
1600 | bool wxVariant::operator!= (const wxString& value) const | |
1601 | { | |
1602 | return (!((*this) == value)); | |
1603 | } | |
1604 | ||
1605 | void wxVariant::operator= (const wxString& value) | |
1606 | { | |
223d09f6 | 1607 | if (GetType() == wxT("string")) |
341287bf JS |
1608 | { |
1609 | ((wxVariantDataString*)GetData())->SetValue(value); | |
1610 | } | |
1611 | else | |
1612 | { | |
1613 | if (m_data) | |
1614 | delete m_data; | |
1615 | m_data = new wxVariantDataString(value); | |
1616 | } | |
1617 | } | |
1618 | ||
783b6cfd | 1619 | void wxVariant::operator= (const wxChar* value) |
341287bf | 1620 | { |
223d09f6 | 1621 | if (GetType() == wxT("string")) |
341287bf JS |
1622 | { |
1623 | ((wxVariantDataString*)GetData())->SetValue(wxString(value)); | |
1624 | } | |
1625 | else | |
1626 | { | |
1627 | if (m_data) | |
1628 | delete m_data; | |
1629 | m_data = new wxVariantDataString(wxString(value)); | |
1630 | } | |
1631 | } | |
1632 | ||
1633 | bool wxVariant::operator== (const wxStringList& value) const | |
1634 | { | |
223d09f6 | 1635 | wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") ); |
341287bf JS |
1636 | |
1637 | wxVariantDataStringList other(value); | |
1638 | return (m_data->Eq(other)); | |
1639 | } | |
1640 | ||
1641 | bool wxVariant::operator!= (const wxStringList& value) const | |
1642 | { | |
1643 | return (!((*this) == value)); | |
1644 | } | |
1645 | ||
1646 | void wxVariant::operator= (const wxStringList& value) | |
1647 | { | |
223d09f6 | 1648 | if (GetType() == wxT("stringlist")) |
341287bf JS |
1649 | { |
1650 | ((wxVariantDataStringList*)GetData())->SetValue(value); | |
1651 | } | |
1652 | else | |
1653 | { | |
1654 | if (m_data) | |
1655 | delete m_data; | |
1656 | m_data = new wxVariantDataStringList(value); | |
1657 | } | |
1658 | } | |
1659 | ||
1660 | bool wxVariant::operator== (const wxList& value) const | |
1661 | { | |
223d09f6 | 1662 | wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for == operator") ); |
341287bf JS |
1663 | |
1664 | wxVariantDataList other(value); | |
1665 | return (m_data->Eq(other)); | |
1666 | } | |
1667 | ||
1668 | bool wxVariant::operator!= (const wxList& value) const | |
1669 | { | |
1670 | return (!((*this) == value)); | |
1671 | } | |
1672 | ||
1673 | void wxVariant::operator= (const wxList& value) | |
1674 | { | |
223d09f6 | 1675 | if (GetType() == wxT("list")) |
341287bf JS |
1676 | { |
1677 | ((wxVariantDataList*)GetData())->SetValue(value); | |
1678 | } | |
1679 | else | |
1680 | { | |
1681 | if (m_data) | |
1682 | delete m_data; | |
1683 | m_data = new wxVariantDataList(value); | |
1684 | } | |
1685 | } | |
1686 | ||
457e6c54 JS |
1687 | // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled |
1688 | #if wxUSE_TIMEDATE && !defined(__WATCOMC__) | |
a0a302dc JS |
1689 | bool wxVariant::operator== (const wxTime& value) const |
1690 | { | |
1691 | wxTime thisValue; | |
1692 | if (!Convert(&thisValue)) | |
dc259b79 | 1693 | return FALSE; |
f6bcfd97 BP |
1694 | |
1695 | return value == thisValue; | |
a0a302dc JS |
1696 | } |
1697 | ||
1698 | bool wxVariant::operator!= (const wxTime& value) const | |
1699 | { | |
1700 | return (!((*this) == value)); | |
1701 | } | |
1702 | ||
1703 | void wxVariant::operator= (const wxTime& value) | |
1704 | { | |
223d09f6 | 1705 | if (GetType() == wxT("time")) |
a0a302dc JS |
1706 | { |
1707 | ((wxVariantDataTime*)GetData())->SetValue(value); | |
1708 | } | |
1709 | else | |
1710 | { | |
1711 | if (m_data) | |
1712 | delete m_data; | |
1713 | m_data = new wxVariantDataTime(value); | |
1714 | } | |
1715 | } | |
1716 | ||
1717 | bool wxVariant::operator== (const wxDate& value) const | |
1718 | { | |
1719 | wxDate thisValue; | |
1720 | if (!Convert(&thisValue)) | |
dc259b79 | 1721 | return FALSE; |
f6bcfd97 BP |
1722 | |
1723 | return (value == thisValue); | |
a0a302dc JS |
1724 | } |
1725 | ||
1726 | bool wxVariant::operator!= (const wxDate& value) const | |
1727 | { | |
1728 | return (!((*this) == value)); | |
1729 | } | |
1730 | ||
1731 | void wxVariant::operator= (const wxDate& value) | |
1732 | { | |
223d09f6 | 1733 | if (GetType() == wxT("date")) |
a0a302dc JS |
1734 | { |
1735 | ((wxVariantDataTime*)GetData())->SetValue(value); | |
1736 | } | |
1737 | else | |
1738 | { | |
1739 | if (m_data) | |
1740 | delete m_data; | |
1741 | m_data = new wxVariantDataDate(value); | |
1742 | } | |
1743 | } | |
1744 | #endif | |
1745 | ||
1746 | bool wxVariant::operator== (void* value) const | |
1747 | { | |
1748 | return (value == ((wxVariantDataVoidPtr*)GetData())->GetValue()); | |
1749 | } | |
1750 | ||
1751 | bool wxVariant::operator!= (void* value) const | |
1752 | { | |
f6bcfd97 | 1753 | return (!((*this) == (void*) value)); |
a0a302dc JS |
1754 | } |
1755 | ||
1756 | void wxVariant::operator= (void* value) | |
1757 | { | |
223d09f6 | 1758 | if (GetType() == wxT("void*")) |
a0a302dc JS |
1759 | { |
1760 | ((wxVariantDataVoidPtr*)GetData())->SetValue(value); | |
1761 | } | |
1762 | else | |
1763 | { | |
1764 | if (m_data) | |
1765 | delete m_data; | |
1766 | m_data = new wxVariantDataVoidPtr(value); | |
1767 | } | |
1768 | } | |
341287bf | 1769 | |
e2b87f38 | 1770 | #if wxUSE_DATETIME |
edca7a82 GT |
1771 | bool wxVariant::operator== (const wxDateTime& value) const |
1772 | { | |
1773 | wxDateTime thisValue; | |
1774 | if (!Convert(&thisValue)) | |
dc259b79 | 1775 | return FALSE; |
edca7a82 GT |
1776 | |
1777 | return value.IsEqualTo(thisValue); | |
1778 | } | |
1779 | ||
1780 | bool wxVariant::operator!= (const wxDateTime& value) const | |
1781 | { | |
1782 | return (!((*this) == value)); | |
1783 | } | |
1784 | ||
1785 | void wxVariant::operator= (const wxDateTime& value) | |
1786 | { | |
1787 | if (GetType() == wxT("datetime")) | |
1788 | { | |
1789 | ((wxVariantDataDateTime*)GetData())->SetValue(value); | |
1790 | } | |
1791 | else | |
1792 | { | |
1793 | if (m_data) | |
1794 | delete m_data; | |
1795 | m_data = new wxVariantDataDateTime(value); | |
1796 | } | |
1797 | } | |
e2b87f38 | 1798 | #endif // wxUSE_DATETIME |
edca7a82 | 1799 | |
edca7a82 GT |
1800 | #if wxUSE_ODBC |
1801 | void wxVariant::operator= (const DATE_STRUCT* value) | |
1802 | { | |
1803 | if (m_data) | |
1804 | delete m_data; | |
1805 | m_data = new wxVariantDataDateTime(value); | |
1806 | } | |
1807 | ||
1808 | ||
1809 | void wxVariant::operator= (const TIME_STRUCT* value) | |
1810 | { | |
1811 | if (m_data) | |
1812 | delete m_data; | |
1813 | m_data = new wxVariantDataDateTime(value); | |
1814 | } | |
1815 | ||
1816 | ||
1817 | void wxVariant::operator= (const TIMESTAMP_STRUCT* value) | |
1818 | { | |
1819 | if (m_data) | |
1820 | delete m_data; | |
1821 | m_data = new wxVariantDataDateTime(value); | |
1822 | } | |
1823 | ||
fb42d7c3 VZ |
1824 | #endif // wxUSE_ODBC |
1825 | ||
574c939e | 1826 | bool wxVariant::operator==(const wxArrayString& WXUNUSED(value)) const |
fb42d7c3 VZ |
1827 | { |
1828 | wxFAIL_MSG( _T("TODO") ); | |
1829 | ||
dc259b79 | 1830 | return FALSE; |
fb42d7c3 VZ |
1831 | } |
1832 | ||
1833 | bool wxVariant::operator!=(const wxArrayString& value) const | |
1834 | { | |
1835 | return !(*this == value); | |
1836 | } | |
1837 | ||
1838 | void wxVariant::operator=(const wxArrayString& value) | |
1839 | { | |
1840 | if (GetType() == wxT("arrstring")) | |
1841 | { | |
1842 | ((wxVariantDataArrayString *)GetData())->SetValue(value); | |
1843 | } | |
1844 | else | |
1845 | { | |
1846 | delete m_data; | |
1847 | m_data = new wxVariantDataArrayString(value); | |
1848 | } | |
1849 | } | |
1850 | ||
1851 | wxArrayString wxVariant::GetArrayString() const | |
1852 | { | |
1853 | if ( GetType() == wxT("arrstring") ) | |
1854 | return ((wxVariantDataArrayString *)GetData())->GetValue(); | |
1855 | ||
1856 | return wxArrayString(); | |
1857 | } | |
1858 | ||
edca7a82 | 1859 | |
341287bf JS |
1860 | // Treat a list variant as an array |
1861 | wxVariant wxVariant::operator[] (size_t idx) const | |
1862 | { | |
223d09f6 | 1863 | wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for array operator") ); |
341287bf | 1864 | |
223d09f6 | 1865 | if (GetType() == wxT("list")) |
341287bf JS |
1866 | { |
1867 | wxVariantDataList* data = (wxVariantDataList*) m_data; | |
b1d4dd7a RL |
1868 | wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") ); |
1869 | return * (wxVariant*) (data->GetValue().Item(idx)->GetData()); | |
341287bf | 1870 | } |
223d09f6 | 1871 | else if (GetType() == wxT("stringlist")) |
341287bf JS |
1872 | { |
1873 | wxVariantDataStringList* data = (wxVariantDataStringList*) m_data; | |
b1d4dd7a | 1874 | wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") ); |
341287bf | 1875 | |
b1d4dd7a | 1876 | wxVariant variant( wxString( (wxChar*) (data->GetValue().Item(idx)->GetData()) )); |
341287bf JS |
1877 | return variant; |
1878 | } | |
1879 | return wxNullVariant; | |
1880 | } | |
1881 | ||
1882 | wxVariant& wxVariant::operator[] (size_t idx) | |
1883 | { | |
1884 | // We can't return a reference to a variant for a string list, since the string | |
1885 | // is actually stored as a char*, not a variant. | |
1886 | ||
223d09f6 | 1887 | wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") ); |
341287bf JS |
1888 | |
1889 | wxVariantDataList* data = (wxVariantDataList*) m_data; | |
b1d4dd7a | 1890 | wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") ); |
341287bf | 1891 | |
b1d4dd7a | 1892 | return * (wxVariant*) (data->GetValue().Item(idx)->GetData()); |
341287bf JS |
1893 | } |
1894 | ||
1895 | // Return the number of elements in a list | |
1896 | int wxVariant::GetCount() const | |
1897 | { | |
223d09f6 | 1898 | wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for GetCount()") ); |
341287bf | 1899 | |
223d09f6 | 1900 | if (GetType() == wxT("list")) |
341287bf JS |
1901 | { |
1902 | wxVariantDataList* data = (wxVariantDataList*) m_data; | |
b1d4dd7a | 1903 | return data->GetValue().GetCount(); |
341287bf | 1904 | } |
223d09f6 | 1905 | else if (GetType() == wxT("stringlist")) |
341287bf JS |
1906 | { |
1907 | wxVariantDataStringList* data = (wxVariantDataStringList*) m_data; | |
b1d4dd7a | 1908 | return data->GetValue().GetCount(); |
341287bf JS |
1909 | } |
1910 | return 0; | |
1911 | } | |
1912 | ||
1913 | wxString wxVariant::MakeString() const | |
1914 | { | |
1915 | if (!IsNull()) | |
1916 | { | |
1917 | wxString str; | |
1918 | if (GetData()->Write(str)) | |
1919 | return str; | |
1920 | } | |
223d09f6 | 1921 | return wxString(wxT("")); |
341287bf JS |
1922 | } |
1923 | ||
1924 | // Accessors | |
1925 | ||
1926 | void wxVariant::SetData(wxVariantData* data) | |
1927 | { | |
1928 | if (m_data) delete m_data; | |
1929 | m_data = data; | |
1930 | } | |
1931 | ||
1932 | ||
1933 | // Returns a string representing the type of the variant, | |
1934 | // e.g. "string", "bool", "stringlist", "list", "double", "long" | |
1935 | wxString wxVariant::GetType() const | |
1936 | { | |
1937 | if (IsNull()) | |
223d09f6 | 1938 | return wxString(wxT("null")); |
341287bf JS |
1939 | else |
1940 | return m_data->GetType(); | |
1941 | } | |
1942 | ||
1943 | ||
1944 | bool wxVariant::IsType(const wxString& type) const | |
1945 | { | |
1946 | return (GetType() == type); | |
1947 | } | |
1948 | ||
1949 | ||
1950 | // Value accessors | |
1951 | double wxVariant::GetReal() const | |
1952 | { | |
1953 | double value; | |
1954 | if (Convert(& value)) | |
1955 | return value; | |
1956 | else | |
1957 | { | |
223d09f6 | 1958 | wxFAIL_MSG(wxT("Could not convert to a real number")); |
341287bf JS |
1959 | return 0.0; |
1960 | } | |
1961 | } | |
1962 | ||
1963 | long wxVariant::GetInteger() const | |
1964 | { | |
1965 | long value; | |
1966 | if (Convert(& value)) | |
1967 | return value; | |
1968 | else | |
1969 | { | |
223d09f6 | 1970 | wxFAIL_MSG(wxT("Could not convert to an integer")); |
341287bf JS |
1971 | return 0; |
1972 | } | |
1973 | } | |
1974 | ||
1975 | char wxVariant::GetChar() const | |
1976 | { | |
1977 | char value; | |
1978 | if (Convert(& value)) | |
1979 | return value; | |
1980 | else | |
1981 | { | |
223d09f6 | 1982 | wxFAIL_MSG(wxT("Could not convert to a char")); |
341287bf JS |
1983 | return 0; |
1984 | } | |
1985 | } | |
1986 | ||
1987 | bool wxVariant::GetBool() const | |
1988 | { | |
1989 | bool value; | |
1990 | if (Convert(& value)) | |
1991 | return value; | |
1992 | else | |
1993 | { | |
223d09f6 | 1994 | wxFAIL_MSG(wxT("Could not convert to a bool")); |
341287bf JS |
1995 | return 0; |
1996 | } | |
1997 | } | |
1998 | ||
1999 | wxString wxVariant::GetString() const | |
2000 | { | |
2001 | wxString value; | |
f6bcfd97 | 2002 | if (!Convert(& value)) |
341287bf | 2003 | { |
223d09f6 | 2004 | wxFAIL_MSG(wxT("Could not convert to a string")); |
341287bf | 2005 | } |
f6bcfd97 BP |
2006 | |
2007 | return value; | |
341287bf JS |
2008 | } |
2009 | ||
457e6c54 JS |
2010 | // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled |
2011 | #if wxUSE_TIMEDATE && !defined(__WATCOMC__) | |
a0a302dc JS |
2012 | wxTime wxVariant::GetTime() const |
2013 | { | |
2014 | wxTime value; | |
f6bcfd97 | 2015 | if (!Convert(& value)) |
a0a302dc | 2016 | { |
223d09f6 | 2017 | wxFAIL_MSG(wxT("Could not convert to a time")); |
a0a302dc | 2018 | } |
f6bcfd97 BP |
2019 | |
2020 | return value; | |
a0a302dc JS |
2021 | } |
2022 | ||
2023 | wxDate wxVariant::GetDate() const | |
2024 | { | |
2025 | wxDate value; | |
f6bcfd97 | 2026 | if (!Convert(& value)) |
a0a302dc | 2027 | { |
223d09f6 | 2028 | wxFAIL_MSG(wxT("Could not convert to a date")); |
a0a302dc | 2029 | } |
f6bcfd97 BP |
2030 | |
2031 | return value; | |
a0a302dc | 2032 | } |
f6bcfd97 | 2033 | #endif // wxUSE_TIMEDATE |
a0a302dc JS |
2034 | |
2035 | void* wxVariant::GetVoidPtr() const | |
2036 | { | |
223d09f6 | 2037 | wxASSERT( (GetType() == wxT("void*")) ); |
a0a302dc JS |
2038 | |
2039 | return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue(); | |
2040 | } | |
2041 | ||
e2b87f38 | 2042 | #if wxUSE_DATETIME |
edca7a82 GT |
2043 | wxDateTime wxVariant::GetDateTime() const |
2044 | { | |
2045 | wxDateTime value; | |
2046 | if (!Convert(& value)) | |
2047 | { | |
2048 | wxFAIL_MSG(wxT("Could not convert to a datetime")); | |
2049 | } | |
2050 | ||
2051 | return value; | |
2052 | } | |
e2b87f38 | 2053 | #endif // wxUSE_DATETIME |
edca7a82 | 2054 | |
341287bf JS |
2055 | wxList& wxVariant::GetList() const |
2056 | { | |
223d09f6 | 2057 | wxASSERT( (GetType() == wxT("list")) ); |
341287bf JS |
2058 | |
2059 | return (wxList&) ((wxVariantDataList*) m_data)->GetValue(); | |
2060 | } | |
2061 | ||
2062 | wxStringList& wxVariant::GetStringList() const | |
2063 | { | |
223d09f6 | 2064 | wxASSERT( (GetType() == wxT("stringlist")) ); |
341287bf JS |
2065 | |
2066 | return (wxStringList&) ((wxVariantDataStringList*) m_data)->GetValue(); | |
2067 | } | |
2068 | ||
5dfe6069 VZ |
2069 | // Make empty list |
2070 | void wxVariant::NullList() | |
2071 | { | |
2072 | SetData(new wxVariantDataList()); | |
2073 | }; | |
2074 | ||
341287bf JS |
2075 | // Append to list |
2076 | void wxVariant::Append(const wxVariant& value) | |
2077 | { | |
2078 | wxList& list = GetList(); | |
2079 | ||
2080 | list.Append(new wxVariant(value)); | |
2081 | } | |
2082 | ||
2083 | // Insert at front of list | |
2084 | void wxVariant::Insert(const wxVariant& value) | |
2085 | { | |
2086 | wxList& list = GetList(); | |
2087 | ||
2088 | list.Insert(new wxVariant(value)); | |
2089 | } | |
2090 | ||
dc259b79 | 2091 | // Returns TRUE if the variant is a member of the list |
341287bf JS |
2092 | bool wxVariant::Member(const wxVariant& value) const |
2093 | { | |
2094 | wxList& list = GetList(); | |
2095 | ||
b1d4dd7a | 2096 | wxNode* node = list.GetFirst(); |
341287bf JS |
2097 | while (node) |
2098 | { | |
b1d4dd7a | 2099 | wxVariant* other = (wxVariant*) node->GetData(); |
341287bf | 2100 | if (value == *other) |
dc259b79 | 2101 | return TRUE; |
b1d4dd7a | 2102 | node = node->GetNext(); |
341287bf | 2103 | } |
dc259b79 | 2104 | return FALSE; |
341287bf JS |
2105 | } |
2106 | ||
2107 | // Deletes the nth element of the list | |
2108 | bool wxVariant::Delete(int item) | |
2109 | { | |
2110 | wxList& list = GetList(); | |
2111 | ||
b1d4dd7a RL |
2112 | wxASSERT_MSG( (item < (int) list.GetCount()), wxT("Invalid index to Delete") ); |
2113 | wxNode* node = list.Item(item); | |
2114 | wxVariant* variant = (wxVariant*) node->GetData(); | |
341287bf JS |
2115 | delete variant; |
2116 | delete node; | |
dc259b79 | 2117 | return TRUE; |
341287bf JS |
2118 | } |
2119 | ||
2120 | // Clear list | |
2121 | void wxVariant::ClearList() | |
2122 | { | |
223d09f6 | 2123 | if (!IsNull() && (GetType() == wxT("list"))) |
341287bf JS |
2124 | { |
2125 | ((wxVariantDataList*) m_data)->Clear(); | |
2126 | } | |
2127 | else | |
2128 | { | |
223d09f6 | 2129 | if (GetType() != wxT("list")) |
341287bf JS |
2130 | { |
2131 | delete m_data; | |
2132 | m_data = NULL; | |
2133 | } | |
2134 | m_data = new wxVariantDataList; | |
2135 | } | |
2136 | } | |
2137 | ||
2138 | // Type conversion | |
2139 | bool wxVariant::Convert(long* value) const | |
2140 | { | |
2141 | wxString type(GetType()); | |
223d09f6 | 2142 | if (type == wxT("double")) |
341287bf | 2143 | *value = (long) (((wxVariantDataReal*)GetData())->GetValue()); |
223d09f6 | 2144 | else if (type == wxT("long")) |
341287bf | 2145 | *value = ((wxVariantDataLong*)GetData())->GetValue(); |
862416e0 | 2146 | #ifdef HAVE_BOOL |
223d09f6 | 2147 | else if (type == wxT("bool")) |
341287bf | 2148 | *value = (long) (((wxVariantDataBool*)GetData())->GetValue()); |
862416e0 | 2149 | #endif |
223d09f6 | 2150 | else if (type == wxT("string")) |
783b6cfd | 2151 | *value = wxAtol((const wxChar*) ((wxVariantDataString*)GetData())->GetValue()); |
341287bf | 2152 | else |
dc259b79 | 2153 | return FALSE; |
341287bf | 2154 | |
dc259b79 | 2155 | return TRUE; |
341287bf JS |
2156 | } |
2157 | ||
2158 | bool wxVariant::Convert(bool* value) const | |
2159 | { | |
2160 | wxString type(GetType()); | |
223d09f6 | 2161 | if (type == wxT("double")) |
341287bf | 2162 | *value = ((int) (((wxVariantDataReal*)GetData())->GetValue()) != 0); |
223d09f6 | 2163 | else if (type == wxT("long")) |
341287bf | 2164 | *value = (((wxVariantDataLong*)GetData())->GetValue() != 0); |
862416e0 | 2165 | #ifdef HAVE_BOOL |
223d09f6 | 2166 | else if (type == wxT("bool")) |
341287bf | 2167 | *value = ((wxVariantDataBool*)GetData())->GetValue(); |
862416e0 | 2168 | #endif |
223d09f6 | 2169 | else if (type == wxT("string")) |
341287bf JS |
2170 | { |
2171 | wxString val(((wxVariantDataString*)GetData())->GetValue()); | |
2172 | val.MakeLower(); | |
dc259b79 DW |
2173 | if (val == wxT("TRUE") || val == wxT("yes")) |
2174 | *value = TRUE; | |
2175 | else if (val == wxT("FALSE") || val == wxT("no")) | |
2176 | *value = FALSE; | |
341287bf | 2177 | else |
dc259b79 | 2178 | return FALSE; |
341287bf JS |
2179 | } |
2180 | else | |
dc259b79 | 2181 | return FALSE; |
341287bf | 2182 | |
dc259b79 | 2183 | return TRUE; |
341287bf JS |
2184 | } |
2185 | ||
2186 | bool wxVariant::Convert(double* value) const | |
2187 | { | |
2188 | wxString type(GetType()); | |
223d09f6 | 2189 | if (type == wxT("double")) |
341287bf | 2190 | *value = ((wxVariantDataReal*)GetData())->GetValue(); |
223d09f6 | 2191 | else if (type == wxT("long")) |
341287bf | 2192 | *value = (double) (((wxVariantDataLong*)GetData())->GetValue()); |
862416e0 | 2193 | #ifdef HAVE_BOOL |
223d09f6 | 2194 | else if (type == wxT("bool")) |
341287bf | 2195 | *value = (double) (((wxVariantDataBool*)GetData())->GetValue()); |
862416e0 | 2196 | #endif |
223d09f6 | 2197 | else if (type == wxT("string")) |
783b6cfd | 2198 | *value = (double) wxAtof((const wxChar*) ((wxVariantDataString*)GetData())->GetValue()); |
341287bf | 2199 | else |
dc259b79 | 2200 | return FALSE; |
341287bf | 2201 | |
dc259b79 | 2202 | return TRUE; |
341287bf JS |
2203 | } |
2204 | ||
2205 | bool wxVariant::Convert(char* value) const | |
2206 | { | |
2207 | wxString type(GetType()); | |
223d09f6 | 2208 | if (type == wxT("char")) |
341287bf | 2209 | *value = ((wxVariantDataChar*)GetData())->GetValue(); |
223d09f6 | 2210 | else if (type == wxT("long")) |
341287bf | 2211 | *value = (char) (((wxVariantDataLong*)GetData())->GetValue()); |
862416e0 | 2212 | #ifdef HAVE_BOOL |
223d09f6 | 2213 | else if (type == wxT("bool")) |
341287bf | 2214 | *value = (char) (((wxVariantDataBool*)GetData())->GetValue()); |
862416e0 | 2215 | #endif |
341287bf | 2216 | else |
dc259b79 | 2217 | return FALSE; |
341287bf | 2218 | |
dc259b79 | 2219 | return TRUE; |
341287bf JS |
2220 | } |
2221 | ||
2222 | bool wxVariant::Convert(wxString* value) const | |
2223 | { | |
2224 | *value = MakeString(); | |
dc259b79 | 2225 | return TRUE; |
341287bf JS |
2226 | } |
2227 | ||
457e6c54 JS |
2228 | // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled |
2229 | #if wxUSE_TIMEDATE && !defined(__WATCOMC__) | |
a0a302dc JS |
2230 | bool wxVariant::Convert(wxTime* value) const |
2231 | { | |
2232 | wxString type(GetType()); | |
223d09f6 | 2233 | if (type == wxT("time")) |
a0a302dc | 2234 | *value = ((wxVariantDataTime*)GetData())->GetValue(); |
223d09f6 | 2235 | else if (type == wxT("date")) |
a0a302dc JS |
2236 | *value = wxTime(((wxVariantDataDate*)GetData())->GetValue()); |
2237 | else | |
dc259b79 | 2238 | return FALSE; |
a0a302dc | 2239 | |
dc259b79 | 2240 | return TRUE; |
a0a302dc JS |
2241 | } |
2242 | ||
2243 | bool wxVariant::Convert(wxDate* value) const | |
2244 | { | |
2245 | wxString type(GetType()); | |
223d09f6 | 2246 | if (type == wxT("date")) |
a0a302dc JS |
2247 | *value = ((wxVariantDataDate*)GetData())->GetValue(); |
2248 | else | |
dc259b79 | 2249 | return FALSE; |
a0a302dc | 2250 | |
dc259b79 | 2251 | return TRUE; |
a0a302dc | 2252 | } |
edca7a82 GT |
2253 | #endif // wxUSE_TIMEDATE |
2254 | ||
e2b87f38 | 2255 | #if wxUSE_DATETIME |
edca7a82 GT |
2256 | bool wxVariant::Convert(wxDateTime* value) const |
2257 | { | |
2258 | wxString type(GetType()); | |
2259 | if (type == wxT("datetime")) | |
9708db20 | 2260 | { |
edca7a82 | 2261 | *value = ((wxVariantDataDateTime*)GetData())->GetValue(); |
dc259b79 DW |
2262 | return TRUE; |
2263 | } | |
9708db20 JS |
2264 | // Fallback to string conversion |
2265 | wxString val; | |
2266 | return Convert(&val) && (value->ParseDate(val)); | |
edca7a82 | 2267 | } |
b1e343f2 VZ |
2268 | #endif // wxUSE_DATETIME |
2269 |