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