[Lemon-commits] Peter Kovacs: Minor improvements in arg_parser f...
Lemon HG
hg at lemon.cs.elte.hu
Mon Mar 17 12:05:32 CET 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/18444049848b
changeset: 88:18444049848b
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Sun Mar 16 01:39:19 2008 +0100
description:
Minor improvements in arg_parser files
diffstat:
3 files changed, 29 insertions(+), 31 deletions(-)
demo/arg_parser_demo.cc | 25 ++++++++++++++-----------
lemon/arg_parser.cc | 4 ----
lemon/arg_parser.h | 31 +++++++++++++++----------------
diffs (173 lines):
diff -r 81e138275860 -r 18444049848b demo/arg_parser_demo.cc
--- a/demo/arg_parser_demo.cc Thu Jan 24 17:25:31 2008 +0000
+++ b/demo/arg_parser_demo.cc Sun Mar 16 01:39:19 2008 +0100
@@ -20,9 +20,9 @@
///\file
///\brief Argument parser demo
///
-/// This example shows how can the argument parser used.
+/// This example shows how the argument parser can be used.
///
-/// \include arg_parser.cc
+/// \include arg_parser_demo.cc
#include <lemon/arg_parser.h>
@@ -35,21 +35,21 @@ int main(int argc, const char **argv)
double d;
bool b,sil;
bool g1,g2,g3;
- ap.refOption("n", "an integer input", i, true)
- .refOption("val", "a double input", d)
+ ap.refOption("n", "An integer input.", i, true)
+ .refOption("val", "A double input.", d)
.synonym("vals","val")
- .refOption("name", "a string input", s)
- .refOption("f", "a switch", b)
+ .refOption("name", "A string input.", s)
+ .refOption("f", "A switch.", b)
.refOption("nohelp", "", sil)
- .refOption("gra","Choise A",g1)
- .refOption("grb","Choise B",g2)
- .refOption("grc","Choise C",g3)
+ .refOption("gra","Choice A",g1)
+ .refOption("grb","Choice B",g2)
+ .refOption("grc","Choice C",g3)
.optionGroup("gr","gra")
.optionGroup("gr","grb")
.optionGroup("gr","grc")
.mandatoryGroup("gr")
.onlyOneGroup("gr")
- .other("infile","The input file")
+ .other("infile","The input file.")
.other("...");
ap.parse();
@@ -61,7 +61,10 @@ int main(int argc, const char **argv)
if(ap.given("name")) std::cout << " Value of -name: " << s << std::endl;
if(ap.given("f")) std::cout << " -f is given\n";
if(ap.given("nohelp")) std::cout << " Value of -nohelp: " << sil << std::endl;
-
+ if(ap.given("gra")) std::cout << " -gra is given\n";
+ if(ap.given("grb")) std::cout << " -grb is given\n";
+ if(ap.given("grc")) std::cout << " -grc is given\n";
+
switch(ap.files().size()) {
case 0:
std::cout << " No file argument was given.\n";
diff -r 81e138275860 -r 18444049848b lemon/arg_parser.cc
--- a/lemon/arg_parser.cc Thu Jan 24 17:25:31 2008 +0000
+++ b/lemon/arg_parser.cc Sun Mar 16 01:39:19 2008 +0100
@@ -69,7 +69,6 @@ namespace lemon {
p.help=help;
p.type=INTEGER;
p.mandatory=obl;
- p.self_delete=true;
_opts[name]=p;
return *this;
}
@@ -99,9 +98,6 @@ namespace lemon {
p.type=BOOL;
p.mandatory=obl;
_opts[name]=p;
-
- value = false;
-
return *this;
}
diff -r 81e138275860 -r 18444049848b lemon/arg_parser.h
--- a/lemon/arg_parser.h Thu Jan 24 17:25:31 2008 +0000
+++ b/lemon/arg_parser.h Sun Mar 16 01:39:19 2008 +0100
@@ -30,17 +30,16 @@
///\ingroup misc
///\file
-///\brief A tools to parse command line arguments.
-///
-///\author Alpar Juttner
+///\brief A tool to parse command line arguments.
namespace lemon {
///Command line arguments parser
///\ingroup misc
- ///Command line arguments parser
+ ///Command line arguments parser.
///
+ ///For a complete example see the \ref arg_parser_demo.cc demo file.
class ArgParser {
static void _showHelp(void *p);
@@ -165,7 +164,7 @@ namespace lemon {
const std::string &help,
std::string value="", bool obl=false);
- ///\name Options with an external strorage.
+ ///\name Options with external storage
///Using this functions, the value of the option will be directly written
///into a variable once the option appears in the command line.
@@ -222,9 +221,9 @@ namespace lemon {
///Boundle some options into a group
/// You can group some option by calling this function repeatedly for each
- /// option to be grupped with the same groupname.
- ///\param group The group name
- ///\param opt The option name
+ /// option to be grouped with the same groupname.
+ ///\param group The group name.
+ ///\param opt The option name.
ArgParser &optionGroup(const std::string &group,
const std::string &opt);
@@ -242,7 +241,7 @@ namespace lemon {
///Create synonym to an option
- ///With this function you can create a sysnonym called \c sys of the
+ ///With this function you can create a synonym \c syn of the
///option \c opt.
ArgParser &synonym(const std::string &syn,
const std::string &opt);
@@ -252,14 +251,14 @@ namespace lemon {
///Give help string for non-parsed arguments.
///With this function you can give help string for non-parsed arguments.
- ///the parameter \c name will be printed in the short usage line, while
+ ///The parameter \c name will be printed in the short usage line, while
///\c help gives a more detailed description.
ArgParser &other(const std::string &name,
const std::string &help="");
- ///Non option type arguments.
+ ///Give back the non-option type arguments.
- ///Gives back a reference to a vector consisting of the program arguments
+ ///Give back a reference to a vector consisting of the program arguments
///not starting with a '-' character.
std::vector<std::string> &files() { return _file_args; }
@@ -298,9 +297,9 @@ namespace lemon {
///Magic type for operator[]
///This is the type of the return value of ArgParser::operator[]().
- ///It automatically converts to int, double, bool or std::string if
- ///the type of the option matches, otherwise it throws an exception.
- ///(i.e. it performs runtime type checking).
+ ///It automatically converts to \c int, \c double, \c bool or
+ ///\c std::string if the type of the option matches, otherwise it
+ ///throws an exception (i.e. it performs runtime type checking).
class RefType
{
ArgParser &_parser;
@@ -355,7 +354,7 @@ namespace lemon {
///Give back the value of an option
- ///Give back the value of an option
+ ///Give back the value of an option.
///\sa RefType
RefType operator[](const std::string &n)
{
More information about the Lemon-commits
mailing list