Changeset 602
- Timestamp:
- Aug 29, 2006, 5:10:05 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/c++_tools/utility/CommandLine.h
r601 r602 36 36 namespace utility { 37 37 38 /// 39 /// @brief Class for parsing the command line. 40 /// 41 /// @see Option 42 /// 38 /** 39 @brief Class for parsing the command line. 40 41 Provides parsing and storage of command line arguments (argc, 42 argv). To use this class first add a set of valid parameters 43 using the add_parameter() function. Each parameter is associated 44 to a one-character flag and/or a longer string flag. The longer 45 flag expects to be preceded by '--' as e.g. '--help' for 46 help. The shorter flag expects to be preceded by '-' as 47 e.g. '-h', and can also be concatenated as e.g. "program -vf" is 48 equivalent to "program -v -f". Associated to each parameter is an 49 attribute telling what type of argument is expected for the 50 parameter. Several types of arguments are supported: no argument, 51 string argument, int argument, double argument. The argument 52 value for all found parameters are set during parsing, which 53 supports both gnu-style "--support-gnu=value", POSIX-like 54 "--support-posix value", as well as shorter "-s value". The 55 argument of an parameter is retrived by the value() function or 56 its sibblings for different types. By using the set_help() 57 function help will be displayed when flag (default is '-h' and 58 '--help') is found in parsing. 59 60 Here is a small code example: 61 @code 62 #include <c++_tools/utility/CommandLine.h> 63 #include <iostream> 64 int main(const int argc,const char* argv[]) 65 { 66 theplu::utility::CommandLine cmd; 67 cmd.set_general_description("This is just an example program"); 68 cmd.add_parameter('n', utility::Option::int_arg, 69 "example of parameter taking an integer"); 70 cmd.add_parameter('t', "target", utility::Option::string_arg); 71 cmd.add_parameter("version",utility::Option::no_arg, 72 "output version infomation and exit"); 73 cmd.set_help(); 74 cmd.parse(argc, argv); 75 if (cmd.present("version")) 76 std::cout << "example 1.0" << std::endl; 77 if (cmd.present("target")) 78 std::cout << "using target: " << target << std::endl; 79 if (cmd.present('n')){ 80 int n=cmd.value('n'); 81 for (size_t i=0; i<n; ++i) 82 std::cout << "Hello World\n"; 83 std::cout << endl; 84 } 85 return 0; 86 } 87 @endcode 88 89 @see Option 90 91 **/ 43 92 class CommandLine 44 93 { … … 59 108 /// 60 109 /// @param long_name string key such as "help" for --help flag 61 /// @param telling what kind argument this option expects110 /// @param arg telling what kind argument this option expects 62 111 /// @param description string used in help display 63 112 /// … … 70 119 /// 71 120 /// @param short_name one character key such as 'h' for -h flag 72 /// @param telling what kind argument this option expects121 /// @param arg telling what kind argument this option expects 73 122 /// @param description string used in help display 74 123 /// … … 82 131 /// @param short_name one character key such as 'h' for -h flag 83 132 /// @param long_name string key such as "help" for --help flag 84 /// @param telling what kind argument this option expects133 /// @param arg telling what kind argument this option expects 85 134 /// @param description string used in help display 86 135 /// … … 162 211 /// will cause an error message and exit. 163 212 /// 164 /// @ todo doc213 /// @return argument value for @a parameter 165 214 /// 166 215 int value_int(const std::string& parameter) const;
Note: See TracChangeset
for help on using the changeset viewer.