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