1 // -*- c++ -*-
2 #ifndef _LIBGDAMM_VALUE_H
3 #define _LIBGDAMM_VALUE_H
4 
5 
6 /* $Id$ */
7 // -*- C++ -*- //
8 
9 /* value.h
10  *
11  * Copyright 2003 libgdamm Development Team
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this library; if not, write to the Free
25  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26  */
27 
28 #include <libgdamm/numeric.h>
29 #include <glibmm/value.h>
30 #include <glibmm/date.h>
31 #include <libgda/gda-value.h> //TODO: Patch libgda to use the struct _ technique.
32 
33 
34 namespace Gnome
35 {
36 
37 namespace Gda
38 {
39 
40 typedef GdaGeometricPoint GeometricPoint;
41 typedef GdaTime Time;
42 typedef GdaTimestamp Timestamp;
43 
44 /**
45  *
46  * Use value_type() to identify the value type at runtime.
47  */
48 class Value : public Glib::ValueBase
49 {
50 public:
51   Value();
52 
53   explicit Value(const GValue* castitem);
54 
55   Value(const Value& src);
56   Value& operator=(const Value& src);
57 
58   ~Value();
59 
60 
61 //We can't have this constructor because gint64 and int are the same on 64-bit systems:
62 //explicit Value(gint64 val);
63   static Value create_as_int64(gint64 val);
64 
65 //We can't have this constructor because guint64 and unsigned int are the same on 64-bit systems:
66 //explicit Value(gint64 val);
67 // explicit Value(guint64 val);
68   static Value create_as_uint64(guint64 val);
69 
70   explicit Value(const guchar* val, long size);
71 
72   explicit Value(const GdaBlob* val);
73 
74   explicit Value(bool val);
75 
76   explicit Value(const Glib::Date& val);
77 
78   explicit Value(const GeometricPoint& val);
79 
80   explicit Value(int val);
81 
82   explicit Value(const Numeric& val);
83 
84 #ifndef LIBGDAMM_DISABLE_DEPRECATED
85   //We shouldn't have this constructor because the double and float constructors are ambiguous.
86   /**
87    * @deprecated Use create_as_double() instead.
88    */
89   explicit Value(double val);
90 #endif //LIBGDAMM_DISABLE_DEPRECATED
91 
92   static Value create_as_double(double val);
93 
94 #ifndef LIBGDAMM_DISABLE_DEPRECATED
95   //We shouldn't have this constructor because the double and float constructors are ambiguous.
96   /**
97    * @deprecated Use create_as_double() instead.
98    */
99   explicit Value(float val);
100 #endif //LIBGDAMM_DISABLE_DEPRECATED
101 
102   static Value create_as_float(float val);
103 
104   explicit Value(gshort val);
105 
106   explicit Value(gushort val);
107 
108   explicit Value(gulong val);
109 
110   explicit Value(const Glib::ustring& val);
111 
112 
113   //If this constructor does not exists, then Value("something") uses Value(bool) instead of Value(ustring).
114   explicit Value(const char* val);
115 
116   explicit Value(const Time& val);
117 
118   explicit Value(const Timestamp& val);
119 
120 
121   //This causes ambiguity with another constructor on 64-bit systems:
122   //explicit Value(time_t val);
123 
124   static Value create_as_time_t(time_t val);
125 
126   explicit Value(gchar val);
127 
128   explicit Value(guchar val);
129 
130   explicit Value(guint val);
131 
132   explicit Value(const Glib::ustring& as_string, GType type);
133 
134   //TODO: explicit Value(const xmlNodePtr node);
135   //__IGNORE(gda_value_new_from_xml)
136 
137   bool operator==(const Value& src) const;
138   bool operator!=(const Value& src) const;
139 
140 
141   GType get_value_type() const;
142 
143   bool is_null() const;
144   void set_null();
145 
146   bool is_number() const;
147 
148 
149   gint64 get_int64() const;
150 
151   // We can't have this as a regular set() overload because it has the same
152   // type as GType on 64bit systems.
153   void set_int64(gint64 val);
154 
155   guint64 get_uint64() const;
156 
157   // We can't have this as a regular set() overload because it has the same
158   // type as GType on 64bit systems.
159   void set_uint64(guint64 val);
160 
161   //TODO: The const here is quite meaningless:
162 
163   const guchar* get_binary(long& size) const;
164 
165   void set(const guchar* val, long size);
166 
167   //TODO: The const here is quite meaningless:
168 
169   const GdaBlob* get_blob() const;
170 
171   void set(const GdaBlob* val);
172 
173   bool get_boolean() const;
174 
175   void set(bool val);
176 
177   Glib::Date get_date() const;
178 
179   void set(const Glib::Date& val);
180 
181   double get_double() const;
182 
183 #ifndef LIBGDAMM_DISABLE_DEPRECATED
184   //set(double) and set(float) are ambiguous.
185   /**
186    * @deprecate Use set_double().
187    */
188   void set(double val);
189 #endif //LIBGDAMM_DISABLE_DEPRECATED
190 
191   void set_double(double val);
192 
193   GeometricPoint get_geometric_point() const;
194 
195   void set(const GeometricPoint& val);
196 
197   Glib::RefPtr<const Glib::Object> get_gobject();
198 
199   void set(const Glib::RefPtr<Glib::Object>& val);
200 
201   int get_int() const;
202 
203   void set(int val);
204 
205   Numeric get_numeric() const;
206 
207   void set(const Numeric& val);
208 
209   float get_float() const;
210 
211 #ifndef LIBGDAMM_DISABLE_DEPRECATED
212   //set(double) and set(float) are ambiguous.
213   /**
214    * @deprecate Use set_float().
215    */
216   void set(float val);
217 #endif //LIBGDAMM_DISABLE_DEPRECATED
218 
219   void set_float(float val);
220 
221   gshort get_short() const;
222 
223   void set(gshort val);
224 
225   gushort get_ushort() const;
226 
227   void set(gushort val);
228 
229   glong get_long() const;
230 
231   void set(glong val);
232 
233   gulong get_ulong() const;
234 
235   void set(gulong val);
236 
237   Glib::ustring get_string() const;
238 
239   void set(const Glib::ustring& val);
240 
241   //If this method does not exists, then set("something") uses set(bool) instead of set(ustring).
242   void set(const char* val);
243 
244   Time get_time() const;
245 
246   void set(const Time& val);
247 
248   Timestamp get_timestamp() const;
249 
250   void set(const Timestamp& val);
251 
252   void set(gchar val);
253 
254   void set(guchar val);
255 
256   guint get_uint() const;
257 
258   void set(guint val);
259 
260   GType get_g_type() const;
261 
262   void set_g_type(GType val);
263 
264   //Use the copy constructor instead: _WRAP_METHOD(bool set_from_value(const Value& from), gda_value_set_from_value)
265 
266 
267   //TODO: Wrap this as some stream operator thing?
268 
269   Glib::ustring to_string() const;
270 };
271 
272 #ifndef DOXYGEN_SHOULD_SKIP_THIS
273 struct ValueTraits
274 {
275   typedef Value CppType;
276   typedef const GValue* CType;
277   typedef GValue* CTypeNonConst;
278 
279   /* TODO: Should to_c_type make a copy of the actualy GValue? */
280   static CType to_c_type(const CppType& obj) { return obj.gobj(); }
281   static CType to_c_type(const CType& obj) { return obj; }
282   static CppType to_cpp_type(const CType& obj) { return CppType(obj); }
283   static void release_c_type(const CType& /*obj*/) {}
284 };
285 #endif
286 
287 GType value_get_type_null();
288 GType value_get_type_binary();
289 GType value_get_type_blob();
290 GType value_get_type_geometric_point();
291 GType value_get_type_numeric();
292 GType value_get_type_short();
293 GType value_get_type_ushort();
294 GType value_get_type_time();
295 GType value_get_type_timestamp();
296 
297 //These can't work because the static instances would be instantiated before the GType system has been initialized.
298 /*
299 extern const GType VALUE_TYPE_NULL;
300 extern const GType VALUE_TYPE_BINARY;
301 extern const GType VALUE_TYPE_BLOB;
302 extern const GType VALUE_TYPE_GEOMETRIC_POINT;
303 extern const GType VALUE_TYPE_LIST;
304 extern const GType VALUE_TYPE_NUMERIC;
305 extern const GType VALUE_TYPE_SHORT;
306 extern const GType VALUE_TYPE_USHORT;
307 extern const GType VALUE_TYPE_TIME;
308 extern const GType VALUE_TYPE_TIMESTAMP;
309 */
310 
311 /*  TODO:
312 typedef struct {
313 	gchar *currency;
314 	double amount;
315 } GdaMoney;
316 
317 */
318 
319 
320 #if 0
321 int value_compare(const Glib::ValueBase& value1, const Glib::ValueBase& value2);
322 int value_compare_ext(const Glib::ValueBase& value1, const Glib::ValueBase& value2);
323 bool value_equal(const Glib::ValueBase& value1, const Glib::ValueBase& value2);
324 #endif
325 
326 
327 /*
328 xmlNodePtr                        gda_value_to_xml(const Glib::ValueBase& value);
329 
330 gchar                            *gda_binary_to_string(const GdaBinary& bin, guint maxlen);
331 bool                          gda_string_to_binary(const gchar *str, GdaBinary *bin);
332 
333 
334 GType                             gda_numeric_get_type (void) G_GNUC_CONST;
335 gpointer                          gda_numeric_copy (gpointer boxed) G_GNUC_CONST;
336 void                              gda_numeric_free (gpointer boxed) G_GNUC_CONST;
337 
338 GType                             gda_time_get_type(void) G_GNUC_CONST;
339 gpointer                          gda_time_copy (gpointer boxed) G_GNUC_CONST;
340 void                              gda_time_free (gpointer boxed) G_GNUC_CONST;
341 
342 GType                             gda_timestamp_get_type(void) G_GNUC_CONST;
343 gpointer                          gda_timestamp_copy (gpointer boxed) G_GNUC_CONST;
344 void                              gda_timestamp_free (gpointer boxed) G_GNUC_CONST;
345 
346 GType                             gda_geometricpoint_get_type(void) G_GNUC_CONST;
347 gpointer                          gda_geometricpoint_copy (gpointer boxed) G_GNUC_CONST;
348 void                              gda_geometricpoint_free (gpointer boxed) G_GNUC_CONST;
349 
350 GType                             gda_binary_get_type(void) G_GNUC_CONST;
351 gpointer                          gda_binary_copy (gpointer boxed) G_GNUC_CONST;
352 void                              gda_binary_free (gpointer boxed) G_GNUC_CONST;
353 
354 GType                             gda_value_list_get_type (void) G_GNUC_CONST;
355 GType                             gda_short_get_type (void) G_GNUC_CONST;
356 GType                             gda_ushort_get_type (void) G_GNUC_CONST;
357 
358 #define                           gda_value_new_null() (g_new0 (GValue, 1))
359 */
360 
361 
362 
363 
364 } //namespace Gda
365 } //namespaec Gnome
366 
367 
368 #endif /* _LIBGDAMM_VALUE_H */
369