From 4a395b32f1a108f1595b12de0441c420a3071fde Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Fri, 15 Feb 2013 17:52:57 +0100 Subject: [PATCH] adg: added adg_dash_append_dashes_array() Variable arguments and variadic containers are not easily bindable: added an array version to let the bindings specify a dash pattern in one go. --- src/adg/adg-dash.c | 27 +++++++++++++++++++++++++++ src/adg/adg-dash.h | 3 +++ src/adg/tests/test-dash.c | 10 ++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/adg/adg-dash.c b/src/adg/adg-dash.c index f5df4288..4a85eb25 100644 --- a/src/adg/adg-dash.c +++ b/src/adg/adg-dash.c @@ -56,6 +56,8 @@ #include "adg-dash.h" #include "adg-dash-private.h" +#include + GType adg_dash_get_type(void) @@ -206,6 +208,31 @@ adg_dash_append_dashes_valist(AdgDash *dash, gint num_dashes, va_list var_args) } /** + * adg_dash_append_dashes_array: + * @dash: an #AdgDash instance + * @num_dashes: number of dashes to append + * @dashes: (array length=num_dashes): array of @num_dashes gdoubles + * + * Array version of adg_dash_append_dashes(). + * + * Rename to: adg_dash_append_dashes + * Since: 1.0 + **/ +void +adg_dash_append_dashes_array(AdgDash *dash, + gint num_dashes, const gdouble *dashes) +{ + g_return_if_fail(dash != NULL); + + if (num_dashes > 0) { + gint old_dashes = dash->num_dashes; + dash->num_dashes += num_dashes; + dash->dashes = g_realloc(dash->dashes, sizeof(gdouble) * dash->num_dashes); + memcpy(dash->dashes + old_dashes, dashes, sizeof(gdouble) * num_dashes); + } +} + +/** * adg_dash_get_num_dashes: * @dash: an #AdgDash instance * diff --git a/src/adg/adg-dash.h b/src/adg/adg-dash.h index e91f7de1..db62f0e2 100644 --- a/src/adg/adg-dash.h +++ b/src/adg/adg-dash.h @@ -49,6 +49,9 @@ void adg_dash_append_dashes (AdgDash *dash, void adg_dash_append_dashes_valist (AdgDash *dash, gint num_dashes, va_list var_args); +void adg_dash_append_dashes_array (AdgDash *dash, + gint num_dashes, + const gdouble *dashes); gint adg_dash_get_num_dashes (const AdgDash *dash); const gdouble * adg_dash_get_dashes (const AdgDash *dash); void adg_dash_clear_dashes (AdgDash *dash); diff --git a/src/adg/tests/test-dash.c b/src/adg/tests/test-dash.c index df6d00a8..735e179c 100644 --- a/src/adg/tests/test-dash.c +++ b/src/adg/tests/test-dash.c @@ -27,6 +27,7 @@ _adg_test_dashes(void) AdgDash *dash; gint num_dashes; const gdouble *dashes; + const gdouble dashes_array[] = { 1., 2., 3. }; dash = adg_dash_new(); g_assert(dash != NULL); @@ -57,6 +58,15 @@ _adg_test_dashes(void) dashes = adg_dash_get_dashes(dash); g_assert(dashes == NULL); + adg_dash_append_dashes_array(dash, 3, dashes_array); + num_dashes = adg_dash_get_num_dashes(dash); + g_assert_cmpint(num_dashes, ==, 3); + dashes = adg_dash_get_dashes(dash); + g_assert(dashes != NULL); + g_assert_cmpfloat(dashes[0], ==, 1.); + g_assert_cmpfloat(dashes[1], ==, 2.); + g_assert_cmpfloat(dashes[2], ==, 3.); + adg_dash_destroy(dash); dash = adg_dash_new_with_dashes(3, 1., 2., 3.); -- 2.11.4.GIT