// This file was automatically generated by: // d:\lorensen\Projects\Slicer3-net\bin\RelWithDebInfo\GenerateCLP.exe GenerateCLP.xml GenerateCLP.h // #include #include #include #include #include "tclap/CmdLine.h" #include "ModuleProcessInformation.h" #include void splitString (std::string &text, std::string &separators, std::vector &words) { int n = text.length(); int start, stop; start = text.find_first_not_of(separators); while ((start >= 0) && (start < n)) { stop = text.find_first_of(separators, start); if ((stop < 0) || (stop > n)) stop = n; words.push_back(text.substr(start, stop - start)); start = text.find_first_not_of(separators, stop+1); } } #ifdef main #ifdef WIN32 #define Slicer_EXPORT __declspec(dllexport) #else #define Slicer_EXPORT #endif extern "C" { Slicer_EXPORT char *GetXMLModuleDescription(); Slicer_EXPORT int SlicerModuleEntryPoint(int, char*[]); } #endif char *GetXMLModuleDescription() { std::string xml; xml += "\n"; xml += "\n"; xml += " utility\n"; xml += " NAMIC Command Line Processing Code Generator\n"; xml += " Generates C++ code that will parse command lines\n"; xml += " 1.0\n"; xml += " \n"; xml += " \n"; xml += " Bill Lorensen\n"; xml += "\n"; xml += " \n"; xml += " \n"; xml += " Parameters used for command line processing\n"; xml += " \n"; xml += " UseTCLAP\n"; xml += " --TCLAP\n"; xml += " Generate TCLAP Code\n"; xml += " \n"; xml += " true\n"; xml += " \n"; xml += " \n"; xml += " \n"; xml += " \n"; xml += " Input/Output parameters\n"; xml += " \n"; xml += " logoFiles\n"; xml += " \n"; xml += " --logoFiles\n"; xml += " Logo files\n"; xml += " \n"; xml += " \n"; xml += " InputXML\n"; xml += " \n"; xml += " input\n"; xml += " 0\n"; xml += " XML description of interface\n"; xml += " \n"; xml += " \n"; xml += " OutputCxx\n"; xml += " \n"; xml += " output\n"; xml += " 1\n"; xml += " C++ Code to process command line arguments\n"; xml += " \n"; xml += " \n"; xml += "\n"; xml += "\n"; xml += "\n"; char *xmlChar = new char[xml.size()+1]; memcpy (xmlChar, xml.c_str(), xml.size()); xmlChar[xml.size()] = '\0'; return xmlChar; } #define GENERATE_XML \ if (argc >= 2 && (strcmp(argv[1],"--xml") == 0)) \ { \ std::cout << GetXMLModuleDescription(); \ return EXIT_SUCCESS; \ } #define GENERATE_TCLAP \ bool UseTCLAP = false; \ std::vector logoFilesTemp; \ std::vector logoFiles; \ std::string InputXML; \ std::string OutputCxx; \ bool echoSwitch = false; \ bool xmlSwitch = false; \ std::string processInformationAddressString = "0"; \ try \ { \ TCLAP::CmdLine commandLine ( \ "Generates C++ code that will parse command lines", \ ' ', \ "1.0" ); \ \ itksys_ios::ostringstream msg; \ msg.str("");msg << "Generate TCLAP Code (default: " << UseTCLAP << ")"; \ TCLAP::SwitchArg UseTCLAPArg("", "TCLAP", msg.str(), commandLine, UseTCLAP); \ \ msg.str("");msg << "Logo files"; TCLAP::MultiArg logoFilesArg("", "logoFiles", msg.str(), 0, "std::vector", commandLine); \ \ msg.str("");msg << "XML description of interface"; TCLAP::UnlabeledValueArg InputXMLArg("InputXML", msg.str(), 1, InputXML, "std::string", commandLine); \ \ msg.str("");msg << "C++ Code to process command line arguments"; TCLAP::UnlabeledValueArg OutputCxxArg("OutputCxx", msg.str(), 1, OutputCxx, "std::string", commandLine); \ \ msg.str("");msg << "Echo the command line arguments (default: " << echoSwitch << ")"; \ TCLAP::SwitchArg echoSwitchArg("", "echo", msg.str(), commandLine, echoSwitch); \ \ msg.str("");msg << "Produce xml description of command line arguments (default: " << xmlSwitch << ")"; \ TCLAP::SwitchArg xmlSwitchArg("", "xml", msg.str(), commandLine, xmlSwitch); \ \ msg.str("");msg << "Address of a structure to store process information (progress, abort, etc.). (default: " << processInformationAddressString << ")"; \ TCLAP::ValueArg processInformationAddressStringArg("", "processinformationaddress", msg.str(), 0, processInformationAddressString, "std::string", commandLine); \ \ commandLine.parse ( argc, (char**) argv ); \ UseTCLAP = UseTCLAPArg.getValue(); \ logoFilesTemp = logoFilesArg.getValue(); \ InputXML = InputXMLArg.getValue(); \ OutputCxx = OutputCxxArg.getValue(); \ echoSwitch = echoSwitchArg.getValue(); \ xmlSwitch = xmlSwitchArg.getValue(); \ processInformationAddressString = processInformationAddressStringArg.getValue(); \ { /* Assignment for logoFiles */ \ for (unsigned int _i = 0; _i < logoFilesTemp.size(); _i++) \ { \ std::vector words; \ std::vector elements; \ words.clear(); \ std::string sep(","); \ splitString(logoFilesTemp[_i], sep, words); \ for (unsigned int _j= 0; _j < words.size(); _j++) \ { \ logoFiles.push_back((words[_j].c_str())); \ } \ } \ } \ } \ catch ( TCLAP::ArgException e ) \ { \ std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; \ return ( EXIT_FAILURE ); \ } #define GENERATE_ECHOARGS \ if (echoSwitch) \ { \ std::cout << "Command Line Arguments" << std::endl; \ std::cout << " UseTCLAP: " << UseTCLAP << std::endl; \ for (unsigned int _i= 0; _i < logoFilesTemp.size(); _i++) \ { \ std::cout << "logoFiles[" << _i << "]: "; \ std::vector words; \ words.clear(); \ std::string sep(","); \ splitString(logoFilesTemp[_i], sep, words); \ for (unsigned int _j= 0; _j < words.size(); _j++) \ { \ std::cout << words[_j] << " "; \ } \ std::cout << std::endl; \ } \ std::cout << " InputXML: " << InputXML << std::endl; \ std::cout << " OutputCxx: " << OutputCxx << std::endl; \ std::cout << " echoSwitch: " << echoSwitch << std::endl; \ std::cout << " xmlSwitch: " << xmlSwitch << std::endl; \ std::cout << " processInformationAddressString: " << processInformationAddressString << std::endl; \ } #define GENERATE_ProcessInformationAddressDecoding \ ModuleProcessInformation *CLPProcessInformation = 0; \ if (processInformationAddressString != "") \ { \ sscanf(processInformationAddressString.c_str(), "%p", &CLPProcessInformation); \ } #define PARSE_ARGS GENERATE_XML;GENERATE_TCLAP;GENERATE_ECHOARGS;GENERATE_ProcessInformationAddressDecoding;