]> Creatis software - cpPlugins.git/blob - appli/bash/cpPlugins_createHost.cxx
...
[cpPlugins.git] / appli / bash / cpPlugins_createHost.cxx
1 #include <cstring>
2 #include <fstream>
3 #include <iostream>
4 #include <sstream>
5 #include <string>
6
7 // -------------------------------------------------------------------------
8 std::string GetFileName( const std::string& path )
9 {
10   // Extract filename
11   char* buffer = new char[ path.size( ) + 1 ];
12   std::memcpy( buffer, path.c_str( ), path.size( ) );
13   buffer[ path.size( ) ] = '\0';
14   char* tok = std::strtok( buffer, "/\\" );
15   char* ptr_fname = tok;
16   while( tok != NULL )
17   {
18     ptr_fname = tok;
19     tok = std::strtok( NULL, "/\\" );
20
21   } // elihw
22   std::string fname( ptr_fname );
23   delete [] buffer;
24
25   // Delete extension
26   std::size_t pos = fname.find_last_of( "." );
27   if( pos != std::string::npos )
28     fname = fname.substr( 0, pos );
29
30   return( fname );
31 }
32
33 // -------------------------------------------------------------------------
34 int main( int argc, char* argv[] )
35 {
36   // Open file
37   if( argc < 4 )
38   {
39     std::cerr
40       << "Usage: " << argv[ 0 ]
41       << " output_code namespace filter1 filter2 ..."
42       << std::endl;
43     return( 1 );
44
45   } // fi
46   std::ofstream output_code( argv[ 1 ] );
47   if( !output_code )
48   {
49     std::cerr
50       << "Could not open file \"" << argv[ 1 ] << "\" for writing"
51       << std::endl;
52     return( 1 );
53
54   } // fi
55
56   output_code << "#include <Pluma/Connector.hpp>" << std::endl;
57   output_code
58     << "#include <cpPlugins/Interface/ProcessObjectProvider.h>"
59     << std::endl;
60   for( int i = 3; i < argc; ++i )
61     output_code << "#include \"" << argv[ i ] << "\"" << std::endl;
62   output_code << std::endl;
63
64   std::istringstream nspaces( argv[ 2 ] );
65   std::string nspace;
66   unsigned int number_of_nspaces = 0;
67   while( std::getline( nspaces, nspace, ':' ) )
68   {
69     if( nspace != "" )
70     {
71       output_code << "namespace " << nspace << std::endl << "{" << std::endl;
72       number_of_nspaces++;
73
74     } // fi
75
76   } // elihw
77
78   for( int i = 3; i < argc; ++i )
79     output_code
80       << "CPPLUGINS_INHERIT_PROVIDER( "
81       << GetFileName( argv[ i ] ) << " );" << std::endl;
82
83   for( unsigned int i = 0; i < number_of_nspaces; ++i )
84     output_code << "}" << std::endl;
85   output_code << std::endl;
86
87
88   output_code
89     << "PLUMA_CONNECTOR" << std::endl
90     << "bool connect( pluma::Host& host )" << std::endl
91     << "{" << std::endl;
92
93   for( int i = 3; i < argc; ++i )
94     output_code
95       << "  host.add( new "
96       << argv[ 2 ] << "::"
97       << GetFileName( argv[ i ] )
98       << "Provider( ) );"
99       << std::endl;
100
101   output_code
102     << "  return( true );" << std::endl
103     << "}" << std::endl;
104
105   output_code << std::endl << "// eof - $RCSfile$" << std::endl << std::endl;
106
107   // Finish
108   output_code.close( );
109   return( 0 );
110 }
111
112 // eof - $RCSfile$