Minor improvements in arg_parser files
authorPeter Kovacs <kpeter@inf.elte.hu>
Sun, 16 Mar 2008 01:39:19 +0100
changeset 8818444049848b
parent 87 81e138275860
child 89 e6452a49192c
Minor improvements in arg_parser files
demo/arg_parser_demo.cc
lemon/arg_parser.cc
lemon/arg_parser.h
     1.1 --- a/demo/arg_parser_demo.cc	Thu Jan 24 17:25:31 2008 +0000
     1.2 +++ b/demo/arg_parser_demo.cc	Sun Mar 16 01:39:19 2008 +0100
     1.3 @@ -20,9 +20,9 @@
     1.4  ///\file
     1.5  ///\brief Argument parser demo
     1.6  ///
     1.7 -/// This example shows how can the argument parser used.
     1.8 +/// This example shows how the argument parser can be used.
     1.9  ///
    1.10 -/// \include arg_parser.cc
    1.11 +/// \include arg_parser_demo.cc
    1.12  
    1.13  #include <lemon/arg_parser.h>
    1.14  
    1.15 @@ -35,21 +35,21 @@
    1.16    double d;
    1.17    bool b,sil;
    1.18    bool g1,g2,g3;
    1.19 -  ap.refOption("n", "an integer input", i, true)
    1.20 -    .refOption("val", "a double input", d)
    1.21 +  ap.refOption("n", "An integer input.", i, true)
    1.22 +    .refOption("val", "A double input.", d)
    1.23      .synonym("vals","val")
    1.24 -    .refOption("name", "a string input", s)
    1.25 -    .refOption("f", "a switch", b)
    1.26 +    .refOption("name", "A string input.", s)
    1.27 +    .refOption("f", "A switch.", b)
    1.28      .refOption("nohelp", "", sil)
    1.29 -    .refOption("gra","Choise A",g1)
    1.30 -    .refOption("grb","Choise B",g2)
    1.31 -    .refOption("grc","Choise C",g3)
    1.32 +    .refOption("gra","Choice A",g1)
    1.33 +    .refOption("grb","Choice B",g2)
    1.34 +    .refOption("grc","Choice C",g3)
    1.35      .optionGroup("gr","gra")
    1.36      .optionGroup("gr","grb")
    1.37      .optionGroup("gr","grc")
    1.38      .mandatoryGroup("gr")
    1.39      .onlyOneGroup("gr")
    1.40 -    .other("infile","The input file")
    1.41 +    .other("infile","The input file.")
    1.42      .other("...");
    1.43    
    1.44    ap.parse();
    1.45 @@ -61,7 +61,10 @@
    1.46    if(ap.given("name")) std::cout << "  Value of -name: " << s << std::endl;
    1.47    if(ap.given("f")) std::cout << "  -f is given\n";
    1.48    if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << sil << std::endl;
    1.49 -
    1.50 +  if(ap.given("gra")) std::cout << "  -gra is given\n";
    1.51 +  if(ap.given("grb")) std::cout << "  -grb is given\n";
    1.52 +  if(ap.given("grc")) std::cout << "  -grc is given\n";
    1.53 +                                     
    1.54    switch(ap.files().size()) {
    1.55    case 0:
    1.56      std::cout << "  No file argument was given.\n";
     2.1 --- a/lemon/arg_parser.cc	Thu Jan 24 17:25:31 2008 +0000
     2.2 +++ b/lemon/arg_parser.cc	Sun Mar 16 01:39:19 2008 +0100
     2.3 @@ -69,7 +69,6 @@
     2.4      p.help=help;
     2.5      p.type=INTEGER;
     2.6      p.mandatory=obl;
     2.7 -    p.self_delete=true;
     2.8      _opts[name]=p;
     2.9      return *this;
    2.10    }
    2.11 @@ -99,9 +98,6 @@
    2.12      p.type=BOOL;
    2.13      p.mandatory=obl;
    2.14      _opts[name]=p;
    2.15 -
    2.16 -    value = false;
    2.17 -
    2.18      return *this;
    2.19    }
    2.20  
     3.1 --- a/lemon/arg_parser.h	Thu Jan 24 17:25:31 2008 +0000
     3.2 +++ b/lemon/arg_parser.h	Sun Mar 16 01:39:19 2008 +0100
     3.3 @@ -30,17 +30,16 @@
     3.4  
     3.5  ///\ingroup misc
     3.6  ///\file
     3.7 -///\brief A tools to parse command line arguments.
     3.8 -///
     3.9 -///\author Alpar Juttner
    3.10 +///\brief A tool to parse command line arguments.
    3.11  
    3.12  namespace lemon {
    3.13  
    3.14    ///Command line arguments parser
    3.15  
    3.16    ///\ingroup misc
    3.17 -  ///Command line arguments parser
    3.18 +  ///Command line arguments parser.
    3.19    ///
    3.20 +  ///For a complete example see the \ref arg_parser_demo.cc demo file.
    3.21    class ArgParser {
    3.22      
    3.23      static void _showHelp(void *p);
    3.24 @@ -165,7 +164,7 @@
    3.25  		      const std::string &help,
    3.26  		      std::string value="", bool obl=false);
    3.27  
    3.28 -    ///\name Options with an external strorage.
    3.29 +    ///\name Options with external storage
    3.30      ///Using this functions, the value of the option will be directly written
    3.31      ///into a variable once the option appears in the command line.
    3.32  
    3.33 @@ -222,9 +221,9 @@
    3.34      ///Boundle some options into a group
    3.35  
    3.36      /// You can group some option by calling this function repeatedly for each
    3.37 -    /// option to be grupped with the same groupname.
    3.38 -    ///\param group The group name
    3.39 -    ///\param opt The option name
    3.40 +    /// option to be grouped with the same groupname.
    3.41 +    ///\param group The group name.
    3.42 +    ///\param opt The option name.
    3.43      ArgParser &optionGroup(const std::string &group,
    3.44  			   const std::string &opt);
    3.45  
    3.46 @@ -242,7 +241,7 @@
    3.47      
    3.48      ///Create synonym to an option
    3.49  
    3.50 -    ///With this function you can create a sysnonym called \c sys of the
    3.51 +    ///With this function you can create a synonym \c syn of the
    3.52      ///option \c opt.
    3.53      ArgParser &synonym(const std::string &syn,
    3.54  			   const std::string &opt);
    3.55 @@ -252,14 +251,14 @@
    3.56      ///Give help string for non-parsed arguments.
    3.57  
    3.58      ///With this function you can give help string for non-parsed arguments.
    3.59 -    ///the parameter \c name will be printed in the short usage line, while
    3.60 +    ///The parameter \c name will be printed in the short usage line, while
    3.61      ///\c help gives a more detailed description.
    3.62      ArgParser &other(const std::string &name,
    3.63  		     const std::string &help="");
    3.64      
    3.65 -    ///Non option type arguments.
    3.66 +    ///Give back the non-option type arguments.
    3.67  
    3.68 -    ///Gives back a reference to a vector consisting of the program arguments
    3.69 +    ///Give back a reference to a vector consisting of the program arguments
    3.70      ///not starting with a '-' character.
    3.71      std::vector<std::string> &files() { return _file_args; }
    3.72  
    3.73 @@ -298,9 +297,9 @@
    3.74      ///Magic type for operator[]
    3.75      
    3.76      ///This is the type of the return value of ArgParser::operator[]().
    3.77 -    ///It automatically converts to int, double, bool or std::string if
    3.78 -    ///the type of the option matches, otherwise it throws an exception.
    3.79 -    ///(i.e. it performs runtime type checking).
    3.80 +    ///It automatically converts to \c int, \c double, \c bool or
    3.81 +    ///\c std::string if the type of the option matches, otherwise it
    3.82 +    ///throws an exception (i.e. it performs runtime type checking).
    3.83      class RefType 
    3.84      {
    3.85        ArgParser &_parser;
    3.86 @@ -355,7 +354,7 @@
    3.87  
    3.88      ///Give back the value of an option
    3.89      
    3.90 -    ///Give back the value of an option
    3.91 +    ///Give back the value of an option.
    3.92      ///\sa RefType
    3.93      RefType operator[](const std::string &n)
    3.94      {