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