-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathparameters_helper.h
More file actions
99 lines (83 loc) · 2.2 KB
/
parameters_helper.h
File metadata and controls
99 lines (83 loc) · 2.2 KB
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
/**
* Class to help read in multiple command line (flagged) parameters
*
* TO DO:
* Error Messages
*/
#ifndef ICE_PARAM
#define ICE_PARAM
#include <stdlib.h>
#include <vector>
#include <string>
#include <map>
#include <iostream>
#include "string_helper.h"
using namespace std;
typedef short unsigned int sui;
typedef long unsigned int lui;
/**
* @class Parameters
*
* Structure to help make reading command line arguments quick and easy
*/
class parameters_helper {
public:
/** @fn Parameters()
*
* Empty Constructor
*/
parameters_helper() {
}
/** @fn ~Parameters()
*
* Empty Destructor
*/
~parameters_helper() {
}
void Read(int argc, char **argv);
/**
* @fn template <class T> void set (T* var, string tag, T dflt)
* @param var Pointer to variable to set to parameter
* @param tag Command line flag to look for
* @param dflt Default value to set var to
*/
template<class T>
void set(T *var, string tag, T dflt) {
if ((it_lookup = lookup.find(tag)) != lookup.end()) {
(*var) = str_to<T>(it_lookup->second[0]);
} else
(*var) = dflt;
}
/**
* @fn template <class T> void set (T* var, string tag)
* @param var Pointer to variable to set to parameter
* @param tag Command line flag to look for
*
* Will throw an exception if the flag is not found in the parameters
*/
template<class T>
void set(T *var, string tag) {
if ((it_lookup = lookup.find(tag)) != lookup.end()) {
(*var) = str_to<T>(it_lookup->second[0]);
} else
throw "Invalid parameters_helper";
}
/**
* @fn void boolset (bool* var, string tag)
* @param var Pointer to variable to set to parameter
* @param tag Command line flag to look for
*
* Will set the boolean to true if the flag is found. False otherwise.
*/
void boolset(bool *var, string tag) {
if ((it_lookup = lookup.find(tag)) != lookup.end()) {
(*var) = true;
} else {
(*var) = false;
}
}
private:
map<string, vector<string>> lookup;
map<string, vector<string>>::iterator it_lookup;
};
#endif