summaryrefslogtreecommitdiff
path: root/tclap-1.2.1/examples/test2.cpp
blob: 404cecdaeda6771fbce36b13dcec00c93ba828db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97


#include "tclap/CmdLine.h"
#include <iostream>
#include <string>

using namespace TCLAP;
using namespace std;

int _intTest;
float _floatTest;
bool _boolTestA;
bool _boolTestB;
bool _boolTestC;
string _stringTest;
string _utest;

void parseOptions(int argc, char** argv);

int main(int argc, char** argv)
{

	parseOptions(argc,argv);

	cout << "for float we got : " << _floatTest << endl
		 << "for int we got : " << _intTest<< endl
		 << "for string we got : " << _stringTest<< endl
		 << "for ulabeled we got : " << _utest << endl
		 << "for bool A we got : " << _boolTestA << endl
		 << "for bool B we got : " << _boolTestB << endl
		 << "for bool C we got : " << _boolTestC << endl;

}


void parseOptions(int argc, char** argv)
{
	try {

	CmdLine cmd("this is a message", ' ', "0.99" );

	//
	// Define arguments
	//

	SwitchArg btest("B","existTestB", "tests for the existence of B", false);
	cmd.add( btest );

	SwitchArg ctest("C","existTestC", "tests for the existence of C", false);
	cmd.add( ctest );

	SwitchArg atest("A","existTestA", "tests for the existence of A", false);
	cmd.add( atest );

	ValueArg<string> stest("s","stringTest","string test",true,"homer",
					       "string");
	cmd.add( stest );

	ValueArg<int> itest("i", "intTest", "integer test", true, 5, "int");
	cmd.add( itest );

	ValueArg<double> ftest("f", "floatTest", "float test", false, 3.7, "float");
	cmd.add( ftest );

	UnlabeledValueArg<string> utest("unTest","unlabeld test", true,
					                "default","string");
	cmd.add( utest );

	UnlabeledMultiArg<string> mtest("fileName", "file names", false, "string");
	cmd.add( mtest );

	//
	// Parse the command line.
	//
	cmd.parse(argc,argv);

	//
	// Set variables
	//
	_intTest = itest.getValue();
	_floatTest = ftest.getValue();
	_stringTest = stest.getValue();
	_boolTestB = btest.getValue();
	_boolTestC = ctest.getValue();
	_boolTestA = atest.getValue();
	_utest = utest.getValue();

	vector<string> v = mtest.getValue();
	for ( int i = 0; static_cast<unsigned int>(i) < v.size(); i++ )
		cout << i << "  " <<  v[i] << endl;

	} catch ( ArgException& e )
	{ cout << "ERROR: " << e.error() << " " << e.argId() << endl; }
}