mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-14 22:54:45 -04:00
added new test for CmdLine arg
This commit is contained in:
parent
389a4f87b1
commit
77592b3a83
@ -1,5 +1,5 @@
|
||||
|
||||
noinst_PROGRAMS = test1 test2 test3 test4 test5 test6 test7
|
||||
noinst_PROGRAMS = test1 test2 test3 test4 test5 test6 test7 test8
|
||||
|
||||
test1_SOURCES = test1.cpp
|
||||
test2_SOURCES = test2.cpp
|
||||
@ -8,6 +8,7 @@ test4_SOURCES = test4.cpp
|
||||
test5_SOURCES = test5.cpp
|
||||
test6_SOURCES = test6.cpp
|
||||
test7_SOURCES = test7.cpp
|
||||
test8_SOURCES = test8.cpp
|
||||
|
||||
test1_LDADD = $(top_builddir)/src/libtclap.a
|
||||
test2_LDADD = $(top_builddir)/src/libtclap.a
|
||||
@ -16,6 +17,7 @@ test4_LDADD = $(top_builddir)/src/libtclap.a
|
||||
test5_LDADD = $(top_builddir)/src/libtclap.a
|
||||
test6_LDADD = $(top_builddir)/src/libtclap.a
|
||||
test7_LDADD = $(top_builddir)/src/libtclap.a
|
||||
test8_LDADD = $(top_builddir)/src/libtclap.a
|
||||
|
||||
INCLUDES = -I$(top_builddir)/include
|
||||
|
||||
|
89
examples/test8.cpp
Normal file
89
examples/test8.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
|
||||
|
||||
#include <tclap/CmdLine.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace TCLAP;
|
||||
using namespace std;
|
||||
|
||||
bool _boolTestB;
|
||||
string _stringTest;
|
||||
string _utest;
|
||||
string _ztest;
|
||||
|
||||
void parseOptions(int argc, char** argv);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
parseOptions(argc,argv);
|
||||
|
||||
cout << "for string we got : " << _stringTest<< endl
|
||||
<< "for ulabeled one we got : " << _utest << endl
|
||||
<< "for ulabeled two we got : " << _ztest << endl
|
||||
<< "for bool B we got : " << _boolTestB << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void parseOptions(int argc, char** argv)
|
||||
{
|
||||
try {
|
||||
|
||||
CmdLine cmd("this is a message", '=', "0.99" );
|
||||
|
||||
//
|
||||
// Define arguments
|
||||
//
|
||||
|
||||
SwitchArg btest("B","existTestB", "exist Test B", false, cmd );
|
||||
|
||||
ValueArg<string> stest("s", "stringTest", "string test", true, "homer",
|
||||
"string", cmd );
|
||||
|
||||
UnlabeledValueArg<string> utest("unTest1","unlabeled test one",
|
||||
"default","string", cmd );
|
||||
|
||||
UnlabeledValueArg<string> ztest("unTest2","unlabeled test two",
|
||||
"default","string", cmd );
|
||||
|
||||
MultiArg<int> itest("i", "intTest", "multi int test", false,"int", cmd );
|
||||
|
||||
MultiArg<float> ftest("f", "floatTest", "multi float test", false,"float",
|
||||
cmd );
|
||||
|
||||
UnlabeledMultiArg<string> mtest("fileName","file names","fileNameString",
|
||||
cmd);
|
||||
//
|
||||
// Parse the command line.
|
||||
//
|
||||
cmd.parse(argc,argv);
|
||||
|
||||
|
||||
//
|
||||
// Set variables
|
||||
//
|
||||
_stringTest = stest.getValue();
|
||||
_boolTestB = btest.getValue();
|
||||
_utest = utest.getValue();
|
||||
_ztest = ztest.getValue();
|
||||
|
||||
vector<int> vi = itest.getValue();
|
||||
for ( int i = 0; (unsigned int)i < vi.size(); i++ )
|
||||
cout << "[-i] " << i << " " << vi[i] << endl;
|
||||
|
||||
vector<float> vf = ftest.getValue();
|
||||
for ( int i = 0; (unsigned int)i < vf.size(); i++ )
|
||||
cout << "[-f] " << i << " " << vf[i] << endl;
|
||||
|
||||
vector<string> v = mtest.getValue();
|
||||
for ( int i = 0; (unsigned int)i < v.size(); i++ )
|
||||
cout << "[ ] " << i << " " << v[i] << endl;
|
||||
|
||||
} catch ( ArgException e )
|
||||
{ cout << "ERROR: " << e.error() << " " << e.argId() << endl; }
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user