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