/* Make a char* from GSList of GValue. Each GValue should be a ref_string. * free the result. Empty list -> "", not NULL. Join strings with '\n'. */ char * vips__gslist_gvalue_get( const GSList *list ) { const GSList *p; size_t length; char *all; char *q; /* Need to estimate length first. */ length = 0; for( p = list; p; p = p->next ) { GValue *value = (GValue *) p->data; size_t l2; g_assert( G_VALUE_TYPE( value ) == VIPS_TYPE_REF_STRING ); /* +1 for the newline we will add for each item. */ (void) vips_value_get_ref_string( value, &l2 ); length += l2 + 1; } if( length == 0 ) return( NULL ); /* More than 10MB of history? Madness! */ g_assert( length < 10 * 1024 * 1024 ); /* +1 for '\0'. */ if( !(all = vips_malloc( NULL, length + 1 )) ) return( NULL ); q = all; for( p = list; p; p = p->next ) { GValue *value = (GValue *) p->data; size_t l2; strcpy( q, vips_value_get_ref_string( value, &l2 ) ); q += l2; strcpy( q, "\n" ); q += 1; } g_assert( (size_t) (q - all) == length ); return( all ); }
static void * vips_fits_write_meta( VipsImage *image, const char *field, GValue *value, void *a ) { VipsFits *fits = (VipsFits *) a; int status; const char *value_str; status = 0; /* We want fields which start "fits-". */ if( !vips_isprefix( "fits-", field ) ) return( NULL ); /* The value should be a refstring, since we wrote it in fits2vips * above ^^. */ value_str = vips_value_get_ref_string( value, NULL ); VIPS_DEBUG_MSG( "vips_fits_write_meta: setting meta on fits image:\n" ); VIPS_DEBUG_MSG( " value == \"%s\"\n", value_str ); if( fits_write_record( fits->fptr, value_str, &status ) ) { vips_fits_error( status ); return( a ); } return( NULL ); }
/* Merge two GSList of GValue ... append to a all elements in b which are not * in a. Return the new value of a. Works for any vips refcounted type * (string, blob, etc.). */ GSList * vips__gslist_gvalue_merge( GSList *a, const GSList *b ) { const GSList *i, *j; GSList *tail; tail = NULL; for( i = b; i; i = i->next ) { GValue *value = (GValue *) i->data; g_assert( G_VALUE_TYPE( value ) == VIPS_TYPE_REF_STRING ); for( j = a; j; j = j->next ) { GValue *value2 = (GValue *) j->data; g_assert( G_VALUE_TYPE( value2 ) == VIPS_TYPE_REF_STRING ); /* Just do a pointer compare ... good enough 99.9% of * the time. */ if( vips_value_get_ref_string( value, NULL ) == vips_value_get_ref_string( value2, NULL ) ) break; } if( !j ) tail = g_slist_prepend( tail, vips__gvalue_copy( value ) ); } a = g_slist_concat( a, g_slist_reverse( tail ) ); return( a ); }
static int vo_set_property( Vo *vo, const char *name, GParamSpec *pspec, GValue *value ) { /* If we're setting an enum from a string, look up the enum nickname. */ if( G_IS_PARAM_SPEC_ENUM( pspec ) && G_VALUE_TYPE( value ) == VIPS_TYPE_REF_STRING ) { const char *str = vips_value_get_ref_string( value, NULL ); if( vips_object_set_argument_from_string( vo->object, name, str ) ) return( -1 ); } else g_object_set_property( G_OBJECT( vo->object ), name, value ); return( 0 ); }
/* To a save string. */ static void transform_ref_string_save_string( const GValue *src_value, GValue *dest_value ) { vips_value_set_save_stringf( dest_value, "%s", vips_value_get_ref_string( src_value, NULL ) ); }
/* Transform a refstring to a G_TYPE_STRING and back. */ static void transform_ref_string_g_string( const GValue *src_value, GValue *dest_value ) { g_value_set_string( dest_value, vips_value_get_ref_string( src_value, NULL ) ); }