]> Creatis software - cpPlugins.git/blob - appli/bash/cpPlugins_createHost.cxx
Plugin system is now instalable. Dependency to boost eliminated.
[cpPlugins.git] / appli / bash / cpPlugins_createHost.cxx
1 #include <cstring>
2 #include <fstream>
3 #include <iostream>
4 #include <string>
5
6 // -------------------------------------------------------------------------
7 std::string GetFileName( const std::string& path )
8 {
9   // Extract filename
10   char* buffer = new char[ path.size( ) + 1 ];
11   std::memcpy( buffer, path.c_str( ), path.size( ) );
12   buffer[ path.size( ) ] = '\0';
13   char* tok = std::strtok( buffer, "/\\" );
14   char* ptr_fname = tok;
15   while( tok != NULL )
16   {
17     ptr_fname = tok;
18     tok = std::strtok( NULL, "/\\" );
19
20   } // elihw
21   std::string fname( ptr_fname );
22   delete [] buffer;
23
24   // Delete extension
25   std::size_t pos = fname.find_last_of( "." );
26   if( pos != std::string::npos )
27     fname = fname.substr( 0, pos );
28   
29   return( fname );
30 }
31
32 // -------------------------------------------------------------------------
33 int main( int argc, char* argv[] )
34 {
35   // Open file
36   if( argc < 4 )
37   {
38     std::cerr
39       << "Usage: " << argv[ 0 ]
40       << " output_code namespace filter1 filter2 ..."
41       << std::endl;
42     return( 1 );
43
44   } // fi
45   std::ofstream output_code( argv[ 1 ] );
46   if( !output_code )
47   {
48     std::cerr
49       << "Could not open file \"" << argv[ 1 ] << "\" for writing"
50       << std::endl;
51     return( 1 );
52
53   } // fi
54
55   output_code << "#include <Pluma/Connector.hpp>" << std::endl;
56   for( int i = 3; i < argc; ++i )
57     output_code << "#include \"" << argv[ i ] << "\"" << std::endl;
58   output_code
59     << std::endl
60     << "PLUMA_CONNECTOR" << std::endl
61     << "bool connect( pluma::Host& host )" << std::endl
62     << "{" << std::endl
63     << "  using namespace " << argv[ 2 ] << ";" << std::endl;
64
65   for( int i = 3; i < argc; ++i )
66     output_code
67       << "  host.add( new "
68       << GetFileName( argv[ i ] )
69       << "Provider( ) );"
70       << std::endl;
71
72   output_code
73     << "  return( true );" << std::endl
74     << "}" << std::endl;
75
76   // Finish
77   output_code.close( );
78   return( 0 );
79 }
80
81 // eof - $RCSfile$