Re: [gnome-db] New Versions of gda-value.c and gda-value.h





2006/4/5, Vivien Malerba <vmalerba gmail com>:
On 4/4/06, Daniel Espinosa <esodan gmail com> wrote:
>
> Attached you'll find the modifications in the gda-value.c and gda-value.h,
> is a completly rewrite of the old ones, define the macros for use in the
> GType system.
>
>  The code use when possible, the GValue API and register the transform
> functions to convert, for example, from string to Gda type and viceversa; as
> recommended I delete the GdaDate for GDate and not used types (like
> GdaMoney). Most of them, can be added as a derived one from the GType
> existing to manage the conversion correctly.
>
>  Please pay attention about I don't define functions to transform the GType
> standar types, like BOOLE and INT, I start in the point that it is exist
> already in the GLib, but to define a new one can create the respective
> functions and register them. The problem is when to register, becouse the
> GType system is initiated by gda_init, and then is there when the new
> transformation functions must be done (before the use of GDA lib API).

There should not be any problem with that because transform functions
are registered the first time each GDA specific type is declared. For
instance the type declaration for timestamp should be like:

GType gda_timestamp_get_type (void) G_GNUC_CONST;

GType
gda_timestamp_get_type (void)
{
        static GType type = 0;

        if (G_UNLIKELY (type == 0)) {
                type = g_boxed_type_register_static ("GdaTimestamp",
                        (GBoxedCopyFunc) gda_timestamp_copy,
                        (GBoxedFreeFunc) gda_timestamp_free);

                g_value_register_transform_func(G_TYPE_STRING,
                                                                        type,
                                                                        timestamp_to_string);

                g_value_register_transform_func(type,
                                                                        G_TYPE_STRING,
                                                                        string_to_timestamp);
        }

        return type;
}

Ok done for all *get_type

>
>  I haven't time to test with the copiler, but to write the core; if it is
> aprobed, I begin to test the GLib standar transformations from the existing
> GType's to G_VALUE_STRING, to validate the result; if it is not acurate as
> the GDA needs, I can create the *_to_string functions to register using
> g_value_register_transform_func,

Great.

I  make some test, and find that it is usefull the transformation from integers, may be from floating point values, but the precision of the values showed it not enough in the case of gdouble, but may is better for the developer to desire the text precision representation required in his application.

In the case of GDate values, it doesn't have a GDate->String transformation, but it is a Locale issue; there a g_date_strftime function that can be used by the developer to create the needed representation. May be could include some Locale code to represent the GDate value, in GDA. If this is needed, the GDate is a value already registered type in GLib initialization, then in the gda_init must exist the code to register the GDate to String transformation.

Now doesn't exist the GdaMoney type; but could derive a type from a G_TYPE_DOUBLE, and write some Locale code to transform in the local text representation.

Need be tested the String->GType (the existing in GLib, not in GDA), to know about if it exist and if it is relable.

>

Just a few remarks:
-> rename TIMEZONE_INVALID to GDA_TIMEZONE_INVALID

Done.

-> forget about the gda_value_type_transformable() and
gda_value_transform() functions and use g_value_transform()

Done.

-> maybe it would be better to remove the GDA_VALUE_HOLDS_* macros as
they are not really usefull

this macros helps in the gda_value_isa and gda_is_number functions to simplify the code.

-> correct the *_get_type() functions as mentionned above for the time stamp

Done.

I hope we don't forget anything (anyway if this is the case it will
come up sooner or later!)

Great, thanks.

Could you also try to give hints about how to migrate the libgda,
libgnomedb, etc code which uses the current version of the GdaValue
API, if possible using regexp replacements? This will greatly help
porting the code.

Ok, I'll write some documentation and send to the list ASAP.

Attached you'll find the last modications.



--
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (entrámite, pero para los cuates: LIBRE)

Attachment: gda-value.tar.gz
Description: GNU Zip compressed data



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