]> Creatis software - cpPlugins.git/blob - appli/bash/CreatePlugins.cxx
Cast image filter added. ROI filter modified.
[cpPlugins.git] / appli / bash / CreatePlugins.cxx
1 #include <bash/Config.h>
2
3 // -------------------------------------------------------------------------
4 typedef std::deque< std::string > TStrings;
5
6 // -------------------------------------------------------------------------
7 int main( int argc, char* argv[] )
8 {
9   // Get inputs
10   if( argc < 3 )
11   {
12     std::cerr
13       << "Usage: " << argv[ 0 ]
14       << " definitons_file library_name"
15       << std::endl;
16     return( 1 );
17
18   } // fi
19   std::string definitions_filename = argv[ 1 ];
20   std::string library_name = argv[ 2 ];
21
22   // Read inputs
23   std::string definitions_buffer;
24   if( !( cpPlugins_bash::Read( definitions_buffer, definitions_filename ) ) )
25   {
26     std::cerr
27       << argv[ 0 ]
28       <<  ": Error reading definitions file \"" << definitions_filename
29       << "\"" << std::endl;
30     return( 1 );
31
32   } // fi
33
34   // Put it in a line-by-line structure
35   TStrings definitions_lines;
36   cpPlugins_bash::Tokenize( definitions_lines, definitions_buffer, "\n" );
37
38   // Parse input file
39   TCommands commands;
40   cpPlugins_bash::Parse( commands, definitions_lines );
41
42   // Load pre-compiled definitions
43   cpPlugins_bash::LoadDefinitions( commands );
44
45   // Expand definitions
46   TCommands definitions;
47   cpPlugins_bash::ExpandDefinitions( definitions, commands );
48   definitions[ "_export_" ].clear( );
49   definitions[ "_export_" ].push_back( library_name + std::string( "_EXPORT" ) );
50
51   // Get class data
52   std::string class_name = commands[ "class" ][ 0 ];
53   std::string namespace_name = commands[ "namespace" ][ 0 ];
54   std::string superclass_name = commands[ "superclass" ][ 0 ];
55   std::stringstream header;
56   header
57     << "namespace "
58     << namespace_name << std::endl << "{" << std::endl
59     << "  class "
60     << class_name << std::endl
61     << "    : public " << superclass_name << std::endl
62     << "  {" << std::endl
63     << "  public:" << std::endl
64     << "    typedef " << class_name << " Self;" << std::endl
65     << "    typedef " << superclass_name << " Superclass;" << std::endl
66     << "    typedef itk::SmartPointer< Self > Pointer;" << std::endl
67     << "    typedef itk::SmartPointer< const Self > Pointer;" << std::endl
68     << "  protected:" << std::endl
69     << "    " << class_name << "( );" << std::endl
70     << "    virtual ~" << class_name << "( );" << std::endl
71     << "    virtual void _GenerateData( ) ITK_OVERRIDE;" << std::endl;
72
73   auto inputs = commands.find( "input" );
74   std::stringstream template_args, input_args;
75   unsigned long id = 0;
76   for(
77     auto iIt = inputs->second.begin( );
78     iIt != inputs->second.end( );
79     ++iIt, ++id
80     )
81   {
82     TStrings toks;
83     cpPlugins_bash::Tokenize( toks, *iIt, "|" );
84     if( iIt == inputs->second.begin( ) )
85     {
86       template_args << "class _T" << toks[ 2 ];
87       input_args << " _T" << toks[ 2 ] << "* input_" << toks[ 2 ];
88     }
89     else
90     {
91       template_args << ", class _T" << toks[ 2 ];
92       input_args << ", _T" << toks[ 2 ] << "* input_" << toks[ 2 ];
93     } // fi
94
95     header
96       << "    template< " << template_args.str( ) << " >" << std::endl
97       << "    inline void _GD_" << id << "( " << input_args.str( )
98       << " );" << std::endl;
99
100   } // rof
101
102   header
103     << "  private:" << std::endl
104     << "    " << class_name << "( const Self& );" << std::endl
105     << "    Self& operator=( const Self& );" << std::endl;
106
107   header
108     << "  };" << std::endl << std::endl
109     << "} // ecapseman" << std::endl;
110
111   // Source code
112   std::stringstream source;
113
114   source
115     << namespace_name << "::" << class_name << "::" << std::endl
116     << class_name << "( )" << std::endl
117     << "  : Superclass( )" << std::endl
118     << "{" << std::endl
119     << "}" << std::endl << std::endl;
120
121   source
122     << namespace_name << "::" << class_name << "::" << std::endl
123     << "~" << class_name << "( )" << std::endl
124     << "{" << std::endl
125     << "}" << std::endl << std::endl;
126
127   source
128     << "void " << namespace_name << "::" << class_name << "::" << std::endl
129     << "_GenerateData( )" << std::endl
130     << "{" << std::endl
131     << "  auto i = this->Get" << std::endl
132     << "}" << std::endl << std::endl;
133
134
135   std::cout << source.str( ) << std::endl;
136
137   return( 0 );
138 }
139
140 // eof - $RCSfile$