improve C++ API

Make VObject inheritance public, so we can have a single set() for all
VObject-derived types.
This commit is contained in:
John Cupitt 2020-08-19 15:08:28 +01:00
parent 2188e79283
commit 409301a200
7 changed files with 54 additions and 91 deletions

View File

@ -1,5 +1,8 @@
14/8/20 started 8.11 14/8/20 started 8.11
- add vips_jpegload_source() and vips_svgload_source() to public C API - add vips_jpegload_source() and vips_svgload_source() to public C API
- integrate doxygen in build system to generate C++ API docs
- improve C++ API doc comments
- add VipsInterpolate and guint64 support to C++ API
9/8/20 started 8.10.1 9/8/20 started 8.10.1
- fix markdown -> xml conversion in doc generation - fix markdown -> xml conversion in doc generation

View File

@ -110,19 +110,6 @@ VSource::new_from_options( const char *options )
return( out ); return( out );
} }
VOption *
VOption::set( const char *name, const VSource value )
{
Pair *pair = new Pair( name );
pair->input = true;
g_value_init( &pair->value, VIPS_TYPE_SOURCE );
g_value_set_object( &pair->value, value.get_source() );
options.push_back( pair );
return( this );
}
VTarget VTarget
VTarget::new_to_descriptor( int descriptor ) VTarget::new_to_descriptor( int descriptor )
{ {
@ -162,17 +149,4 @@ VTarget::new_to_memory()
return( out ); return( out );
} }
VOption *
VOption::set( const char *name, const VTarget value )
{
Pair *pair = new Pair( name );
pair->input = true;
g_value_init( &pair->value, VIPS_TYPE_TARGET );
g_value_set_object( &pair->value, value.get_target() );
options.push_back( pair );
return( this );
}
VIPS_NAMESPACE_END VIPS_NAMESPACE_END

View File

@ -140,20 +140,6 @@ VOption::set( const char *name, int value )
return( this ); return( this );
} }
// input double
VOption *
VOption::set( const char *name, double value )
{
Pair *pair = new Pair( name );
pair->input = true;
g_value_init( &pair->value, G_TYPE_DOUBLE );
g_value_set_double( &pair->value, value );
options.push_back( pair );
return( this );
}
// input guint64 // input guint64
VOption * VOption *
VOption::set( const char *name, guint64 value ) VOption::set( const char *name, guint64 value )
@ -168,6 +154,20 @@ VOption::set( const char *name, guint64 value )
return( this ); return( this );
} }
// input double
VOption *
VOption::set( const char *name, double value )
{
Pair *pair = new Pair( name );
pair->input = true;
g_value_init( &pair->value, G_TYPE_DOUBLE );
g_value_set_double( &pair->value, value );
options.push_back( pair );
return( this );
}
VOption * VOption *
VOption::set( const char *name, const char *value ) VOption::set( const char *name, const char *value )
{ {
@ -181,39 +181,17 @@ VOption::set( const char *name, const char *value )
return( this ); return( this );
} }
// input image // input vips object (image, source, target, etc. etc.)
VOption * VOption *
VOption::set( const char *name, const VImage value ) VOption::set( const char *name, const VObject value )
{ {
Pair *pair = new Pair( name ); Pair *pair = new Pair( name );
VipsObject *object = value.get_object();
GType type = G_VALUE_TYPE( object );
pair->input = true; pair->input = true;
g_value_init( &pair->value, VIPS_TYPE_IMAGE ); g_value_init( &pair->value, type );
g_value_set_object( &pair->value, value.get_image() ); g_value_set_object( &pair->value, object );
options.push_back( pair );
return( this );
}
// input double array
VOption *
VOption::set( const char *name, std::vector<double> value )
{
Pair *pair = new Pair( name );
double *array;
unsigned int i;
pair->input = true;
g_value_init( &pair->value, VIPS_TYPE_ARRAY_DOUBLE );
vips_value_set_array_double( &pair->value, NULL,
static_cast< int >( value.size() ) );
array = vips_value_get_array_double( &pair->value, NULL );
for( i = 0; i < value.size(); i++ )
array[i] = value[i];
options.push_back( pair ); options.push_back( pair );
return( this ); return( this );
@ -243,6 +221,30 @@ VOption::set( const char *name, std::vector<int> value )
return( this ); return( this );
} }
// input double array
VOption *
VOption::set( const char *name, std::vector<double> value )
{
Pair *pair = new Pair( name );
double *array;
unsigned int i;
pair->input = true;
g_value_init( &pair->value, VIPS_TYPE_ARRAY_DOUBLE );
vips_value_set_array_double( &pair->value, NULL,
static_cast< int >( value.size() ) );
array = vips_value_get_array_double( &pair->value, NULL );
for( i = 0; i < value.size(); i++ )
array[i] = value[i];
options.push_back( pair );
return( this );
}
// input image array // input image array
VOption * VOption *
VOption::set( const char *name, std::vector<VImage> value ) VOption::set( const char *name, std::vector<VImage> value )

View File

@ -60,17 +60,4 @@ VInterpolate::new_from_name( const char *name, VOption *options )
return( out ); return( out );
} }
VOption *
VOption::set( const char *name, const VInterpolate value )
{
Pair *pair = new Pair( name );
pair->input = true;
g_value_init( &pair->value, VIPS_TYPE_INTERPOLATE );
g_value_set_object( &pair->value, value.get_interpolate() );
options.push_back( pair );
return( this );
}
VIPS_NAMESPACE_END VIPS_NAMESPACE_END

View File

@ -34,7 +34,7 @@
VIPS_NAMESPACE_START VIPS_NAMESPACE_START
class VSource : VObject class VSource : public VObject
{ {
public: public:
VSource( VipsSource *input, VSteal steal = STEAL ) : VSource( VipsSource *input, VSteal steal = STEAL ) :
@ -66,7 +66,7 @@ public:
}; };
class VTarget : VObject class VTarget : public VObject
{ {
public: public:
VTarget( VipsTarget *output, VSteal steal = STEAL ) : VTarget( VipsTarget *output, VSteal steal = STEAL ) :

View File

@ -223,13 +223,10 @@ public:
VOption *set( const char *name, guint64 value ); VOption *set( const char *name, guint64 value );
VOption *set( const char *name, double value ); VOption *set( const char *name, double value );
VOption *set( const char *name, const char *value ); VOption *set( const char *name, const char *value );
VOption *set( const char *name, const VImage value ); VOption *set( const char *name, const VObject value );
VOption *set( const char *name, const VInterpolate value );
VOption *set( const char *name, const VSource value );
VOption *set( const char *name, const VTarget value );
VOption *set( const char *name, std::vector<VImage> value );
VOption *set( const char *name, std::vector<double> value );
VOption *set( const char *name, std::vector<int> value ); VOption *set( const char *name, std::vector<int> value );
VOption *set( const char *name, std::vector<double> value );
VOption *set( const char *name, std::vector<VImage> value );
VOption *set( const char *name, VipsBlob *value ); VOption *set( const char *name, VipsBlob *value );
VOption *set( const char *name, bool *value ); VOption *set( const char *name, bool *value );
@ -244,7 +241,7 @@ public:
}; };
class VImage : VObject class VImage : public VObject
{ {
public: public:
using VObject::is_null; using VObject::is_null;

View File

@ -41,7 +41,7 @@ VIPS_NAMESPACE_START
* The available interpolators vary a bit with your libvips version and how it * The available interpolators vary a bit with your libvips version and how it
* was built, but will include `nearest`, `bilinear` and `bicubic`. * was built, but will include `nearest`, `bilinear` and `bicubic`.
*/ */
class VInterpolate : VObject class VInterpolate : public VObject
{ {
public: public:
/** /**