]> git.saurik.com Git - wxWidgets.git/blame - include/wx/variant.h
fixed typo
[wxWidgets.git] / include / wx / variant.h
CommitLineData
8cb50e4b
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: variant.h
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)
3f4a0c5b 9// Licence: wxWindows licence
8cb50e4b
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_VARIANT_H_
13#define _WX_VARIANT_H_
14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
8cb50e4b
JS
16#pragma interface "variant.h"
17#endif
18
19#include "wx/defs.h"
20#include "wx/object.h"
21#include "wx/string.h"
22#include "wx/list.h"
23
e2b87f38
VZ
24#if wxUSE_DATETIME
25 #include "wx/datetime.h"
26#endif // wxUSE_DATETIME
edca7a82
GT
27
28#if wxUSE_ODBC
29 #include "wx/db.h" // will #include sqltypes.h
30#endif //ODBC
31
65f19af1 32#include "wx/iosfwrap.h"
8cb50e4b
JS
33
34/*
35 * wxVariantData stores the actual data in a wxVariant object,
36 * to allow it to store any type of data.
37 * Derive from this to provide custom data handling.
38 *
39 * TODO: in order to replace wxPropertyValue, we would need
40 * to consider adding constructors that take pointers to C++ variables,
41 * or removing that functionality from the wxProperty library.
42 * Essentially wxPropertyValue takes on some of the wxValidator functionality
43 * by storing pointers and not just actual values, allowing update of C++ data
44 * to be handled automatically. Perhaps there's another way of doing this without
45 * overloading wxVariant with unnecessary functionality.
46 */
47
48class WXDLLEXPORT wxVariantData: public wxObject
49{
50DECLARE_ABSTRACT_CLASS(wxVariantData)
51public:
52
53// Construction & destruction
54 wxVariantData() {};
55
56// Override these to provide common functionality
57 // Copy to data
58 virtual void Copy(wxVariantData& data) = 0;
59 virtual bool Eq(wxVariantData& data) const = 0;
38830220 60#if wxUSE_STD_IOSTREAM
dd107c50 61 virtual bool Write(wxSTD ostream& str) const = 0;
38830220 62#endif
8cb50e4b 63 virtual bool Write(wxString& str) const = 0;
38830220 64#if wxUSE_STD_IOSTREAM
dd107c50 65 virtual bool Read(wxSTD istream& str) = 0;
38830220 66#endif
8cb50e4b
JS
67 virtual bool Read(wxString& str) = 0;
68 // What type is it? Return a string name.
69 virtual wxString GetType() const = 0;
70};
71
72/*
73 * wxVariant can store any kind of data, but has some basic types
74 * built in.
75 * NOTE: this eventually should have a reference-counting implementation.
76 * PLEASE, if you change it to ref-counting, make sure it doesn't involve bloating
77 * this class too much.
78 */
79
80class WXDLLEXPORT wxVariant: public wxObject
81{
82DECLARE_DYNAMIC_CLASS(wxVariant)
83public:
84
85// Construction & destruction
86 wxVariant();
e90c1d2a
VZ
87 wxVariant(double val, const wxString& name = wxEmptyString);
88 wxVariant(long val, const wxString& name = wxEmptyString);
57493f9f 89#ifdef HAVE_BOOL
e90c1d2a 90 wxVariant(bool val, const wxString& name = wxEmptyString);
57493f9f 91#endif
e90c1d2a
VZ
92 wxVariant(char val, const wxString& name = wxEmptyString);
93 wxVariant(const wxString& val, const wxString& name = wxEmptyString);
94 wxVariant(const wxChar* val, const wxString& name = wxEmptyString); // Necessary or VC++ assumes bool!
95 wxVariant(const wxStringList& val, const wxString& name = wxEmptyString);
96 wxVariant(const wxList& val, const wxString& name = wxEmptyString); // List of variants
e90c1d2a
VZ
97 wxVariant(void* ptr, const wxString& name = wxEmptyString); // void* (general purpose)
98 wxVariant(wxVariantData* data, const wxString& name = wxEmptyString); // User-defined data
edca7a82 99//TODO: Need to document
e2b87f38 100#if wxUSE_DATETIME
edca7a82 101 wxVariant(const wxDateTime& val, const wxString& name = wxEmptyString); // Date
e2b87f38 102#endif // wxUSE_DATETIME
fb42d7c3 103 wxVariant(const wxArrayString& val, const wxString& name = wxEmptyString); // String array
edca7a82
GT
104#if wxUSE_ODBC
105 wxVariant(const DATE_STRUCT* valptr, const wxString& name = wxEmptyString); // DateTime
106 wxVariant(const TIME_STRUCT* valptr, const wxString& name = wxEmptyString); // DateTime
107 wxVariant(const TIMESTAMP_STRUCT* valptr, const wxString& name = wxEmptyString); // DateTime
108#endif
109//TODO: End of Need to document
110
8cb50e4b 111 wxVariant(const wxVariant& variant);
8cb50e4b
JS
112 ~wxVariant();
113
114// Generic operators
115 // Assignment
116 void operator= (const wxVariant& variant);
117
edca7a82 118//TODO: Need to document
e2b87f38 119#if wxUSE_DATETIME
edca7a82
GT
120 bool operator== (const wxDateTime& value) const;
121 bool operator!= (const wxDateTime& value) const;
122 void operator= (const wxDateTime& value) ;
e2b87f38 123#endif // wxUSE_DATETIME
fb42d7c3
VZ
124
125 bool operator== (const wxArrayString& value) const;
126 bool operator!= (const wxArrayString& value) const;
127 void operator= (const wxArrayString& value) ;
edca7a82
GT
128#if wxUSE_ODBC
129 void operator= (const DATE_STRUCT* value) ;
130 void operator= (const TIME_STRUCT* value) ;
131 void operator= (const TIMESTAMP_STRUCT* value) ;
132#endif
133//TODO: End of Need to document
134
8cb50e4b
JS
135 // Assignment using data, e.g.
136 // myVariant = new wxStringVariantData("hello");
137 void operator= (wxVariantData* variantData);
138 bool operator== (const wxVariant& variant) const;
139 bool operator!= (const wxVariant& variant) const;
140
141// Specific operators
142 bool operator== (double value) const;
143 bool operator!= (double value) const;
144 void operator= (double value) ;
145 bool operator== (long value) const;
146 bool operator!= (long value) const;
147 void operator= (long value) ;
148 bool operator== (char value) const;
149 bool operator!= (char value) const;
150 void operator= (char value) ;
57493f9f 151#ifdef HAVE_BOOL
8cb50e4b
JS
152 bool operator== (bool value) const;
153 bool operator!= (bool value) const;
154 void operator= (bool value) ;
57493f9f 155#endif
8cb50e4b
JS
156 bool operator== (const wxString& value) const;
157 bool operator!= (const wxString& value) const;
158 void operator= (const wxString& value) ;
2ed57eb7 159 void operator= (const wxChar* value) ; // Necessary or VC++ assumes bool!
8cb50e4b
JS
160 bool operator== (const wxStringList& value) const;
161 bool operator!= (const wxStringList& value) const;
162 void operator= (const wxStringList& value) ;
163 bool operator== (const wxList& value) const;
164 bool operator!= (const wxList& value) const;
165 void operator= (const wxList& value) ;
a0a302dc
JS
166 bool operator== (void* value) const;
167 bool operator!= (void* value) const;
168 void operator= (void* value) ;
8cb50e4b
JS
169
170 // Treat a list variant as an array
171 wxVariant operator[] (size_t idx) const;
172 wxVariant& operator[] (size_t idx) ;
173
174 // Implicit conversion to a wxString
175 inline operator wxString () const { return MakeString(); }
176 wxString MakeString() const;
177
178 // Other implicit conversions
179 inline operator double () const { return GetDouble(); }
a0a302dc 180 inline operator char () const { return GetChar(); }
8cb50e4b
JS
181 inline operator long () const { return GetLong(); }
182 inline operator bool () const { return GetBool(); }
a0a302dc 183 inline operator void* () const { return GetVoidPtr(); }
edca7a82 184//TODO: Need to document
e2b87f38 185#if wxUSE_DATETIME
edca7a82 186 inline operator wxDateTime () const { return GetDateTime(); }
e2b87f38 187#endif // wxUSE_DATETIME
edca7a82 188//TODO: End of Need to document
8cb50e4b
JS
189
190// Accessors
a0a302dc
JS
191 // Sets/gets name
192 inline void SetName(const wxString& name) { m_name = name; }
193 inline const wxString& GetName() const { return m_name; }
194
8cb50e4b
JS
195 // Tests whether there is data
196 inline bool IsNull() const { return (m_data == (wxVariantData*) NULL); }
197
198 wxVariantData* GetData() const { return m_data; }
199 void SetData(wxVariantData* data) ;
200
201 // Returns a string representing the type of the variant,
202 // e.g. "string", "bool", "stringlist", "list", "double", "long"
203 wxString GetType() const;
204
205 bool IsType(const wxString& type) const;
206
207 // Return the number of elements in a list
208 int GetCount() const;
209
210// Value accessors
211 double GetReal() const ;
212 inline double GetDouble() const { return GetReal(); };
213 long GetInteger() const ;
214 inline long GetLong() const { return GetInteger(); };
215 char GetChar() const ;
216 bool GetBool() const ;
217 wxString GetString() const ;
218 wxList& GetList() const ;
219 wxStringList& GetStringList() const ;
457e6c54 220
a0a302dc 221 void* GetVoidPtr() const ;
edca7a82 222//TODO: Need to document
e2b87f38 223#if wxUSE_DATETIME
edca7a82 224 wxDateTime GetDateTime() const ;
e2b87f38 225#endif // wxUSE_DATETIME
fb42d7c3 226 wxArrayString GetArrayString() const;
edca7a82 227//TODO: End of Need to document
8cb50e4b
JS
228
229// Operations
230 // Make NULL (i.e. delete the data)
231 void MakeNull();
232
233 // Make empty list
234 void NullList();
235
236 // Append to list
237 void Append(const wxVariant& value);
238
239 // Insert at front of list
240 void Insert(const wxVariant& value);
241
242 // Returns TRUE if the variant is a member of the list
243 bool Member(const wxVariant& value) const;
244
245 // Deletes the nth element of the list
246 bool Delete(int item);
247
248 // Clear list
249 void ClearList();
250
a0a302dc 251// Implementation
9708db20 252public:
8cb50e4b
JS
253// Type conversion
254 bool Convert(long* value) const;
255 bool Convert(bool* value) const;
256 bool Convert(double* value) const;
257 bool Convert(wxString* value) const;
258 bool Convert(char* value) const;
edca7a82 259//TODO: Need to document
e2b87f38 260#if wxUSE_DATETIME
edca7a82 261 bool Convert(wxDateTime* value) const;
e2b87f38 262#endif // wxUSE_DATETIME
edca7a82 263//TODO: End of Need to document
8cb50e4b
JS
264
265// Attributes
266protected:
267 wxVariantData* m_data;
a0a302dc 268 wxString m_name;
8cb50e4b
JS
269};
270
3ba055ac 271extern wxVariant WXDLLEXPORT wxNullVariant;
a0a302dc 272
8cb50e4b
JS
273#endif
274 // _WX_VARIANT_H_