new C++ interface works!

phew
This commit is contained in:
John Cupitt 2014-10-27 12:57:28 +00:00
parent 620bff2d78
commit 266e120676
7 changed files with 23 additions and 106 deletions

20
TODO
View File

@ -1,23 +1,5 @@
- see
- remove VipsCollect
http://www.parashift.com/c++-faq/named-parameter-idiom.html
good idea? seems clumsy
could do it something like:
VImage sum = image.add(image2).set("max", 12).build();
or maybe:
VImage result = image.sin().build().cos().build();
could the options go into an optional param?
VImage result = image.sin().cos();
VImage sum = image.add(image2,
VOption().set("max", 12).set("title", "poop"));
- use vips_autorot() in jpegload and vipsthumbnail

View File

@ -374,6 +374,10 @@ void VImage::call_option_string( const char *operation_name,
if( options )
options->get_operation( operation );
/* We're done with options!
*/
delete options;
/* The operation we have built should now have been reffed by
* one of its arguments or have finished its work. Either
* way, we can unref.
@ -467,25 +471,9 @@ main( int argc, char **argv )
vips_error_exit( NULL );
}
/*
VipsImage *in;
VipsImage *out;
if( !(in = vips_image_new_from_file( argv[1], NULL )) )
vips_error_exit( NULL );
if( vips_invert( in, &out, NULL ) )
vips_error_exit( NULL );
if( vips_image_write_to_file( out, argv[2], NULL ) )
vips_error_exit( NULL );
g_object_unref( in );
g_object_unref( out );
*/
printf( "these should match, if the class is compile-time-only,\n" );
printf( "as it should be\n" );
printf( "sizeof( VipsImage *) = %zd\n", sizeof( VipsImage *) );
printf( "sizeof( VImage ) = %zd\n", sizeof( VImage ) );
@ -493,9 +481,9 @@ main( int argc, char **argv )
VImage in = VImage::new_from_file( argv[1] );
VImage out;
//out = in.invert();
out = in.invert();
//out.write_to_file( argv[2] );
out.write_to_file( argv[2] );
}
vips_shutdown();

View File

@ -59,25 +59,6 @@ typedef void *(*VipsSListMap4Fn)( void *item,
typedef void *(*VipsSListFold2Fn)( void *item,
void *a, void *b, void *c );
/* The value has been read from the VipsOperation and written to the
* arg pointer. @arg is eg. gboolean* for a bool value.
*/
typedef void (*VipsCollectGet)( GParamSpec *pspec, void *arg );
/* The value has been read from argv into a GValue. Do any
* boxing/unboxing before the GValue is used to set the property.
*/
typedef void (*VipsCollectSet)( GParamSpec *pspec, GValue *value );
/* We need to be able to use different things to collect values for the C++
* API: we have to box and unbox VipsImage. Set/get need to be parameters.
*/
typedef struct _VipsCollect {
VipsCollectGet get;
VipsCollectSet set;
} VipsCollect;
#ifdef __cplusplus
}
#endif /*__cplusplus*/

View File

@ -601,8 +601,7 @@ typedef void *(*VipsObjectSetArguments)( VipsObject *object, void *a, void *b );
VipsObject *vips_object_new( GType type,
VipsObjectSetArguments set, void *a, void *b );
int vips_object_set_valist( VipsObject *object,
VipsCollect *collect, va_list ap );
int vips_object_set_valist( VipsObject *object, va_list ap );
int vips_object_set( VipsObject *object, ... )
__attribute__((sentinel));
int vips_object_set_from_string( VipsObject *object, const char *string );

View File

@ -101,7 +101,7 @@ void vips_operation_invalidate( VipsOperation *operation );
int vips_operation_call_valist( VipsOperation *operation, va_list ap );
VipsOperation *vips_operation_new( const char *name );
int vips_call_required_optional( VipsOperation **operation,
VipsCollect *collect, va_list required, va_list optional );
va_list required, va_list optional );
int vips_call( const char *operation_name, ... )
__attribute__((sentinel));
int vips_call_split( const char *operation_name, va_list optional, ... );

View File

@ -2157,7 +2157,6 @@ vips_object_new( GType type, VipsObjectSetArguments set, void *a, void *b )
/**
* vips_object_set_valist:
* @object: object to set arguments on
* @collect: how to box or unbox values
* @ap: %NULL-terminated list of argument/value pairs
*
* See vips_object_set().
@ -2165,7 +2164,7 @@ vips_object_new( GType type, VipsObjectSetArguments set, void *a, void *b )
* Returns: 0 on success, -1 on error
*/
int
vips_object_set_valist( VipsObject *object, VipsCollect *collect, va_list ap )
vips_object_set_valist( VipsObject *object, va_list ap )
{
char *name;
@ -2184,9 +2183,6 @@ vips_object_set_valist( VipsObject *object, VipsCollect *collect, va_list ap )
VIPS_ARGUMENT_COLLECT_SET( pspec, argument_class, ap );
if( collect )
collect->set( pspec, &value );
g_object_set_property( G_OBJECT( object ), name, &value );
VIPS_ARGUMENT_COLLECT_GET( pspec, argument_class, ap );
@ -2225,7 +2221,7 @@ vips_object_set( VipsObject *object, ... )
int result;
va_start( ap, object );
result = vips_object_set_valist( object, NULL, ap );
result = vips_object_set_valist( object, ap );
va_end( ap );
return( result );

View File

@ -181,13 +181,6 @@
* compatibility only and should be hidden from users.
*/
/**
* VipsCollect:
*
* We need to be able to use different things to collect values for the C++
* API: we have to box and unbox VipsImage. Set/get need to be parameters.
*/
/* Abstract base class for operations.
*/
@ -584,8 +577,7 @@ vips_operation_new( const char *name )
#endif
static int
vips_operation_set_valist_required( VipsOperation *operation,
VipsCollect *collect, va_list ap )
vips_operation_set_valist_required( VipsOperation *operation, va_list ap )
{
VIPS_DEBUG_MSG( "vips_operation_set_valist_required:\n" );
@ -611,9 +603,6 @@ vips_operation_set_valist_required( VipsOperation *operation,
}
#endif /*VIPS_DEBUG */
if( collect )
collect->set( pspec, &value );
g_object_set_property( G_OBJECT( operation ),
g_param_spec_get_name( pspec ), &value );
@ -632,8 +621,7 @@ vips_operation_set_valist_required( VipsOperation *operation,
}
static int
vips_operation_get_valist_required( VipsOperation *operation,
VipsCollect *collect, va_list ap )
vips_operation_get_valist_required( VipsOperation *operation, va_list ap )
{
VIPS_DEBUG_MSG( "vips_operation_get_valist_required:\n" );
@ -679,11 +667,6 @@ vips_operation_get_valist_required( VipsOperation *operation,
g_object_unref( object );
}
/* Do any boxing/unboxing.
*/
if( collect )
collect->get( pspec, arg );
VIPS_ARGUMENT_COLLECT_END
}
} VIPS_ARGUMENT_FOR_ALL_END
@ -692,8 +675,7 @@ vips_operation_get_valist_required( VipsOperation *operation,
}
static int
vips_operation_get_valist_optional( VipsOperation *operation,
VipsCollect *collect, va_list ap )
vips_operation_get_valist_optional( VipsOperation *operation, va_list ap )
{
char *name;
@ -743,11 +725,6 @@ vips_operation_get_valist_optional( VipsOperation *operation,
object = *((GObject **) arg);
g_object_unref( object );
}
/* Do any boxing/unboxing.
*/
if( collect )
collect->get( pspec, arg );
}
VIPS_ARGUMENT_COLLECT_END
@ -759,14 +736,11 @@ vips_operation_get_valist_optional( VipsOperation *operation,
/**
* vips_call_required_optional:
* @operation: the operation to execute
* @collect: how to box and unbox arguments
* @required: %va_list of required arguments
* @optional: NULL-terminated %va_list of name / value pairs
*
* This is the main entry point for the C and C++ varargs APIs. @operation
* is executed, supplying @required and @optional arguments. @collect is used
* to do any boxing or unboxing. It can be %NULL for no boxing on unboxing
* required (the C case).
* is executed, supplying @required and @optional arguments.
*
* Beware, this can change @operation to point at an old, cached one.
*
@ -774,7 +748,7 @@ vips_operation_get_valist_optional( VipsOperation *operation,
*/
int
vips_call_required_optional( VipsOperation **operation,
VipsCollect *collect, va_list required, va_list optional )
va_list required, va_list optional )
{
int result;
va_list a;
@ -786,8 +760,8 @@ vips_call_required_optional( VipsOperation **operation,
*/
va_copy( a, required );
va_copy( b, optional );
result = vips_operation_set_valist_required( *operation, collect, a ) ||
vips_object_set_valist( VIPS_OBJECT( *operation ), collect, b );
result = vips_operation_set_valist_required( *operation, a ) ||
vips_object_set_valist( VIPS_OBJECT( *operation ), b );
va_end( a );
va_end( b );
@ -803,10 +777,8 @@ vips_call_required_optional( VipsOperation **operation,
*/
va_copy( a, required );
va_copy( b, optional );
result = vips_operation_get_valist_required( *operation,
collect, required ) ||
vips_operation_get_valist_optional( *operation,
collect, optional );
result = vips_operation_get_valist_required( *operation, required ) ||
vips_operation_get_valist_optional( *operation, optional );
va_end( a );
va_end( b );
@ -838,8 +810,7 @@ vips_call_by_name( const char *operation_name,
return( -1 );
}
result = vips_call_required_optional( &operation,
NULL, required, optional );
result = vips_call_required_optional( &operation, required, optional );
/* Build failed: junk args and back out.
*/