added class print

This commit is contained in:
John Cupitt 2008-11-30 13:01:48 +00:00
parent 7496082f2c
commit 11352c8f1b
6 changed files with 83 additions and 54 deletions

View File

@ -18,7 +18,7 @@
- IM_FORMAT_FLAG_PARTIAL -> VIPS_FORMAT_PARTIAL - IM_FORMAT_FLAG_PARTIAL -> VIPS_FORMAT_PARTIAL
- updated docs - updated docs
- interpolators use type introspection - interpolators use type introspection
- added vips --list interpolators - added vips --list classes, does formats too
11/9/08 started 7.16.3 11/9/08 started 7.16.3
- oop typo in manpage for im_project() - oop typo in manpage for im_project()
@ -52,7 +52,6 @@
- revised po/ - revised po/
- released as 7.16.0! - released as 7.16.0!
>>>>>>> .merge-right.r488
25/5/08 fork for loadable image format branch 25/5/08 fork for loadable image format branch
- image load/save in non-vips format code moved to own dir - image load/save in non-vips format code moved to own dir
- simple format searching added - simple format searching added

11
TODO
View File

@ -1,4 +1,13 @@
- nip2 Interpolate needs updating to new affinei thing - add params
use property system
use construtors, see docs for g_object_new(), rather than vips8 build funcs
nickname, description etc need to be properties so nip2 can read them
add a g_get_children( "classname" ) -> ["child1-name", ..] to nip2, see old
vips8.c cooe?

View File

@ -62,6 +62,10 @@ typedef struct _VipsObjectClass {
*/ */
void (*changed)( VipsObject * ); void (*changed)( VipsObject * );
/* Try to print something about the class, handy for help displays.
*/
void (*print_class)( struct _VipsObjectClass *, im_buf_t * );
/* Try to print something about the object, handy for debugging. /* Try to print something about the object, handy for debugging.
*/ */
void (*print)( VipsObject *, im_buf_t * ); void (*print)( VipsObject *, im_buf_t * );
@ -76,7 +80,8 @@ typedef struct _VipsObjectClass {
const char *description; const char *description;
} VipsObjectClass; } VipsObjectClass;
void *vips_object_changed( VipsObject *vips_object ); void *vips_object_changed( VipsObject *object );
void vips_object_print_class( VipsObjectClass *klass );
void vips_object_print( VipsObject *object ); void vips_object_print( VipsObject *object );
GType vips_object_get_type( void ); GType vips_object_get_type( void );

View File

@ -81,9 +81,43 @@ vips_format_map( VSListMap2Fn fn, void *a, void *b )
/* Abstract base class for image formats. /* Abstract base class for image formats.
*/ */
G_DEFINE_ABSTRACT_TYPE( VipsFormat, vips_format, VIPS_TYPE_OBJECT );
static void
vips_format_print_class( VipsObjectClass *object_class, im_buf_t *buf )
{
VipsFormatClass *class = VIPS_FORMAT_CLASS( object_class );
const char **p;
VIPS_OBJECT_CLASS( vips_format_parent_class )->
print_class( object_class, buf );
im_buf_appends( buf, ", (" );
for( p = class->suffs; *p; p++ ) {
im_buf_appendf( buf, "%s", *p );
if( p[1] )
im_buf_appends( buf, ", " );
}
im_buf_appends( buf, ") " );
if( class->is_a )
im_buf_appends( buf, "is_a " );
if( class->header )
im_buf_appends( buf, "header " );
if( class->load )
im_buf_appends( buf, "load " );
if( class->save )
im_buf_appends( buf, "save " );
if( class->get_flags )
im_buf_appends( buf, "get_flags " );
}
static void static void
vips_format_class_init( VipsFormatClass *class ) vips_format_class_init( VipsFormatClass *class )
{ {
VipsObjectClass *object_class = (VipsObjectClass *) class;
object_class->print_class = vips_format_print_class;
} }
static void static void
@ -91,8 +125,6 @@ vips_format_init( VipsFormat *object )
{ {
} }
G_DEFINE_ABSTRACT_TYPE( VipsFormat, vips_format, VIPS_TYPE_OBJECT );
/* VIPS format class. /* VIPS format class.
*/ */

View File

@ -77,15 +77,27 @@ vips_object_changed( VipsObject *object )
} }
void void
vips_object_print( VipsObject *object ) vips_object_print_class( VipsObjectClass *class )
{ {
VipsObjectClass *object_class = VIPS_OBJECT_GET_CLASS( object );
im_buf_t buf; im_buf_t buf;
char str[1000]; char str[1000];
im_buf_init_static( &buf, str, 1000 ); im_buf_init_static( &buf, str, 1000 );
object_class->print( object, &buf ); class->print_class( class, &buf );
printf( "%s (%p)\n", im_buf_all( &buf ), object ); printf( "%s\n", im_buf_all( &buf ) );
}
void
vips_object_print( VipsObject *object )
{
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
im_buf_t buf;
char str[1000];
vips_object_print_class( class );
im_buf_init_static( &buf, str, 1000 );
class->print( object, &buf );
printf( "\n%s (%p)\n", im_buf_all( &buf ), object );
} }
static void static void
@ -127,13 +139,21 @@ vips_object_real_changed( VipsObject *object )
#endif /*DEBUG*/ #endif /*DEBUG*/
} }
static void
vips_object_real_print_class( VipsObjectClass *class, im_buf_t *buf )
{
im_buf_appendf( buf, "%s", G_OBJECT_CLASS_NAME( class ) );
if( class->nickname )
im_buf_appendf( buf, " (%s)", class->nickname );
if( class->description )
im_buf_appendf( buf, ", %s", class->description );
}
static void static void
vips_object_real_print( VipsObject *object, im_buf_t *buf ) vips_object_real_print( VipsObject *object, im_buf_t *buf )
{ {
im_buf_appendf( buf, "%s(", G_OBJECT_TYPE_NAME( object ) );
if( object->name ) if( object->name )
im_buf_appendf( buf, "\"%s\"", object->name ); im_buf_appendf( buf, "\"%s\"", object->name );
im_buf_appendf( buf, ")" );
} }
static void static void
@ -145,6 +165,7 @@ vips_object_class_init( VipsObjectClass *class )
gobject_class->finalize = vips_object_finalize; gobject_class->finalize = vips_object_finalize;
class->changed = vips_object_real_changed; class->changed = vips_object_real_changed;
class->print_class = vips_object_real_print_class;
class->print = vips_object_real_print; class->print = vips_object_real_print;
class->nickname = "object"; class->nickname = "object";
class->description = _( "VIPS base class" ); class->description = _( "VIPS base class" );

View File

@ -166,42 +166,9 @@ list_function( im_function *func )
} }
static void * static void *
list_format( VipsFormatClass *class ) list_class( VipsObjectClass *class )
{ {
const char **p; vips_object_print_class( class );
printf( "%-20s - ",
VIPS_OBJECT_CLASS( class )->description );
printf( "(" );
for( p = class->suffs; *p; p++ ) {
printf( "%s", *p );
if( p[1] )
printf( ", " );
}
printf( ") " );
if( class->is_a )
printf( "is_a " );
if( class->header )
printf( "header " );
if( class->load )
printf( "load " );
if( class->save )
printf( "save " );
if( class->get_flags )
printf( "get_flags " );
printf( "\n" );
return( NULL );
}
static void *
list_interpolate( VipsInterpolateClass *class )
{
printf( "%-20s - %s\n",
VIPS_OBJECT_CLASS( class )->nickname,
VIPS_OBJECT_CLASS( class )->description );
return( NULL ); return( NULL );
} }
@ -211,13 +178,9 @@ print_list( const char *name )
{ {
if( strcmp( name, "packages" ) == 0 ) if( strcmp( name, "packages" ) == 0 )
im_map_packages( (VSListMap2Fn) list_package, NULL ); im_map_packages( (VSListMap2Fn) list_package, NULL );
else if( strcmp( name, "formats" ) == 0 ) else if( strcmp( name, "classes" ) == 0 )
vips_format_map( (VSListMap2Fn) list_format, NULL, NULL ); vips_class_map_concrete_all( g_type_from_name( "VipsObject" ),
else if( strcmp( name, "interpolators" ) == 0 ) { (VipsClassMap) list_class, NULL );
vips_class_map_concrete_all(
g_type_from_name( "VipsInterpolate" ),
(VipsClassMap) list_interpolate, NULL );
}
else { else {
if( map_name( name, list_function ) ) if( map_name( name, list_function ) )
error_exit( "unknown package \"%s\"", name ); error_exit( "unknown package \"%s\"", name );