From 77592b3a83c00ab58042889852924bd245ab3c50 Mon Sep 17 00:00:00 2001 From: mes5k Date: Sun, 12 Sep 2004 02:33:57 +0000 Subject: [PATCH] added new test for CmdLine arg --- examples/Makefile.am | 4 +- examples/test8.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 examples/test8.cpp diff --git a/examples/Makefile.am b/examples/Makefile.am index 9a22674..fbd28cb 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -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 diff --git a/examples/test8.cpp b/examples/test8.cpp new file mode 100644 index 0000000..dd479c5 --- /dev/null +++ b/examples/test8.cpp @@ -0,0 +1,89 @@ + + +#include +#include +#include + +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 stest("s", "stringTest", "string test", true, "homer", + "string", cmd ); + + UnlabeledValueArg utest("unTest1","unlabeled test one", + "default","string", cmd ); + + UnlabeledValueArg ztest("unTest2","unlabeled test two", + "default","string", cmd ); + + MultiArg itest("i", "intTest", "multi int test", false,"int", cmd ); + + MultiArg ftest("f", "floatTest", "multi float test", false,"float", + cmd ); + + UnlabeledMultiArg 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 vi = itest.getValue(); + for ( int i = 0; (unsigned int)i < vi.size(); i++ ) + cout << "[-i] " << i << " " << vi[i] << endl; + + vector vf = ftest.getValue(); + for ( int i = 0; (unsigned int)i < vf.size(); i++ ) + cout << "[-f] " << i << " " << vf[i] << endl; + + vector 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; } +} + + +