2e73e7bc
David Mayerich
basic changes for...
|
1
2
|
#ifndef STIM_ARGUMENTS
#define STIM_ARGUMENTS
|
7a2d0012
David Mayerich
mirst1d updates
|
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <iterator>
#include <algorithm>
#ifdef _WIN32
#include <Windows.h>
#endif
|
feb0c9dd
David Mayerich
network processin...
|
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
|
/**The arglist class implements command line arguments.
Example:
1) Create an arglist instance:
stim::arglist args;
2) Add arguments:
args.add("help", "prints this help");
args.add("foo", "foo takes a single integer value", "", "[intval]");
args.add("bar", "bar takes two floating point values", "", "[value1], [value2]");
3) Parse the command line:
args.parse(argc, argv);
4) You generally want to immediately test for help and output available arguments:
if(args["help"].is_set())
std::cout<<args.str();
5) Retrieve values:
int foo;
float bar1, bar2;
if(args["foo"])
foo = args["foo"].as_int();
if(args["bar"]){
bar1 = args["bar"].as_float(0);
bar2 = args["bar"].as_float(1);
}
**/
|
2e73e7bc
David Mayerich
basic changes for...
|
54
|
namespace stim{
|
7a2d0012
David Mayerich
mirst1d updates
|
55
|
|
81e0d221
David Mayerich
separated executa...
|
56
|
class cmd_option
|
7a2d0012
David Mayerich
mirst1d updates
|
57
58
59
60
61
62
63
|
{
private:
bool ansi;
//argument name
std::string name;
|
904614c3
David Mayerich
added normalizati...
|
64
|
//description of the option
|
7a2d0012
David Mayerich
mirst1d updates
|
65
66
67
|
std::vector<std::string> desc;
//argument values
|
3b012a80
David Mayerich
added code for co...
|
68
69
|
std::vector<std::string> vals;
|
904614c3
David Mayerich
added normalizati...
|
70
71
72
73
|
//integral and numerical flags for each argument
std::vector<bool> integral;
std::vector<bool> numerical;
|
3b012a80
David Mayerich
added code for co...
|
74
75
76
77
|
//range or example
std::string range;
//flag is true when the argument is user-specified
|
7a2d0012
David Mayerich
mirst1d updates
|
78
79
|
bool flag;
|
904614c3
David Mayerich
added normalizati...
|
80
81
82
|
bool char_numerical(char c){
if( (c >= '0' && c <= '9') || c == '-' || c == '.')
return true;
|
963d0676
David Mayerich
bug fixes related...
|
83
|
return false;
|
904614c3
David Mayerich
added normalizati...
|
84
85
86
87
88
|
}
bool char_integral(char c){
if( (c >= '0' && c <= '9') || c == '-')
return true;
|
963d0676
David Mayerich
bug fixes related...
|
89
|
return false;
|
904614c3
David Mayerich
added normalizati...
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
}
/// Test if a given string contains a numerical (real) value
bool test_numerical(std::string v){
for(size_t i = 0; i < v.length(); i++){ //for each character in the string
if(!char_numerical(v[i]))
return false;
}
return true;
}
/// Test if a given string contains an integer value
bool test_integral(std::string v){
for(size_t i = 0; i < v.length(); i++){ //for each character in the string
if(!char_integral(v[i]))
return false;
}
return true;
}
|
7a2d0012
David Mayerich
mirst1d updates
|
110
111
|
void parse_val(const std::string &s){
|
3b012a80
David Mayerich
added code for co...
|
112
113
|
vals.clear();
|
7a2d0012
David Mayerich
mirst1d updates
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, ' ')) {
vals.push_back(item);
}
}
void parse_desc(const std::string &s){
desc.clear();
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, '\n')) {
desc.push_back(item);
}
}
|
3b012a80
David Mayerich
added code for co...
|
132
133
|
public:
void set_ansi(bool b){ ansi = b; }
|
81e0d221
David Mayerich
separated executa...
|
134
135
|
//create an option with a given name, description, and default value
cmd_option(std::string _name, std::string _desc, std::string _default = "", std::string _range = "")
|
7a2d0012
David Mayerich
mirst1d updates
|
136
137
138
|
{
name = _name;
parse_desc(_desc);
|
3b012a80
David Mayerich
added code for co...
|
139
140
141
142
143
144
145
146
147
|
parse_val(_default);
//if a default value is provided, set the flag
if(_default != "")
flag = true;
else flag = false;
range = _range;
|
7a2d0012
David Mayerich
mirst1d updates
|
148
|
|
3b012a80
David Mayerich
added code for co...
|
149
150
|
}
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
151
|
size_t nargs()
|
3b012a80
David Mayerich
added code for co...
|
152
153
154
155
|
{
return vals.size();
}
|
81e0d221
David Mayerich
separated executa...
|
156
|
//return the value of a text option
|
a2bf1d08
David Mayerich
general bug fixes...
|
157
|
std::string as_string(size_t n = 0)
|
3b012a80
David Mayerich
added code for co...
|
158
159
160
|
{
if(!flag)
{
|
81e0d221
David Mayerich
separated executa...
|
161
|
std::cout<<"ERROR - Option requested without being set: "<<name<<std::endl;
|
3b012a80
David Mayerich
added code for co...
|
162
163
164
165
166
167
168
169
170
|
exit(1);
}
if(vals.size() > n)
return vals[n];
else return "";
}
|
81e0d221
David Mayerich
separated executa...
|
171
|
//return the value of a floating point option
|
ba51ae6a
David Mayerich
fixed metric calc...
|
172
|
double as_float(size_t n = 0)
|
3b012a80
David Mayerich
added code for co...
|
173
174
175
|
{
if(!flag)
{
|
81e0d221
David Mayerich
separated executa...
|
176
|
std::cout<<"ERROR - option requested without being set: "<<name<<std::endl;
|
3b012a80
David Mayerich
added code for co...
|
177
178
179
180
181
182
|
exit(1);
}
if(vals.size() > n)
{
float r;
|
2e73e7bc
David Mayerich
basic changes for...
|
183
|
if ( ! (std::istringstream(vals[n]) >> r) ) r = 0;
|
3b012a80
David Mayerich
added code for co...
|
184
185
186
187
188
189
|
return r;
}
else return 0;
}
|
81e0d221
David Mayerich
separated executa...
|
190
|
//return the value of an integer option
|
a2bf1d08
David Mayerich
general bug fixes...
|
191
|
int as_int(size_t n = 0)
|
3b012a80
David Mayerich
added code for co...
|
192
193
194
|
{
if(!flag)
{
|
81e0d221
David Mayerich
separated executa...
|
195
|
std::cout<<"ERROR - option requested without being set: "<<name<<std::endl;
|
3b012a80
David Mayerich
added code for co...
|
196
197
198
199
200
201
|
exit(1);
}
if(vals.size() > n)
{
int r;
|
2e73e7bc
David Mayerich
basic changes for...
|
202
|
if ( ! (std::istringstream(vals[n]) >> r) ) r = 0;
|
3b012a80
David Mayerich
added code for co...
|
203
204
205
206
207
|
return r;
}
else return 0;
}
|
83cdf0dc
David Mayerich
added the ability...
|
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
//returns true if the specified argument can be represented as a number
bool is_num(size_t n = 0){
bool decimal = false;
for(size_t i = 0; i < vals[n].size(); i++){
if(vals[n][i] == '-' && i != 0) return false;
else if(vals[n][i] == '.'){
if(decimal) return false;
else decimal = true;
}
else if(vals[n][i] < '0') return false;
else if(vals[n][i] > '9') return false;
}
return true;
}
|
3b012a80
David Mayerich
added code for co...
|
222
223
|
//get the width of the left column
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
224
|
size_t col_width()
|
3b012a80
David Mayerich
added code for co...
|
225
|
{
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
226
|
size_t n = 3;
|
81e0d221
David Mayerich
separated executa...
|
227
|
//add the length of the option name
|
3b012a80
David Mayerich
added code for co...
|
228
229
230
231
232
233
234
235
|
n += name.size();
//if there are any default parameters
if(vals.size() > 0)
{
//padding (parenthesis, =, etc.)
n += 6;
|
81e0d221
David Mayerich
separated executa...
|
236
|
//for each default option value
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
237
|
for(size_t v=0; v<vals.size(); v++)
|
3b012a80
David Mayerich
added code for co...
|
238
239
240
241
242
243
244
|
n += vals[v].size() + 1;
}
//add a buffer of 4 characters
n += 4;
return n;
|
7a2d0012
David Mayerich
mirst1d updates
|
245
246
247
248
|
}
//string output
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
249
|
std::string toStr(size_t width = 0)
|
7a2d0012
David Mayerich
mirst1d updates
|
250
|
{
|
3b012a80
David Mayerich
added code for co...
|
251
252
253
254
|
std::stringstream ss;
int color_size = 0;
|
7a2d0012
David Mayerich
mirst1d updates
|
255
256
257
258
|
//create the left column
std::string left_part = std::string(" --") + name;
if(vals.size() != 0)
|
3b012a80
David Mayerich
added code for co...
|
259
260
261
|
{
if(ansi)
left_part += "\033[1;32m";
|
7a2d0012
David Mayerich
mirst1d updates
|
262
|
left_part += " ( = ";
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
263
|
for(size_t v=0; v<vals.size(); v++)
|
7a2d0012
David Mayerich
mirst1d updates
|
264
|
left_part += vals[v] + std::string(" ");
|
3b012a80
David Mayerich
added code for co...
|
265
266
267
268
269
270
271
|
left_part += ")";
if(ansi)
left_part += "\033[0m";
if(ansi)
color_size = 11;
}
else
|
7a2d0012
David Mayerich
mirst1d updates
|
272
273
274
|
color_size = 0;
//if no width is passed, put 4 spaces between left and right columns
|
3b012a80
David Mayerich
added code for co...
|
275
|
if(width == 0) width = col_width();
|
7a2d0012
David Mayerich
mirst1d updates
|
276
277
278
279
|
ss<<std::left<<std::setw(width + color_size)<<left_part;
//output right column
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
280
|
for(size_t d=0; d<desc.size(); d++)
|
7a2d0012
David Mayerich
mirst1d updates
|
281
282
283
|
{
if(d == 0)
ss<<desc[0];
|
3b012a80
David Mayerich
added code for co...
|
284
|
else
|
0ef519a4
David Mayerich
optimized materia...
|
285
|
ss<<std::endl<<std::setfill(' ')<<std::setw(width)<<" "<<desc[d];
|
7a2d0012
David Mayerich
mirst1d updates
|
286
|
|
3b012a80
David Mayerich
added code for co...
|
287
288
289
290
|
}
//output the range in the right column
if(range != "" && ansi)
|
0ef519a4
David Mayerich
optimized materia...
|
291
|
ss<<std::endl<<std::setfill(' ')<<std::setw(width)<<" "<<" "<<std::string("\033[1;36m") + range + "\033[0m";
|
7a2d0012
David Mayerich
mirst1d updates
|
292
|
else if(range != "")
|
0ef519a4
David Mayerich
optimized materia...
|
293
|
ss<<std::endl<<std::setfill(' ')<<std::setw(width)<<" "<<" "<<range;
|
7a2d0012
David Mayerich
mirst1d updates
|
294
295
|
return ss.str();
|
3b012a80
David Mayerich
added code for co...
|
296
297
|
}
|
81e0d221
David Mayerich
separated executa...
|
298
|
//compare the name of the option to a string
|
3b012a80
David Mayerich
added code for co...
|
299
300
301
302
303
|
bool operator==(std::string rhs)
{
return (name == rhs);
}
|
81e0d221
David Mayerich
separated executa...
|
304
|
//set the option to a given value
|
3b012a80
David Mayerich
added code for co...
|
305
306
307
308
309
310
311
312
|
void set(std::string _value)
{
parse_val(_value);
//set the flag
flag = true;
}
|
feb0c9dd
David Mayerich
network processin...
|
313
|
bool is_set() const{
|
3b012a80
David Mayerich
added code for co...
|
314
|
return flag;
|
7a2d0012
David Mayerich
mirst1d updates
|
315
|
}
|
feb0c9dd
David Mayerich
network processin...
|
316
317
318
|
operator bool() const{
return is_set();
}
|
7a2d0012
David Mayerich
mirst1d updates
|
319
|
|
3b012a80
David Mayerich
added code for co...
|
320
321
322
323
324
|
};
struct argsection
{
std::string name;
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
325
|
size_t index;
|
3b012a80
David Mayerich
added code for co...
|
326
327
|
};
|
025d4bf3
David Mayerich
added documentati...
|
328
|
|
025d4bf3
David Mayerich
added documentati...
|
329
|
|
3b012a80
David Mayerich
added code for co...
|
330
331
332
333
334
|
class arglist
{
private:
bool ansi;
|
81e0d221
David Mayerich
separated executa...
|
335
336
337
|
//vector of options
std::vector<cmd_option> opts;
std::vector<std::string> args;
|
3b012a80
David Mayerich
added code for co...
|
338
|
|
81e0d221
David Mayerich
separated executa...
|
339
|
//column width of the longest option
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
340
|
size_t col_width;
|
3b012a80
David Mayerich
added code for co...
|
341
342
343
344
345
346
|
//list of sections
std::vector<argsection> sections;
public:
|
0ef519a4
David Mayerich
optimized materia...
|
347
348
|
arglist(){
col_width = 0;
|
9c97e126
David Mayerich
added an axis-ali...
|
349
350
351
352
353
354
355
356
357
|
ansi = true;
//set ansi to false by default if this is a Windows system
// (console doesn't support ANSI colors)
#ifdef _WIN32
ansi=false;
#endif
|
0ef519a4
David Mayerich
optimized materia...
|
358
|
}
|
3b012a80
David Mayerich
added code for co...
|
359
|
|
025d4bf3
David Mayerich
added documentati...
|
360
361
362
|
///Sets ANSI support (default is on), which allows colored values in the help output.
/// @param b is a boolean value specifying ANSI support (true is on, false is off)
|
3b012a80
David Mayerich
added code for co...
|
363
364
365
|
void set_ansi(bool b)
{
ansi = b;
|
81e0d221
David Mayerich
separated executa...
|
366
367
|
for(unsigned int i=0; i<opts.size(); i++)
opts[i].set_ansi(ansi);
|
3b012a80
David Mayerich
added code for co...
|
368
369
|
}
|
025d4bf3
David Mayerich
added documentati...
|
370
371
372
373
374
375
|
///Add a supported command line argument.
/// @param _name is the name of the command line argument (supplied as --name)
/// @param _desc is a text description of the argument
/// @param _default is the default value of the argument
/// @param _range is the supported range of values, list of values, etc. It will be displayed to the user.
|
3b012a80
David Mayerich
added code for co...
|
376
377
|
void add(std::string _name, std::string _desc, std::string _default = "", std::string _range = "")
{
|
81e0d221
David Mayerich
separated executa...
|
378
379
380
|
cmd_option opt(_name, _desc, _default, _range);
opt.set_ansi(ansi);
opts.push_back(opt);
|
3b012a80
David Mayerich
added code for co...
|
381
|
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
382
|
col_width = std::max<size_t>(col_width, opt.col_width());
|
3b012a80
David Mayerich
added code for co...
|
383
384
|
}
|
025d4bf3
David Mayerich
added documentati...
|
385
386
387
|
///Specifies a section name that can be used to organize parameters in the output.
/// @param _name is the name of the section, which will be displayed to the user
|
3b012a80
David Mayerich
added code for co...
|
388
389
390
391
|
void section(std::string _name)
{
argsection s;
s.name = _name;
|
81e0d221
David Mayerich
separated executa...
|
392
|
s.index = opts.size();
|
3b012a80
David Mayerich
added code for co...
|
393
394
395
|
sections.push_back(s);
}
|
025d4bf3
David Mayerich
added documentati...
|
396
|
///Outputs supported arguments. If ANSI support is available, they will be color-coded. Generally this is called in response to "--help"
|
7a2d0012
David Mayerich
mirst1d updates
|
397
|
std::string str()
|
3b012a80
David Mayerich
added code for co...
|
398
399
400
401
402
403
404
405
|
{
std::stringstream ss;
int si = -1;
if(sections.size() > 0)
si = 0;
|
81e0d221
David Mayerich
separated executa...
|
406
407
|
//for each option
for(unsigned int a=0; a<opts.size(); a++)
|
3b012a80
David Mayerich
added code for co...
|
408
409
410
411
|
{
if(si != -1 && a == sections[si].index)
{
if(ansi)
|
eb5dfb2b
David Mayerich
fixed linux compa...
|
412
|
ss<<std::endl<<std::left<<std::setw(col_width)<<std::string("\033[1;31m") + sections[si].name<<"\033[0m"<<std::endl;
|
3b012a80
David Mayerich
added code for co...
|
413
|
else
|
eb5dfb2b
David Mayerich
fixed linux compa...
|
414
|
ss<<std::endl<<std::left<<std::setw(col_width)<<sections[si].name<<std::endl;
|
3b012a80
David Mayerich
added code for co...
|
415
|
si++;
|
2e73e7bc
David Mayerich
basic changes for...
|
416
|
if(si == (int)sections.size()) si = -1;
|
3b012a80
David Mayerich
added code for co...
|
417
418
|
}
|
81e0d221
David Mayerich
separated executa...
|
419
|
ss<<opts[a].toStr(col_width)<<std::endl;
|
3b012a80
David Mayerich
added code for co...
|
420
421
422
423
424
|
}
return ss.str();
}
|
025d4bf3
David Mayerich
added documentati...
|
425
426
427
|
///Retrieves the index for a supported argument, given that argument's name.
/// @param _name is the name of the requested argument
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
428
|
size_t index(std::string _name)
|
3b012a80
David Mayerich
added code for co...
|
429
|
{
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
430
|
size_t i = find(opts.begin(), opts.end(), _name) - opts.begin();
|
3b012a80
David Mayerich
added code for co...
|
431
|
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
432
433
434
435
|
if(i >= opts.size()){
std::cout<<"ERROR stim::arglist: option name '"<<_name<<"' not found"<<std::endl;
exit(1);
}
|
3b012a80
David Mayerich
added code for co...
|
436
|
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
437
|
return i;
|
3b012a80
David Mayerich
added code for co...
|
438
439
|
}
|
025d4bf3
David Mayerich
added documentati...
|
440
441
442
443
|
///Sets an argument to a specified value
/// @param _name is the name of the argument to be set
/// @param _value is the value that it is given
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
444
445
|
void set(std::string _name, std::string _value){
size_t i = index(_name);
|
3b012a80
David Mayerich
added code for co...
|
446
|
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
447
448
449
|
opts[i].set(_value);
//adjust the column width if necessary
col_width = (std::max)(col_width, opts[i].col_width());
|
3b012a80
David Mayerich
added code for co...
|
450
451
|
}
|
025d4bf3
David Mayerich
added documentati...
|
452
453
454
455
|
///Parses the command line
/// @param argc is the number of command line arguments (provided by the OS)
/// @param argv[] is the list of command line arguments (provided by the OS)
|
3b012a80
David Mayerich
added code for co...
|
456
457
|
void parse(int argc, char* argv[])
{
|
81e0d221
David Mayerich
separated executa...
|
458
|
//if the number of options is 1, we're done
|
3b012a80
David Mayerich
added code for co...
|
459
460
461
462
463
|
if(argc <= 1) return;
std::string name;
std::string params;
|
81e0d221
David Mayerich
separated executa...
|
464
465
|
bool args_done = false; //create a flag that turns true when the first option is encountered
|
3b012a80
David Mayerich
added code for co...
|
466
467
|
for(int i=1; i<argc; i++)
{
|
81e0d221
David Mayerich
separated executa...
|
468
|
//if the argument is an option
|
3b012a80
David Mayerich
added code for co...
|
469
470
|
if(argv[i][0] == '-' && argv[i][1] == '-')
{
|
81e0d221
David Mayerich
separated executa...
|
471
472
|
args_done = true; //arguments for the executable are done, all options now
//add any previous options
|
3b012a80
David Mayerich
added code for co...
|
473
474
|
if(name != "")
set(name, params);
|
81e0d221
David Mayerich
separated executa...
|
475
|
//set the current option to this name
|
3b012a80
David Mayerich
added code for co...
|
476
477
478
479
|
name = argv[i]+2;
//clear the parameters list
params = "";
}
|
81e0d221
David Mayerich
separated executa...
|
480
481
482
483
|
else if(!args_done){
args.push_back(argv[i]);
}
else{ //everything else is an arg for the most recent option
|
3b012a80
David Mayerich
added code for co...
|
484
485
486
487
488
489
|
if(params != "")
params += " ";
params += argv[i];
}
}
|
81e0d221
David Mayerich
separated executa...
|
490
|
//set the last option
|
27b826a8
David Mayerich
added a spherical...
|
491
492
|
if(name != "")
set(name, params);
|
3b012a80
David Mayerich
added code for co...
|
493
494
|
}
|
025d4bf3
David Mayerich
added documentati...
|
495
496
497
|
///Determines of a parameter has been set and returns true if it has
/// @param _name is the name of the argument
|
963d0676
David Mayerich
bug fixes related...
|
498
499
500
|
bool operator()(std::string _name){
std::vector<cmd_option>::iterator it;
it = std::find(opts.begin(), opts.end(), _name);// - opts.begin();
|
3b012a80
David Mayerich
added code for co...
|
501
|
|
963d0676
David Mayerich
bug fixes related...
|
502
|
if(it == opts.end()){
|
3b012a80
David Mayerich
added code for co...
|
503
504
505
506
|
std::cout<<"ERROR - Unspecified parameter name: "<<_name<<std::endl;
exit(1);
}
|
963d0676
David Mayerich
bug fixes related...
|
507
|
return it->is_set();
|
3b012a80
David Mayerich
added code for co...
|
508
509
|
}
|
025d4bf3
David Mayerich
added documentati...
|
510
511
512
|
///Returns the number of parameters for a specified argument
/// @param _name is the name of the argument whose parameter number will be returned
|
963d0676
David Mayerich
bug fixes related...
|
513
514
515
|
size_t nargs(std::string _name){
std::vector<cmd_option>::iterator it;
it = find(opts.begin(), opts.end(), _name);// - opts.begin();
|
3b012a80
David Mayerich
added code for co...
|
516
|
|
963d0676
David Mayerich
bug fixes related...
|
517
|
if(it == opts.end()){
|
3b012a80
David Mayerich
added code for co...
|
518
519
520
521
|
std::cout<<"ERROR - Unspecified parameter name: "<<_name<<std::endl;
exit(1);
}
|
963d0676
David Mayerich
bug fixes related...
|
522
|
return it->nargs();
|
81e0d221
David Mayerich
separated executa...
|
523
524
|
}
|
025d4bf3
David Mayerich
added documentati...
|
525
|
///Returns the number of arguments that have been set
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
526
|
size_t nargs(){
|
81e0d221
David Mayerich
separated executa...
|
527
528
529
|
return args.size();
}
|
e9bddc57
David Mayerich
added band croppi...
|
530
|
/// Returns the number of options that are set
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
531
532
533
|
size_t nopts(){
size_t n = 0; //initialize the counter for the number of options
for(size_t i = 0; i < opts.size(); i++) //go through each option
|
e9bddc57
David Mayerich
added band croppi...
|
534
535
536
537
|
if(opts[i].is_set()) n++; //if a value is specified, increment the counter
return n;
}
|
025d4bf3
David Mayerich
added documentati...
|
538
539
540
|
///Returns the name of an argument, given its index
/// @param a is the index of the requested argument
|
9d3ba0b1
David Mayerich
added stim::hsi a...
|
541
|
std::string arg(size_t a){
|
81e0d221
David Mayerich
separated executa...
|
542
|
return args[a];
|
3b012a80
David Mayerich
added code for co...
|
543
|
}
|
23dbe234
david
fixed linux compi...
|
544
545
546
547
548
|
/// Returns an std::vector of argument strings
std::vector<std::string> arg_vector(){
return args;
}
|
feb0c9dd
David Mayerich
network processin...
|
549
|
///Returns an object describing the argument
|
3b012a80
David Mayerich
added code for co...
|
550
|
|
feb0c9dd
David Mayerich
network processin...
|
551
552
553
554
|
/// @param _name is the name of the requested argument
cmd_option operator[](std::string _name){
std::vector<cmd_option>::iterator it;
it = find(opts.begin(), opts.end(), _name);// - opts.begin();
|
3b012a80
David Mayerich
added code for co...
|
555
|
|
feb0c9dd
David Mayerich
network processin...
|
556
557
558
|
if(it == opts.end()){
std::cout<<"ERROR - Unspecified parameter name: "<<_name<<std::endl;
exit(1);
|
3b012a80
David Mayerich
added code for co...
|
559
560
|
}
|
feb0c9dd
David Mayerich
network processin...
|
561
562
563
|
return *it;
}
|
3b012a80
David Mayerich
added code for co...
|
564
|
|
7a2d0012
David Mayerich
mirst1d updates
|
565
566
567
568
|
};
|
2e73e7bc
David Mayerich
basic changes for...
|
569
|
} //end namespace stim
|
3b012a80
David Mayerich
added code for co...
|
570
571
|
#endif
|