From 4fdebb8f8dda879531b39139969016e446c6abb5 Mon Sep 17 00:00:00 2001 From: lilo_booter Date: Mon, 16 Aug 2004 06:48:51 +0000 Subject: [PATCH] Object validity checks git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@366 d19143bc-622f-0410-bfdd-b5b2a6649095 --- mlt++/README | 3 +++ mlt++/src/MltProperties.cpp | 5 +++++ mlt++/src/MltProperties.h | 2 ++ mlt++/test/play.cpp | 7 ++++++- 4 files changed, 16 insertions(+), 1 deletions(-) diff --git a/mlt++/README b/mlt++/README index 26cc441..f4e8bed 100644 --- a/mlt++/README +++ b/mlt++/README @@ -82,6 +82,9 @@ SPECIAL CASES This excludes the use of the RTTI to determine the real type of the object - this can only be done by parsing the objects properties. + Non-NULL objects may be invalid - always use the is_valid method to + check validity before use. + LIMITATIONS ----------- diff --git a/mlt++/src/MltProperties.cpp b/mlt++/src/MltProperties.cpp index 72dcba3..9558fcc 100644 --- a/mlt++/src/MltProperties.cpp +++ b/mlt++/src/MltProperties.cpp @@ -46,6 +46,11 @@ PropertiesInstance::~PropertiesInstance( ) mlt_properties_close( instance ); } +bool Properties::is_valid( ) +{ + return get_properties( ) != NULL; +} + int Properties::count( ) { return mlt_properties_count( get_properties( ) ); diff --git a/mlt++/src/MltProperties.h b/mlt++/src/MltProperties.h index c9429c1..51d0952 100644 --- a/mlt++/src/MltProperties.h +++ b/mlt++/src/MltProperties.h @@ -32,6 +32,7 @@ namespace Mlt { public: virtual mlt_properties get_properties( ) = 0; + bool is_valid( ); int count( ); char *get( char *name ); int get_int( char *name ); @@ -41,6 +42,7 @@ namespace Mlt int set( char *name, int value ); int set( char *name, double value ); int set( char *name, void *value, int size, mlt_destructor destroy = NULL, mlt_serialiser serial = NULL ); + }; /** Instance class. diff --git a/mlt++/test/play.cpp b/mlt++/test/play.cpp index 5920a4b..1707d05 100644 --- a/mlt++/test/play.cpp +++ b/mlt++/test/play.cpp @@ -11,9 +11,14 @@ using namespace Mlt; int main( int argc, char **argv ) { Factory::init( NULL ); + Producer *producer = Factory::producer( argv[ 1 ] ); + if ( !producer->is_valid( ) ) + { + cerr << "Can't construct producer for " << argv[ 1 ] << endl; + return 0; + } Consumer *consumer = Factory::consumer( "sdl" ); consumer->set( "rescale", "none" ); - Producer *producer = Factory::producer( argv[ 1 ] ); Filter *filter = Factory::filter( "greyscale" ); filter->connect( *producer ); consumer->connect( *filter ); -- 1.7.4.4