From fe9ce0e4b5665bf9147e6dd7832ea7a545315f6d Mon Sep 17 00:00:00 2001 From: Phil Longstaff Date: Wed, 6 Dec 2006 03:16:18 +0000 Subject: [PATCH] Add support for gnc_numeric as a boxed GValue git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gda-dev@15186 57a11ea4-9604-0410-9ed3-97b8803252fd --- lib/libqof/qof/gnc-numeric.c | 34 ++++++++++++++++++++++++++++++++++ lib/libqof/qof/gnc-numeric.h | 9 +++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/libqof/qof/gnc-numeric.c b/lib/libqof/qof/gnc-numeric.c index 235848b1de..9554524949 100644 --- a/lib/libqof/qof/gnc-numeric.c +++ b/lib/libqof/qof/gnc-numeric.c @@ -1260,6 +1260,40 @@ string_to_gnc_numeric(const gchar* str, gnc_numeric *n) return TRUE; } +/* ******************************************************************* + * GValue handling + ********************************************************************/ +static gpointer +gnc_numeric_boxed_copy_func( gpointer in_gnc_numeric ) +{ + gnc_numeric* newvalue; + + newvalue = g_malloc( sizeof( gnc_numeric ) ); + memcpy( newvalue, in_gnc_numeric, sizeof( gnc_numeric ) ); + + return newvalue; +} + +static void +gnc_numeric_boxed_free_func( gpointer in_gnc_numeric ) +{ + g_free( in_gnc_numeric ); +} + +GType +gnc_numeric_get_type( void ) +{ + static GType type = 0; + + if( type == 0 ) { + type = g_boxed_type_register_static( "gnc_numeric", + gnc_numeric_boxed_copy_func, + gnc_numeric_boxed_free_func ); + } + + return type; +} + /* ******************************************************************* * gnc_numeric misc testing ********************************************************************/ diff --git a/lib/libqof/qof/gnc-numeric.h b/lib/libqof/qof/gnc-numeric.h index 435f19835c..28983fa79d 100644 --- a/lib/libqof/qof/gnc-numeric.h +++ b/lib/libqof/qof/gnc-numeric.h @@ -50,6 +50,8 @@ See \ref gncnumericexample #ifndef GNC_NUMERIC_H #define GNC_NUMERIC_H +#include + struct _gnc_numeric { gint64 num; @@ -445,6 +447,13 @@ gnc_numeric gnc_numeric_convert_with_error(gnc_numeric in, gint64 denom, gnc_numeric gnc_numeric_reduce(gnc_numeric in); /** @} */ +/** @name GValue + @{ +*/ +GType gnc_numeric_get_type( void ); + +/** @} */ + /** @name Deprecated, backwards-compatible definitions @{ */