$search
00001 00009 /***************************************************************************** 00010 ** Includes 00011 *****************************************************************************/ 00012 00013 #include <iostream> 00014 #include <string> 00015 #include "../../include/ecl/command_line.hpp" 00016 00017 /***************************************************************************** 00018 ** Using 00019 *****************************************************************************/ 00020 00021 using std::cout; 00022 using std::cerr; 00023 using std::endl; 00024 using std::string; 00025 using ecl::CmdLine; 00026 using ecl::SwitchArg; 00027 using ecl::ValueArg; 00028 using ecl::UnlabeledValueArg; 00029 using ecl::ArgException; 00030 00031 /***************************************************************************** 00032 ** Main 00033 *****************************************************************************/ 00034 00035 int main(int argc, char** argv) { 00036 00037 int test(0); 00038 bool debug(false); 00039 string nolabel; 00040 00041 std::cout << std::endl; 00042 std::cout << "***********************************************************" << std::endl; 00043 std::cout << " Command Line Parsing" << std::endl; 00044 std::cout << "***********************************************************" << std::endl; 00045 std::cout << std::endl; 00046 00047 try { 00048 // Supply a program description, argument separator (optional) and version number (optional). 00049 CmdLine cmd("This is a test program to test the command line parsing facilities provided by TCLAP."); 00050 // CmdLine cmd("This is a test program to test the command line parsing facilities provided by TCLAP.", ' ', "0.01"); 00051 00052 // Add a boolean (flag, name, description), sets the default state to false unless it is found on the command line. 00053 SwitchArg debugSwitch("d","debug","Enable debugging."); 00054 // Add a boolean (flag, name, description, default) 00055 // SwitchArg debug("d","debug","Enable debugging.", false); 00056 cmd.add(debugSwitch); 00057 00058 // Add an int (flag,name,description,compulsory flag?,default value,help description of the type") 00059 ValueArg<int> intArg("i","integer","An integer argument for testing.",false,5,"integer"); 00060 cmd.add(intArg); 00061 00062 // (one word argument name, long description, req/not req, default value, type) 00063 UnlabeledValueArg<string> nolabelArg( "echo", "An unlabeled argument", false, "dude", "string" ); 00064 cmd.add(nolabelArg); 00065 00066 /********************* 00067 ** Parse 00068 **********************/ 00069 cmd.parse(argc,argv); 00070 debug = debugSwitch.getValue(); 00071 test = intArg.getValue(); 00072 nolabel = nolabelArg.getValue(); 00073 00074 } catch ( ArgException &e ) 00075 { 00076 cerr << "error: " << e.error() << " for arg " << e.argId() << endl; 00077 } 00078 00079 cout << "Test Integer: " << test << endl; 00080 if ( debug ) { 00081 cout << "Debug Switch (bool): true" << endl; 00082 } else { 00083 cout << "Debug Switch (bool): false" << endl; 00084 } 00085 std::cout << "Echoing unlabelled arg: " << nolabel << std::endl; 00086 std::cout << std::endl; 00087 00088 return 0; 00089 } 00090 00091 00092