summaryrefslogtreecommitdiff
path: root/tclap-1.2.1/examples/test5.cpp
blob: ebc5e4ade2cc1a8e659d1bb8b4e3a9016c6f4dcb (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118


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

using namespace TCLAP;
using namespace std;

string _orTest;
string _orTest2;
string _testc;
bool _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
		 << "for E or F or G we got: " << _orTest2 << 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");
	cmd.xorAdd( atest, btest );

	ValueArg<string> ctest("c", "ccc", "c test", true, "homer", "string");
	cmd.add( ctest );

	SwitchArg dtest("", "ddd", "d test", false);
	cmd.add( dtest );

	ValueArg<string> etest("", "eee", "e test", false, "homer", "string");
	ValueArg<string> ftest("", "fff", "f test", false, "homer", "string");
	ValueArg<string> gtest("g", "ggg", "g test", false, "homer", "string");
	vector<Arg*> xorlist;
	xorlist.push_back(&etest);
	xorlist.push_back(&ftest);
	xorlist.push_back(&gtest);
	cmd.xorAdd( xorlist );

	MultiArg<string> itest("i", "iii", "or test i", true, "string");
	MultiArg<string> jtest("j", "jjj", "or test j", true, "string");
	cmd.xorAdd( itest, jtest );

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


	//
	// Set variables
	//

	if ( atest.isSet() )
		_orTest = atest.getValue();
	else if ( btest.isSet() )
		_orTest = btest.getValue();
	else
		// Should never get here because TCLAP will note that one of the
		// required args above has not been set.
		throw("very bad things...");

	_testc = ctest.getValue();
	_testd = dtest.getValue();

	if ( etest.isSet() )
		_orTest2 = etest.getValue();
	else if ( ftest.isSet() )
		_orTest2 = ftest.getValue();
	else if ( gtest.isSet() )
		_orTest2 = gtest.getValue();
	else
		throw("still bad");

    if ( jtest.isSet() )
    {
        cout << "for J:" << endl;
        vector<string> v = jtest.getValue();
        for ( int z = 0; static_cast<unsigned int>(z) < v.size(); z++ )
            cout << " " << z << "  " << v[z] << endl;
    }
    else if ( itest.isSet() )
    {
        cout << "for I:" << endl;
        vector<string> v = itest.getValue();
        for ( int z = 0; static_cast<unsigned int>(z) < v.size(); z++ )
            cout << " " << z << "  " << v[z] << endl;
    }
    else
		throw("yup, still bad");



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