diff --git a/examples/Makefile.am b/examples/Makefile.am index 7287468..e3cf7a2 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,19 +1,17 @@ -noinst_PROGRAMS = test1 test2 test3 test4 +noinst_PROGRAMS = test1 test2 test3 test4 test5 test1_SOURCES = test1.cpp - test2_SOURCES = test2.cpp - test3_SOURCES = test3.cpp test4_SOURCES = test4.cpp +test5_SOURCES = test5.cpp test1_LDADD = $(top_builddir)/src/libtclap.a - test2_LDADD = $(top_builddir)/src/libtclap.a - test3_LDADD = $(top_builddir)/src/libtclap.a test4_LDADD = $(top_builddir)/src/libtclap.a +test5_LDADD = $(top_builddir)/src/libtclap.a INCLUDES = -I$(top_builddir)/include diff --git a/examples/test5.cpp b/examples/test5.cpp new file mode 100644 index 0000000..6229d83 --- /dev/null +++ b/examples/test5.cpp @@ -0,0 +1,77 @@ + + +#include +#include +#include + +using namespace TCLAP; + +string _orTest; +string _testc; +string _testd; + +void parseOptions(int argc, char** argv); + +int main(int argc, char** argv) +{ + + parseOptions(argc,argv); + + cout << "for A OR B we got : " << _orTest<< endl + << "for string C we got : " << _testc << endl + << "for string D we got : " << _testd << endl; + +} + + +void parseOptions(int argc, char** argv) +{ + try { + + CmdLine cmd("this is a message", ' ', "0.99" ); + + // + // Define arguments + // + + ValueArg atest("a", "aaa", "or test a", true, "homer", "string"); + ValueArg btest("b", "bbb", "or test b", true, "homer", "string"); + + ValueArg ctest("c", "ccc", "c test", true, "homer", "string"); + ValueArg dtest("d", "ddd", "d test", false, "homer", "string"); + + cmd.xorAdd( atest, btest ); + cmd.add( ctest ); + cmd.add( dtest ); + + // + // Parse the command line. + // + cmd.parse(argc,argv); + + + // + // Set variables + // + + if ( atest.isSet() ) + _orTest = atest.getValue(); + else if ( btest.isSet() ) + _orTest = btest.getValue(); + else + { + cout << "badness" << endl; + exit(1); + } + + + _testc = ctest.getValue(); + _testd = dtest.getValue(); + + + } catch ( ArgException e ) + { cout << "ERROR: " << e.error() << " " << e.argId() << endl; } +} + + + diff --git a/include/tclap/Makefile.am b/include/tclap/Makefile.am index b8c4d92..da66a2a 100644 --- a/include/tclap/Makefile.am +++ b/include/tclap/Makefile.am @@ -3,6 +3,8 @@ libtclapincludedir = $(includedir)/tclap libtclapinclude_HEADERS = ArgException.h \ CmdLine.h \ + CommandLine.h \ + XorHandler.h \ MultiArg.h \ UnlabeledMultiArg.h \ ValueArg.h \ diff --git a/include/tclap/UnlabeledValueArg.h b/include/tclap/UnlabeledValueArg.h index bba1c3b..478d6ff 100644 --- a/include/tclap/UnlabeledValueArg.h +++ b/include/tclap/UnlabeledValueArg.h @@ -28,6 +28,7 @@ #include #include #include +#include using namespace std; diff --git a/include/tclap/XorHandler.h b/include/tclap/XorHandler.h new file mode 100644 index 0000000..1c9d2da --- /dev/null +++ b/include/tclap/XorHandler.h @@ -0,0 +1,79 @@ + +/****************************************************************************** + * + * file: XorHandler.h + * + * Copyright (c) 2003, Michael E. Smoot . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef __ORHANDLER_HH__ +#define __ORHANDLER_HH__ + +#include +#include +#include + +using namespace std; + +namespace TCLAP { + +class XorHandler +{ + protected: + + /** + * The list of of lists of Arg's to be or'd together. + */ + vector< vector > _orList; + + public: + + /** + * Constructor. Does nothing. + */ + XorHandler( ); + + /** + * Add a list of Arg*'s that will be orred together. + * \param ors - list of Arg* that will be xor'd. + */ + void add( vector& ors ); + + /** + * + */ + int check( const Arg* a ); + + /** + * + */ + void shortUsage(); + + /** + * + */ + void longUsage(); + + /** + * + */ + bool contains( const Arg* a ); + +}; + +} + +#endif