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