move some vips object stuff about

move some vipsobject code out of util.c
This commit is contained in:
John Cupitt 2011-03-17 13:22:02 +00:00
parent ac801dd1fc
commit 73839df294
3 changed files with 129 additions and 130 deletions

13
TODO
View File

@ -1,7 +1,3 @@
- add FITS and MATLAB write
- rename Rect to VipsRect
- png read/write needs redoing:
@ -14,6 +10,12 @@
argh
- add FITS and MATLAB write
- sink.c, sinkdisc.c, sinkmemory.c all define this function:
static int
@ -40,9 +42,6 @@
sink.c is the replacement for im_iterate()
- decls for type_map etc. are now in object.h, move the code to object.c
- need a way to make the vips.1 etc. man pages

View File

@ -1243,6 +1243,129 @@ vips_object_map( VSListMap2Fn fn, void *a, void *b )
return( args.result );
}
/* Map over all a type's children.
*/
void *
vips_type_map( GType base, VipsTypeMap2 fn, void *a, void *b )
{
GType *child;
guint n_children;
unsigned int i;
void *result;
child = g_type_children( base, &n_children );
result = NULL;
for( i = 0; i < n_children && !result; i++ )
result = fn( child[i], a, b );
g_free( child );
return( result );
}
/* Loop over all the concrete subtypes of a base type.
*/
void *
vips_type_map_concrete_all( GType base, VipsTypeMap fn, void *a )
{
void *result;
result = NULL;
if( !G_TYPE_IS_ABSTRACT( base ) )
result = fn( base, a );
if( !result )
result = vips_type_map( base,
(VipsTypeMap2) vips_type_map_concrete_all, fn, a );
return( result );
}
/* Loop over all the subclasses of a base type.
*/
void *
vips_class_map_concrete_all( GType type, VipsClassMap fn, void *a )
{
void *result;
result = NULL;
if( !G_TYPE_IS_ABSTRACT( type ) ) {
GTypeClass *class;
/* Does this class exist? Try to create if not.
*/
if( !(class = g_type_class_peek( type )) )
/* We don't unref, so the class is never finalized.
* This will make the peek work next time around and
* save us from constantly building and destroying
* classes.
*/
if( !(class = g_type_class_ref( type )) ) {
vips_error( "vips_class_map_concrete_all",
"%s", _( "unable to build class" ) );
return( NULL );
}
result = fn( VIPS_OBJECT_CLASS( class ), a );
}
if( !result )
result = vips_type_map( type,
(VipsTypeMap2) vips_class_map_concrete_all, fn, a );
return( result );
}
static void *
test_name( VipsObjectClass *class, const char *nickname )
{
if( strcasecmp( class->nickname, nickname ) == 0 )
return( class );
/* Check the class name too, why not.
*/
if( strcasecmp( G_OBJECT_CLASS_NAME( class ), nickname ) == 0 )
return( class );
return( NULL );
}
/* Find a class ... search below base, return the first match on a nickname or
* a name.
*/
VipsObjectClass *
vips_class_find( const char *basename, const char *nickname )
{
VipsObjectClass *class;
GType base;
if( !(base = g_type_from_name( basename )) ) {
vips_error( "vips_class_find",
_( "base class \"%s\" not found" ), basename );
return( NULL );
}
if( !(class = vips_class_map_concrete_all( base,
(VipsClassMap) test_name, (void *) nickname )) ) {
vips_error( "vips_class_find",
_( "class \"%s\" not found" ), nickname );
return( NULL );
}
return( class );
}
GType
vips_type_find( const char *basename, const char *nickname )
{
VipsObjectClass *class;
if( !(class = vips_class_find( "VipsInterpolate", 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 ) );
}
void
vips_object_local_cb( VipsObject *vobject, GObject *gobject )
{

View File

@ -243,129 +243,6 @@ im_hash_table_map( GHashTable *hash, VSListMap2Fn fn, void *a, void *b )
return( pair.result );
}
/* Map over all a type's children.
*/
void *
vips_type_map( GType base, VipsTypeMap2 fn, void *a, void *b )
{
GType *child;
guint n_children;
unsigned int i;
void *result;
child = g_type_children( base, &n_children );
result = NULL;
for( i = 0; i < n_children && !result; i++ )
result = fn( child[i], a, b );
g_free( child );
return( result );
}
/* Loop over all the concrete subtypes of a base type.
*/
void *
vips_type_map_concrete_all( GType base, VipsTypeMap fn, void *a )
{
void *result;
result = NULL;
if( !G_TYPE_IS_ABSTRACT( base ) )
result = fn( base, a );
if( !result )
result = vips_type_map( base,
(VipsTypeMap2) vips_type_map_concrete_all, fn, a );
return( result );
}
/* Loop over all the subclasses of a base type.
*/
void *
vips_class_map_concrete_all( GType type, VipsClassMap fn, void *a )
{
void *result;
result = NULL;
if( !G_TYPE_IS_ABSTRACT( type ) ) {
GTypeClass *class;
/* Does this class exist? Try to create if not.
*/
if( !(class = g_type_class_peek( type )) )
/* We don't unref, so the class is never finalized.
* This will make the peek work next time around and
* save us from constantly building and destroying
* classes.
*/
if( !(class = g_type_class_ref( type )) ) {
vips_error( "vips_class_map_concrete_all",
"%s", _( "unable to build class" ) );
return( NULL );
}
result = fn( VIPS_OBJECT_CLASS( class ), a );
}
if( !result )
result = vips_type_map( type,
(VipsTypeMap2) vips_class_map_concrete_all, fn, a );
return( result );
}
static void *
test_name( VipsObjectClass *class, const char *nickname )
{
if( strcasecmp( class->nickname, nickname ) == 0 )
return( class );
/* Check the class name too, why not.
*/
if( strcasecmp( G_OBJECT_CLASS_NAME( class ), nickname ) == 0 )
return( class );
return( NULL );
}
/* Find a class ... search below base, return the first match on a nickname or
* a name.
*/
VipsObjectClass *
vips_class_find( const char *basename, const char *nickname )
{
VipsObjectClass *class;
GType base;
if( !(base = g_type_from_name( basename )) ) {
vips_error( "vips_class_find",
_( "base class \"%s\" not found" ), basename );
return( NULL );
}
if( !(class = vips_class_map_concrete_all( base,
(VipsClassMap) test_name, (void *) nickname )) ) {
vips_error( "vips_class_find",
_( "class \"%s\" not found" ), nickname );
return( NULL );
}
return( class );
}
GType
vips_type_find( const char *basename, const char *nickname )
{
VipsObjectClass *class;
if( !(class = vips_class_find( "VipsInterpolate", 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 ) );
}
/* Like strncpy(), but always NULL-terminate, and don't pad with NULLs.
*/
char *