-
Notifications
You must be signed in to change notification settings - Fork 0
/
ECArgs.C
75 lines (64 loc) · 1.18 KB
/
ECArgs.C
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
#include "ECArgs.h"
#include <assert.h>
#include <stdio.h>
#include <list>
#include <algorithm>
#include "utils.h"
//#include "algo.h"
using namespace std;
ECArgs::
ECArgs(int argc, char *argv[])
{
nargs_ = 0;
for(int i = 1 ; i < argc ; i++)
{
ECString arg(argv[i]);
if(arg[0] != '-')
{
argList[nargs_] = arg;
nargs_++;
}
else
{
nopts_++;
int l = arg.length();
assert(l > 1);
// ECString opt(1,arg[1]);
ECString opt(arg,1,1);
optList.push_back(opt);
if(l == 2) optList.push_back("");
else
{
ECString v(arg,2,l-2);
optList.push_back(v);
}
}
}
}
bool
ECArgs::
isset(char c)
{
ECString sig = "";
sig += c;
list<ECString>::iterator
oIter = std::find(optList.begin(), optList.end(), sig);
bool found = (oIter != optList.end());
return found;
}
ECString
ECArgs::
value(char c)
{
ECString sig;
sig += c;
list<ECString>::iterator oIter = std::find(optList.begin(), optList.end(), sig);
bool found = (oIter != optList.end());
if(!found)
{
cerr << "Looking for value of on-line argument " << sig << endl;
error("could not find value");
}
++oIter;
return *oIter;
}