mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-12 05:35:08 -04:00
xor stuff
This commit is contained in:
parent
59b98dd182
commit
848a66aa75
@ -1,19 +1,17 @@
|
|||||||
|
|
||||||
noinst_PROGRAMS = test1 test2 test3 test4
|
noinst_PROGRAMS = test1 test2 test3 test4 test5
|
||||||
|
|
||||||
test1_SOURCES = test1.cpp
|
test1_SOURCES = test1.cpp
|
||||||
|
|
||||||
test2_SOURCES = test2.cpp
|
test2_SOURCES = test2.cpp
|
||||||
|
|
||||||
test3_SOURCES = test3.cpp
|
test3_SOURCES = test3.cpp
|
||||||
test4_SOURCES = test4.cpp
|
test4_SOURCES = test4.cpp
|
||||||
|
test5_SOURCES = test5.cpp
|
||||||
|
|
||||||
test1_LDADD = $(top_builddir)/src/libtclap.a
|
test1_LDADD = $(top_builddir)/src/libtclap.a
|
||||||
|
|
||||||
test2_LDADD = $(top_builddir)/src/libtclap.a
|
test2_LDADD = $(top_builddir)/src/libtclap.a
|
||||||
|
|
||||||
test3_LDADD = $(top_builddir)/src/libtclap.a
|
test3_LDADD = $(top_builddir)/src/libtclap.a
|
||||||
test4_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
|
INCLUDES = -I$(top_builddir)/include
|
||||||
|
|
||||||
|
77
examples/test5.cpp
Normal file
77
examples/test5.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include <tclap/CmdLine.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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<string> atest("a", "aaa", "or test a", true, "homer", "string");
|
||||||
|
ValueArg<string> btest("b", "bbb", "or test b", true, "homer", "string");
|
||||||
|
|
||||||
|
ValueArg<string> ctest("c", "ccc", "c test", true, "homer", "string");
|
||||||
|
ValueArg<string> 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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -3,6 +3,8 @@ libtclapincludedir = $(includedir)/tclap
|
|||||||
|
|
||||||
libtclapinclude_HEADERS = ArgException.h \
|
libtclapinclude_HEADERS = ArgException.h \
|
||||||
CmdLine.h \
|
CmdLine.h \
|
||||||
|
CommandLine.h \
|
||||||
|
XorHandler.h \
|
||||||
MultiArg.h \
|
MultiArg.h \
|
||||||
UnlabeledMultiArg.h \
|
UnlabeledMultiArg.h \
|
||||||
ValueArg.h \
|
ValueArg.h \
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <tclap/Visitor.h>
|
#include <tclap/Visitor.h>
|
||||||
#include <tclap/Arg.h>
|
#include <tclap/Arg.h>
|
||||||
|
#include <tclap/ValueArg.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
79
include/tclap/XorHandler.h
Normal file
79
include/tclap/XorHandler.h
Normal file
@ -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 <tclap/Arg.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace TCLAP {
|
||||||
|
|
||||||
|
class XorHandler
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of of lists of Arg's to be or'd together.
|
||||||
|
*/
|
||||||
|
vector< vector<Arg*> > _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<Arg*>& ors );
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int check( const Arg* a );
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void shortUsage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void longUsage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool contains( const Arg* a );
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user