[gnome-db] GdaValue sustitution for GValue



I propose to modify the GdaValue to use allways GValue for the next reasons:

1. GdaValue relays on GValue, must be clear to the developer that; and that the he/she can use g_value_* functions. Then Delete the GdaValue and use in all GDA's code just GValue. Please take note that Mono use GValue as the returning value from Gda.DataModel.GetValueAt.

2. Deprecate the use of GdaValueType for the API; it is usefull in the switch code of the providers, but for the API user, the developers, just want to know that he/she Gets a data of the type "this" that can use in, for example, any kind of Widget transparent.

3. Deprecate the gda_value_new_* functions, use the GValue creation API.

4. Deprecate any function that already exist in the GValue API. Then any value like gint, guint, gint64, and so on, must use the g_value_get_* functions.

5. Deprecate the use of "not GLib's standar names", like BIGINT (INT64), SINGLE (FLOAT), to ensure that the developer all ways know the type of data gets from the providers. Then, modify the new numeric types like SMALLINT, TINYINT, INTEGER, BIGINT with SHORT, INT8, INT and INT64 respectly.

6. May other sugestion is Deprecate GdaDate and use GDate and his API.

Please review the attached gda-vaue.h. If you agree I can change the gda-value.c and gda-value.h and send it; of couse this will break the providers code but I think is better for the future of the GDA's API live.

--
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (entrámite, pero para los cuates: LIBRE)
/* GDA library
 * Copyright (C) 1998-2002 The GNOME Foundation.
 *
 * AUTHORS:
 *	Michael Lausch <michael lausch at>
 *	Rodrigo Moya <rodrigo gnome-db org>
 *	Juan-Mariano de Goyeneche <jmseyas dit upm es> (BLOB issues) 
 *      Daniel Espinosa Ortiz <esodan gmail com> (Port to GValue)
 *
 * This Library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This Library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this Library; see the file COPYING.LIB.  If not,
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#if !defined(__gda_value_h__)
#  define __gda_value_h__

#include <time.h>
#include <glib/glist.h>
#include <glib/gmacros.h>
#include <glib-object.h>
#include <libxml/tree.h>
#include <libgda/gda-blob.h>

G_BEGIN_DECLS

#define TIMEZONE_INVALID (2*12*60*60)

/* Definition of the GType's values used in GdaValue*/

#define G_VALUE_TYPE_NULL G_TYPE_NONE
//#define G_VALUE_TYPE_BIGINT G_TYPE_INT64
//#define	G_VALUE_TYPE_BIGUINT G_TYPE_UINT64
#define	G_VALUE_TYPE_BINARY (gda_binary_get_type())
#define G_VALUE_TYPE_BLOB (gda_blob_get_type())
#define	G_VALUE_TYPE_BOOLEAN G_TYPE_BOOLEAN
#define	G_VALUE_TYPE_DATE (gda_date_get_type())
//#define	G_VALUE_TYPE_DOUBLE G_TYPE_DOUBLE
#define	G_VALUE_TYPE_GEOMETRIC_POINT (gda_geometricpoint_get_type())
//#define	G_VALUE_TYPE_GOBJECT G_TYPE_OBJECT
//#define	G_VALUE_TYPE_INTEGER G_TYPE_INT
//#define G_VALUE_TYPE_UINTEGER G_TYPE_UINT
#define	G_VALUE_TYPE_LIST (gda_value_list_get_type())
#define	G_VALUE_TYPE_MONEY (gda_money_get_type())
#define	G_VALUE_TYPE_NUMERIC (gda_numeric_get_type())
//#define	G_VALUE_TYPE_SINGLE G_TYPE_FLOAT
#define	G_VALUE_TYPE_SHORT (gda_smallint_get_type()) //G_VALUE_TYPE_SMALLINT
#define	G_VALUE_TYPE_USHORT (gda_smalluint_get_type())
#define	G_VALUE_TYPE_STRING G_TYPE_STRING
#define	G_VALUE_TYPE_INT8 G_TYPE_CHAR //G_VALUE_TYPE_TINYINT, could be deleted
#define	G_VALUE_TYPE_UINT8 G_TYPE_UCHAR //G_VALUE_TYPE_TINYUINT, could be deleted
#define G_VALUE_TYPE_TIME (gda_time_get_type())
#define G_VALUE_TYPE_TIMESTAMP (gda_timestamp_get_type())
#define	G_VALUE_TYPE_UNKNOWN G_TYPE_INVALID
#define	G_VALUE_TYPE_TYPE (gda_gdatype_get_type())

typedef enum {
	GDA_VALUE_TYPE_NULL,
	
	GDA_VALUE_TYPE_BOOLEAN,
	GDA_VALUE_TYPE_OBJECT,//GDA_VALUE_TYPE_GOBJECT
	GDA_VALUE_TYPE_STRING,

	GDA_VALUE_TYPE_TIME,
	GDA_VALUE_TYPE_TIMESTAMP,	
	GDA_VALUE_TYPE_DATE,	
	GDA_VALUE_TYPE_BINARY,
	GDA_VALUE_TYPE_BLOB,
	GDA_VALUE_TYPE_GEOMETRIC_POINT,
	GDA_VALUE_TYPE_LIST,
	
	GDA_VALUE_TYPE_INT,//GDA_VALUE_TYPE_INTEGER
	GDA_VALUE_TYPE_UINT, //GDA_VALUE_TYPE_UINTEGER,
	GDA_VALUE_TYPE_INT64, //GDA_VALUE_TYPE_BIGINT
	GDA_VALUE_TYPE_UINT64, //GDA_VALUE_TYPE_BIGUINT
	GDA_VALUE_TYPE_FLOAT, //GDA_VALUE_TYPE_SINGLE
	GDA_VALUE_TYPE_DOUBLE,
	
	GDA_VALUE_TYPE_SHORT, //GDA_VALUE_TYPE_SMALLINT
	GDA_VALUE_TYPE_USHORT, //GDA_VALUE_TYPE_SMALLUINT

	GDA_VALUE_TYPE_INT8, //GDA_VALUE_TYPE_TINYINT
	GDA_VALUE_TYPE_UINT8,

	GDA_VALUE_TYPE_MONEY,
	GDA_VALUE_TYPE_NUMERIC,

	GDA_VALUE_TYPE_TYPE,
    GDA_VALUE_TYPE_UNKNOWN
	
} GdaValueType;
#define GDA_VALUE_NB_TYPES GDA_VALUE_TYPE_UNKNOWN

//FIXME: Possible sustitud GDate and realated functions

typedef struct {
	gshort year;
	gushort month;
	gushort day;
} GdaDate;


typedef struct {
	gdouble x;
	gdouble y;
} GdaGeometricPoint;

typedef struct {
	gchar *currency;
	gdouble amount;
} GdaMoney;

typedef struct {
	gchar *number;
	glong precision;
	glong width;
} GdaNumeric;

typedef struct {
	gushort hour;
	gushort minute;
	gushort second;
	glong timezone;	/* # of seconds to the east UTC */
} GdaTime;

typedef struct {
	gshort year;
	gushort month;
	gushort day;
	gushort hour;
	gushort minute;
	gushort second;
	gulong fraction;
	glong timezone;	/* # of seconds to the east UTC */
} GdaTimestamp;

typedef struct {
	guchar *data;
	glong  binary_length;
} GdaBinary;

typedef GList GdaValueList;

//typedef GValue GdaValue;

#define GDA_TYPE_VALUE G_TYPE_VALUE
#define GDA_VALUE_TYPE(value) (gda_value_get_type(value))
#define gda_value_isa(value, type) (gda_value_get_type (value) == type)

GdaValueType                      gda_value_get_type(GValue *value);
GType                             gda_value_convert_gdatype_to_gtype (GValueType type);
GdaValueType                      gda_value_convert_gtype_to_gdatype (GType type);

gboolean                          gda_value_type_transformable (GdaValueType src_type, GdaValueType dest_type, gboolean strict);
gboolean                          gda_value_transform (const GdaValue *src, GdaValue *dest);

GValue                           *gda_value_new_from_string (const gchar *as_string, GdaValueType type);
GValue                           *gda_value_new_from_xml (const xmlNodePtr node);

void                              gda_value_free (GValue *value);
void                              gda_value_reset_with_type (GValue *value, GdaValueType type);


gboolean                          gda_value_is_null (GdaValue *value);
gboolean                          gda_value_is_number (GdaValue *value);
//GdaValue                         *gda_value_copy (GdaValue *value);

G_CONST_RETURN GdaBinary         *gda_value_get_binary (GdaValue *value);
void                              gda_value_set_binary (GdaValue *value, const GdaBinary *binary);
G_CONST_RETURN GdaBlob           *gda_value_get_blob (GdaValue *value);
void                              gda_value_set_blob (GdaValue *value, const GdaBlob *val);
G_CONST_RETURN GdaDate           *gda_value_get_date (GdaValue *value);
void                              gda_value_set_date (GdaValue *value, const GdaDate *val);
G_CONST_RETURN GdaGeometricPoint *gda_value_get_geometric_point (GdaValue *value);
void                              gda_value_set_geometric_point (GdaValue *value, const GdaGeometricPoint *val);
G_CONST_RETURN GdaValueList      *gda_value_get_list (GdaValue *value);
void                              gda_value_set_list (GdaValue *value, const GdaValueList *val);
void                              gda_value_set_null (GdaValue *value);
G_CONST_RETURN GdaMoney          *gda_value_get_money (GdaValue *value);
void                              gda_value_set_money (GdaValue *value, const GdaMoney *val);
G_CONST_RETURN GdaNumeric        *gda_value_get_numeric (GdaValue *value);
void                              gda_value_set_numeric (GdaValue *value, const GdaNumeric *val);
G_CONST_RETURN GdaTime           *gda_value_get_time (GdaValue *value);
void                              gda_value_set_time (GdaValue *value, const GdaTime *val);
G_CONST_RETURN GdaTimestamp      *gda_value_get_timestamp (GdaValue *value);
void                              gda_value_set_timestamp (GdaValue *value, const GdaTimestamp *val);
gchar                             gda_value_get_int8 (GdaValue *value);
void                              gda_value_set_int8 (GdaValue *value, gchar val);
guchar                            gda_value_get_uint8 (GdaValue *value);
void                              gda_value_set_uint8 (GdaValue *value, guchar val);
void                              gda_value_set_gdatype (GValue *value, GdaValueType val);
GdaValueType                      gda_value_get_gdatype (GValue *value);


gboolean                          gda_value_set_from_string (GdaValue *value, 
						             const gchar *as_string,
						             GdaValueType type);
gboolean                          gda_value_set_from_value (GdaValue *value, const GdaValue *from);


gint                              gda_value_compare (GdaValue *value1, GdaValue *value2);
gint                              gda_value_compare_ext (GdaValue *value1, GdaValue *value2);
gchar                            *gda_value_stringify (GdaValue *value);
xmlNodePtr                        gda_value_to_xml (GdaValue *value);

gchar                            *gda_binary_to_string (const GdaBinary *bin, guint maxlen);
gboolean                          gda_string_to_binary (const gchar *str, GdaBinary *bin);

/* Custom data types */
GType                             gda_money_get_type (void);
gpointer                          gda_money_copy (gpointer boxed);
void                              gda_money_free (gpointer boxed);

GType                             gda_numeric_get_type (void);
gpointer                          gda_numeric_copy (gpointer boxed);
void                              gda_numeric_free (gpointer boxed);

GType                             gda_time_get_type(void);
gpointer                          gda_time_copy (gpointer boxed);
void                              gda_time_free (gpointer boxed);

GType                             gda_timestamp_get_type(void);
gpointer                          gda_timestamp_copy (gpointer boxed);
void                              gda_timestamp_free (gpointer boxed);

GType                             gda_date_get_type(void);
gpointer                          gda_date_copy (gpointer boxed);
void                              gda_date_free (gpointer boxed);

GType                             gda_geometricpoint_get_type(void);
gpointer                          gda_geometricpoint_copy (gpointer boxed);
void                              gda_geometricpoint_free (gpointer boxed);

GType                             gda_binary_get_type(void);
gpointer                          gda_binary_copy (gpointer boxed);
void                              gda_binary_free (gpointer boxed);

GType                             gda_value_list_get_type (void);
GType                             gda_smallint_get_type (void);
GType                             gda_smalluint_get_type (void);
GType                             gda_gdatype_get_type (void);

G_END_DECLS

#endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]