-#include <iostream>
-#include <sstream>
-#include <vector>
-#include <appli/bash/Utility.h>
-
-// -------------------------------------------------------------------------
-void Output(
- std::stringstream& out,
- const std::vector< std::string >& defs
- )
-{
- if( defs.size( ) > 0 )
- {
- for( unsigned int k = 0; k < defs.size( ); ++k )
- {
- std::string cast_str = "dynamic_cast< ";
- cast_str += defs[ k ];
- cast_str += "* >( _obj )";
- if( k == 0 )
- out
- << " if( " << cast_str << " != NULL ) \\" << std::endl
- << " this->_fun( " << cast_str << " )";
- else
- out
- << " else if( " << cast_str << " != NULL ) \\" << std::endl
- << " this->_fun( " << cast_str << " )";
- if( k < defs.size( ) - 1 )
- out << "; \\";
- out << std::endl;
-
- } // rof
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-void Dims(
- std::stringstream& out,
- const std::string& macro,
- const std::vector< std::string >& dims
- )
-{
- for( unsigned int k = 0; k < dims.size( ); ++k )
- {
- if( k == 0 )
- out
- << " " << macro << dims[ k ] << " )";
- else
- out
- << " else " << macro << dims[ k ] << " )";
- if( k < dims.size( ) - 1 )
- out << "; \\";
- out << std::endl;
-
- } // rof
-}
-
-// -------------------------------------------------------------------------
-int main( int argc, char* argv[] )
-{
- // Get parameters from input
- if( argc < 2 )
- {
- std::cerr
- << "Usage: " << argv[ 0 ]
- << " output_filename" << std::endl;
- return( 1 );
-
- } // fi
- std::string output_filename = argv[ 1 ];
- std::stringstream out;
-
- out << "#ifndef __cpPlugins__DEMANGLEBASE_MACROS__h__" << std::endl;
- out << "#define __cpPlugins__DEMANGLEBASE_MACROS__h__" << std::endl << std::endl;
-
- // Get base types
- std::vector< std::string > int_types, real_types, process_dims, visual_dims;
- cpPlugins_bash::Tokenize( int_types, "@cpPlugins_INTEGER_TYPES@", ";" );
- cpPlugins_bash::Tokenize( real_types, "@cpPlugins_REAL_TYPES@", ";" );
- cpPlugins_bash::Tokenize( process_dims, "@cpPlugins_PROCESS_DIMENSIONS@", ";" );
- cpPlugins_bash::Tokenize( visual_dims, "@cpPlugins_VISUAL_DIMENSIONS@", ";" );
-
- // Process image base
- std::string op = "itk::ImageBase< ";
- std::string cl = " >";
- std::vector< std::string > process_dims_tokens;
- for( auto i = process_dims.begin( ); i != process_dims.end( ); ++i )
- process_dims_tokens.push_back( op + *i + cl );
-
- out
- << "#define cpPlugins_Demangle_ImageProcessDims( _obj, _fun ) \\"
- << std::endl;
- Output( out, process_dims_tokens );
- out << std::endl;
-
- // Visual image base
- std::vector< std::string > visual_dims_tokens;
- for( auto i = visual_dims.begin( ); i != visual_dims.end( ); ++i )
- visual_dims_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageVisualDims( _obj, _fun ) \\"
- << std::endl;
- Output( out, visual_dims_tokens );
- out << std::endl;
-
- // Integer types
- op = "itk::Image< ";
- cl = ", _dim >";
- std::vector< std::string > int_tokens;
- for( auto i = int_types.begin( ); i != int_types.end( ); ++i )
- {
- int_tokens.push_back( op + *i + cl );
- int_tokens.push_back( op + std::string( "unsigned " ) + *i + cl );
-
- } // rof
- out
- << "#define cpPlugins_Demangle_ImageIntegers( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, int_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImageIntegers_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_ImageIntegers( _obj, _fun, ", process_dims );
- out << std::endl;
-
- // Real types
- std::vector< std::string > real_tokens;
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- real_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageReals( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, real_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImageReals_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_ImageReals( _obj, _fun, ", process_dims );
- out << std::endl;
-
- // Complex types
- op = "itk::Image< std::complex< ";
- cl = " >, _dim >";
- std::vector< std::string > complex_tokens;
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- complex_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageComplexes( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, complex_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImageComplexes_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_ImageComplexes( _obj, _fun, ", process_dims );
- out << std::endl;
-
- // Color types
- op = "itk::Image< itk::RGBPixel< ";
- cl = " >, _dim >";
- std::vector< std::string > color_tokens;
- for( auto i = int_types.begin( ); i != int_types.end( ); ++i )
- color_tokens.push_back( op + *i + cl );
- for( auto i = int_types.begin( ); i != int_types.end( ); ++i )
- color_tokens.push_back( op + std::string( "unsigned " ) + *i + cl );
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- color_tokens.push_back( op + *i + cl );
- op = "itk::Image< itk::RGBAPixel< ";
- for( auto i = int_types.begin( ); i != int_types.end( ); ++i )
- color_tokens.push_back( op + *i + cl );
- for( auto i = int_types.begin( ); i != int_types.end( ); ++i )
- color_tokens.push_back( op + std::string( "unsigned " ) + *i + cl );
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- color_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageColors( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, color_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImageColors_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_ImageColors( _obj, _fun, ", process_dims );
- out << std::endl;
-
- // FixedArray types
- op = "itk::Image< itk::FixedArray< ";
- cl = ", _dim >, _dim >";
- std::vector< std::string > fixedarray_tokens;
- for( auto i = int_types.begin( ); i != int_types.end( ); ++i )
- fixedarray_tokens.push_back( op + *i + cl );
- for( auto i = int_types.begin( ); i != int_types.end( ); ++i )
- fixedarray_tokens.push_back( op + "unsigned " + *i + cl );
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- fixedarray_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageFixedArrays( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, fixedarray_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImageFixedArrays_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_ImageFixedArrays( _obj, _fun, ", process_dims );
- out << std::endl;
-
- // Covariant types
- op = "itk::Image< itk::CovariantVector< ";
- cl = ", _dim >, _dim >";
- std::vector< std::string > cov_tokens;
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- cov_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageCovariantVectors( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, cov_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImageCovariantVectors_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims(
- out, "cpPlugins_Demangle_ImageCovariantVectors( _obj, _fun, ", process_dims
- );
- out << std::endl;
-
- // Vector types
- op = "itk::Image< itk::Vector< ";
- cl = ", _dim >, _dim >";
- std::vector< std::string > vec_tokens;
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- vec_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageVectors( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, vec_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImageVectors_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_ImageVectors( _obj, _fun, ", process_dims );
- out << std::endl;
-
- // Point types
- op = "itk::Image< itk::Point< ";
- cl = ", _dim >, _dim >";
- std::vector< std::string > pnt_tokens;
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- pnt_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImagePoints( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, pnt_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImagePoints_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_ImagePoints( _obj, _fun, ", process_dims );
- out << std::endl;
-
- // 2nd rank types
- op = "itk::Image< itk::SymmetricSecondRankTensor< ";
- cl = ", _dim >, _dim >";
- std::vector< std::string > sym_tokens;
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- sym_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageSymmetricSecondRankTensors( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, sym_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImageSymmetricSecondRankTensors_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_ImageSymmetricSecondRankTensors( _obj, _fun, ", process_dims );
- out << std::endl;
-
- // Diffusion tensors
- op = "itk::Image< itk::DiffusionTensor3D< ";
- cl = " >, 3 >";
- std::vector< std::string > diff_tokens;
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- diff_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageDiffusionTensors3D( _obj, _fun ) \\"
- << std::endl;
- Output( out, diff_tokens );
- out << std::endl;
-
- // Matrix types
- op = "itk::Image< itk::Matrix< ";
- cl = ", _dim, _dim >, _dim >";
- std::vector< std::string > mat_tokens;
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- mat_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageMatrices( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, mat_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_ImageMatrices_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_ImageMatrices( _obj, _fun, ", process_dims );
- out << std::endl;
-
- // Offset types
- op = "itk::Image< itk::Offset< ";
- cl = " > >";
- std::vector< std::string > off_tokens;
- for( auto i = process_dims.begin( ); i != process_dims.end( ); ++i )
- off_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_ImageOffsets( _obj, _fun ) \\"
- << std::endl;
- Output( out, off_tokens );
- out << std::endl;
-
- // Real types
- op = "itk::Mesh< ";
- cl = ", _dim >";
- std::vector< std::string > mesh_tokens;
- for( auto i = real_types.begin( ); i != real_types.end( ); ++i )
- mesh_tokens.push_back( op + *i + cl );
- out
- << "#define cpPlugins_Demangle_Meshes( _obj, _fun, _dim ) \\"
- << std::endl;
- Output( out, mesh_tokens );
- out << std::endl;
- out
- << "#define cpPlugins_Demangle_Meshes_Dims( _obj, _fun ) \\"
- << std::endl;
- Dims( out, "cpPlugins_Demangle_Meshes( _obj, _fun, ", visual_dims );
- out << std::endl;
-
- out << std::endl;
- out << "#endif // __cpPlugins__DEMANGLEBASE_MACROS__h__" << std::endl << std::endl;
-
- if( !( cpPlugins_bash::Write( out.str( ), output_filename ) ) )
- {
- std::cerr << "Error writing header" << std::endl;
- return( 1 );
-
- } // fi
- return( 0 );
-}
-
-// eof - $RCSfile$