X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=ModuleCall%2Fmain.cpp;fp=ModuleCall%2Fmain.cpp;h=70764132b90a178a46423df6b85bbecc26845b5e;hb=e7b4e2c9254e9e431f74acc92e3f0d40fc5e7ef6;hp=afb754449fac9786369d44ff34a22954addf4bb1;hpb=cd590ce5fff20d69c7060340235a35e9c2a9ef86;p=creaCLI.git diff --git a/ModuleCall/main.cpp b/ModuleCall/main.cpp index afb7544..7076413 100644 --- a/ModuleCall/main.cpp +++ b/ModuleCall/main.cpp @@ -32,23 +32,23 @@ char* getModuleDescription ( const std::string lib ) { - void* handle = dlopen( lib.c_str( ) , RTLD_NOW | RTLD_LOCAL ) ; + void* handle = dlopen ( lib.c_str ( ) , RTLD_NOW | RTLD_LOCAL ) ; if ( ! handle ) { - std::cerr << "CAN'T OPEN LIBRARY: " << dlerror( ) << '\n' ; + std::cerr << "CAN'T OPEN LIBRARY: " << dlerror ( ) << '\n' ; return NULL ; } typedef char* ( *method_t )( void ) ; // RESET ERRORS - dlerror( ) ; - method_t myMethod = ( method_t ) dlsym( handle , "GetXMLModuleDescription" ) ; - const char *dlsym_error = dlerror( ) ; + dlerror ( ) ; + method_t myMethod = ( method_t ) dlsym ( handle , "GetXMLModuleDescription" ) ; + const char *dlsym_error = dlerror ( ) ; if ( dlsym_error ) { std::cerr << "CAN'T LOAD SYMBOL 'GetXMLModuleDescription: " << dlsym_error << '\n' ; - dlclose( handle ) ; + dlclose ( handle ) ; return NULL ; } // CALLING METHOD - char* descrption = myMethod( ) ; + char* descrption = myMethod ( ) ; // CLOSING LIB //dlclose( handle ) ; @@ -58,123 +58,178 @@ char* getModuleDescription ( const std::string lib ) { } void execute ( const std::string lib , int _argc , char * _argv[] ) { - void* handle = dlopen( lib.c_str( ) , RTLD_NOW | RTLD_LOCAL ) ; + void* handle = dlopen ( lib.c_str ( ) , RTLD_NOW | RTLD_LOCAL ) ; if ( ! handle ) { - std::cerr << "CAN'T OPEN LIBRARY: " << dlerror( ) << '\n' ; + std::cerr << "CAN'T OPEN LIBRARY: " << dlerror ( ) << '\n' ; return ; } typedef int (*method_t )( int argc , char * argv[] ) ; // RESET ERRORS - dlerror( ) ; - method_t myMethod = ( method_t ) dlsym( handle , "ModuleEntryPoint" ) ; - const char *dlsym_error = dlerror( ) ; + dlerror ( ) ; + method_t myMethod = ( method_t ) dlsym ( handle , "ModuleEntryPoint" ) ; + const char *dlsym_error = dlerror ( ) ; if ( dlsym_error ) { std::cerr << "CAN'T LOAD SYMBOL 'ModuleEntryPoint' " << dlsym_error << '\n' ; - dlclose( handle ) ; + dlclose ( handle ) ; return ; } // CALLING METHOD - myMethod( _argc , _argv ) ; + myMethod ( _argc , _argv ) ; // CLOSING LIB - dlclose( handle ) ; + dlclose ( handle ) ; } /// FILE RELATED /// void saveFile ( const std::string content , const std::string file_name ) { std::ofstream myfile ; - myfile.open( file_name.c_str( ) ) ; + myfile.open ( file_name.c_str ( ) ) ; myfile << content ; - myfile.close( ) ; + myfile.close ( ) ; } std::string loadFile ( const std::string filename ) { - std::string line = std::string( "" ) ; - std::string content = std::string( "" ) ; + std::string line = std::string ( "" ) ; + std::string content = std::string ( "" ) ; std::ifstream infile ; - infile.open( filename.c_str( ) ) ; - while ( ! infile.eof( ) ) { - getline( infile , line ) ; + infile.open ( filename.c_str ( ) ) ; + while ( ! infile.eof ( ) ) { + getline ( infile , line ) ; content += line + "\n" ; - line.clear( ) ; + line.clear ( ) ; } - infile.close( ) ; + infile.close ( ) ; return content ; } std::string loadDummyBody ( ) { - return loadFile( "bbSlicerDummy.dummy_cxx" ) ; + return loadFile ( "bbSlicerDummy.dummy_cxx" ) ; } std::string loadDummyHeader ( ) { - return loadFile( "bbSlicerDummy.dummy_h" ) ; + return loadFile ( "bbSlicerDummy.dummy_h" ) ; } /// BBTK BOX CREATION /// std::string updateBoxDescription ( const ModuleDescription* module , std::string _header ) { - _header = Mthd::Aux::replace_str( _header , "_NNNNN_" , Mthd::Aux::replace_str( module->GetTitle( ) , " " , "" ) ) ; - _header = Mthd::Aux::replace_str( _header , "_AAAAA_" , module->GetContributor( ) ) ; - _header = Mthd::Aux::replace_str( _header , "_DDDDD_" , module->GetDescription( ) ) ; - _header = Mthd::Aux::replace_str( _header , "_CCCCC_" , module->GetCategory( ) ) ; + + std::string tmp_str = std::string ( "" ) ; + tmp_str = module->GetTitle ( ) ; + + tmp_str = Mthd::Aux::replace_str ( tmp_str , " " , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , "<" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , ">" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , "(" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , ")" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , "\n" , "" ) ; + _header = Mthd::Aux::replace_str ( _header , "_NNNNN_" , tmp_str ) ; + + tmp_str.clear ( ) ; + tmp_str = module->GetContributor ( ) ; + + tmp_str = Mthd::Aux::replace_str ( tmp_str , "<" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , ">" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , "(" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , ")" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , "\n" , "" ) ; + _header = Mthd::Aux::replace_str ( _header , "_AAAAA_" , tmp_str ) ; + + tmp_str.clear ( ) ; + tmp_str = module->GetDescription ( ) ; + + tmp_str = Mthd::Aux::replace_str ( tmp_str , "<" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , ">" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , "(" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , ")" , "" ) ; + tmp_str = Mthd::Aux::replace_str ( tmp_str , "\n" , "" ) ; + _header = Mthd::Aux::replace_str ( _header , "_DDDDD_" , tmp_str ) ; + + + _header = Mthd::Aux::replace_str ( _header , "_CCCCC_" , module->GetCategory ( ) ) ; return _header ; } std::string updateBoxName ( const ModuleDescription* module , std::string content ) { - std::string _new_box_name = Mthd::Aux::replace_str( module->GetTitle( ) , " " , "" ) ; - content = Mthd::Aux::replace_str( content , "Dummy" , _new_box_name ) ; + std::string _new_box_name = module->GetTitle ( ) ; + _new_box_name = Mthd::Aux::replace_str ( _new_box_name , " " , "" ) ; + _new_box_name = Mthd::Aux::replace_str ( _new_box_name , "<" , "" ) ; + _new_box_name = Mthd::Aux::replace_str ( _new_box_name , ">" , "" ) ; + _new_box_name = Mthd::Aux::replace_str ( _new_box_name , "(" , "" ) ; + _new_box_name = Mthd::Aux::replace_str ( _new_box_name , ")" , "" ) ; + _new_box_name = Mthd::Aux::replace_str ( _new_box_name , "\n" , "" ) ; + content = Mthd::Aux::replace_str ( content , "Dummy" , _new_box_name ) ; return content ; } std::string getHeaderFileName ( const ModuleDescription* module ) { - std::string name = Mthd::Aux::replace_str( module->GetTitle( ) , " " , "" ) ; + std::string name = Mthd::Aux::replace_str ( module->GetTitle ( ) , " " , "" ) ; + name = Mthd::Aux::replace_str ( name , "<" , "" ) ; + name = Mthd::Aux::replace_str ( name , ">" , "" ) ; + name = Mthd::Aux::replace_str ( name , "(" , "" ) ; + name = Mthd::Aux::replace_str ( name , ")" , "" ) ; + name = Mthd::Aux::replace_str ( name , "\n" , "" ) ; return "bbSlicer" + name + ".h" ; } std::string getBodyFileName ( const ModuleDescription* module ) { - std::string name = Mthd::Aux::replace_str( module->GetTitle( ) , " " , "" ) ; - + std::string name = module->GetTitle ( ) ; + name = Mthd::Aux::replace_str ( name , " " , "" ) ; + name = Mthd::Aux::replace_str ( name , "<" , "" ) ; + name = Mthd::Aux::replace_str ( name , ">" , "" ) ; + name = Mthd::Aux::replace_str ( name , "(" , "" ) ; + name = Mthd::Aux::replace_str ( name , ")" , "" ) ; + name = Mthd::Aux::replace_str ( name , "\n" , "" ) ; return "bbSlicer" + name + ".cxx" ; } std::string updateBoxInputs ( const ModuleDescription* module , std::string content ) { - std::string _cxx_inputs = std::string( "\n" ) ; - std::string _cxx_inputs_end = std::string( "\n" ) ; - std::string _box_name = Mthd::Aux::replace_str( module->GetTitle( ) , " " , "" ) ; + std::string _cxx_inputs = std::string ( "\n" ) ; + std::string _cxx_inputs_end = std::string ( "\n" ) ; + + std::string _box_name = module->GetTitle ( ) ; + _box_name = Mthd::Aux::replace_str ( _box_name , " " , "" ) ; + _box_name = Mthd::Aux::replace_str ( _box_name , "<" , "" ) ; + _box_name = Mthd::Aux::replace_str ( _box_name , ">" , "" ) ; + _box_name = Mthd::Aux::replace_str ( _box_name , "(" , "" ) ; + _box_name = Mthd::Aux::replace_str ( _box_name , ")" , "" ) ; + _box_name = Mthd::Aux::replace_str ( _box_name , "\n" , "" ) ; + + for ( unsigned long int i = 0 ; i < module->GetParameterGroups ( ).size ( ) ; i ++ ) { + ModuleParameterGroup pGroup = module->GetParameterGroups ( ).at ( i ) ; + for ( unsigned long int j = 0 ; j < pGroup.GetParameters ( ).size ( ) ; j ++ ) { + + ModuleParameter mPara = pGroup.GetParameters ( ).at ( j ) ; - for ( unsigned long int i = 0 ; i < module->GetParameterGroups( ).size( ) ; i ++ ) { - ModuleParameterGroup pGroup = module->GetParameterGroups( ).at( i ) ; - for ( unsigned long int j = 0 ; j < pGroup.GetParameters( ).size( ) ; j ++ ) { - ModuleParameter mPara = pGroup.GetParameters( ).at( j ) ; _cxx_inputs += "BBTK_DECLARE_INPUT ( " + - mPara.GetName( ) + " , " + - mPara.GetCPPType( ) + " );\n" ; + mPara.GetName ( ) + " , " + + mPara.GetCPPType ( ) + " );\n" ; _cxx_inputs_end += "BBTK_INPUT(" + _box_name + " , " + - mPara.GetName( ) + " , " + - "\"" + mPara.GetName( ) + "\"" + " , " + - mPara.GetCPPType( ) + ", \"\");\n" ; + mPara.GetName ( ) + " , " + + "\"" + mPara.GetName ( ) + "\"" + " , " + + mPara.GetCPPType ( ) + ", \"\");\n" ; } } - content = Mthd::Aux::replace_str( content , "_11111_" , _cxx_inputs ) ; - content = Mthd::Aux::replace_str( content , "_22222_" , _cxx_inputs_end ) ; + content = Mthd::Aux::replace_str ( content , "_11111_" , _cxx_inputs ) ; + content = Mthd::Aux::replace_str ( content , "_22222_" , _cxx_inputs_end ) ; return content ; } const int getNumberOfArguments ( const ModuleDescription* module ) { int number = 0 ; - for ( unsigned long int i = 0 ; i < module->GetParameterGroups( ).size( ) ; i ++ ) { - ModuleParameterGroup pGroup = module->GetParameterGroups( ).at( i ) ; - for ( unsigned long int j = 0 ; j < pGroup.GetParameters( ).size( ) ; j ++ ) { + for ( unsigned long int i = 0 ; i < module->GetParameterGroups ( ).size ( ) ; i ++ ) { + ModuleParameterGroup pGroup = module->GetParameterGroups ( ).at ( i ) ; + for ( unsigned long int j = 0 ; j < pGroup.GetParameters ( ).size ( ) ; j ++ ) { - ModuleParameter mPara = pGroup.GetParameters( ).at( j ) ; + ModuleParameter mPara = pGroup.GetParameters ( ).at ( j ) ; number ++ ; } } @@ -183,56 +238,58 @@ const int getNumberOfArguments ( const ModuleDescription* module ) { std::string updateProcessMethod ( const ModuleDescription* module , std::string content , std::string lib ) { int number = 0 ; - std::string arg_list = std::string( "" ) ; - for ( unsigned long int i = 0 ; i < module->GetParameterGroups( ).size( ) ; i ++ ) { - ModuleParameterGroup pGroup = module->GetParameterGroups( ).at( i ) ; - for ( unsigned long int j = 0 ; j < pGroup.GetParameters( ).size( ) ; j ++ ) { - - ModuleParameter mPara = pGroup.GetParameters( ).at( j ) ; + std::string arg_list = std::string ( "" ) ; + for ( unsigned long int i = 0 ; i < module->GetParameterGroups ( ).size ( ) ; i ++ ) { + ModuleParameterGroup pGroup = module->GetParameterGroups ( ).at ( i ) ; + for ( unsigned long int j = 0 ; j < pGroup.GetParameters ( ).size ( ) ; j ++ ) { + std::string flag = std::string ( "\"\"" ) ; + ModuleParameter mPara = pGroup.GetParameters ( ).at ( j ) ; arg_list += "Mthd::Aux::toCharArrray( " ; - if ( mPara.GetFlag( ) != "" ) { + if ( mPara.GetFlag ( ) != "" ) { arg_list += "Mthd::Aux::toString( \"" ; - arg_list += "-" + mPara.GetFlag( ) + "\" " ; + arg_list += "-" + mPara.GetFlag ( ) + "\" " ; arg_list += " ) + " ; + flag = "\" -" + mPara.GetFlag ( ) +" \"" ; - } else if ( mPara.GetLongFlag( ) != "" ) { + } else if ( mPara.GetLongFlag ( ) != "" ) { arg_list += "Mthd::Aux::toString( \"" ; - arg_list += "--" + mPara.GetLongFlag( ) + "\" " ; + arg_list += "--" + mPara.GetLongFlag ( ) + "\" " ; arg_list += " ) + " ; + flag = "\" --" + mPara.GetLongFlag ( ) +" \"" ; } - arg_list += "Mthd::Aux::toString( bbGetInput" + mPara.GetName( ) + "( ) )" ; - arg_list += " ),\n" ; + arg_list += "Mthd::Aux::replace_str ( ( Mthd::Aux::toString( bbGetInput" + mPara.GetName ( ) + "( ) )" ; + arg_list += " ) ,\"@@@@@\"," + flag + ") ),\n" ; number ++ ; } } arg_list += "_EEENNNDDD_" ; - arg_list = Mthd::Aux::replace_str( arg_list , ",\n_EEENNNDDD_" , "" ) ; - std::string _argc = "\nint _argc =" + Mthd::Aux::toString( number ) + ";\n" ; + arg_list = Mthd::Aux::replace_str ( arg_list , ",\n_EEENNNDDD_" , "" ) ; + std::string _argc = "\nint _argc =" + Mthd::Aux::toString ( number ) + ";\n" ; std::string _slib = "std::string lib = \"" + lib + "\";\n" ; std::string _argv = "char * _argv[ ] = { " + arg_list + " };\n" ; - return Mthd::Aux::replace_str( content , "_33333_" , _argc + _slib + _argv ) ; + return Mthd::Aux::replace_str ( content , "_33333_" , _argc + _slib + _argv ) ; } std::vector < std::string > getFilesByExtention ( std::string dir , std::string ext ) { std::vector < std::string > files ; - files.clear( ) ; + files.clear ( ) ; DIR *dp ; struct dirent *dirp ; - if ( ( dp = opendir( dir.c_str( ) ) ) == NULL ) { + if ( ( dp = opendir ( dir.c_str ( ) ) ) == NULL ) { std::cout << "ERROR OPENING " << dir << std::endl ; return files ; } - while ( ( dirp = readdir( dp ) ) != NULL ) { - std::string file = std::string( dirp->d_name ) ; - if ( Mthd::Aux::str_ends_with( file , ext ) ) { - files.push_back( file ) ; + while ( ( dirp = readdir ( dp ) ) != NULL ) { + std::string file = std::string ( dirp->d_name ) ; + if ( Mthd::Aux::str_ends_with ( file , ext ) ) { + files.push_back ( file ) ; } } - closedir( dp ) ; + closedir ( dp ) ; return files ; } @@ -242,53 +299,53 @@ int main ( int argc , char* argv[] ) { // char * _argv[] = { "-s 20" , "/home/riveros/Desktop/Experiments/RA1.mhd" , "/home/riveros/Desktop/Experiments/RA1-OUT-MAIN.mhd" } ; // execute( gblib , _argc , _argv ) ; - const std::string dummy_body_str = loadDummyBody( ) ; - const std::string dummy_header_str = loadDummyHeader( ) ; + const std::string dummy_body_str = loadDummyBody ( ) ; + const std::string dummy_header_str = loadDummyHeader ( ) ; const std::string directory = "/home/riveros/.slicer/Slicer4-bin/Slicer-build/lib/Slicer-4.0/cli-modules/" ; - const std::vector < std::string > files = getFilesByExtention( directory , ".so" ) ; + const std::vector < std::string > files = getFilesByExtention ( directory , ".so" ) ; - for ( unsigned int i = 0 ; i < files.size( ) ; i ++ ) { + for ( unsigned int i = 0 ; i < files.size ( ) ; i ++ ) { - std::string gblib = directory + files.at( i ) ; - std::cout << "/// " << files.at( i ) << " ///" << std::endl ; + std::string gblib = directory + files.at ( i ) ; + std::cout << "/// " << files.at ( i ) << " ///" << std::endl ; /// MODULE INFORMATION /// - std::string des = getModuleDescription( gblib ) ; + std::string des = getModuleDescription ( gblib ) ; std::cout << " getModuleDescription( gblib )...OK" << std::endl ; ModuleDescription module ; ModuleDescriptionParser parser ; - parser.Parse( des , module ) ; + parser.Parse ( des , module ) ; std::cout << " parser.Parse( des , module )...OK" << std::endl ; /// LOADING DUMMY FILES /// - std::string _body = std::string( dummy_body_str ) ; + std::string _body = std::string ( dummy_body_str ) ; std::cout << " loadDummyBody( )...OK" << std::endl ; - std::string _header = std::string( dummy_header_str ) ; + std::string _header = std::string ( dummy_header_str ) ; std::cout << " loadDummyHeader( )...OK" << std::endl ; /// SETTING HEADER FILE /// - _header = updateBoxName( &module , _header ) ; + _header = updateBoxName ( &module , _header ) ; std::cout << " updateBoxName( &module , _header )...OK" << std::endl ; - _header = updateBoxDescription( &module , _header ) ; + _header = updateBoxDescription ( &module , _header ) ; std::cout << " updateBoxDescription( &module , _header )...OK" << std::endl ; - _header = updateBoxInputs( &module , _header ) ; + _header = updateBoxInputs ( &module , _header ) ; std::cout << " updateBoxInputs( &module , _header )...OK" << std::endl ; - saveFile( _header , getHeaderFileName( &module ) ) ; + saveFile ( _header , "./GenSrc/" + getHeaderFileName ( &module ) ) ; /// SETTING BODY FILE /// - _body = updateBoxName( &module , _body ) ; + _body = updateBoxName ( &module , _body ) ; std::cout << " updateBoxName( &module , _body )...OK" << std::endl ; - _body = updateProcessMethod( &module , _body , gblib ) ; + _body = updateProcessMethod ( &module , _body , gblib ) ; std::cout << " updateProcessMethod( &module , _body , gblib )...OK" << std::endl ; - saveFile( _body , getBodyFileName( &module ) ) ; + saveFile ( _body , "./GenSrc/" + getBodyFileName ( &module ) ) ; - std::cout << "/// EO " << files.at( i ) << " ///" << std::endl << std::endl ; + std::cout << "/// EO " << files.at ( i ) << " ///" << std::endl << std::endl ; - gblib.clear( ) ; - des.clear( ) ; + gblib.clear ( ) ; + des.clear ( ) ; //while ( getchar( ) != '\n' ) ; }