From 77a0ee9bfb58af4e52cde4bc648e81be1b48c2d4 Mon Sep 17 00:00:00 2001 From: dezeroex Date: Sun, 21 Aug 2005 20:46:01 +0000 Subject: [PATCH] Introduce some more civilized ways to copy properties. See code comments for usage. git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@806 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/mlt_properties.c | 49 +++++++++++++++++++++++++++++++++++++++- src/framework/mlt_properties.h | 2 + src/framework/mlt_property.c | 27 ++++++++++++++++++++++ src/framework/mlt_property.h | 2 + 4 files changed, 79 insertions(+), 1 deletions(-) diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index b42d02a..18452dd 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -215,7 +215,7 @@ int mlt_properties_ref_count( mlt_properties this ) return 0; } -/** Allow the specification of a mirror. +/** Mirror properties set on 'this' to 'that'. */ void mlt_properties_mirror( mlt_properties this, mlt_properties that ) @@ -264,6 +264,7 @@ int mlt_properties_pass( mlt_properties this, mlt_properties that, const char *p return 0; } + /** Locate a property by name */ @@ -335,6 +336,52 @@ static mlt_property mlt_properties_fetch( mlt_properties this, const char *name return property; } +/** Pass property 'name' from 'that' to 'this' +* Who to blame: Zach +*/ + +void mlt_properties_pass_property( mlt_properties this, mlt_properties that, const char *name ) +{ + // Make sure the source property isn't null. + mlt_property that_prop = mlt_properties_find( that, name ); + if( that_prop == NULL ) + return; + + mlt_property_pass( mlt_properties_fetch( this, name ), that_prop ); +} + +/** Pass all properties from 'that' to 'this' as found in comma seperated 'list'. +* Who to blame: Zach +*/ + +int mlt_properties_pass_list( mlt_properties this, mlt_properties that, const char *list ) +{ + char *props = strdup( list ); + char *ptr = props; + char *delim = " ,\t\n"; // Any combination of spaces, commas, tabs, and newlines + int count, done = 0; + + while( !done ) + { + count = strcspn( ptr, delim ); + + if( ptr[count] == '\0' ) + done = 1; + else + ptr[count] = '\0'; // Make it a real string + + mlt_properties_pass_property( this, that, ptr ); + + ptr += count + 1; + ptr += strspn( ptr, delim ); + } + + free( props ); + + return 0; +} + + /** Set the property. */ diff --git a/src/framework/mlt_properties.h b/src/framework/mlt_properties.h index c2cbebc..12edfca 100644 --- a/src/framework/mlt_properties.h +++ b/src/framework/mlt_properties.h @@ -49,6 +49,8 @@ extern int mlt_properties_ref_count( mlt_properties self ); extern void mlt_properties_mirror( mlt_properties self, mlt_properties that ); extern int mlt_properties_inherit( mlt_properties self, mlt_properties that ); extern int mlt_properties_pass( mlt_properties self, mlt_properties that, const char *prefix ); +extern void mlt_properties_pass_property( mlt_properties this, mlt_properties that, const char *name ); +extern int mlt_properties_pass_list( mlt_properties this, mlt_properties that, const char *list ); extern int mlt_properties_set( mlt_properties self, const char *name, const char *value ); extern int mlt_properties_set_or_default( mlt_properties self, const char *name, const char *value, const char *def ); extern int mlt_properties_parse( mlt_properties self, const char *namevalue ); diff --git a/src/framework/mlt_property.c b/src/framework/mlt_property.c index 016ea91..d057f0c 100644 --- a/src/framework/mlt_property.c +++ b/src/framework/mlt_property.c @@ -310,4 +310,31 @@ void mlt_property_close( mlt_property this ) free( this ); } +/** Pass the property 'that' to 'this'. +* Who to blame: Zach +*/ +void mlt_property_pass( mlt_property this, mlt_property that ) +{ + mlt_property_clear( this ); + + this->types = that->types; + if ( this->types & mlt_prop_int64 ) + this->prop_int64 = that->prop_int64; + else if ( this->types & mlt_prop_int ) + this->prop_int = that->prop_int; + else if ( this->types & mlt_prop_double ) + this->prop_double = that->prop_double; + else if ( this->types & mlt_prop_position ) + this->prop_position = that->prop_position; + else if ( this->types & mlt_prop_string ) + { + if ( that->prop_string != NULL ) + this->prop_string = strdup( that->prop_string ); + } + else if ( this->types & mlt_prop_data && this->serialiser != NULL ) + { + this->types = mlt_prop_string; + this->prop_string = this->serialiser( this->data, this->length ); + } +} diff --git a/src/framework/mlt_property.h b/src/framework/mlt_property.h index 51a8f41..493839d 100644 --- a/src/framework/mlt_property.h +++ b/src/framework/mlt_property.h @@ -81,5 +81,7 @@ extern char *mlt_property_get_string( mlt_property self ); extern void *mlt_property_get_data( mlt_property self, int *length ); extern void mlt_property_close( mlt_property self ); +extern void mlt_property_pass( mlt_property this, mlt_property that ); + #endif -- 1.7.4.4