added vips_object_set_from_string()

This commit is contained in:
John Cupitt 2014-04-23 12:57:49 +01:00
parent 5baf0dfdcd
commit c03d9440cb
4 changed files with 49 additions and 12 deletions

View File

@ -24,6 +24,7 @@
- add ".vips" as an alternative suffix for vips files
- added vips_tiffload_buffer()
- added vips_foreign_load_buffer(), vips_foreign_save_buffer()
- added vips_object_set_from_string()
6/3/14 started 7.38.6
- grey ramp minimum was wrong

15
TODO
View File

@ -6,22 +6,19 @@
- set options from suffix
no. 2 needs something like:
use vips__find_rightmost_brackets() and vips_object_set_from_string()
vips_object_set_options_from_string( object, "[a=12,b=13]" );
- use vips_object_set_from_string() for vips_foreign_load_options() and
friends
perhaps with the outermost brackets optional?
maybe vips_object_set_from_string()?
read object.c and see how close we are to this model now
- clean up foreign.c, there seems to be some cruft
- use this for dzsave_buffer
- clean up foreign.c, there seems to be some cruft
- vips_filename_suffix_match() is used by
vips_foreign_load_new_from_foreign_sub(), but it splits on ':' ... argh!

View File

@ -587,6 +587,7 @@ VipsObject *vips_object_new( GType type,
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 );
VipsObject *vips_object_new_from_string( VipsObjectClass *object_class,
const char *p );

View File

@ -2054,7 +2054,7 @@ vips_object_set_valist( VipsObject *object, va_list ap )
* Input arguments are given in-line, output arguments are given as pointers
* to where the output value should be written.
*
* See also: vips_object_set_valist().
* See also: vips_object_set_valist(), vips_object_set_from_string().
*
* Returns: 0 on success, -1 on error
*/
@ -2072,7 +2072,7 @@ vips_object_set( VipsObject *object, ... )
}
/* Set object args from a string. @p should be the initial left bracket and
* there should be no tokens after the matching right bracket.
* there should be no tokens after the matching right bracket. @p is modified.
*/
static int
vips_object_set_args( VipsObject *object, const char *p )
@ -2154,6 +2154,44 @@ vips_object_set_args( VipsObject *object, const char *p )
return( 0 );
}
/**
* vips_object_set_from_string:
* @object: object to set arguments on
* @string: arguments as a string
*
* Set object arguments from a string. The string can be something like
* "a=12", or "a = 12, b = 13", or "fred". The string can optionally be
* enclosed in brackets.
*
* You'd typically use this between creating the object and building it.
*
* See also: vips_object_set(), vips_object_build(),
* vips_cache_operation_buildp().
*
* Returns: 0 on success, -1 on error
*/
int
vips_object_set_from_string( VipsObject *object, const char *string )
{
const char *q;
VipsToken token;
char buffer[VIPS_PATH_MAX];
char str[VIPS_PATH_MAX];
vips_strncpy( buffer, string, VIPS_PATH_MAX );
/* Does string start with a bracket? If it doesn't, enclose the whole
* thing in [].
*/
if( !(q = vips__token_get( buffer, &token, str, VIPS_PATH_MAX )) !!
token != VIPS_TOKEN_LEFT )
vips_snprintf( buffer, VIPS_PATH_MAX, "[%s]", string );
else
vips_strncpy( buffer, string, VIPS_PATH_MAX );
return( vips_object_set_args( object, buffer ) );
}
VipsObject *
vips_object_new_from_string( VipsObjectClass *object_class, const char *p )
{
@ -2177,7 +2215,7 @@ vips_object_new_from_string( VipsObjectClass *object_class, const char *p )
/* More tokens there? Set any other args.
*/
if( q &&
vips_object_set_args( object, q ) ) {
vips_object_set_from_string( object, q ) ) {
g_object_unref( object );
return( NULL );
}