]> Creatis software - cpPlugins.git/blobdiff - appli/bash/cpPlugins_createHost.cxx
...
[cpPlugins.git] / appli / bash / cpPlugins_createHost.cxx
index 0914cca5a607def05c39aee0aaf771e039f6e097..d75292774d2501b52a0f5511355201f1ca7a98c1 100644 (file)
@@ -1,9 +1,36 @@
+#include <cstring>
 #include <fstream>
 #include <iostream>
+#include <sstream>
 #include <string>
 
-#include <boost/filesystem/path.hpp>
+// -------------------------------------------------------------------------
+std::string GetFileName( const std::string& path )
+{
+  // Extract filename
+  char* buffer = new char[ path.size( ) + 1 ];
+  std::memcpy( buffer, path.c_str( ), path.size( ) );
+  buffer[ path.size( ) ] = '\0';
+  char* tok = std::strtok( buffer, "/\\" );
+  char* ptr_fname = tok;
+  while( tok != NULL )
+  {
+    ptr_fname = tok;
+    tok = std::strtok( NULL, "/\\" );
+
+  } // elihw
+  std::string fname( ptr_fname );
+  delete [] buffer;
+
+  // Delete extension
+  std::size_t pos = fname.find_last_of( "." );
+  if( pos != std::string::npos )
+    fname = fname.substr( 0, pos );
+
+  return( fname );
+}
 
+// -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
 {
   // Open file
@@ -27,30 +54,56 @@ int main( int argc, char* argv[] )
   } // fi
 
   output_code << "#include <Pluma/Connector.hpp>" << std::endl;
+  output_code
+    << "#include <cpPlugins/Interface/ProcessObjectProvider.h>"
+    << std::endl;
   for( int i = 3; i < argc; ++i )
     output_code << "#include \"" << argv[ i ] << "\"" << std::endl;
+  output_code << std::endl;
+
+  std::istringstream nspaces( argv[ 2 ] );
+  std::string nspace;
+  unsigned int number_of_nspaces = 0;
+  while( std::getline( nspaces, nspace, ':' ) )
+  {
+    if( nspace != "" )
+    {
+      output_code << "namespace " << nspace << std::endl << "{" << std::endl;
+      number_of_nspaces++;
+
+    } // fi
+
+  } // elihw
+
+  for( int i = 3; i < argc; ++i )
+    output_code
+      << "CPPLUGINS_INHERIT_PROVIDER( "
+      << GetFileName( argv[ i ] ) << " );" << std::endl;
+
+  for( unsigned int i = 0; i < number_of_nspaces; ++i )
+    output_code << "}" << std::endl;
+  output_code << std::endl;
+
+
   output_code
-    << std::endl
     << "PLUMA_CONNECTOR" << std::endl
     << "bool connect( pluma::Host& host )" << std::endl
-    << "{" << std::endl
-    << "  using namespace " << argv[ 2 ] << ";" << std::endl;
+    << "{" << std::endl;
 
   for( int i = 3; i < argc; ++i )
-  {
-    boost::filesystem::path p( argv[ i ] );
     output_code
       << "  host.add( new "
-      << p.stem( ).generic_string( )
+      << argv[ 2 ] << "::"
+      << GetFileName( argv[ i ] )
       << "Provider( ) );"
       << std::endl;
 
-  } // rof
-
   output_code
     << "  return( true );" << std::endl
     << "}" << std::endl;
 
+  output_code << std::endl << "// eof - $RCSfile$" << std::endl << std::endl;
+
   // Finish
   output_code.close( );
   return( 0 );