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