1 #include <bash/Config.h>
3 // -------------------------------------------------------------------------
4 typedef std::deque< std::string > TStrings;
6 // -------------------------------------------------------------------------
7 int main( int argc, char* argv[] )
13 << "Usage: " << argv[ 0 ]
14 << " definitons_file library_name"
19 std::string definitions_filename = argv[ 1 ];
20 std::string library_name = argv[ 2 ];
23 std::string definitions_buffer;
24 if( !( cpPlugins_bash::Read( definitions_buffer, definitions_filename ) ) )
28 << ": Error reading definitions file \"" << definitions_filename
34 // Put it in a line-by-line structure
35 TStrings definitions_lines;
36 cpPlugins_bash::Tokenize( definitions_lines, definitions_buffer, "\n" );
40 cpPlugins_bash::Parse( commands, definitions_lines );
42 // Load pre-compiled definitions
43 cpPlugins_bash::LoadDefinitions( commands );
46 TCommands definitions;
47 cpPlugins_bash::ExpandDefinitions( definitions, commands );
48 definitions[ "_export_" ].clear( );
49 definitions[ "_export_" ].push_back( library_name + std::string( "_EXPORT" ) );
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;
58 << namespace_name << std::endl << "{" << std::endl
60 << class_name << std::endl
61 << " : public " << superclass_name << 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;
73 auto inputs = commands.find( "input" );
74 std::stringstream template_args, input_args;
77 auto iIt = inputs->second.begin( );
78 iIt != inputs->second.end( );
83 cpPlugins_bash::Tokenize( toks, *iIt, "|" );
84 if( iIt == inputs->second.begin( ) )
86 template_args << "class _T" << toks[ 2 ];
87 input_args << " _T" << toks[ 2 ] << "* input_" << toks[ 2 ];
91 template_args << ", class _T" << toks[ 2 ];
92 input_args << ", _T" << toks[ 2 ] << "* input_" << toks[ 2 ];
96 << " template< " << template_args.str( ) << " >" << std::endl
97 << " inline void _GD_" << id << "( " << input_args.str( )
98 << " );" << std::endl;
103 << " private:" << std::endl
104 << " " << class_name << "( const Self& );" << std::endl
105 << " Self& operator=( const Self& );" << std::endl;
108 << " };" << std::endl << std::endl
109 << "} // ecapseman" << std::endl;
112 std::stringstream source;
115 << namespace_name << "::" << class_name << "::" << std::endl
116 << class_name << "( )" << std::endl
117 << " : Superclass( )" << std::endl
119 << "}" << std::endl << std::endl;
122 << namespace_name << "::" << class_name << "::" << std::endl
123 << "~" << class_name << "( )" << std::endl
125 << "}" << std::endl << std::endl;
128 << "void " << namespace_name << "::" << class_name << "::" << std::endl
129 << "_GenerateData( )" << std::endl
131 << " auto i = this->Get" << std::endl
132 << "}" << std::endl << std::endl;
135 std::cout << source.str( ) << std::endl;