updated changelog, news, docs, and added tests for flag and name defines

This commit is contained in:
mes5k 2011-04-16 22:31:18 +00:00
parent 122b50e26d
commit 3627d9402e
9 changed files with 962 additions and 266 deletions

1079
ChangeLog

File diff suppressed because it is too large Load Diff

2
NEWS
View File

@ -91,3 +91,5 @@ See examples/test6.cpp for details.
to using traits, which necessitates the minor version bump. Take a look to using traits, which necessitates the minor version bump. Take a look
at test11.cpp and test12.cpp for examples on using ArgTraits for extending at test11.cpp and test12.cpp for examples on using ArgTraits for extending
tclap for different types. tclap for different types.
4/16/11 - Another long break! Several minor bug and memory leak fixes.

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Templatized C++ Command Line Parser Manual</title><link rel="stylesheet" href="style.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.71.1" /></head><body><div class="book" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="id415879"></a>Templatized C++ Command Line Parser Manual</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Michael</span> <span class="othername">E</span> <span class="surname">Smoot</span></h3></div></div><div><p class="copyright">Copyright © 2003,2004,2005,2006,2009 Michael E. Smoot</p></div></div><hr /></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#BASIC_USAGE">1. Basic Usage</a></span></dt><dd><dl><dt><span class="sect1"><a href="#OVERVIEW">Overview</a></span></dt><dt><span class="sect1"><a href="#EXAMPLE">Example</a></span></dt><dd><dl><dt><span class="sect2"><a href="#LIBRARY_PROPERTIES">Library Properties</a></span></dt><dt><span class="sect2"><a href="#ARG_PROPERTIES">Common Argument Properties</a></span></dt></dl></dd><dt><span class="sect1"><a href="#COMPILING">Compiling</a></span></dt></dl></dd><dt><span class="chapter"><a href="#FUNDAMENTAL_CLASSES">2. Fundamental Classes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#COMMAND_LINE"><code class="classname">CmdLine</code></a></span></dt><dt><span class="sect1"><a href="#SWITCH_ARG"><code class="classname">SwitchArg</code></a></span></dt><dt><span class="sect1"><a href="#VALUE_ARG"><code class="classname">ValueArg</code></a></span></dt><dt><span class="sect1"><a href="#MULTI_ARG"><code class="classname">MultiArg</code></a></span></dt><dt><span class="sect1"><a href="#MULTI_SWITCH_ARG"><code class="classname">MultiSwitchArg</code></a></span></dt><dt><span class="sect1"><a href="#UNLABELED_VALUE_ARG"><code class="classname">UnlabeledValueArg</code></a></span></dt><dt><span class="sect1"><a href="#UNLABELED_MULTI_ARG"><code class="classname">UnlabeledMultiArg</code></a></span></dt></dl></dd><dt><span class="chapter"><a href="#COMPLICATIONS">3. Complications</a></span></dt><dd><dl><dt><span class="sect1"><a href="#COMBINE_SWITCHES">I want to combine multiple switches into one argument...</a></span></dt><dt><span class="sect1"><a href="#XOR">I want one argument or the other, but not both...</a></span></dt><dt><span class="sect1"><a href="#NO_FLAG">I have more arguments than single flags make sense for...</a></span></dt><dt><span class="sect1"><a href="#CONSTRAINT">I want to constrain the values allowed for a particular <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Templatized C++ Command Line Parser Manual</title><link rel="stylesheet" href="style.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.71.1" /></head><body><div class="book" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="id400620"></a>Templatized C++ Command Line Parser Manual</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Michael</span> <span class="othername">E</span> <span class="surname">Smoot</span></h3></div></div><div><p class="copyright">Copyright © 2003,2004,2005,2006,2009,2011 Michael E. Smoot</p></div></div><hr /></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#BASIC_USAGE">1. Basic Usage</a></span></dt><dd><dl><dt><span class="sect1"><a href="#OVERVIEW">Overview</a></span></dt><dt><span class="sect1"><a href="#EXAMPLE">Example</a></span></dt><dd><dl><dt><span class="sect2"><a href="#LIBRARY_PROPERTIES">Library Properties</a></span></dt><dt><span class="sect2"><a href="#ARG_PROPERTIES">Common Argument Properties</a></span></dt></dl></dd><dt><span class="sect1"><a href="#COMPILING">Compiling</a></span></dt></dl></dd><dt><span class="chapter"><a href="#FUNDAMENTAL_CLASSES">2. Fundamental Classes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#COMMAND_LINE"><code class="classname">CmdLine</code></a></span></dt><dt><span class="sect1"><a href="#SWITCH_ARG"><code class="classname">SwitchArg</code></a></span></dt><dt><span class="sect1"><a href="#VALUE_ARG"><code class="classname">ValueArg</code></a></span></dt><dt><span class="sect1"><a href="#MULTI_ARG"><code class="classname">MultiArg</code></a></span></dt><dt><span class="sect1"><a href="#MULTI_SWITCH_ARG"><code class="classname">MultiSwitchArg</code></a></span></dt><dt><span class="sect1"><a href="#UNLABELED_VALUE_ARG"><code class="classname">UnlabeledValueArg</code></a></span></dt><dt><span class="sect1"><a href="#UNLABELED_MULTI_ARG"><code class="classname">UnlabeledMultiArg</code></a></span></dt></dl></dd><dt><span class="chapter"><a href="#COMPLICATIONS">3. Complications</a></span></dt><dd><dl><dt><span class="sect1"><a href="#COMBINE_SWITCHES">I want to combine multiple switches into one argument...</a></span></dt><dt><span class="sect1"><a href="#XOR">I want one argument or the other, but not both...</a></span></dt><dt><span class="sect1"><a href="#NO_FLAG">I have more arguments than single flags make sense for...</a></span></dt><dt><span class="sect1"><a href="#CONSTRAINT">I want to constrain the values allowed for a particular
argument...</a></span></dt><dt><span class="sect1"><a href="#ARG_ADD_CMDLINE">I want the Args to add themselves to the CmdLine...</a></span></dt><dt><span class="sect1"><a href="#CHANGE_OUTPUT">I want different output than what is provided...</a></span></dt><dt><span class="sect1"><a href="#NO_HELP_VERSION">I don't want the --help and --version switches to be created automatically...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_ARGS">I want to ignore certain arguments...</a></span></dt><dt><span class="sect1"><a href="#READING_HEX_INTEGERS">I want to read hex integers as arguments...</a></span></dt><dt><span class="sect1"><a href="#USING_ARGTRAITS">I want to use different types...</a></span></dt></dl></dd><dt><span class="chapter"><a href="#NOTES">4. Notes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#DESCRIPTION_EXCEPTIONS">Type Descriptions</a></span></dt><dt><span class="sect1"><a href="#VISITORS">Visitors</a></span></dt><dt><span class="sect1"><a href="#MORE_INFO">More Information</a></span></dt></dl></dd></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="BASIC_USAGE"></a>Chapter 1. Basic Usage</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#OVERVIEW">Overview</a></span></dt><dt><span class="sect1"><a href="#EXAMPLE">Example</a></span></dt><dd><dl><dt><span class="sect2"><a href="#LIBRARY_PROPERTIES">Library Properties</a></span></dt><dt><span class="sect2"><a href="#ARG_PROPERTIES">Common Argument Properties</a></span></dt></dl></dd><dt><span class="sect1"><a href="#COMPILING">Compiling</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="OVERVIEW"></a>Overview</h2></div></div></div><p> argument...</a></span></dt><dt><span class="sect1"><a href="#ARG_ADD_CMDLINE">I want the Args to add themselves to the CmdLine...</a></span></dt><dt><span class="sect1"><a href="#CHANGE_OUTPUT">I want different output than what is provided...</a></span></dt><dt><span class="sect1"><a href="#NO_HELP_VERSION">I don't want the --help and --version switches to be created automatically...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_ARGS">I want to ignore certain arguments...</a></span></dt><dt><span class="sect1"><a href="#READING_HEX_INTEGERS">I want to read hex integers as arguments...</a></span></dt><dt><span class="sect1"><a href="#USING_ARGTRAITS">I want to use different types...</a></span></dt><dt><span class="sect1"><a href="#CHANGING_STARTSTRINGS">I want to use Windows-style flags like "/x" and "/y"...</a></span></dt></dl></dd><dt><span class="chapter"><a href="#NOTES">4. Notes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#DESCRIPTION_EXCEPTIONS">Type Descriptions</a></span></dt><dt><span class="sect1"><a href="#VISITORS">Visitors</a></span></dt><dt><span class="sect1"><a href="#MORE_INFO">More Information</a></span></dt></dl></dd></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="BASIC_USAGE"></a>Chapter 1. Basic Usage</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#OVERVIEW">Overview</a></span></dt><dt><span class="sect1"><a href="#EXAMPLE">Example</a></span></dt><dd><dl><dt><span class="sect2"><a href="#LIBRARY_PROPERTIES">Library Properties</a></span></dt><dt><span class="sect2"><a href="#ARG_PROPERTIES">Common Argument Properties</a></span></dt></dl></dd><dt><span class="sect1"><a href="#COMPILING">Compiling</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="OVERVIEW"></a>Overview</h2></div></div></div><p>
<span class="emphasis"><em>TCLAP</em></span> has a few key classes to be aware of. <span class="emphasis"><em>TCLAP</em></span> has a few key classes to be aware of.
The first is the The first is the
<code class="classname">CmdLine</code> (command line) class. This class parses <code class="classname">CmdLine</code> (command line) class. This class parses
@ -414,7 +414,7 @@ then just declare the <code class="classname">UnlabeledMultiArg</code> as type
<code class="classname">string</code> and parse the different values yourself or use <code class="classname">string</code> and parse the different values yourself or use
several <code class="classname">UnlabeledValueArg</code>s. several <code class="classname">UnlabeledValueArg</code>s.
</p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="COMPLICATIONS"></a>Chapter 3. Complications</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#COMBINE_SWITCHES">I want to combine multiple switches into one argument...</a></span></dt><dt><span class="sect1"><a href="#XOR">I want one argument or the other, but not both...</a></span></dt><dt><span class="sect1"><a href="#NO_FLAG">I have more arguments than single flags make sense for...</a></span></dt><dt><span class="sect1"><a href="#CONSTRAINT">I want to constrain the values allowed for a particular </p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="COMPLICATIONS"></a>Chapter 3. Complications</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#COMBINE_SWITCHES">I want to combine multiple switches into one argument...</a></span></dt><dt><span class="sect1"><a href="#XOR">I want one argument or the other, but not both...</a></span></dt><dt><span class="sect1"><a href="#NO_FLAG">I have more arguments than single flags make sense for...</a></span></dt><dt><span class="sect1"><a href="#CONSTRAINT">I want to constrain the values allowed for a particular
argument...</a></span></dt><dt><span class="sect1"><a href="#ARG_ADD_CMDLINE">I want the Args to add themselves to the CmdLine...</a></span></dt><dt><span class="sect1"><a href="#CHANGE_OUTPUT">I want different output than what is provided...</a></span></dt><dt><span class="sect1"><a href="#NO_HELP_VERSION">I don't want the --help and --version switches to be created automatically...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_ARGS">I want to ignore certain arguments...</a></span></dt><dt><span class="sect1"><a href="#READING_HEX_INTEGERS">I want to read hex integers as arguments...</a></span></dt><dt><span class="sect1"><a href="#USING_ARGTRAITS">I want to use different types...</a></span></dt></dl></div><p> argument...</a></span></dt><dt><span class="sect1"><a href="#ARG_ADD_CMDLINE">I want the Args to add themselves to the CmdLine...</a></span></dt><dt><span class="sect1"><a href="#CHANGE_OUTPUT">I want different output than what is provided...</a></span></dt><dt><span class="sect1"><a href="#NO_HELP_VERSION">I don't want the --help and --version switches to be created automatically...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_ARGS">I want to ignore certain arguments...</a></span></dt><dt><span class="sect1"><a href="#READING_HEX_INTEGERS">I want to read hex integers as arguments...</a></span></dt><dt><span class="sect1"><a href="#USING_ARGTRAITS">I want to use different types...</a></span></dt><dt><span class="sect1"><a href="#CHANGING_STARTSTRINGS">I want to use Windows-style flags like "/x" and "/y"...</a></span></dt></dl></div><p>
Naturally, what we have seen to this point doesn't satisfy all of Naturally, what we have seen to this point doesn't satisfy all of
our needs. our needs.
</p><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="COMBINE_SWITCHES"></a>I want to combine multiple switches into one argument...</h2></div></div></div><p> </p><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="COMBINE_SWITCHES"></a>I want to combine multiple switches into one argument...</h2></div></div></div><p>
@ -775,6 +775,37 @@ To accomplish this, add the following declaration to your file:
For complete examples see the files <code class="filename">test11.cpp</code> For complete examples see the files <code class="filename">test11.cpp</code>
and <code class="filename">test12.cpp</code> in the examples directory. and <code class="filename">test12.cpp</code> in the examples directory.
</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="CHANGING_STARTSTRINGS"></a>I want to use Windows-style flags like "/x" and "/y"...</h2></div></div></div><p>
It is traditional in Posix environments that the "-" and "--" strings are used to signify
the beginning of argument flags and long argument names. However, other environments,
namely Windows, use different strings. <span class="emphasis"><em>TCLAP</em></span> allows you to
control which strings are used with <code class="methodname">#define</code> directives. This allows
you to use different strings based on your operating environment. Here is an example:
</p><pre class="programlisting">
//
// This illustrates how to change the flag and name start strings for
// Windows, otherwise the defaults are used.
//
// Note that these defines need to happen *before* tclap is included!
//
#ifdef WINDOWS
#define TCLAP_NAMESTARTSTRING "~~"
#define TCLAP_FLAGSTARTSTRING "/"
#endif
#include "tclap/CmdLine.h"
using namespace TCLAP;
using namespace std;
int main(int argc, char** argv)
{
// Everything else is identical!
...
</pre><p>
</p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="NOTES"></a>Chapter 4. Notes</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#DESCRIPTION_EXCEPTIONS">Type Descriptions</a></span></dt><dt><span class="sect1"><a href="#VISITORS">Visitors</a></span></dt><dt><span class="sect1"><a href="#MORE_INFO">More Information</a></span></dt></dl></div><p> </p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="NOTES"></a>Chapter 4. Notes</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#DESCRIPTION_EXCEPTIONS">Type Descriptions</a></span></dt><dt><span class="sect1"><a href="#VISITORS">Visitors</a></span></dt><dt><span class="sect1"><a href="#MORE_INFO">More Information</a></span></dt></dl></div><p>
Like all good rules, there are many exceptions.... Like all good rules, there are many exceptions....
</p><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="DESCRIPTION_EXCEPTIONS"></a>Type Descriptions</h2></div></div></div><p> </p><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="DESCRIPTION_EXCEPTIONS"></a>Type Descriptions</h2></div></div></div><p>

View File

@ -30,7 +30,7 @@
<othername role='mi'>E</othername> <othername role='mi'>E</othername>
</author> </author>
<copyright> <copyright>
<year>2003,2004,2005,2006,2009</year> <year>2003,2004,2005,2006,2009,2011</year>
<holder>Michael E. Smoot</holder> <holder>Michael E. Smoot</holder>
</copyright> </copyright>
</bookinfo> </bookinfo>
@ -987,6 +987,41 @@ and <filename>test12.cpp</filename> in the examples directory.
</para> </para>
</sect1> </sect1>
<sect1 id="CHANGING_STARTSTRINGS">
<title>I want to use Windows-style flags like "/x" and "/y"...</title>
<para>
It is traditional in Posix environments that the "-" and "--" strings are used to signify
the beginning of argument flags and long argument names. However, other environments,
namely Windows, use different strings. <emphasis>TCLAP</emphasis> allows you to
control which strings are used with <methodname>#define</methodname> directives. This allows
you to use different strings based on your operating environment. Here is an example:
<programlisting>
//
// This illustrates how to change the flag and name start strings for
// Windows, otherwise the defaults are used.
//
// Note that these defines need to happen *before* tclap is included!
//
#ifdef WINDOWS
#define TCLAP_NAMESTARTSTRING "~~"
#define TCLAP_FLAGSTARTSTRING "/"
#endif
#include "tclap/CmdLine.h"
using namespace TCLAP;
using namespace std;
int main(int argc, char** argv)
{
// Everything else is identical!
...
</programlisting>
</para>
</sect1>
</chapter> </chapter>

View File

@ -1,7 +1,7 @@
noinst_PROGRAMS = test1 test2 test3 test4 test5 test6 test7 test8 test9 \ noinst_PROGRAMS = test1 test2 test3 test4 test5 test6 test7 test8 test9 \
test10 test11 test12 test13 test14 test15 test16 \ test10 test11 test12 test13 test14 test15 test16 \
test17 test18 test19 test20 test17 test18 test19 test20 test21
test1_SOURCES = test1.cpp test1_SOURCES = test1.cpp
test2_SOURCES = test2.cpp test2_SOURCES = test2.cpp
@ -23,6 +23,7 @@ test17_SOURCES = test17.cpp test17-a.cpp
test18_SOURCES = test18.cpp test18_SOURCES = test18.cpp
test19_SOURCES = test19.cpp test19_SOURCES = test19.cpp
test20_SOURCES = test20.cpp test20_SOURCES = test20.cpp
test21_SOURCES = test21.cpp
AM_CPPFLAGS = -I$(top_srcdir)/include AM_CPPFLAGS = -I$(top_srcdir)/include

52
examples/test21.cpp Normal file
View File

@ -0,0 +1,52 @@
// This illustrates how to change the flag and name start strings.
// Note that these defines need to happen *before* tclap is included!
#define TCLAP_NAMESTARTSTRING "~~"
#define TCLAP_FLAGSTARTSTRING "/"
#include <string>
#include <iostream>
#include <algorithm>
#include "tclap/CmdLine.h"
using namespace TCLAP;
using namespace std;
int main(int argc, char** argv)
{
// Wrap everything in a try block. Do this every time,
// because exceptions will be thrown for problems.
try {
// Define the command line object.
CmdLine cmd("Command description message", ' ', "0.9");
// Define a value argument and add it to the command line.
ValueArg<string> nameArg("n","name","Name to print",true,"homer","string");
cmd.add( nameArg );
// Define a switch and add it to the command line.
SwitchArg reverseSwitch("r","reverse","Print name backwards", false);
cmd.add( reverseSwitch );
// Parse the args.
cmd.parse( argc, argv );
// Get the value parsed by each arg.
string name = nameArg.getValue();
bool reverseName = reverseSwitch.getValue();
// Do what you intend too...
if ( reverseName )
{
reverse(name.begin(),name.end());
cout << "My name (spelled backwards) is: " << name << endl;
}
else
cout << "My name is: " << name << endl;
} catch (ArgException &e) // catch any exceptions
{ cerr << "error: " << e.error() << " for arg " << e.argId() << endl; }
}

View File

@ -76,7 +76,8 @@ TESTS = test1.sh \
test74.sh \ test74.sh \
test75.sh \ test75.sh \
test76.sh \ test76.sh \
test77.sh test77.sh \
test78.sh
EXTRA_DIST = $(TESTS) \ EXTRA_DIST = $(TESTS) \
test1.out \ test1.out \
@ -155,6 +156,7 @@ EXTRA_DIST = $(TESTS) \
test74.out \ test74.out \
test75.out \ test75.out \
test76.out \ test76.out \
test77.out test77.out \
test78.out
CLEANFILES = tmp.out CLEANFILES = tmp.out

1
tests/test78.out Normal file
View File

@ -0,0 +1 @@
My name (spelled backwards) is: ekim

11
tests/test78.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
# success
../examples/test21 ~~reverse /n mike > tmp.out 2>&1
if cmp -s tmp.out $srcdir/test78.out; then
exit 0
else
exit 1
fi