Changeset 602


Ignore:
Timestamp:
Aug 29, 2006, 5:10:05 AM (15 years ago)
Author:
Peter
Message:

closes #99 documentation on CommandLine? class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/utility/CommandLine.h

    r601 r602  
    3636namespace utility {
    3737
    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>
     64int 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  **/
    4392  class CommandLine
    4493  {
     
    59108    ///
    60109    /// @param long_name string key such as "help" for --help flag
    61     /// @param telling what kind argument this option expects
     110    /// @param arg telling what kind argument this option expects
    62111    /// @param description string used in help display
    63112    ///
     
    70119    ///
    71120    /// @param short_name one character key such as 'h' for -h flag
    72     /// @param telling what kind argument this option expects
     121    /// @param arg telling what kind argument this option expects
    73122    /// @param description string used in help display
    74123    ///
     
    82131    /// @param short_name one character key such as 'h' for -h flag
    83132    /// @param long_name string key such as "help" for --help flag
    84     /// @param telling what kind argument this option expects
     133    /// @param arg telling what kind argument this option expects
    85134    /// @param description string used in help display
    86135    ///
     
    162211    /// will cause an error message and exit.
    163212    ///
    164     /// @todo doc
     213    /// @return argument value for @a parameter
    165214    ///
    166215    int value_int(const std::string& parameter) const;
Note: See TracChangeset for help on using the changeset viewer.