value.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 #ifndef _LIBGDAMM_VALUE_H
00003 #define _LIBGDAMM_VALUE_H
00004 
00005 
00006 /* $Id: value.h 978 2007-02-04 12:20:31Z arminb $ */
00007 // -*- C++ -*- //
00008 
00009 /* value.h
00010  *
00011  * Copyright 2003 libgdamm Development Team
00012  *
00013  * This library is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU Library General Public
00015  * License as published by the Free Software Foundation; either
00016  * version 2 of the License, or (at your option) any later version.
00017  *
00018  * This library is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  * Library General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU Library General Public
00024  * License along with this library; if not, write to the Free
00025  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00026  */
00027 
00028 #include <glibmm.h>
00029 #include <glibmm/value.h>
00030 #include <libgda/gda-value.h> //TODO: Patch libgda to use the struct _ technique.
00031 
00032 
00033 namespace Gnome
00034 {
00035 
00036 namespace Gda
00037 {
00038 
00039 typedef GdaGeometricPoint GeometricPoint;
00040 typedef GdaTime Time;
00041 typedef GdaTimestamp Timestamp;
00042 
00047 class Value : public Glib::ValueBase
00048 {
00049 public:
00050   Value();
00051 
00052   explicit Value(const GValue* castitem);
00053 
00054   Value(const Value& src);
00055   Value& operator=(const Value& src);
00056 
00057   ~Value();
00058   
00059 
00060 //We can't have this constructor because gint64 and int are the same on 64-bit systems:
00061 //explicit Value(gint64 val);
00062   static Value create_as_int64(gint64 val);
00063 
00064 //We can't have this constructor because guint64 and unsigned int are the same on 64-bit systems:
00065 //explicit Value(gint64 val);
00066 // explicit Value(guint64 val);
00067    static Value create_as_uint64(guint64 val);
00068   
00069   explicit Value(const guchar* val, long size); 
00070 
00071   explicit Value(const GdaBlob* val);
00072 
00073   explicit Value(bool val);
00074   
00075   explicit Value(const Glib::Date& val);
00076   
00077   explicit Value(double val);
00078   
00079   explicit Value(const GeometricPoint& val);
00080   
00081   explicit Value(int val);
00082   
00083   explicit Value(const GdaValueList* val);
00084   
00085   explicit Value(const GdaNumeric* val);
00086   
00087   explicit Value(float val);
00088   
00089   explicit Value(gshort val);
00090   
00091   explicit Value(gushort val);
00092   
00093   explicit Value(const Glib::ustring& val);
00094   
00095 
00096   //If this constructor does not exists, then Value("something") uses Value(bool) instead of Value(ustring).
00097   explicit Value(const char* val);
00098 
00099   explicit Value(const Time& val);
00100   
00101   explicit Value(const Timestamp& val);
00102   
00103   
00104   //This causes ambiguity with another constructor on 64-bit systems:
00105   //explicit Value(time_t val);
00106   
00107   static Value create_as_time_t(time_t val);
00108 
00109   explicit Value(gchar val);
00110   
00111   explicit Value(guchar val);
00112   
00113   explicit Value(guint val);
00114   
00115   explicit Value(const Glib::ustring& as_string, GType type);
00116   
00117   //TODO: explicit Value(const xmlNodePtr node);
00118   //__IGNORE(gda_value_new_from_xml)
00119 
00120   bool operator==(const Value& src) const;
00121   bool operator!=(const Value& src) const;
00122 
00123   
00124   GType get_value_type() const;
00125   
00126   bool is_null() const;
00127   
00128   bool is_number() const;
00129 
00130   
00131   gint64 get_int64() const;
00132   
00133   void set(gint64 val);
00134   
00135   guint64 get_uint64() const;
00136   
00137   void set(guint64 val);
00138 
00139   //TODO: The const here is quite meaningless:
00140   
00141   const guchar* get_binary(long& size) const;
00142   
00143   void set(const guchar* val, long size);
00144 
00145   //TODO: The const here is quite meaningless:
00146   
00147   const GdaBlob* get_blob() const;
00148   
00149   void set(const GdaBlob* val);
00150   
00151   bool get_boolean() const;
00152   
00153   void set(bool val);
00154   
00155   Glib::Date get_date() const;
00156   
00157   void set(const Glib::Date& val);
00158   
00159   double get_double() const;
00160   
00161   void set(double val);
00162   
00163   GeometricPoint get_geometric_point() const;
00164   
00165   void set(const GeometricPoint& val);
00166   
00167   Glib::RefPtr<const Glib::Object> get_gobject();
00168   
00169   void set(const Glib::RefPtr<Glib::Object>& val);
00170   
00171   int get_int() const;
00172   
00173   void set(int val);
00174   
00175   const GdaValueList* get_list();
00176   
00177   void set(const GdaValueList *val);
00178   
00179   const GdaNumeric* get_numeric() const;
00180   
00181   void set(const GdaNumeric *val);
00182   
00183   float get_float() const;
00184   
00185   void set(float val);
00186   
00187   gshort get_short() const;
00188   
00189   void set(gshort val);
00190   
00191   gushort get_ushort() const;
00192   
00193   void set(gushort val);
00194   
00195   Glib::ustring get_string() const;
00196   
00197   void set(const Glib::ustring& val);
00198 
00199   //If this method does not exists, then set("something") uses set(bool) instead of set(ustring).
00200   void set(const char* val);
00201   
00202   Time get_time() const;
00203   
00204   void set(const Time& val);
00205   
00206   Timestamp get_timestamp() const;
00207   
00208   void set(const Timestamp& val);
00209   
00210   void set(gchar val);
00211   
00212   void set(guchar val);
00213   
00214   guint get_uint() const;
00215   
00216   void set(guint val);
00217   
00218   GType get_g_type() const;
00219   
00220   void set(GType val);
00221   
00222   //Use the copy constructor instead: _WRAP_METHOD(bool set_from_value(const Value& from), gda_value_set_from_value)
00223   
00224 
00225   //TODO: Wrap this as some stream operator thing?
00226   
00227   Glib::ustring to_string() const;
00228 };
00229 
00230 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00231 struct ValueTraits
00232 {
00233   typedef Value CppType;
00234   typedef const GValue* CType;
00235   typedef GValue* CTypeNonConst;
00236 
00237   /* TODO: Should to_c_type make a copy of the actualy GValue? */
00238   static CType to_c_type(const CppType& obj) { return obj.gobj(); }
00239   static CType to_c_type(const CType& obj) { return obj; }
00240   static CppType to_cpp_type(const CType& obj) { return CppType(obj); }
00241   static void release_c_type(const CType& obj) {}
00242 };
00243 #endif
00244 
00245 typedef Glib::ListHandle<Value, ValueTraits> ValueList;
00246 typedef Glib::SListHandle<Value, ValueTraits> ValueSList;
00247 
00248 GType value_get_type_null();
00249 GType value_get_type_binary();
00250 GType value_get_type_blob();
00251 GType value_get_type_geometric_point();
00252 GType value_get_type_list();
00253 GType value_get_type_numeric();
00254 GType value_get_type_short();
00255 GType value_get_type_ushort();
00256 GType value_get_type_time();
00257 GType value_get_type_timestamp();
00258 
00259 //These can't work because the static instances would be instantiated before the GType system has been initialized.
00260 /*
00261 extern const GType VALUE_TYPE_NULL;
00262 extern const GType VALUE_TYPE_BINARY;
00263 extern const GType VALUE_TYPE_BLOB;
00264 extern const GType VALUE_TYPE_GEOMETRIC_POINT;
00265 extern const GType VALUE_TYPE_LIST;
00266 extern const GType VALUE_TYPE_NUMERIC;
00267 extern const GType VALUE_TYPE_SHORT;
00268 extern const GType VALUE_TYPE_USHORT;
00269 extern const GType VALUE_TYPE_TIME;
00270 extern const GType VALUE_TYPE_TIMESTAMP;
00271 */
00272 
00273 typedef GdaGeometricPoint GeometricPoint;
00274 
00275 /*  TODO:
00276 typedef struct {
00277         gchar *currency;
00278         double amount;
00279 } GdaMoney;
00280 
00281 typedef struct {
00282         gchar *number;
00283         long precision;
00284         long width;
00285 } GdaNumeric;
00286 */
00287 
00288 
00289 int value_compare(const Glib::ValueBase& value1, const Glib::ValueBase& value2);
00290 int value_compare_ext(const Glib::ValueBase& value1, const Glib::ValueBase& value2);
00291 bool value_equal(const Glib::ValueBase& value1, const Glib::ValueBase& value2);
00292 
00293 
00294 /*
00295 xmlNodePtr                        gda_value_to_xml(const Glib::ValueBase& value);
00296 
00297 gchar                            *gda_binary_to_string(const GdaBinary& bin, guint maxlen);
00298 bool                          gda_string_to_binary(const gchar *str, GdaBinary *bin);
00299 
00300 
00301 GType                             gda_numeric_get_type (void) G_GNUC_CONST;
00302 gpointer                          gda_numeric_copy (gpointer boxed) G_GNUC_CONST;
00303 void                              gda_numeric_free (gpointer boxed) G_GNUC_CONST;
00304 
00305 GType                             gda_time_get_type(void) G_GNUC_CONST;
00306 gpointer                          gda_time_copy (gpointer boxed) G_GNUC_CONST;
00307 void                              gda_time_free (gpointer boxed) G_GNUC_CONST;
00308 
00309 GType                             gda_timestamp_get_type(void) G_GNUC_CONST;
00310 gpointer                          gda_timestamp_copy (gpointer boxed) G_GNUC_CONST;
00311 void                              gda_timestamp_free (gpointer boxed) G_GNUC_CONST;
00312 
00313 GType                             gda_geometricpoint_get_type(void) G_GNUC_CONST;
00314 gpointer                          gda_geometricpoint_copy (gpointer boxed) G_GNUC_CONST;
00315 void                              gda_geometricpoint_free (gpointer boxed) G_GNUC_CONST;
00316 
00317 GType                             gda_binary_get_type(void) G_GNUC_CONST;
00318 gpointer                          gda_binary_copy (gpointer boxed) G_GNUC_CONST;
00319 void                              gda_binary_free (gpointer boxed) G_GNUC_CONST;
00320 
00321 GType                             gda_value_list_get_type (void) G_GNUC_CONST;
00322 GType                             gda_short_get_type (void) G_GNUC_CONST;
00323 GType                             gda_ushort_get_type (void) G_GNUC_CONST;
00324 
00325 #define                           gda_value_new_null() (g_new0 (GValue, 1))
00326 */
00327 
00328 
00329 
00330 
00331 } //namespace Gda
00332 } //namespaec Gnome
00333 
00334 
00335 #endif /* _LIBGDAMM_VALUE_H */
00336 

Generated on Sat Feb 10 20:06:26 2007 for libgdamm by  doxygen 1.4.7