1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxVariant class, container for any type
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "variant.h"
14 #pragma implementation "time.h"
15 #pragma implementation "date.h"
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
25 #if wxUSE_STD_IOSTREAM
34 #include "wx/stream.h"
35 #include "wx/txtstrm.h"
38 #include "wx/string.h"
39 #include "wx/variant.h"
42 IMPLEMENT_DYNAMIC_CLASS(wxDate
, wxObject
)
43 IMPLEMENT_DYNAMIC_CLASS(wxTime
, wxObject
)
45 wxTime::tFormat
wxTime::ms_Format
= wxTime::wx12h
;
46 wxTime::tPrecision
wxTime::ms_Precision
= wxTime::wxStdMinSec
;
47 wxChar
wxTime::ms_bufTime
[128];
50 IMPLEMENT_ABSTRACT_CLASS(wxVariantData
, wxObject
)
52 wxVariant WXDLLEXPORT wxNullVariant
;
58 class WXDLLEXPORT wxVariantDataList
: public wxVariantData
60 DECLARE_DYNAMIC_CLASS(wxVariantDataList
)
62 wxVariantDataList() {}
63 wxVariantDataList(const wxList
& list
);
66 wxList
& GetValue() const { return (wxList
&) m_value
; }
67 void SetValue(const wxList
& value
) ;
69 virtual void Copy(wxVariantData
& data
);
70 virtual bool Eq(wxVariantData
& data
) const;
71 #if wxUSE_STD_IOSTREAM
72 virtual bool Write(wxSTD ostream
& str
) const;
74 virtual bool Write(wxString
& str
) const;
75 #if wxUSE_STD_IOSTREAM
76 virtual bool Read(wxSTD istream
& str
);
78 virtual bool Read(wxString
& str
);
79 virtual wxString
GetType() const { return wxT("list"); };
87 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataList
, wxVariantData
)
89 wxVariantDataList::wxVariantDataList(const wxList
& list
)
94 wxVariantDataList::~wxVariantDataList()
99 void wxVariantDataList::SetValue(const wxList
& value
)
102 wxNode
* node
= value
.First();
105 wxVariant
* var
= (wxVariant
*) node
->Data();
106 m_value
.Append(new wxVariant(*var
));
111 void wxVariantDataList::Clear()
113 wxNode
* node
= m_value
.First();
116 wxVariant
* var
= (wxVariant
*) node
->Data();
123 void wxVariantDataList::Copy(wxVariantData
& data
)
125 wxASSERT_MSG( (data
.GetType() == wxT("list")), wxT("wxVariantDataList::Copy: Can't copy to this type of data") );
127 wxVariantDataList
& listData
= (wxVariantDataList
&) data
;
130 wxNode
* node
= m_value
.First();
133 wxVariant
* var
= (wxVariant
*) node
->Data();
134 listData
.m_value
.Append(new wxVariant(*var
));
139 bool wxVariantDataList::Eq(wxVariantData
& data
) const
141 wxASSERT_MSG( (data
.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") );
143 wxVariantDataList
& listData
= (wxVariantDataList
&) data
;
144 wxNode
* node1
= m_value
.First();
145 wxNode
* node2
= listData
.GetValue().First();
146 while (node1
&& node2
)
148 wxVariant
* var1
= (wxVariant
*) node1
->Data();
149 wxVariant
* var2
= (wxVariant
*) node2
->Data();
150 if ((*var1
) != (*var2
))
152 node1
= node1
->Next();
153 node2
= node2
->Next();
155 if (node1
|| node2
) return FALSE
;
159 #if wxUSE_STD_IOSTREAM
160 bool wxVariantDataList::Write(wxSTD ostream
& str
) const
164 str
<< (const char*) s
.mb_str();
169 bool wxVariantDataList::Write(wxString
& str
) const
172 wxNode
* node
= m_value
.First();
175 wxVariant
* var
= (wxVariant
*) node
->Data();
176 if (node
!= m_value
.First())
179 str
+= var
->MakeString();
186 #if wxUSE_STD_IOSTREAM
187 bool wxVariantDataList::Read(wxSTD istream
& WXUNUSED(str
))
189 wxFAIL_MSG(wxT("Unimplemented"));
195 bool wxVariantDataList::Read(wxString
& WXUNUSED(str
))
197 wxFAIL_MSG(wxT("Unimplemented"));
203 * wxVariantDataStringList
206 class WXDLLEXPORT wxVariantDataStringList
: public wxVariantData
208 DECLARE_DYNAMIC_CLASS(wxVariantDataStringList
)
210 wxVariantDataStringList() {}
211 wxVariantDataStringList(const wxStringList
& list
) { m_value
= list
; }
213 wxStringList
& GetValue() const { return (wxStringList
&) m_value
; }
214 void SetValue(const wxStringList
& value
);
216 virtual void Copy(wxVariantData
& data
);
217 virtual bool Eq(wxVariantData
& data
) const;
218 #if wxUSE_STD_IOSTREAM
219 virtual bool Write(wxSTD ostream
& str
) const;
221 virtual bool Write(wxString
& str
) const;
222 #if wxUSE_STD_IOSTREAM
223 virtual bool Read(wxSTD istream
& str
);
225 virtual bool Read(wxString
& str
);
226 virtual wxString
GetType() const { return wxT("stringlist"); };
229 wxStringList m_value
;
232 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataStringList
, wxVariantData
)
234 void wxVariantDataStringList::SetValue(const wxStringList
& value
)
239 void wxVariantDataStringList::Copy(wxVariantData
& data
)
241 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Copy: Can't copy to this type of data") );
243 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
245 listData
.m_value
= m_value
;
248 bool wxVariantDataStringList::Eq(wxVariantData
& data
) const
250 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") );
252 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
253 wxNode
* node1
= m_value
.First();
254 wxNode
* node2
= listData
.GetValue().First();
255 while (node1
&& node2
)
257 wxString
str1 ((wxChar
*) node1
->Data());
258 wxString
str2 ((wxChar
*) node2
->Data());
261 node1
= node1
->Next();
262 node2
= node2
->Next();
264 if (node1
|| node2
) return FALSE
;
268 #if wxUSE_STD_IOSTREAM
269 bool wxVariantDataStringList::Write(wxSTD ostream
& str
) const
273 str
<< (const char*) s
.mb_str();
278 bool wxVariantDataStringList::Write(wxString
& str
) const
281 wxNode
* node
= m_value
.First();
284 wxChar
* s
= (wxChar
*) node
->Data();
285 if (node
!= m_value
.First())
294 #if wxUSE_STD_IOSTREAM
295 bool wxVariantDataStringList::Read(wxSTD istream
& WXUNUSED(str
))
297 wxFAIL_MSG(wxT("Unimplemented"));
303 bool wxVariantDataStringList::Read(wxString
& WXUNUSED(str
))
305 wxFAIL_MSG(wxT("Unimplemented"));
314 class WXDLLEXPORT wxVariantDataLong
: public wxVariantData
316 DECLARE_DYNAMIC_CLASS(wxVariantDataLong
)
318 wxVariantDataLong() { m_value
= 0; }
319 wxVariantDataLong(long value
) { m_value
= value
; }
321 inline long GetValue() const { return m_value
; }
322 inline void SetValue(long value
) { m_value
= value
; }
324 virtual void Copy(wxVariantData
& data
);
325 virtual bool Eq(wxVariantData
& data
) const;
327 virtual bool Read(wxString
& str
);
328 virtual bool Write(wxString
& str
) const;
329 #if wxUSE_STD_IOSTREAM
330 virtual bool Read(wxSTD istream
& str
);
331 virtual bool Write(wxSTD ostream
& str
) const;
334 virtual bool Read(wxInputStream
& str
);
335 virtual bool Write(wxOutputStream
&str
) const;
336 #endif // wxUSE_STREAMS
338 virtual wxString
GetType() const { return wxT("long"); };
344 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataLong
, wxVariantData
)
346 void wxVariantDataLong::Copy(wxVariantData
& data
)
348 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Copy: Can't copy to this type of data") );
350 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
352 otherData
.m_value
= m_value
;
355 bool wxVariantDataLong::Eq(wxVariantData
& data
) const
357 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Eq: argument mismatch") );
359 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
361 return (otherData
.m_value
== m_value
);
364 #if wxUSE_STD_IOSTREAM
365 bool wxVariantDataLong::Write(wxSTD ostream
& str
) const
369 str
<< (const char*) s
.mb_str();
374 bool wxVariantDataLong::Write(wxString
& str
) const
376 str
.Printf(wxT("%ld"), m_value
);
380 #if wxUSE_STD_IOSTREAM
381 bool wxVariantDataLong::Read(wxSTD istream
& str
)
389 bool wxVariantDataLong::Write(wxOutputStream
& str
) const
391 wxTextOutputStream
s(str
);
393 s
.Write32((size_t)m_value
);
397 bool wxVariantDataLong::Read(wxInputStream
& str
)
399 wxTextInputStream
s(str
);
400 m_value
= s
.Read32();
403 #endif // wxUSE_STREAMS
405 bool wxVariantDataLong::Read(wxString
& str
)
407 m_value
= wxAtol((const wxChar
*) str
);
415 class WXDLLEXPORT wxVariantDataReal
: public wxVariantData
417 DECLARE_DYNAMIC_CLASS(wxVariantDataReal
)
419 wxVariantDataReal() { m_value
= 0.0; }
420 wxVariantDataReal(double value
) { m_value
= value
; }
422 inline double GetValue() const { return m_value
; }
423 inline void SetValue(double value
) { m_value
= value
; }
425 virtual void Copy(wxVariantData
& data
);
426 virtual bool Eq(wxVariantData
& data
) const;
427 virtual bool Read(wxString
& str
);
428 #if wxUSE_STD_IOSTREAM
429 virtual bool Write(wxSTD ostream
& str
) const;
431 virtual bool Write(wxString
& str
) const;
432 #if wxUSE_STD_IOSTREAM
433 virtual bool Read(wxSTD istream
& str
);
436 virtual bool Read(wxInputStream
& str
);
437 virtual bool Write(wxOutputStream
&str
) const;
438 #endif // wxUSE_STREAMS
439 virtual wxString
GetType() const { return wxT("double"); };
445 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataReal
, wxVariantData
)
447 void wxVariantDataReal::Copy(wxVariantData
& data
)
449 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Copy: Can't copy to this type of data") );
451 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
453 otherData
.m_value
= m_value
;
456 bool wxVariantDataReal::Eq(wxVariantData
& data
) const
458 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Eq: argument mismatch") );
460 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
462 return (otherData
.m_value
== m_value
);
465 #if wxUSE_STD_IOSTREAM
466 bool wxVariantDataReal::Write(wxSTD ostream
& str
) const
470 str
<< (const char*) s
.mb_str();
475 bool wxVariantDataReal::Write(wxString
& str
) const
477 str
.Printf(wxT("%.4f"), m_value
);
481 #if wxUSE_STD_IOSTREAM
482 bool wxVariantDataReal::Read(wxSTD istream
& str
)
490 bool wxVariantDataReal::Write(wxOutputStream
& str
) const
492 wxTextOutputStream
s(str
);
493 s
.WriteDouble((double)m_value
);
497 bool wxVariantDataReal::Read(wxInputStream
& str
)
499 wxTextInputStream
s(str
);
500 m_value
= (float)s
.ReadDouble();
503 #endif // wxUSE_STREAMS
505 bool wxVariantDataReal::Read(wxString
& str
)
507 m_value
= wxAtof((const wxChar
*) str
);
516 class WXDLLEXPORT wxVariantDataBool
: public wxVariantData
518 DECLARE_DYNAMIC_CLASS(wxVariantDataBool
)
520 wxVariantDataBool() { m_value
= 0; }
521 wxVariantDataBool(bool value
) { m_value
= value
; }
523 inline bool GetValue() const { return m_value
; }
524 inline void SetValue(bool value
) { m_value
= value
; }
526 virtual void Copy(wxVariantData
& data
);
527 virtual bool Eq(wxVariantData
& data
) const;
528 #if wxUSE_STD_IOSTREAM
529 virtual bool Write(wxSTD ostream
& str
) const;
531 virtual bool Write(wxString
& str
) const;
532 virtual bool Read(wxString
& str
);
533 #if wxUSE_STD_IOSTREAM
534 virtual bool Read(wxSTD istream
& str
);
537 virtual bool Read(wxInputStream
& str
);
538 virtual bool Write(wxOutputStream
& str
) const;
539 #endif // wxUSE_STREAMS
540 virtual wxString
GetType() const { return wxT("bool"); };
546 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataBool
, wxVariantData
)
548 void wxVariantDataBool::Copy(wxVariantData
& data
)
550 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Copy: Can't copy to this type of data") );
552 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
554 otherData
.m_value
= m_value
;
557 bool wxVariantDataBool::Eq(wxVariantData
& data
) const
559 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Eq: argument mismatch") );
561 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
563 return (otherData
.m_value
== m_value
);
566 #if wxUSE_STD_IOSTREAM
567 bool wxVariantDataBool::Write(wxSTD ostream
& str
) const
571 str
<< (const char*) s
.mb_str();
576 bool wxVariantDataBool::Write(wxString
& str
) const
578 str
.Printf(wxT("%d"), (int) m_value
);
582 #if wxUSE_STD_IOSTREAM
583 bool wxVariantDataBool::Read(wxSTD istream
& WXUNUSED(str
))
585 wxFAIL_MSG(wxT("Unimplemented"));
586 // str >> (long) m_value;
592 bool wxVariantDataBool::Write(wxOutputStream
& str
) const
594 wxTextOutputStream
s(str
);
600 bool wxVariantDataBool::Read(wxInputStream
& str
)
602 wxTextInputStream
s(str
);
604 m_value
= s
.Read8() != 0;
607 #endif // wxUSE_STREAMS
609 bool wxVariantDataBool::Read(wxString
& str
)
611 m_value
= (wxAtol((const wxChar
*) str
) != 0);
620 class WXDLLEXPORT wxVariantDataChar
: public wxVariantData
622 DECLARE_DYNAMIC_CLASS(wxVariantDataChar
)
624 wxVariantDataChar() { m_value
= 0; }
625 wxVariantDataChar(char value
) { m_value
= value
; }
627 inline char GetValue() const { return m_value
; }
628 inline void SetValue(char value
) { m_value
= value
; }
630 virtual void Copy(wxVariantData
& data
);
631 virtual bool Eq(wxVariantData
& data
) const;
632 #if wxUSE_STD_IOSTREAM
633 virtual bool Read(wxSTD istream
& str
);
634 virtual bool Write(wxSTD ostream
& str
) const;
636 virtual bool Read(wxString
& str
);
637 virtual bool Write(wxString
& str
) const;
639 virtual bool Read(wxInputStream
& str
);
640 virtual bool Write(wxOutputStream
& str
) const;
641 #endif // wxUSE_STREAMS
642 virtual wxString
GetType() const { return wxT("char"); };
648 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataChar
, wxVariantData
)
650 void wxVariantDataChar::Copy(wxVariantData
& data
)
652 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Copy: Can't copy to this type of data") );
654 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
656 otherData
.m_value
= m_value
;
659 bool wxVariantDataChar::Eq(wxVariantData
& data
) const
661 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Eq: argument mismatch") );
663 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
665 return (otherData
.m_value
== m_value
);
668 #if wxUSE_STD_IOSTREAM
669 bool wxVariantDataChar::Write(wxSTD ostream
& str
) const
673 str
<< (const char*) s
.mb_str();
678 bool wxVariantDataChar::Write(wxString
& str
) const
680 str
.Printf(wxT("%c"), m_value
);
684 #if wxUSE_STD_IOSTREAM
685 bool wxVariantDataChar::Read(wxSTD istream
& WXUNUSED(str
))
687 wxFAIL_MSG(wxT("Unimplemented"));
694 bool wxVariantDataChar::Write(wxOutputStream
& str
) const
696 wxTextOutputStream
s(str
);
702 bool wxVariantDataChar::Read(wxInputStream
& str
)
704 wxTextInputStream
s(str
);
709 #endif // wxUSE_STREAMS
711 bool wxVariantDataChar::Read(wxString
& str
)
713 m_value
= str
[(size_t)0];
718 * wxVariantDataString
721 #if defined(__BORLANDC__) && defined(__WIN16__)
722 // Change name because of truncation
723 #define wxVariantDataString wxVariantStringData
726 class WXDLLEXPORT wxVariantDataString
: public wxVariantData
728 #if defined(__BORLANDC__) && defined(__WIN16__)
729 DECLARE_DYNAMIC_CLASS(wxVariantStringData
)
731 DECLARE_DYNAMIC_CLASS(wxVariantDataString
)
734 wxVariantDataString() { }
735 wxVariantDataString(const wxString
& value
) { m_value
= value
; }
737 inline wxString
GetValue() const { return m_value
; }
738 inline void SetValue(const wxString
& value
) { m_value
= value
; }
740 virtual void Copy(wxVariantData
& data
);
741 virtual bool Eq(wxVariantData
& data
) const;
742 #if wxUSE_STD_IOSTREAM
743 virtual bool Write(wxSTD ostream
& str
) const;
745 virtual bool Read(wxString
& str
);
746 virtual bool Write(wxString
& str
) const;
747 #if wxUSE_STD_IOSTREAM
748 virtual bool Read(wxSTD istream
& str
);
751 virtual bool Read(wxInputStream
& str
);
752 virtual bool Write(wxOutputStream
& str
) const;
753 #endif // wxUSE_STREAMS
754 virtual wxString
GetType() const { return wxT("string"); };
760 void wxVariantDataString::Copy(wxVariantData
& data
)
762 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Copy: Can't copy to this type of data") );
764 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
766 otherData
.m_value
= m_value
;
769 bool wxVariantDataString::Eq(wxVariantData
& data
) const
771 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") );
773 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
775 return (otherData
.m_value
== m_value
);
778 #if wxUSE_STD_IOSTREAM
779 bool wxVariantDataString::Write(wxSTD ostream
& str
) const
781 str
<< (const char*) m_value
.mb_str();
786 bool wxVariantDataString::Write(wxString
& str
) const
792 #if wxUSE_STD_IOSTREAM
793 bool wxVariantDataString::Read(wxSTD istream
& str
)
801 bool wxVariantDataString::Write(wxOutputStream
& str
) const
803 // why doesn't wxOutputStream::operator<< take "const wxString&"
804 wxTextOutputStream
s(str
);
805 s
.WriteString(m_value
);
809 bool wxVariantDataString::Read(wxInputStream
& str
)
811 wxTextInputStream
s(str
);
813 m_value
= s
.ReadString();
816 #endif // wxUSE_STREAMS
818 bool wxVariantDataString::Read(wxString
& str
)
824 #if defined(__BORLANDC__) && defined(__WIN16__)
825 IMPLEMENT_DYNAMIC_CLASS(wxVariantStringData
, wxVariantData
)
827 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString
, wxVariantData
)
834 // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled
835 #if wxUSE_TIMEDATE && !defined(__WATCOMC__)
837 class wxVariantDataTime
: public wxVariantData
839 DECLARE_DYNAMIC_CLASS(wxVariantDataTime
)
841 wxVariantDataTime() { }
842 wxVariantDataTime(const wxTime
& value
) { m_value
= value
; }
844 inline wxTime
GetValue() const { return m_value
; }
845 inline void SetValue(const wxTime
& value
) { m_value
= value
; }
847 virtual void Copy(wxVariantData
& data
);
848 virtual bool Eq(wxVariantData
& data
) const;
849 #if wxUSE_STD_IOSTREAM
850 virtual bool Write(wxSTD ostream
& str
) const;
852 virtual bool Write(wxString
& str
) const;
853 #if wxUSE_STD_IOSTREAM
854 virtual bool Read(wxSTD istream
& str
);
856 virtual bool Read(wxString
& str
);
857 virtual wxString
GetType() const { return wxT("time"); };
858 virtual wxVariantData
* Clone() { return new wxVariantDataTime
; }
864 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataTime
, wxVariantData
)
866 void wxVariantDataTime::Copy(wxVariantData
& data
)
868 wxASSERT_MSG( (data
.GetType() == wxT("time")), wxT("wxVariantDataTime::Copy: Can't copy to this type of data") );
870 wxVariantDataTime
& otherData
= (wxVariantDataTime
&) data
;
872 otherData
.m_value
= m_value
;
875 bool wxVariantDataTime::Eq(wxVariantData
& data
) const
877 wxASSERT_MSG( (data
.GetType() == wxT("time")), wxT("wxVariantDataTime::Eq: argument mismatch") );
879 wxVariantDataTime
& otherData
= (wxVariantDataTime
&) data
;
881 return (otherData
.m_value
== m_value
);
884 #if wxUSE_STD_IOSTREAM
885 bool wxVariantDataTime::Write(wxSTD ostream
& str
) const
889 str
<< (const char*) s
.mb_str();
894 bool wxVariantDataTime::Write(wxString
& str
) const
896 wxChar
*s
= m_value
.FormatTime();
901 #if wxUSE_STD_IOSTREAM
902 bool wxVariantDataTime::Read(wxSTD istream
& WXUNUSED(str
))
909 bool wxVariantDataTime::Read(wxString
& WXUNUSED(str
))
919 class wxVariantDataDate
: public wxVariantData
921 DECLARE_DYNAMIC_CLASS(wxVariantDataDate
)
923 wxVariantDataDate() { }
924 wxVariantDataDate(const wxDate
& value
) { m_value
= value
; }
926 inline wxDate
GetValue() const { return m_value
; }
927 inline void SetValue(const wxDate
& value
) { m_value
= value
; }
929 virtual void Copy(wxVariantData
& data
);
930 virtual bool Eq(wxVariantData
& data
) const;
931 #if wxUSE_STD_IOSTREAM
932 virtual bool Write(wxSTD ostream
& str
) const;
934 virtual bool Write(wxString
& str
) const;
935 #if wxUSE_STD_IOSTREAM
936 virtual bool Read(wxSTD istream
& str
);
938 virtual bool Read(wxString
& str
);
939 virtual wxString
GetType() const { return wxT("date"); };
940 virtual wxVariantData
* Clone() { return new wxVariantDataDate
; }
946 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDate
, wxVariantData
)
948 void wxVariantDataDate::Copy(wxVariantData
& data
)
950 wxASSERT_MSG( (data
.GetType() == wxT("date")), wxT("wxVariantDataDate::Copy: Can't copy to this type of data") );
952 wxVariantDataDate
& otherData
= (wxVariantDataDate
&) data
;
954 otherData
.m_value
= m_value
;
957 bool wxVariantDataDate::Eq(wxVariantData
& data
) const
959 wxASSERT_MSG( (data
.GetType() == wxT("date")), wxT("wxVariantDataDate::Eq: argument mismatch") );
961 wxVariantDataDate
& otherData
= (wxVariantDataDate
&) data
;
963 return (otherData
.m_value
== m_value
);
966 #if wxUSE_STD_IOSTREAM
967 bool wxVariantDataDate::Write(wxSTD ostream
& str
) const
971 str
<< (const char*) s
.mb_str();
976 bool wxVariantDataDate::Write(wxString
& str
) const
978 str
= m_value
.FormatDate();
982 #if wxUSE_STD_IOSTREAM
983 bool wxVariantDataDate::Read(wxSTD istream
& WXUNUSED(str
))
990 bool wxVariantDataDate::Read(wxString
& WXUNUSED(str
))
999 * wxVariantDataVoidPtr
1002 class wxVariantDataVoidPtr
: public wxVariantData
1004 DECLARE_DYNAMIC_CLASS(wxVariantDataVoidPtr
)
1006 wxVariantDataVoidPtr() { }
1007 wxVariantDataVoidPtr(void* value
) { m_value
= value
; }
1009 inline void* GetValue() const { return m_value
; }
1010 inline void SetValue(void* value
) { m_value
= value
; }
1012 virtual void Copy(wxVariantData
& data
);
1013 virtual bool Eq(wxVariantData
& data
) const;
1014 #if wxUSE_STD_IOSTREAM
1015 virtual bool Write(wxSTD ostream
& str
) const;
1017 virtual bool Write(wxString
& str
) const;
1018 #if wxUSE_STD_IOSTREAM
1019 virtual bool Read(wxSTD istream
& str
);
1021 virtual bool Read(wxString
& str
);
1022 virtual wxString
GetType() const { return wxT("void*"); };
1023 virtual wxVariantData
* Clone() { return new wxVariantDataVoidPtr
; }
1029 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr
, wxVariantData
)
1031 void wxVariantDataVoidPtr::Copy(wxVariantData
& data
)
1033 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Copy: Can't copy to this type of data") );
1035 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
1037 otherData
.m_value
= m_value
;
1040 bool wxVariantDataVoidPtr::Eq(wxVariantData
& data
) const
1042 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") );
1044 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
1046 return (otherData
.m_value
== m_value
);
1049 #if wxUSE_STD_IOSTREAM
1050 bool wxVariantDataVoidPtr::Write(wxSTD ostream
& str
) const
1054 str
<< (const char*) s
.mb_str();
1059 bool wxVariantDataVoidPtr::Write(wxString
& str
) const
1061 str
.Printf(wxT("%ld"), (long) m_value
);
1065 #if wxUSE_STD_IOSTREAM
1066 bool wxVariantDataVoidPtr::Read(wxSTD istream
& WXUNUSED(str
))
1073 bool wxVariantDataVoidPtr::Read(wxString
& WXUNUSED(str
))
1080 * wxVariantDataDateTime
1083 class wxVariantDataDateTime
: public wxVariantData
1085 DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime
)
1088 wxVariantDataDateTime() { }
1089 wxVariantDataDateTime(const wxDateTime
& value
) { m_value
= value
; }
1091 wxVariantDataDateTime(const TIME_STRUCT
* valptr
)
1092 { m_value
= wxDateTime(valptr
->hour
, valptr
->minute
, valptr
->second
); }
1093 wxVariantDataDateTime(const DATE_STRUCT
* valptr
)
1094 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1),valptr
->year
); }
1095 wxVariantDataDateTime(const TIMESTAMP_STRUCT
* valptr
)
1096 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1), valptr
->year
,
1097 valptr
->hour
, valptr
->minute
, valptr
->second
, valptr
->fraction
); }
1100 inline wxDateTime
GetValue() const { return m_value
; }
1101 inline void SetValue(const wxDateTime
& value
) { m_value
= value
; }
1103 virtual void Copy(wxVariantData
& data
);
1104 virtual bool Eq(wxVariantData
& data
) const;
1105 #if wxUSE_STD_IOSTREAM
1106 virtual bool Write(ostream
& str
) const;
1108 virtual bool Write(wxString
& str
) const;
1109 #if wxUSE_STD_IOSTREAM
1110 virtual bool Read(istream
& str
);
1112 virtual bool Read(wxString
& str
);
1113 virtual wxString
GetType() const { return wxT("datetime"); };
1114 virtual wxVariantData
* Clone() { return new wxVariantDataDateTime
; }
1121 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDateTime
, wxVariantData
)
1123 void wxVariantDataDateTime::Copy(wxVariantData
& data
)
1125 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Copy: Can't copy to this type of data") );
1127 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1129 otherData
.m_value
= m_value
;
1133 bool wxVariantDataDateTime::Eq(wxVariantData
& data
) const
1135 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Eq: argument mismatch") );
1137 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1139 return (otherData
.m_value
== m_value
);
1143 #if wxUSE_STD_IOSTREAM
1144 bool wxVariantDataDateTime::Write(ostream
& str
) const
1152 bool wxVariantDataDateTime::Write(wxString
& str
) const
1154 str
= m_value
.Format();
1159 #if wxUSE_STD_IOSTREAM
1160 bool wxVariantDataDateTime::Read(istream
& WXUNUSED(str
))
1168 bool wxVariantDataDateTime::Read(wxString
& str
)
1170 if(! m_value
.ParseDateTime(str
))
1180 IMPLEMENT_DYNAMIC_CLASS(wxVariant
, wxObject
)
1182 // Construction & destruction
1183 wxVariant::wxVariant()
1185 m_data
= (wxVariantData
*) NULL
;
1188 wxVariant::wxVariant(double val
, const wxString
& name
)
1190 m_data
= new wxVariantDataReal(val
);
1194 wxVariant::wxVariant(long val
, const wxString
& name
)
1196 m_data
= new wxVariantDataLong(val
);
1201 wxVariant::wxVariant(bool val
, const wxString
& name
)
1203 m_data
= new wxVariantDataBool(val
);
1208 wxVariant::wxVariant(char val
, const wxString
& name
)
1210 m_data
= new wxVariantDataChar(val
);
1214 wxVariant::wxVariant(const wxString
& val
, const wxString
& name
)
1216 m_data
= new wxVariantDataString(val
);
1220 wxVariant::wxVariant(const wxChar
* val
, const wxString
& name
)
1222 m_data
= new wxVariantDataString(wxString(val
));
1226 wxVariant::wxVariant(const wxStringList
& val
, const wxString
& name
)
1228 m_data
= new wxVariantDataStringList(val
);
1232 wxVariant::wxVariant(const wxList
& val
, const wxString
& name
) // List of variants
1234 m_data
= new wxVariantDataList(val
);
1238 // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled
1239 #if wxUSE_TIMEDATE && !defined(__WATCOMC__)
1240 wxVariant::wxVariant(const wxTime
& val
, const wxString
& name
) // Time
1242 m_data
= new wxVariantDataTime(val
);
1246 wxVariant::wxVariant(const wxDate
& val
, const wxString
& name
) // Date
1248 m_data
= new wxVariantDataDate(val
);
1253 wxVariant::wxVariant(void* val
, const wxString
& name
) // Void ptr
1255 m_data
= new wxVariantDataVoidPtr(val
);
1259 wxVariant::wxVariant(const wxDateTime
& val
, const wxString
& name
) // Date
1261 m_data
= new wxVariantDataDateTime(val
);
1266 wxVariant::wxVariant(const TIME_STRUCT
* valptr
, const wxString
& name
) // Date
1268 m_data
= new wxVariantDataDateTime(valptr
);
1272 wxVariant::wxVariant(const TIMESTAMP_STRUCT
* valptr
, const wxString
& name
) // Date
1274 m_data
= new wxVariantDataDateTime(valptr
);
1278 wxVariant::wxVariant(const DATE_STRUCT
* valptr
, const wxString
& name
) // Date
1280 m_data
= new wxVariantDataDateTime(valptr
);
1285 wxVariant::wxVariant(const wxVariant
& variant
)
1287 if (!variant
.IsNull())
1289 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1290 variant
.m_data
->Copy(*m_data
);
1293 m_data
= (wxVariantData
*) NULL
;
1294 m_name
= variant
.m_name
;
1297 wxVariant::wxVariant(wxVariantData
* data
, const wxString
& name
) // User-defined data
1303 wxVariant::~wxVariant()
1309 // Make NULL (i.e. delete the data)
1310 void wxVariant::MakeNull()
1316 // Generic operators
1318 void wxVariant::operator= (const wxVariant
& variant
)
1320 if (variant
.IsNull())
1326 if (IsNull() || (GetType() != variant
.GetType()))
1330 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1332 // GetData()->Copy(* variant.GetData());
1333 variant
.GetData()->Copy(* GetData());
1336 // Assignment using data, e.g.
1337 // myVariant = new wxStringVariantData("hello")
1338 void wxVariant::operator= (wxVariantData
* variantData
)
1341 m_data
= variantData
;
1344 bool wxVariant::operator== (const wxVariant
& variant
) const
1346 if (IsNull() || variant
.IsNull())
1347 return (IsNull() == variant
.IsNull());
1349 return (GetData()->Eq(* variant
.GetData()));
1352 bool wxVariant::operator!= (const wxVariant
& variant
) const
1354 return (!(*this == variant
));
1358 // Specific operators
1359 bool wxVariant::operator== (double value
) const
1362 if (!Convert(&thisValue
))
1365 return (value
== thisValue
);
1368 bool wxVariant::operator!= (double value
) const
1370 return (!((*this) == value
));
1373 void wxVariant::operator= (double value
)
1375 if (GetType() == wxT("double"))
1377 ((wxVariantDataReal
*)GetData())->SetValue(value
);
1383 m_data
= new wxVariantDataReal(value
);
1387 bool wxVariant::operator== (long value
) const
1390 if (!Convert(&thisValue
))
1393 return (value
== thisValue
);
1396 bool wxVariant::operator!= (long value
) const
1398 return (!((*this) == value
));
1401 void wxVariant::operator= (long value
)
1403 if (GetType() == wxT("long"))
1405 ((wxVariantDataLong
*)GetData())->SetValue(value
);
1411 m_data
= new wxVariantDataLong(value
);
1415 bool wxVariant::operator== (char value
) const
1418 if (!Convert(&thisValue
))
1421 return (value
== thisValue
);
1424 bool wxVariant::operator!= (char value
) const
1426 return (!((*this) == value
));
1429 void wxVariant::operator= (char value
)
1431 if (GetType() == wxT("char"))
1433 ((wxVariantDataChar
*)GetData())->SetValue(value
);
1439 m_data
= new wxVariantDataChar(value
);
1444 bool wxVariant::operator== (bool value
) const
1447 if (!Convert(&thisValue
))
1450 return (value
== thisValue
);
1453 bool wxVariant::operator!= (bool value
) const
1455 return (!((*this) == value
));
1458 void wxVariant::operator= (bool value
)
1460 if (GetType() == wxT("bool"))
1462 ((wxVariantDataBool
*)GetData())->SetValue(value
);
1468 m_data
= new wxVariantDataBool(value
);
1473 bool wxVariant::operator== (const wxString
& value
) const
1476 if (!Convert(&thisValue
))
1479 return value
== thisValue
;
1482 bool wxVariant::operator!= (const wxString
& value
) const
1484 return (!((*this) == value
));
1487 void wxVariant::operator= (const wxString
& value
)
1489 if (GetType() == wxT("string"))
1491 ((wxVariantDataString
*)GetData())->SetValue(value
);
1497 m_data
= new wxVariantDataString(value
);
1501 void wxVariant::operator= (const wxChar
* value
)
1503 if (GetType() == wxT("string"))
1505 ((wxVariantDataString
*)GetData())->SetValue(wxString(value
));
1511 m_data
= new wxVariantDataString(wxString(value
));
1515 bool wxVariant::operator== (const wxStringList
& value
) const
1517 wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") );
1519 wxVariantDataStringList
other(value
);
1520 return (m_data
->Eq(other
));
1523 bool wxVariant::operator!= (const wxStringList
& value
) const
1525 return (!((*this) == value
));
1528 void wxVariant::operator= (const wxStringList
& value
)
1530 if (GetType() == wxT("stringlist"))
1532 ((wxVariantDataStringList
*)GetData())->SetValue(value
);
1538 m_data
= new wxVariantDataStringList(value
);
1542 bool wxVariant::operator== (const wxList
& value
) const
1544 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for == operator") );
1546 wxVariantDataList
other(value
);
1547 return (m_data
->Eq(other
));
1550 bool wxVariant::operator!= (const wxList
& value
) const
1552 return (!((*this) == value
));
1555 void wxVariant::operator= (const wxList
& value
)
1557 if (GetType() == wxT("list"))
1559 ((wxVariantDataList
*)GetData())->SetValue(value
);
1565 m_data
= new wxVariantDataList(value
);
1569 // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled
1570 #if wxUSE_TIMEDATE && !defined(__WATCOMC__)
1571 bool wxVariant::operator== (const wxTime
& value
) const
1574 if (!Convert(&thisValue
))
1577 return value
== thisValue
;
1580 bool wxVariant::operator!= (const wxTime
& value
) const
1582 return (!((*this) == value
));
1585 void wxVariant::operator= (const wxTime
& value
)
1587 if (GetType() == wxT("time"))
1589 ((wxVariantDataTime
*)GetData())->SetValue(value
);
1595 m_data
= new wxVariantDataTime(value
);
1599 bool wxVariant::operator== (const wxDate
& value
) const
1602 if (!Convert(&thisValue
))
1605 return (value
== thisValue
);
1608 bool wxVariant::operator!= (const wxDate
& value
) const
1610 return (!((*this) == value
));
1613 void wxVariant::operator= (const wxDate
& value
)
1615 if (GetType() == wxT("date"))
1617 ((wxVariantDataTime
*)GetData())->SetValue(value
);
1623 m_data
= new wxVariantDataDate(value
);
1628 bool wxVariant::operator== (void* value
) const
1630 return (value
== ((wxVariantDataVoidPtr
*)GetData())->GetValue());
1633 bool wxVariant::operator!= (void* value
) const
1635 return (!((*this) == (void*) value
));
1638 void wxVariant::operator= (void* value
)
1640 if (GetType() == wxT("void*"))
1642 ((wxVariantDataVoidPtr
*)GetData())->SetValue(value
);
1648 m_data
= new wxVariantDataVoidPtr(value
);
1652 bool wxVariant::operator== (const wxDateTime
& value
) const
1654 wxDateTime thisValue
;
1655 if (!Convert(&thisValue
))
1658 return value
.IsEqualTo(thisValue
);
1661 bool wxVariant::operator!= (const wxDateTime
& value
) const
1663 return (!((*this) == value
));
1666 void wxVariant::operator= (const wxDateTime
& value
)
1668 if (GetType() == wxT("datetime"))
1670 ((wxVariantDataDateTime
*)GetData())->SetValue(value
);
1676 m_data
= new wxVariantDataDateTime(value
);
1682 void wxVariant::operator= (const DATE_STRUCT
* value
)
1686 m_data
= new wxVariantDataDateTime(value
);
1690 void wxVariant::operator= (const TIME_STRUCT
* value
)
1694 m_data
= new wxVariantDataDateTime(value
);
1698 void wxVariant::operator= (const TIMESTAMP_STRUCT
* value
)
1702 m_data
= new wxVariantDataDateTime(value
);
1707 // Treat a list variant as an array
1708 wxVariant
wxVariant::operator[] (size_t idx
) const
1710 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for array operator") );
1712 if (GetType() == wxT("list"))
1714 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1715 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().Number()), wxT("Invalid index for array") );
1716 return * (wxVariant
*) (data
->GetValue().Nth(idx
)->Data());
1718 else if (GetType() == wxT("stringlist"))
1720 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1721 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().Number()), wxT("Invalid index for array") );
1723 wxVariant
variant( wxString( (wxChar
*) (data
->GetValue().Nth(idx
)->Data()) ));
1726 return wxNullVariant
;
1729 wxVariant
& wxVariant::operator[] (size_t idx
)
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.
1734 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
1736 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1737 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().Number()), wxT("Invalid index for array") );
1739 return * (wxVariant
*) (data
->GetValue().Nth(idx
)->Data());
1742 // Return the number of elements in a list
1743 int wxVariant::GetCount() const
1745 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for GetCount()") );
1747 if (GetType() == wxT("list"))
1749 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1750 return data
->GetValue().Number();
1752 else if (GetType() == wxT("stringlist"))
1754 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1755 return data
->GetValue().Number();
1760 wxString
wxVariant::MakeString() const
1765 if (GetData()->Write(str
))
1768 return wxString(wxT(""));
1773 void wxVariant::SetData(wxVariantData
* data
)
1775 if (m_data
) delete m_data
;
1780 // Returns a string representing the type of the variant,
1781 // e.g. "string", "bool", "stringlist", "list", "double", "long"
1782 wxString
wxVariant::GetType() const
1785 return wxString(wxT("null"));
1787 return m_data
->GetType();
1791 bool wxVariant::IsType(const wxString
& type
) const
1793 return (GetType() == type
);
1798 double wxVariant::GetReal() const
1801 if (Convert(& value
))
1805 wxFAIL_MSG(wxT("Could not convert to a real number"));
1810 long wxVariant::GetInteger() const
1813 if (Convert(& value
))
1817 wxFAIL_MSG(wxT("Could not convert to an integer"));
1822 char wxVariant::GetChar() const
1825 if (Convert(& value
))
1829 wxFAIL_MSG(wxT("Could not convert to a char"));
1834 bool wxVariant::GetBool() const
1837 if (Convert(& value
))
1841 wxFAIL_MSG(wxT("Could not convert to a bool"));
1846 wxString
wxVariant::GetString() const
1849 if (!Convert(& value
))
1851 wxFAIL_MSG(wxT("Could not convert to a string"));
1857 // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled
1858 #if wxUSE_TIMEDATE && !defined(__WATCOMC__)
1859 wxTime
wxVariant::GetTime() const
1862 if (!Convert(& value
))
1864 wxFAIL_MSG(wxT("Could not convert to a time"));
1870 wxDate
wxVariant::GetDate() const
1873 if (!Convert(& value
))
1875 wxFAIL_MSG(wxT("Could not convert to a date"));
1880 #endif // wxUSE_TIMEDATE
1882 void* wxVariant::GetVoidPtr() const
1884 wxASSERT( (GetType() == wxT("void*")) );
1886 return (void*) ((wxVariantDataVoidPtr
*) m_data
)->GetValue();
1889 wxDateTime
wxVariant::GetDateTime() const
1892 if (!Convert(& value
))
1894 wxFAIL_MSG(wxT("Could not convert to a datetime"));
1900 wxList
& wxVariant::GetList() const
1902 wxASSERT( (GetType() == wxT("list")) );
1904 return (wxList
&) ((wxVariantDataList
*) m_data
)->GetValue();
1907 wxStringList
& wxVariant::GetStringList() const
1909 wxASSERT( (GetType() == wxT("stringlist")) );
1911 return (wxStringList
&) ((wxVariantDataStringList
*) m_data
)->GetValue();
1915 void wxVariant::Append(const wxVariant
& value
)
1917 wxList
& list
= GetList();
1919 list
.Append(new wxVariant(value
));
1922 // Insert at front of list
1923 void wxVariant::Insert(const wxVariant
& value
)
1925 wxList
& list
= GetList();
1927 list
.Insert(new wxVariant(value
));
1930 // Returns TRUE if the variant is a member of the list
1931 bool wxVariant::Member(const wxVariant
& value
) const
1933 wxList
& list
= GetList();
1935 wxNode
* node
= list
.First();
1938 wxVariant
* other
= (wxVariant
*) node
->Data();
1939 if (value
== *other
)
1941 node
= node
->Next();
1946 // Deletes the nth element of the list
1947 bool wxVariant::Delete(int item
)
1949 wxList
& list
= GetList();
1951 wxASSERT_MSG( (item
< list
.Number()), wxT("Invalid index to Delete") );
1952 wxNode
* node
= list
.Nth(item
);
1953 wxVariant
* variant
= (wxVariant
*) node
->Data();
1960 void wxVariant::ClearList()
1962 if (!IsNull() && (GetType() == wxT("list")))
1964 ((wxVariantDataList
*) m_data
)->Clear();
1968 if (GetType() != wxT("list"))
1973 m_data
= new wxVariantDataList
;
1978 bool wxVariant::Convert(long* value
) const
1980 wxString
type(GetType());
1981 if (type
== wxT("double"))
1982 *value
= (long) (((wxVariantDataReal
*)GetData())->GetValue());
1983 else if (type
== wxT("long"))
1984 *value
= ((wxVariantDataLong
*)GetData())->GetValue();
1986 else if (type
== wxT("bool"))
1987 *value
= (long) (((wxVariantDataBool
*)GetData())->GetValue());
1989 else if (type
== wxT("string"))
1990 *value
= wxAtol((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
1997 bool wxVariant::Convert(bool* value
) const
1999 wxString
type(GetType());
2000 if (type
== wxT("double"))
2001 *value
= ((int) (((wxVariantDataReal
*)GetData())->GetValue()) != 0);
2002 else if (type
== wxT("long"))
2003 *value
= (((wxVariantDataLong
*)GetData())->GetValue() != 0);
2005 else if (type
== wxT("bool"))
2006 *value
= ((wxVariantDataBool
*)GetData())->GetValue();
2008 else if (type
== wxT("string"))
2010 wxString
val(((wxVariantDataString
*)GetData())->GetValue());
2012 if (val
== wxT("true") || val
== wxT("yes"))
2014 else if (val
== wxT("false") || val
== wxT("no"))
2025 bool wxVariant::Convert(double* value
) const
2027 wxString
type(GetType());
2028 if (type
== wxT("double"))
2029 *value
= ((wxVariantDataReal
*)GetData())->GetValue();
2030 else if (type
== wxT("long"))
2031 *value
= (double) (((wxVariantDataLong
*)GetData())->GetValue());
2033 else if (type
== wxT("bool"))
2034 *value
= (double) (((wxVariantDataBool
*)GetData())->GetValue());
2036 else if (type
== wxT("string"))
2037 *value
= (double) wxAtof((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2044 bool wxVariant::Convert(char* value
) const
2046 wxString
type(GetType());
2047 if (type
== wxT("char"))
2048 *value
= ((wxVariantDataChar
*)GetData())->GetValue();
2049 else if (type
== wxT("long"))
2050 *value
= (char) (((wxVariantDataLong
*)GetData())->GetValue());
2052 else if (type
== wxT("bool"))
2053 *value
= (char) (((wxVariantDataBool
*)GetData())->GetValue());
2061 bool wxVariant::Convert(wxString
* value
) const
2063 *value
= MakeString();
2067 // For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled
2068 #if wxUSE_TIMEDATE && !defined(__WATCOMC__)
2069 bool wxVariant::Convert(wxTime
* value
) const
2071 wxString
type(GetType());
2072 if (type
== wxT("time"))
2073 *value
= ((wxVariantDataTime
*)GetData())->GetValue();
2074 else if (type
== wxT("date"))
2075 *value
= wxTime(((wxVariantDataDate
*)GetData())->GetValue());
2082 bool wxVariant::Convert(wxDate
* value
) const
2084 wxString
type(GetType());
2085 if (type
== wxT("date"))
2086 *value
= ((wxVariantDataDate
*)GetData())->GetValue();
2092 #endif // wxUSE_TIMEDATE
2094 bool wxVariant::Convert(wxDateTime
* value
) const
2096 wxString
type(GetType());
2097 if (type
== wxT("datetime"))
2098 *value
= ((wxVariantDataDateTime
*)GetData())->GetValue();