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