]> git.saurik.com Git - wxWidgets.git/blob - src/common/variant.cpp
Sorry folks, a lot of changes to remedy GetFont, GetBrush etc.
[wxWidgets.git] / src / common / variant.cpp
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)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "variant.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #if wxUSE_IOSTREAMH
24 # include <fstream.h>
25 #else
26 # include <fstream>
27 # ifdef _MSC_VER
28 using namespace std;
29 # endif
30 #endif
31
32 #include "wx/stream.h"
33 #include "wx/string.h"
34 #include "wx/variant.h"
35
36 IMPLEMENT_ABSTRACT_CLASS(wxVariantData, wxObject)
37
38 wxVariant wxNullVariant;
39
40 /*
41 * wxVariantDataList
42 */
43
44 class WXDLLEXPORT wxVariantDataList: public wxVariantData
45 {
46 DECLARE_DYNAMIC_CLASS(wxVariantDataList)
47 public:
48 wxVariantDataList() {}
49 wxVariantDataList(const wxList& list);
50 ~wxVariantDataList();
51
52 wxList& GetValue() const { return (wxList&) m_value; }
53 void SetValue(const wxList& value) ;
54
55 virtual void Copy(wxVariantData& data);
56 virtual bool Eq(wxVariantData& data) const;
57 virtual bool Write(ostream& str) const;
58 virtual bool Write(wxString& str) const;
59 virtual bool Read(istream& str);
60 virtual bool Read(wxString& str);
61 virtual wxString GetType() const { return "list"; };
62
63 void Clear();
64
65 protected:
66 wxList m_value;
67 };
68
69 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataList, wxVariantData)
70
71 wxVariantDataList::wxVariantDataList(const wxList& list)
72 {
73 SetValue(list);
74 }
75
76 wxVariantDataList::~wxVariantDataList()
77 {
78 Clear();
79 }
80
81 void wxVariantDataList::SetValue(const wxList& value)
82 {
83 Clear();
84 wxNode* node = value.First();
85 while (node)
86 {
87 wxVariant* var = (wxVariant*) node->Data();
88 m_value.Append(new wxVariant(*var));
89 node = node->Next();
90 }
91 }
92
93 void wxVariantDataList::Clear()
94 {
95 wxNode* node = m_value.First();
96 while (node)
97 {
98 wxVariant* var = (wxVariant*) node->Data();
99 delete var;
100 node = node->Next();
101 }
102 m_value.Clear();
103 }
104
105 void wxVariantDataList::Copy(wxVariantData& data)
106 {
107 wxASSERT_MSG( (data.GetType() == "list"), "wxVariantDataList::Copy: Can't copy to this type of data" );
108
109 wxVariantDataList& listData = (wxVariantDataList&) data;
110
111 listData.Clear();
112 wxNode* node = m_value.First();
113 while (node)
114 {
115 wxVariant* var = (wxVariant*) node->Data();
116 listData.m_value.Append(new wxVariant(*var));
117 node = node->Next();
118 }
119 }
120
121 bool wxVariantDataList::Eq(wxVariantData& data) const
122 {
123 wxASSERT_MSG( (data.GetType() == "list"), "wxVariantDataList::Eq: argument mismatch" );
124
125 wxVariantDataList& listData = (wxVariantDataList&) data;
126 wxNode* node1 = m_value.First();
127 wxNode* node2 = listData.GetValue().First();
128 while (node1 && node2)
129 {
130 wxVariant* var1 = (wxVariant*) node1->Data();
131 wxVariant* var2 = (wxVariant*) node2->Data();
132 if ((*var1) != (*var2))
133 return FALSE;
134 node1 = node1->Next();
135 node2 = node2->Next();
136 }
137 if (node1 || node2) return FALSE;
138 return TRUE;
139 }
140
141 bool wxVariantDataList::Write(ostream& str) const
142 {
143 wxString s;
144 Write(s);
145 str << (const char*) s;
146 return TRUE;
147 }
148
149 bool wxVariantDataList::Write(wxString& str) const
150 {
151 str = "";
152 wxNode* node = m_value.First();
153 while (node)
154 {
155 wxVariant* var = (wxVariant*) node->Data();
156 if (node != m_value.First())
157 str += " ";
158 wxString str1;
159 str += var->MakeString();
160 node = node->Next();
161 }
162
163 return TRUE;
164 }
165
166 bool wxVariantDataList::Read(istream& WXUNUSED(str))
167 {
168 wxFAIL_MSG("Unimplemented");
169 // TODO
170 return FALSE;
171 }
172
173 bool wxVariantDataList::Read(wxString& WXUNUSED(str))
174 {
175 wxFAIL_MSG("Unimplemented");
176 // TODO
177 return FALSE;
178 }
179
180 /*
181 * wxVariantDataStringList
182 */
183
184 class WXDLLEXPORT wxVariantDataStringList: public wxVariantData
185 {
186 DECLARE_DYNAMIC_CLASS(wxVariantDataStringList)
187 public:
188 wxVariantDataStringList() {}
189 wxVariantDataStringList(const wxStringList& list) { m_value = list; }
190
191 wxStringList& GetValue() const { return (wxStringList&) m_value; }
192 void SetValue(const wxStringList& value);
193
194 virtual void Copy(wxVariantData& data);
195 virtual bool Eq(wxVariantData& data) const;
196 virtual bool Write(ostream& str) const;
197 virtual bool Write(wxString& str) const;
198 virtual bool Read(istream& str);
199 virtual bool Read(wxString& str);
200 virtual wxString GetType() const { return "stringlist"; };
201
202 protected:
203 wxStringList m_value;
204 };
205
206 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataStringList, wxVariantData)
207
208 void wxVariantDataStringList::SetValue(const wxStringList& value)
209 {
210 m_value = value;
211 }
212
213 void wxVariantDataStringList::Copy(wxVariantData& data)
214 {
215 wxASSERT_MSG( (data.GetType() == "stringlist"), "wxVariantDataStringList::Copy: Can't copy to this type of data" );
216
217 wxVariantDataStringList& listData = (wxVariantDataStringList&) data;
218
219 listData.m_value = m_value ;
220 }
221
222 bool wxVariantDataStringList::Eq(wxVariantData& data) const
223 {
224 wxASSERT_MSG( (data.GetType() == "stringlist"), "wxVariantDataStringList::Eq: argument mismatch" );
225
226 wxVariantDataStringList& listData = (wxVariantDataStringList&) data;
227 wxNode* node1 = m_value.First();
228 wxNode* node2 = listData.GetValue().First();
229 while (node1 && node2)
230 {
231 wxString str1 ((char*) node1->Data());
232 wxString str2 ((char*) node2->Data());
233 if (str1 != str2)
234 return FALSE;
235 node1 = node1->Next();
236 node2 = node2->Next();
237 }
238 if (node1 || node2) return FALSE;
239 return TRUE;
240 }
241
242 bool wxVariantDataStringList::Write(ostream& str) const
243 {
244 wxString s;
245 Write(s);
246 str << (const char*) s;
247 return TRUE;
248 }
249
250 bool wxVariantDataStringList::Write(wxString& str) const
251 {
252 str = "";
253 wxNode* node = m_value.First();
254 while (node)
255 {
256 char* s = (char*) node->Data();
257 if (node != m_value.First())
258 str += " ";
259 str += s;
260 node = node->Next();
261 }
262
263 return TRUE;
264 }
265
266 bool wxVariantDataStringList::Read(istream& WXUNUSED(str))
267 {
268 wxFAIL_MSG("Unimplemented");
269 // TODO
270 return FALSE;
271 }
272
273 bool wxVariantDataStringList::Read(wxString& WXUNUSED(str))
274 {
275 wxFAIL_MSG("Unimplemented");
276 // TODO
277 return FALSE;
278 }
279
280 /*
281 * wxVariantDataLong
282 */
283
284 class WXDLLEXPORT wxVariantDataLong: public wxVariantData
285 {
286 DECLARE_DYNAMIC_CLASS(wxVariantDataLong)
287 public:
288 wxVariantDataLong() { m_value = 0; }
289 wxVariantDataLong(long value) { m_value = value; }
290
291 inline long GetValue() const { return m_value; }
292 inline void SetValue(long value) { m_value = value; }
293
294 virtual void Copy(wxVariantData& data);
295 virtual bool Eq(wxVariantData& data) const;
296 virtual bool Write(ostream& str) const;
297 virtual bool Write(wxString& str) const;
298 virtual bool Write(wxOutputStream &str) const;
299 virtual bool Read(istream& str);
300 virtual bool Read(wxInputStream& str);
301 virtual bool Read(wxString& str);
302 virtual wxString GetType() const { return "long"; };
303
304 protected:
305 long m_value;
306 };
307
308 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataLong, wxVariantData)
309
310 void wxVariantDataLong::Copy(wxVariantData& data)
311 {
312 wxASSERT_MSG( (data.GetType() == "long"), "wxVariantDataLong::Copy: Can't copy to this type of data" );
313
314 wxVariantDataLong& otherData = (wxVariantDataLong&) data;
315
316 otherData.m_value = m_value;
317 }
318
319 bool wxVariantDataLong::Eq(wxVariantData& data) const
320 {
321 wxASSERT_MSG( (data.GetType() == "long"), "wxVariantDataLong::Eq: argument mismatch" );
322
323 wxVariantDataLong& otherData = (wxVariantDataLong&) data;
324
325 return (otherData.m_value == m_value);
326 }
327
328 bool wxVariantDataLong::Write(ostream& str) const
329 {
330 wxString s;
331 Write(s);
332 str << (const char*) s;
333 return TRUE;
334 }
335
336 bool wxVariantDataLong::Write(wxOutputStream& str) const
337 {
338 str << m_value;
339 return TRUE;
340 }
341
342 bool wxVariantDataLong::Write(wxString& str) const
343 {
344 str.Printf("%ld", m_value);
345 return TRUE;
346 }
347
348 bool wxVariantDataLong::Read(istream& str)
349 {
350 str >> m_value;
351 return TRUE;
352 }
353
354 bool wxVariantDataLong::Read(wxInputStream& str)
355 {
356 str >> m_value;
357 return TRUE;
358 }
359
360 bool wxVariantDataLong::Read(wxString& str)
361 {
362 m_value = atol((const char*) str);
363 return TRUE;
364 }
365
366 /*
367 * wxVariantDataReal
368 */
369
370 class WXDLLEXPORT wxVariantDataReal: public wxVariantData
371 {
372 DECLARE_DYNAMIC_CLASS(wxVariantDataReal)
373 public:
374 wxVariantDataReal() { m_value = 0.0; }
375 wxVariantDataReal(double value) { m_value = value; }
376
377 inline double GetValue() const { return m_value; }
378 inline void SetValue(double value) { m_value = value; }
379
380 virtual void Copy(wxVariantData& data);
381 virtual bool Eq(wxVariantData& data) const;
382 virtual bool Write(ostream& str) const;
383 virtual bool Write(wxString& str) const;
384 virtual bool Write(wxOutputStream &str) const;
385 virtual bool Read(istream& str);
386 virtual bool Read(wxInputStream& str);
387 virtual bool Read(wxString& str);
388 virtual wxString GetType() const { return "double"; };
389
390 protected:
391 double m_value;
392 };
393
394 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataReal, wxVariantData)
395
396 void wxVariantDataReal::Copy(wxVariantData& data)
397 {
398 wxASSERT_MSG( (data.GetType() == "double"), "wxVariantDataReal::Copy: Can't copy to this type of data" );
399
400 wxVariantDataReal& otherData = (wxVariantDataReal&) data;
401
402 otherData.m_value = m_value;
403 }
404
405 bool wxVariantDataReal::Eq(wxVariantData& data) const
406 {
407 wxASSERT_MSG( (data.GetType() == "double"), "wxVariantDataReal::Eq: argument mismatch" );
408
409 wxVariantDataReal& otherData = (wxVariantDataReal&) data;
410
411 return (otherData.m_value == m_value);
412 }
413
414 bool wxVariantDataReal::Write(ostream& str) const
415 {
416 wxString s;
417 Write(s);
418 str << (const char*) s;
419 return TRUE;
420 }
421
422 bool wxVariantDataReal::Write(wxOutputStream& str) const
423 {
424 str << m_value;
425 return TRUE;
426 }
427
428 bool wxVariantDataReal::Write(wxString& str) const
429 {
430 str.Printf("%.4f", m_value);
431 return TRUE;
432 }
433
434 bool wxVariantDataReal::Read(istream& str)
435 {
436 str >> m_value;
437 return TRUE;
438 }
439
440 bool wxVariantDataReal::Read(wxInputStream& str)
441 {
442 str >> (float&)m_value;
443 return TRUE;
444 }
445
446 bool wxVariantDataReal::Read(wxString& str)
447 {
448 m_value = atof((const char*) str);
449 return TRUE;
450 }
451
452 /*
453 * wxVariantDataBool
454 */
455
456 class WXDLLEXPORT wxVariantDataBool: public wxVariantData
457 {
458 DECLARE_DYNAMIC_CLASS(wxVariantDataBool)
459 public:
460 wxVariantDataBool() { m_value = 0; }
461 wxVariantDataBool(bool value) { m_value = value; }
462
463 inline bool GetValue() const { return m_value; }
464 inline void SetValue(bool value) { m_value = value; }
465
466 virtual void Copy(wxVariantData& data);
467 virtual bool Eq(wxVariantData& data) const;
468 virtual bool Write(ostream& str) const;
469 virtual bool Write(wxOutputStream& str) const;
470 virtual bool Write(wxString& str) const;
471 virtual bool Read(istream& str);
472 virtual bool Read(wxInputStream& str);
473 virtual bool Read(wxString& str);
474 virtual wxString GetType() const { return "bool"; };
475
476 protected:
477 bool m_value;
478 };
479
480 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataBool, wxVariantData)
481
482 void wxVariantDataBool::Copy(wxVariantData& data)
483 {
484 wxASSERT_MSG( (data.GetType() == "bool"), "wxVariantDataBool::Copy: Can't copy to this type of data" );
485
486 wxVariantDataBool& otherData = (wxVariantDataBool&) data;
487
488 otherData.m_value = m_value;
489 }
490
491 bool wxVariantDataBool::Eq(wxVariantData& data) const
492 {
493 wxASSERT_MSG( (data.GetType() == "bool"), "wxVariantDataBool::Eq: argument mismatch" );
494
495 wxVariantDataBool& otherData = (wxVariantDataBool&) data;
496
497 return (otherData.m_value == m_value);
498 }
499
500 bool wxVariantDataBool::Write(ostream& str) const
501 {
502 wxString s;
503 Write(s);
504 str << (const char*) s;
505 return TRUE;
506 }
507
508 bool wxVariantDataBool::Write(wxOutputStream& str) const
509 {
510 str << (char)m_value;
511 return TRUE;
512 }
513
514 bool wxVariantDataBool::Write(wxString& str) const
515 {
516 str.Printf("%d", (int) m_value);
517 return TRUE;
518 }
519
520 bool wxVariantDataBool::Read(istream& WXUNUSED(str))
521 {
522 wxFAIL_MSG("Unimplemented");
523 // str >> (long) m_value;
524 return FALSE;
525 }
526
527 bool wxVariantDataBool::Read(wxInputStream& str)
528 {
529 str >> (char&)m_value;
530 return TRUE;
531 }
532
533 bool wxVariantDataBool::Read(wxString& str)
534 {
535 m_value = (atol((const char*) str) != 0);
536 return TRUE;
537 }
538
539 /*
540 * wxVariantDataChar
541 */
542
543 class WXDLLEXPORT wxVariantDataChar: public wxVariantData
544 {
545 DECLARE_DYNAMIC_CLASS(wxVariantDataChar)
546 public:
547 wxVariantDataChar() { m_value = 0; }
548 wxVariantDataChar(char value) { m_value = value; }
549
550 inline char GetValue() const { return m_value; }
551 inline void SetValue(char value) { m_value = value; }
552
553 virtual void Copy(wxVariantData& data);
554 virtual bool Eq(wxVariantData& data) const;
555 virtual bool Write(ostream& str) const;
556 virtual bool Write(wxOutputStream& str) const;
557 virtual bool Write(wxString& str) const;
558 virtual bool Read(istream& str);
559 virtual bool Read(wxInputStream& str);
560 virtual bool Read(wxString& str);
561 virtual wxString GetType() const { return "char"; };
562
563 protected:
564 char m_value;
565 };
566
567 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataChar, wxVariantData)
568
569 void wxVariantDataChar::Copy(wxVariantData& data)
570 {
571 wxASSERT_MSG( (data.GetType() == "char"), "wxVariantDataChar::Copy: Can't copy to this type of data" );
572
573 wxVariantDataChar& otherData = (wxVariantDataChar&) data;
574
575 otherData.m_value = m_value;
576 }
577
578 bool wxVariantDataChar::Eq(wxVariantData& data) const
579 {
580 wxASSERT_MSG( (data.GetType() == "char"), "wxVariantDataChar::Eq: argument mismatch" );
581
582 wxVariantDataChar& otherData = (wxVariantDataChar&) data;
583
584 return (otherData.m_value == m_value);
585 }
586
587 bool wxVariantDataChar::Write(ostream& str) const
588 {
589 wxString s;
590 Write(s);
591 str << (const char*) s;
592 return TRUE;
593 }
594
595 bool wxVariantDataChar::Write(wxOutputStream& str) const
596 {
597 str << m_value;
598 return TRUE;
599 }
600
601 bool wxVariantDataChar::Write(wxString& str) const
602 {
603 str.Printf("%c", m_value);
604 return TRUE;
605 }
606
607 bool wxVariantDataChar::Read(istream& WXUNUSED(str))
608 {
609 wxFAIL_MSG("Unimplemented");
610 // str >> m_value;
611 return FALSE;
612 }
613
614 bool wxVariantDataChar::Read(wxInputStream& str)
615 {
616 str >> m_value;
617 return TRUE;
618 }
619
620 bool wxVariantDataChar::Read(wxString& str)
621 {
622 m_value = str[(size_t)0];
623 return TRUE;
624 }
625
626 /*
627 * wxVariantDataString
628 */
629
630 class WXDLLEXPORT wxVariantDataString: public wxVariantData
631 {
632 DECLARE_DYNAMIC_CLASS(wxVariantDataString)
633 public:
634 wxVariantDataString() { }
635 wxVariantDataString(const wxString& value) { m_value = value; }
636
637 inline wxString GetValue() const { return m_value; }
638 inline void SetValue(const wxString& value) { m_value = value; }
639
640 virtual void Copy(wxVariantData& data);
641 virtual bool Eq(wxVariantData& data) const;
642 virtual bool Write(ostream& str) const;
643 virtual bool Write(wxOutputStream& str) const;
644 virtual bool Write(wxString& str) const;
645 virtual bool Read(istream& str);
646 virtual bool Read(wxInputStream& str);
647 virtual bool Read(wxString& str);
648 virtual wxString GetType() const { return "string"; };
649
650 protected:
651 wxString m_value;
652 };
653
654 void wxVariantDataString::Copy(wxVariantData& data)
655 {
656 wxASSERT_MSG( (data.GetType() == "string"), "wxVariantDataString::Copy: Can't copy to this type of data" );
657
658 wxVariantDataString& otherData = (wxVariantDataString&) data;
659
660 otherData.m_value = m_value;
661 }
662
663 bool wxVariantDataString::Eq(wxVariantData& data) const
664 {
665 wxASSERT_MSG( (data.GetType() == "string"), "wxVariantDataString::Eq: argument mismatch" );
666
667 wxVariantDataString& otherData = (wxVariantDataString&) data;
668
669 return (otherData.m_value == m_value);
670 }
671
672 bool wxVariantDataString::Write(ostream& str) const
673 {
674 str << (const char*) m_value;
675 return TRUE;
676 }
677
678 bool wxVariantDataString::Write(wxOutputStream& str) const
679 {
680 str << (const char*) m_value;
681 return TRUE;
682 }
683
684 bool wxVariantDataString::Write(wxString& str) const
685 {
686 str = m_value;
687 return TRUE;
688 }
689
690 bool wxVariantDataString::Read(istream& str)
691 {
692 str >> m_value;
693 return TRUE;
694 }
695
696 bool wxVariantDataString::Read(wxInputStream& str)
697 {
698 str >> m_value;
699 return TRUE;
700 }
701
702 bool wxVariantDataString::Read(wxString& str)
703 {
704 m_value = str;
705 return TRUE;
706 }
707
708 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString, wxVariantData)
709
710 /*
711 * wxVariantDataTime
712 */
713
714 #if wxUSE_TIMEDATE
715
716 class wxVariantDataTime: public wxVariantData
717 {
718 DECLARE_DYNAMIC_CLASS(wxVariantDataTime)
719 public:
720 wxVariantDataTime() { }
721 wxVariantDataTime(const wxTime& value) { m_value = value; }
722
723 inline wxTime GetValue() const { return m_value; }
724 inline void SetValue(const wxTime& value) { m_value = value; }
725
726 virtual void Copy(wxVariantData& data);
727 virtual bool Eq(wxVariantData& data) const;
728 virtual bool Write(ostream& str) const;
729 virtual bool Write(wxString& str) const;
730 virtual bool Read(istream& str);
731 virtual bool Read(wxString& str);
732 virtual wxString GetType() const { return "time"; };
733 virtual wxVariantData* Clone() { return new wxVariantDataTime; }
734
735 protected:
736 wxTime m_value;
737 };
738
739 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataTime, wxVariantData)
740
741 void wxVariantDataTime::Copy(wxVariantData& data)
742 {
743 wxASSERT_MSG( (data.GetType() == "time"), "wxVariantDataTime::Copy: Can't copy to this type of data" );
744
745 wxVariantDataTime& otherData = (wxVariantDataTime&) data;
746
747 otherData.m_value = m_value;
748 }
749
750 bool wxVariantDataTime::Eq(wxVariantData& data) const
751 {
752 wxASSERT_MSG( (data.GetType() == "time"), "wxVariantDataTime::Eq: argument mismatch" );
753
754 wxVariantDataTime& otherData = (wxVariantDataTime&) data;
755
756 return (otherData.m_value == m_value);
757 }
758
759 bool wxVariantDataTime::Write(ostream& str) const
760 {
761 wxString s;
762 Write(s);
763 str << (const char*) s;
764 return TRUE;
765 }
766
767 bool wxVariantDataTime::Write(wxString& str) const
768 {
769 char*s = m_value.FormatTime();
770 str = s;
771 return TRUE;
772 }
773
774 bool wxVariantDataTime::Read(istream& str)
775 {
776 // Not implemented
777 return FALSE;
778 }
779
780 bool wxVariantDataTime::Read(wxString& str)
781 {
782 // Not implemented
783 return FALSE;
784 }
785
786 /*
787 * wxVariantDataDate
788 */
789
790 class wxVariantDataDate: public wxVariantData
791 {
792 DECLARE_DYNAMIC_CLASS(wxVariantDataDate)
793 public:
794 wxVariantDataDate() { }
795 wxVariantDataDate(const wxDate& value) { m_value = value; }
796
797 inline wxDate GetValue() const { return m_value; }
798 inline void SetValue(const wxDate& value) { m_value = value; }
799
800 virtual void Copy(wxVariantData& data);
801 virtual bool Eq(wxVariantData& data) const;
802 virtual bool Write(ostream& str) const;
803 virtual bool Write(wxString& str) const;
804 virtual bool Read(istream& str);
805 virtual bool Read(wxString& str);
806 virtual wxString GetType() const { return "date"; };
807 virtual wxVariantData* Clone() { return new wxVariantDataDate; }
808
809 protected:
810 wxDate m_value;
811 };
812
813 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDate, wxVariantData)
814
815 void wxVariantDataDate::Copy(wxVariantData& data)
816 {
817 wxASSERT_MSG( (data.GetType() == "date"), "wxVariantDataDate::Copy: Can't copy to this type of data" );
818
819 wxVariantDataDate& otherData = (wxVariantDataDate&) data;
820
821 otherData.m_value = m_value;
822 }
823
824 bool wxVariantDataDate::Eq(wxVariantData& data) const
825 {
826 wxASSERT_MSG( (data.GetType() == "date"), "wxVariantDataDate::Eq: argument mismatch" );
827
828 wxVariantDataDate& otherData = (wxVariantDataDate&) data;
829
830 return (otherData.m_value == m_value);
831 }
832
833 bool wxVariantDataDate::Write(ostream& str) const
834 {
835 wxString s;
836 Write(s);
837 str << (const char*) s;
838 return TRUE;
839 }
840
841 bool wxVariantDataDate::Write(wxString& str) const
842 {
843 str = m_value.FormatDate();
844 return TRUE;
845 }
846
847 bool wxVariantDataDate::Read(istream& str)
848 {
849 // Not implemented
850 return FALSE;
851 }
852
853 bool wxVariantDataDate::Read(wxString& str)
854 {
855 // Not implemented
856 return FALSE;
857 }
858 #endif
859 // wxUSE_TIMEDATE
860
861 /*
862 * wxVariantDataVoidPtr
863 */
864
865 class wxVariantDataVoidPtr: public wxVariantData
866 {
867 DECLARE_DYNAMIC_CLASS(wxVariantDataVoidPtr)
868 public:
869 wxVariantDataVoidPtr() { }
870 wxVariantDataVoidPtr(void* value) { m_value = value; }
871
872 inline void* GetValue() const { return m_value; }
873 inline void SetValue(void* value) { m_value = value; }
874
875 virtual void Copy(wxVariantData& data);
876 virtual bool Eq(wxVariantData& data) const;
877 virtual bool Write(ostream& str) const;
878 virtual bool Write(wxString& str) const;
879 virtual bool Read(istream& str);
880 virtual bool Read(wxString& str);
881 virtual wxString GetType() const { return "void*"; };
882 virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; }
883
884 protected:
885 void* m_value;
886 };
887
888 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr, wxVariantData)
889
890 void wxVariantDataVoidPtr::Copy(wxVariantData& data)
891 {
892 wxASSERT_MSG( (data.GetType() == "void*"), "wxVariantDataVoidPtr::Copy: Can't copy to this type of data" );
893
894 wxVariantDataVoidPtr& otherData = (wxVariantDataVoidPtr&) data;
895
896 otherData.m_value = m_value;
897 }
898
899 bool wxVariantDataVoidPtr::Eq(wxVariantData& data) const
900 {
901 wxASSERT_MSG( (data.GetType() == "void*"), "wxVariantDataVoidPtr::Eq: argument mismatch" );
902
903 wxVariantDataVoidPtr& otherData = (wxVariantDataVoidPtr&) data;
904
905 return (otherData.m_value == m_value);
906 }
907
908 bool wxVariantDataVoidPtr::Write(ostream& str) const
909 {
910 wxString s;
911 Write(s);
912 str << (const char*) s;
913 return TRUE;
914 }
915
916 bool wxVariantDataVoidPtr::Write(wxString& str) const
917 {
918 char buf[80];
919 sprintf(buf, "%ld", (long) m_value);
920 str = buf;
921 return TRUE;
922 }
923
924 bool wxVariantDataVoidPtr::Read(istream& str)
925 {
926 // Not implemented
927 return FALSE;
928 }
929
930 bool wxVariantDataVoidPtr::Read(wxString& str)
931 {
932 // Not implemented
933 return FALSE;
934 }
935
936
937 /*
938 * wxVariant
939 */
940
941 IMPLEMENT_DYNAMIC_CLASS(wxVariant, wxObject)
942
943 // Construction & destruction
944 wxVariant::wxVariant()
945 {
946 m_data = (wxVariantData*) NULL;
947 }
948
949 wxVariant::wxVariant(double val, const wxString& name)
950 {
951 m_data = new wxVariantDataReal(val);
952 m_name = name;
953 }
954
955 wxVariant::wxVariant(long val, const wxString& name)
956 {
957 m_data = new wxVariantDataLong(val);
958 m_name = name;
959 }
960
961 wxVariant::wxVariant(bool val, const wxString& name)
962 {
963 m_data = new wxVariantDataBool(val);
964 m_name = name;
965 }
966
967 wxVariant::wxVariant(char val, const wxString& name)
968 {
969 m_data = new wxVariantDataChar(val);
970 m_name = name;
971 }
972
973 wxVariant::wxVariant(const wxString& val, const wxString& name)
974 {
975 m_data = new wxVariantDataString(val);
976 m_name = name;
977 }
978
979 wxVariant::wxVariant(const char* val, const wxString& name)
980 {
981 m_data = new wxVariantDataString(wxString(val));
982 m_name = name;
983 }
984
985 wxVariant::wxVariant(const wxStringList& val, const wxString& name)
986 {
987 m_data = new wxVariantDataStringList(val);
988 m_name = name;
989 }
990
991 wxVariant::wxVariant(const wxList& val, const wxString& name) // List of variants
992 {
993 m_data = new wxVariantDataList(val);
994 m_name = name;
995 }
996
997 #if wxUSE_TIMEDATE
998 wxVariant::wxVariant(const wxTime& val, const wxString& name) // Time
999 {
1000 m_data = new wxVariantDataTime(val);
1001 m_name = name;
1002 }
1003
1004 wxVariant::wxVariant(const wxDate& val, const wxString& name) // Date
1005 {
1006 m_data = new wxVariantDataDate(val);
1007 m_name = name;
1008 }
1009 #endif
1010
1011 wxVariant::wxVariant(void* val, const wxString& name) // Void ptr
1012 {
1013 m_data = new wxVariantDataVoidPtr(val);
1014 m_name = name;
1015 }
1016
1017 wxVariant::wxVariant(const wxVariant& variant)
1018 {
1019 if (!variant.IsNull())
1020 {
1021 m_data = (wxVariantData*) variant.GetData()->GetClassInfo()->CreateObject();
1022 variant.m_data->Copy(*m_data);
1023 }
1024 else
1025 m_data = (wxVariantData*) NULL;
1026 m_name = variant.m_name;
1027 }
1028
1029 wxVariant::wxVariant(wxVariantData* data, const wxString& name) // User-defined data
1030 {
1031 m_data = data;
1032 m_name = name;
1033 }
1034
1035 wxVariant::~wxVariant()
1036 {
1037 delete m_data;
1038 }
1039
1040
1041 // Make NULL (i.e. delete the data)
1042 void wxVariant::MakeNull()
1043 {
1044 delete m_data;
1045 m_data = NULL;
1046 }
1047
1048 // Generic operators
1049 // Assignment
1050 void wxVariant::operator= (const wxVariant& variant)
1051 {
1052 if (variant.IsNull())
1053 {
1054 MakeNull();
1055 return;
1056 }
1057
1058 if (IsNull() || (GetType() != variant.GetType()))
1059 {
1060 if (m_data)
1061 delete m_data;
1062 m_data = (wxVariantData*) variant.GetData()->GetClassInfo()->CreateObject();
1063 }
1064 // GetData()->Copy(* variant.GetData());
1065 variant.GetData()->Copy(* GetData());
1066 }
1067
1068 // Assignment using data, e.g.
1069 // myVariant = new wxStringVariantData("hello")
1070 void wxVariant::operator= (wxVariantData* variantData)
1071 {
1072 MakeNull();
1073 m_data = variantData;
1074 }
1075
1076 bool wxVariant::operator== (const wxVariant& variant) const
1077 {
1078 if (IsNull() || variant.IsNull())
1079 return (IsNull() == variant.IsNull());
1080
1081 return (GetData()->Eq(* variant.GetData()));
1082 }
1083
1084 bool wxVariant::operator!= (const wxVariant& variant) const
1085 {
1086 return (!(*this == variant));
1087 }
1088
1089
1090 // Specific operators
1091 bool wxVariant::operator== (double value) const
1092 {
1093 double thisValue;
1094 if (!Convert(&thisValue))
1095 return FALSE;
1096 else
1097 return (value == thisValue);
1098 }
1099
1100 bool wxVariant::operator!= (double value) const
1101 {
1102 return (!((*this) == value));
1103 }
1104
1105 void wxVariant::operator= (double value)
1106 {
1107 if (GetType() == "double")
1108 {
1109 ((wxVariantDataReal*)GetData())->SetValue(value);
1110 }
1111 else
1112 {
1113 if (m_data)
1114 delete m_data;
1115 m_data = new wxVariantDataReal(value);
1116 }
1117 }
1118
1119 bool wxVariant::operator== (long value) const
1120 {
1121 long thisValue;
1122 if (!Convert(&thisValue))
1123 return FALSE;
1124 else
1125 return (value == thisValue);
1126 }
1127
1128 bool wxVariant::operator!= (long value) const
1129 {
1130 return (!((*this) == value));
1131 }
1132
1133 void wxVariant::operator= (long value)
1134 {
1135 if (GetType() == "long")
1136 {
1137 ((wxVariantDataLong*)GetData())->SetValue(value);
1138 }
1139 else
1140 {
1141 if (m_data)
1142 delete m_data;
1143 m_data = new wxVariantDataLong(value);
1144 }
1145 }
1146
1147 bool wxVariant::operator== (char value) const
1148 {
1149 char thisValue;
1150 if (!Convert(&thisValue))
1151 return FALSE;
1152 else
1153 return (value == thisValue);
1154 }
1155
1156 bool wxVariant::operator!= (char value) const
1157 {
1158 return (!((*this) == value));
1159 }
1160
1161 void wxVariant::operator= (char value)
1162 {
1163 if (GetType() == "char")
1164 {
1165 ((wxVariantDataChar*)GetData())->SetValue(value);
1166 }
1167 else
1168 {
1169 if (m_data)
1170 delete m_data;
1171 m_data = new wxVariantDataChar(value);
1172 }
1173 }
1174
1175 bool wxVariant::operator== (bool value) const
1176 {
1177 bool thisValue;
1178 if (!Convert(&thisValue))
1179 return FALSE;
1180 else
1181 return (value == thisValue);
1182 }
1183
1184 bool wxVariant::operator!= (bool value) const
1185 {
1186 return (!((*this) == value));
1187 }
1188
1189 void wxVariant::operator= (bool value)
1190 {
1191 if (GetType() == "bool")
1192 {
1193 ((wxVariantDataBool*)GetData())->SetValue(value);
1194 }
1195 else
1196 {
1197 if (m_data)
1198 delete m_data;
1199 m_data = new wxVariantDataBool(value);
1200 }
1201 }
1202
1203 bool wxVariant::operator== (const wxString& value) const
1204 {
1205 wxString thisValue;
1206 if (!Convert(&thisValue))
1207 return FALSE;
1208 else
1209 return (value == thisValue);
1210 }
1211
1212 bool wxVariant::operator!= (const wxString& value) const
1213 {
1214 return (!((*this) == value));
1215 }
1216
1217 void wxVariant::operator= (const wxString& value)
1218 {
1219 if (GetType() == "string")
1220 {
1221 ((wxVariantDataString*)GetData())->SetValue(value);
1222 }
1223 else
1224 {
1225 if (m_data)
1226 delete m_data;
1227 m_data = new wxVariantDataString(value);
1228 }
1229 }
1230
1231 void wxVariant::operator= (const char* value)
1232 {
1233 if (GetType() == "string")
1234 {
1235 ((wxVariantDataString*)GetData())->SetValue(wxString(value));
1236 }
1237 else
1238 {
1239 if (m_data)
1240 delete m_data;
1241 m_data = new wxVariantDataString(wxString(value));
1242 }
1243 }
1244
1245 bool wxVariant::operator== (const wxStringList& value) const
1246 {
1247 wxASSERT_MSG( (GetType() == "stringlist"), "Invalid type for == operator" );
1248
1249 wxVariantDataStringList other(value);
1250 return (m_data->Eq(other));
1251 }
1252
1253 bool wxVariant::operator!= (const wxStringList& value) const
1254 {
1255 return (!((*this) == value));
1256 }
1257
1258 void wxVariant::operator= (const wxStringList& value)
1259 {
1260 if (GetType() == "stringlist")
1261 {
1262 ((wxVariantDataStringList*)GetData())->SetValue(value);
1263 }
1264 else
1265 {
1266 if (m_data)
1267 delete m_data;
1268 m_data = new wxVariantDataStringList(value);
1269 }
1270 }
1271
1272 bool wxVariant::operator== (const wxList& value) const
1273 {
1274 wxASSERT_MSG( (GetType() == "list"), "Invalid type for == operator" );
1275
1276 wxVariantDataList other(value);
1277 return (m_data->Eq(other));
1278 }
1279
1280 bool wxVariant::operator!= (const wxList& value) const
1281 {
1282 return (!((*this) == value));
1283 }
1284
1285 void wxVariant::operator= (const wxList& value)
1286 {
1287 if (GetType() == "list")
1288 {
1289 ((wxVariantDataList*)GetData())->SetValue(value);
1290 }
1291 else
1292 {
1293 if (m_data)
1294 delete m_data;
1295 m_data = new wxVariantDataList(value);
1296 }
1297 }
1298
1299 #if wxUSE_TIMEDATE
1300 bool wxVariant::operator== (const wxTime& value) const
1301 {
1302 wxTime thisValue;
1303 if (!Convert(&thisValue))
1304 return FALSE;
1305 else
1306 return (value == thisValue);
1307 }
1308
1309 bool wxVariant::operator!= (const wxTime& value) const
1310 {
1311 return (!((*this) == value));
1312 }
1313
1314 void wxVariant::operator= (const wxTime& value)
1315 {
1316 if (GetType() == "time")
1317 {
1318 ((wxVariantDataTime*)GetData())->SetValue(value);
1319 }
1320 else
1321 {
1322 if (m_data)
1323 delete m_data;
1324 m_data = new wxVariantDataTime(value);
1325 }
1326 }
1327
1328 bool wxVariant::operator== (const wxDate& value) const
1329 {
1330 wxDate thisValue;
1331 if (!Convert(&thisValue))
1332 return FALSE;
1333 else
1334 return (value == thisValue);
1335 }
1336
1337 bool wxVariant::operator!= (const wxDate& value) const
1338 {
1339 return (!((*this) == value));
1340 }
1341
1342 void wxVariant::operator= (const wxDate& value)
1343 {
1344 if (GetType() == "date")
1345 {
1346 ((wxVariantDataTime*)GetData())->SetValue(value);
1347 }
1348 else
1349 {
1350 if (m_data)
1351 delete m_data;
1352 m_data = new wxVariantDataDate(value);
1353 }
1354 }
1355 #endif
1356
1357 bool wxVariant::operator== (void* value) const
1358 {
1359 return (value == ((wxVariantDataVoidPtr*)GetData())->GetValue());
1360 }
1361
1362 bool wxVariant::operator!= (void* value) const
1363 {
1364 return (!((*this) == value));
1365 }
1366
1367 void wxVariant::operator= (void* value)
1368 {
1369 if (GetType() == "void*")
1370 {
1371 ((wxVariantDataVoidPtr*)GetData())->SetValue(value);
1372 }
1373 else
1374 {
1375 if (m_data)
1376 delete m_data;
1377 m_data = new wxVariantDataVoidPtr(value);
1378 }
1379 }
1380
1381 // Treat a list variant as an array
1382 wxVariant wxVariant::operator[] (size_t idx) const
1383 {
1384 wxASSERT_MSG( (GetType() == "list" || GetType() == "stringlist"), "Invalid type for array operator" );
1385
1386 if (GetType() == "list")
1387 {
1388 wxVariantDataList* data = (wxVariantDataList*) m_data;
1389 wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), "Invalid index for array" );
1390 return * (wxVariant*) (data->GetValue().Nth(idx)->Data());
1391 }
1392 else if (GetType() == "stringlist")
1393 {
1394 wxVariantDataStringList* data = (wxVariantDataStringList*) m_data;
1395 wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), "Invalid index for array" );
1396
1397 wxVariant variant( wxString( (char*) (data->GetValue().Nth(idx)->Data()) ));
1398 return variant;
1399 }
1400 return wxNullVariant;
1401 }
1402
1403 wxVariant& wxVariant::operator[] (size_t idx)
1404 {
1405 // We can't return a reference to a variant for a string list, since the string
1406 // is actually stored as a char*, not a variant.
1407
1408 wxASSERT_MSG( (GetType() == "list"), "Invalid type for array operator" );
1409
1410 wxVariantDataList* data = (wxVariantDataList*) m_data;
1411 wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), "Invalid index for array" );
1412
1413 return * (wxVariant*) (data->GetValue().Nth(idx)->Data());
1414 }
1415
1416 // Return the number of elements in a list
1417 int wxVariant::GetCount() const
1418 {
1419 wxASSERT_MSG( (GetType() == "list" || GetType() == "stringlist"), "Invalid type for GetCount()" );
1420
1421 if (GetType() == "list")
1422 {
1423 wxVariantDataList* data = (wxVariantDataList*) m_data;
1424 return data->GetValue().Number();
1425 }
1426 else if (GetType() == "stringlist")
1427 {
1428 wxVariantDataStringList* data = (wxVariantDataStringList*) m_data;
1429 return data->GetValue().Number();
1430 }
1431 return 0;
1432 }
1433
1434 wxString wxVariant::MakeString() const
1435 {
1436 if (!IsNull())
1437 {
1438 wxString str;
1439 if (GetData()->Write(str))
1440 return str;
1441 }
1442 return wxString("");
1443 }
1444
1445 // Accessors
1446
1447 void wxVariant::SetData(wxVariantData* data)
1448 {
1449 if (m_data) delete m_data;
1450 m_data = data;
1451 }
1452
1453
1454 // Returns a string representing the type of the variant,
1455 // e.g. "string", "bool", "stringlist", "list", "double", "long"
1456 wxString wxVariant::GetType() const
1457 {
1458 if (IsNull())
1459 return wxString("null");
1460 else
1461 return m_data->GetType();
1462 }
1463
1464
1465 bool wxVariant::IsType(const wxString& type) const
1466 {
1467 return (GetType() == type);
1468 }
1469
1470
1471 // Value accessors
1472 double wxVariant::GetReal() const
1473 {
1474 double value;
1475 if (Convert(& value))
1476 return value;
1477 else
1478 {
1479 wxFAIL_MSG("Could not convert to a real number");
1480 return 0.0;
1481 }
1482 }
1483
1484 long wxVariant::GetInteger() const
1485 {
1486 long value;
1487 if (Convert(& value))
1488 return value;
1489 else
1490 {
1491 wxFAIL_MSG("Could not convert to an integer");
1492 return 0;
1493 }
1494 }
1495
1496 char wxVariant::GetChar() const
1497 {
1498 char value;
1499 if (Convert(& value))
1500 return value;
1501 else
1502 {
1503 wxFAIL_MSG("Could not convert to a char");
1504 return 0;
1505 }
1506 }
1507
1508 bool wxVariant::GetBool() const
1509 {
1510 bool value;
1511 if (Convert(& value))
1512 return value;
1513 else
1514 {
1515 wxFAIL_MSG("Could not convert to a bool");
1516 return 0;
1517 }
1518 }
1519
1520 wxString wxVariant::GetString() const
1521 {
1522 wxString value;
1523 if (Convert(& value))
1524 return value;
1525 else
1526 {
1527 wxFAIL_MSG("Could not convert to a string");
1528 return wxString("");
1529 }
1530 }
1531
1532 #if wxUSE_TIMEDATE
1533 wxTime wxVariant::GetTime() const
1534 {
1535 wxTime value;
1536 if (Convert(& value))
1537 return value;
1538 else
1539 {
1540 wxFAIL_MSG("Could not convert to a time");
1541 return wxTime();
1542 }
1543 }
1544
1545 wxDate wxVariant::GetDate() const
1546 {
1547 wxDate value;
1548 if (Convert(& value))
1549 return value;
1550 else
1551 {
1552 wxFAIL_MSG("Could not convert to a date");
1553 return wxDate();
1554 }
1555 }
1556 #endif
1557
1558 void* wxVariant::GetVoidPtr() const
1559 {
1560 wxASSERT( (GetType() == "void*") );
1561
1562 return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue();
1563 }
1564
1565 wxList& wxVariant::GetList() const
1566 {
1567 wxASSERT( (GetType() == "list") );
1568
1569 return (wxList&) ((wxVariantDataList*) m_data)->GetValue();
1570 }
1571
1572 wxStringList& wxVariant::GetStringList() const
1573 {
1574 wxASSERT( (GetType() == "stringlist") );
1575
1576 return (wxStringList&) ((wxVariantDataStringList*) m_data)->GetValue();
1577 }
1578
1579 // Append to list
1580 void wxVariant::Append(const wxVariant& value)
1581 {
1582 wxList& list = GetList();
1583
1584 list.Append(new wxVariant(value));
1585 }
1586
1587 // Insert at front of list
1588 void wxVariant::Insert(const wxVariant& value)
1589 {
1590 wxList& list = GetList();
1591
1592 list.Insert(new wxVariant(value));
1593 }
1594
1595 // Returns TRUE if the variant is a member of the list
1596 bool wxVariant::Member(const wxVariant& value) const
1597 {
1598 wxList& list = GetList();
1599
1600 wxNode* node = list.First();
1601 while (node)
1602 {
1603 wxVariant* other = (wxVariant*) node->Data();
1604 if (value == *other)
1605 return TRUE;
1606 node = node->Next();
1607 }
1608 return FALSE;
1609 }
1610
1611 // Deletes the nth element of the list
1612 bool wxVariant::Delete(int item)
1613 {
1614 wxList& list = GetList();
1615
1616 wxASSERT_MSG( (item < list.Number()), "Invalid index to Delete" );
1617 wxNode* node = list.Nth(item);
1618 wxVariant* variant = (wxVariant*) node->Data();
1619 delete variant;
1620 delete node;
1621 return TRUE;
1622 }
1623
1624 // Clear list
1625 void wxVariant::ClearList()
1626 {
1627 if (!IsNull() && (GetType() == "list"))
1628 {
1629 ((wxVariantDataList*) m_data)->Clear();
1630 }
1631 else
1632 {
1633 if (GetType() != "list")
1634 {
1635 delete m_data;
1636 m_data = NULL;
1637 }
1638 m_data = new wxVariantDataList;
1639 }
1640 }
1641
1642 // Type conversion
1643 bool wxVariant::Convert(long* value) const
1644 {
1645 wxString type(GetType());
1646 if (type == "double")
1647 *value = (long) (((wxVariantDataReal*)GetData())->GetValue());
1648 else if (type == "long")
1649 *value = ((wxVariantDataLong*)GetData())->GetValue();
1650 else if (type == "bool")
1651 *value = (long) (((wxVariantDataBool*)GetData())->GetValue());
1652 else if (type == "string")
1653 *value = atol((const char*) ((wxVariantDataString*)GetData())->GetValue());
1654 else
1655 return FALSE;
1656
1657 return TRUE;
1658 }
1659
1660 bool wxVariant::Convert(bool* value) const
1661 {
1662 wxString type(GetType());
1663 if (type == "double")
1664 *value = ((int) (((wxVariantDataReal*)GetData())->GetValue()) != 0);
1665 else if (type == "long")
1666 *value = (((wxVariantDataLong*)GetData())->GetValue() != 0);
1667 else if (type == "bool")
1668 *value = ((wxVariantDataBool*)GetData())->GetValue();
1669 else if (type == "string")
1670 {
1671 wxString val(((wxVariantDataString*)GetData())->GetValue());
1672 val.MakeLower();
1673 if (val == "true" || val == "yes")
1674 *value = TRUE;
1675 else if (val == "false" || val == "no")
1676 *value = FALSE;
1677 else
1678 return FALSE;
1679 }
1680 else
1681 return FALSE;
1682
1683 return TRUE;
1684 }
1685
1686 bool wxVariant::Convert(double* value) const
1687 {
1688 wxString type(GetType());
1689 if (type == "double")
1690 *value = ((wxVariantDataReal*)GetData())->GetValue();
1691 else if (type == "long")
1692 *value = (double) (((wxVariantDataLong*)GetData())->GetValue());
1693 else if (type == "bool")
1694 *value = (double) (((wxVariantDataBool*)GetData())->GetValue());
1695 else if (type == "string")
1696 *value = (double) atof((const char*) ((wxVariantDataString*)GetData())->GetValue());
1697 else
1698 return FALSE;
1699
1700 return TRUE;
1701 }
1702
1703 bool wxVariant::Convert(char* value) const
1704 {
1705 wxString type(GetType());
1706 if (type == "char")
1707 *value = ((wxVariantDataChar*)GetData())->GetValue();
1708 else if (type == "long")
1709 *value = (char) (((wxVariantDataLong*)GetData())->GetValue());
1710 else if (type == "bool")
1711 *value = (char) (((wxVariantDataBool*)GetData())->GetValue());
1712 else
1713 return FALSE;
1714
1715 return TRUE;
1716 }
1717
1718 bool wxVariant::Convert(wxString* value) const
1719 {
1720 *value = MakeString();
1721 return TRUE;
1722 }
1723
1724 #if wxUSE_TIMEDATE
1725 bool wxVariant::Convert(wxTime* value) const
1726 {
1727 wxString type(GetType());
1728 if (type == "time")
1729 *value = ((wxVariantDataTime*)GetData())->GetValue();
1730 else if (type == "date")
1731 *value = wxTime(((wxVariantDataDate*)GetData())->GetValue());
1732 else
1733 return FALSE;
1734
1735 return TRUE;
1736 }
1737
1738 bool wxVariant::Convert(wxDate* value) const
1739 {
1740 wxString type(GetType());
1741 if (type == "date")
1742 *value = ((wxVariantDataDate*)GetData())->GetValue();
1743 else
1744 return FALSE;
1745
1746 return TRUE;
1747 }
1748 #endif
1749 // wxUSE_TIMEDATE