From 3126e5100d2eb0e7ee66c32ac22b3128bb37002d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 21 Jun 2011 11:08:56 +0100 Subject: [PATCH] get interpolate new from string working vips_type_map() has to see abstract types now so we can get the baseclass for interpolate. interpolate class has to set the nickname. --- .gitignore | 2 ++ libvips/format/format.c | 9 +++++---- libvips/include/vips/object.h | 4 ++-- libvips/iofuncs/object.c | 34 ++++++++++++---------------------- libvips/resample/interpolate.c | 5 +++++ tools/vips.c | 7 +++++-- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index d5ae75fc..7d60d1db 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ TAGS .*.swp *.lo *.la +Vips-8.0.gir +Vips-8.0.typelib *.pc *.pyc .deps diff --git a/libvips/format/format.c b/libvips/format/format.c index 17639ebc..b956a70b 100644 --- a/libvips/format/format.c +++ b/libvips/format/format.c @@ -230,9 +230,10 @@ G_DEFINE_TYPE( VipsFormatTiff, vips_format_tiff, VIPS_TYPE_FORMAT ); static void * format_add_class( VipsFormatClass *format, GSList **formats ) { - /* Append so we don't reverse the list of formats. - */ - *formats = g_slist_append( *formats, format ); + if( !G_TYPE_IS_ABSTRACT( G_OBJECT_CLASS_TYPE( format ) ) ) + /* Append so we don't reverse the list of formats. + */ + *formats = g_slist_append( *formats, format ); return( NULL ); } @@ -267,7 +268,7 @@ vips_format_map( VSListMap2Fn fn, void *a, void *b ) void *result; formats = NULL; - (void) vips_class_map_concrete_all( g_type_from_name( "VipsFormat" ), + (void) vips_class_map_all( g_type_from_name( "VipsFormat" ), (VipsClassMap) format_add_class, (void *) &formats ); formats = g_slist_sort( formats, (GCompareFunc) format_compare ); diff --git a/libvips/include/vips/object.h b/libvips/include/vips/object.h index 81f04cfe..39eff878 100644 --- a/libvips/include/vips/object.h +++ b/libvips/include/vips/object.h @@ -344,8 +344,8 @@ typedef void *(*VipsTypeMap)( GType, void * ); typedef void *(*VipsTypeMap2)( GType, void *, void * ); typedef void *(*VipsClassMap)( VipsObjectClass *, void * ); void *vips_type_map( GType base, VipsTypeMap2 fn, void *a, void *b ); -void *vips_type_map_concrete_all( GType base, VipsTypeMap fn, void *a ); -void *vips_class_map_concrete_all( GType base, VipsClassMap fn, void *a ); +void *vips_type_map_all( GType base, VipsTypeMap fn, void *a ); +void *vips_class_map_all( GType base, VipsClassMap fn, void *a ); VipsObjectClass *vips_class_find( const char *basename, const char *nickname ); GType vips_type_find( const char *basename, const char *nickname ); diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 252bab22..2697021d 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -1544,19 +1544,16 @@ vips_type_map( GType base, VipsTypeMap2 fn, void *a, void *b ) return( result ); } -/* Loop over all the concrete subtypes of a base type. +/* Loop over all the subtypes of a base type. */ void * -vips_type_map_concrete_all( GType base, VipsTypeMap fn, void *a ) +vips_type_map_all( GType base, VipsTypeMap fn, void *a ) { void *result; - result = NULL; - if( !G_TYPE_IS_ABSTRACT( base ) ) - result = fn( base, a ); - if( !result ) + if( !(result = fn( base, a )) ) result = vips_type_map( base, - (VipsTypeMap2) vips_type_map_concrete_all, fn, a ); + (VipsTypeMap2) vips_type_map_all, fn, a ); return( result ); } @@ -1564,20 +1561,16 @@ vips_type_map_concrete_all( GType base, VipsTypeMap fn, void *a ) /* Loop over all the subclasses of a base type. */ void * -vips_class_map_concrete_all( GType type, VipsClassMap fn, void *a ) +vips_class_map_all( GType type, VipsClassMap fn, void *a ) { void *result; - result = NULL; - if( !G_TYPE_IS_ABSTRACT( type ) ) - /* We never unref this ref, but we never unload classes - * anyway, so so what. - */ - result = fn( VIPS_OBJECT_CLASS( g_type_class_ref( type ) ), a ); - - if( !result ) + /* We never unref this ref, but we never unload classes + * anyway, so so what. + */ + if( !(result = fn( VIPS_OBJECT_CLASS( g_type_class_ref( type ) ), a )) ) result = vips_type_map( type, - (VipsTypeMap2) vips_class_map_concrete_all, fn, a ); + (VipsTypeMap2) vips_class_map_all, fn, a ); return( result ); } @@ -1611,7 +1604,7 @@ vips_class_find( const char *basename, const char *nickname ) return( NULL ); } - if( !(class = vips_class_map_concrete_all( base, + if( !(class = vips_class_map_all( base, (VipsClassMap) test_name, (void *) nickname )) ) { vips_error( "VipsObject", _( "class \"%s\" not found" ), nickname ); @@ -1629,10 +1622,7 @@ vips_type_find( const char *basename, const char *nickname ) if( !(class = vips_class_find( "VipsObject", nickname )) ) return( 0 ); - /* FIXME ... we've not supposed to use G_TYPE_FROM_CLASS(), I think. - * I'm not sure what the alternative is. - */ - return( G_TYPE_FROM_CLASS( class ) ); + return( G_OBJECT_CLASS_TYPE( class ) ); } void diff --git a/libvips/resample/interpolate.c b/libvips/resample/interpolate.c index ade28442..31351673 100644 --- a/libvips/resample/interpolate.c +++ b/libvips/resample/interpolate.c @@ -170,6 +170,8 @@ vips_interpolate_real_get_window_offset( VipsInterpolate *interpolate ) static void vips_interpolate_class_init( VipsInterpolateClass *class ) { + VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class ); + #ifdef DEBUG GObjectClass *gobject_class = G_OBJECT_CLASS( class ); #endif /*DEBUG*/ @@ -178,6 +180,9 @@ vips_interpolate_class_init( VipsInterpolateClass *class ) gobject_class->finalize = vips_interpolate_finalize; #endif /*DEBUG*/ + vobject_class->nickname = "interpolate"; + vobject_class->description = _( "VIPS interpolation class" ); + class->interpolate = NULL; class->get_window_size = vips_interpolate_real_get_window_size; class->get_window_offset = vips_interpolate_real_get_window_offset; diff --git a/tools/vips.c b/tools/vips.c index f31b062d..ef0a6741 100644 --- a/tools/vips.c +++ b/tools/vips.c @@ -168,7 +168,10 @@ list_function( im_function *func ) static void * list_class( VipsObjectClass *class ) { - vips_object_print_class( class ); + /* Ignore abstract classes. + */ + if( !G_TYPE_IS_ABSTRACT( G_OBJECT_CLASS_TYPE( class ) ) ) + vips_object_print_class( class ); return( NULL ); } @@ -179,7 +182,7 @@ print_list( int argc, char **argv ) if( !argv[0] || strcmp( argv[0], "packages" ) == 0 ) im_map_packages( (VSListMap2Fn) list_package, NULL ); else if( strcmp( argv[0], "classes" ) == 0 ) - vips_class_map_concrete_all( g_type_from_name( "VipsObject" ), + vips_class_map_all( g_type_from_name( "VipsObject" ), (VipsClassMap) list_class, NULL ); else { if( map_name( argv[0], list_function ) )