From 045c2b37aa75e25fb9f122eebcee11ca9e705187 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 24 Oct 2011 08:57:13 +0100 Subject: [PATCH] sync --- TODO | 15 ++++++++++++++ libvips/iofuncs/header.c | 42 +++++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 81743056..a8c97f3a 100644 --- a/TODO +++ b/TODO @@ -12,10 +12,25 @@ to spot vector args, since we don't have the idea of generic vector in the type system + we can't make a generic VIPS_TYPE_ARRAY boxed, since + g_boxed_type_register_static() does not let us specify a parent class, the + code has G_TYPE_BOXED hardwired as the parent class + instead, perhaps derive from G_TYPE_PARAM_BOXED to create VIPS_TYPE_PARAM_ARRAY, a boxed param that can only be a VipsArea array ... would this work? + nope, g_param_type_register_static() is also hardwired to have G_TYPE_PARAM + as its parent class argh + + best we can do is register a char->value transform in each array type, and + have the generic transformer as a utility function + + + + break in transform_g_string_array() and try running with --background + + do we have anything in dest_value we can use to decide what type to write? diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index d8c57f77..00e7ea82 100644 --- a/libvips/iofuncs/header.c +++ b/libvips/iofuncs/header.c @@ -1575,13 +1575,39 @@ transform_array_g_string( const GValue *src_value, GValue *dest_value ) g_value_set_string( dest_value, vips_buf_all( &buf ) ); } -/* We don't have functions to save arrays to save_str and back. We'd need to - * save the type as well as the members and number of members, something like: - * - * double { 12.3, 13.7 } - * - * Anyway, no call for this yet. - */ +static void +transform_g_string_array( const GValue *src_value, GValue *dest_value ) +{ + const char *str = g_value_get_string( src_value ); + + int n; + const char *p; + int i; + GType type; + + /* Walk the string to get the number of elements. Empty string is zero + * elements. + */ + for( n = 0, p = str; p && *p; n += 1 ) { + p = strchr( p, ',' ); + if( p ) + p += 1; + } + + for( i = 0; i < n; i++ ) { + GValue value = { 0, }; + char *str; + + g_value_init( &value, type ); + //g_value_set_instance( &value, array ); + + g_value_unset( &value ); + + // array += sizeof_type; + } + + // g_value_set_string( dest_value, vips_buf_all( &buf ) ); +} GType vips_array_double_get_type( void ) @@ -1594,6 +1620,8 @@ vips_array_double_get_type( void ) (GBoxedFreeFunc) vips_area_unref ); g_value_register_transform_func( type, G_TYPE_STRING, transform_array_g_string ); + g_value_register_transform_func( G_TYPE_STRING, type, + transform_g_string_array ); } return( type );