]> Creatis software - cpPlugins.git/blobdiff - appli/examples/example_RGBImageToHSVChannels.cxx
Garbage collector added
[cpPlugins.git] / appli / examples / example_RGBImageToHSVChannels.cxx
index 7266800302c47aa44ebd84b1b82b587d26c3f1e3..9a2a46893fd33e684e628ef9f549e2a8337f4920 100644 (file)
@@ -18,12 +18,9 @@ void SaveImage(
   TInterface& plugins, const std::string& fname, TDataObject* image
   )
 {
-  cpPlugins::Interface::ProcessObject* writer;
-  writer =
-    dynamic_cast< TProcessObject* >(
-      plugins.CreateObject( "cpPlugins::Plugins::ImageWriter" )
-      );
-  if( writer == NULL )
+  TProcessObject::Pointer writer;
+  writer = plugins.CreateProcessObject( "cpPlugins::Plugins::ImageWriter" );
+  if( writer.IsNull( ) )
   {
     std::cerr << "No suitable writer found in plugins." << std::endl;
     return;
@@ -38,7 +35,6 @@ void SaveImage(
   std::string msg = writer->Update( );
   if( msg != "" )
     std::cerr << "ERROR: " << msg << std::endl;
-  delete writer;
 }
 
 // -------------------------------------------------------------------------
@@ -69,24 +65,18 @@ int main( int argc, char* argv[] )
   plugins.Load( plugins_file );
 
   // Create objects
-  cpPlugins::Interface::ProcessObject* reader;
-  cpPlugins::Interface::ProcessObject* filter;
-
-  reader =
-    dynamic_cast< TProcessObject* >(
-      plugins.CreateObject( "cpPlugins::Plugins::ImageReader" )
-      );
-  if( reader == NULL )
+  TProcessObject::Pointer reader;
+  TProcessObject::Pointer filter;
+
+  reader = plugins.CreateProcessObject( "cpPlugins::Plugins::ImageReader" );
+  if( reader.IsNull( ) )
   {
     std::cerr << "No suitable reader found in plugins." << std::endl;
     return( 1 );
 
   } // fi
-  filter =
-    dynamic_cast< TProcessObject* >(
-      plugins.CreateObject( "cpPlugins::Plugins::RGBImageToHSVChannelsFilter" )
-      );
-  if( filter == NULL )
+  filter = plugins.CreateProcessObject( "cpPlugins::Plugins::RGBImageToHSVChannelsFilter" );
+  if( filter.IsNull( ) )
   {
     std::cerr << "No suitable filter found in plugins." << std::endl;
     return( 1 );
@@ -109,10 +99,6 @@ int main( int argc, char* argv[] )
   SaveImage( plugins, output_saturation_image_file, filter->GetOutput( 1 ) );
   SaveImage( plugins, output_value_image_file, filter->GetOutput( 2 ) );
 
-  // Free memory
-  delete filter;
-  delete reader;
-
   return( 0 );
 }