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