-
Notifications
You must be signed in to change notification settings - Fork 22
/
config.h
54 lines (44 loc) · 1.26 KB
/
config.h
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
#pragma once
#include <vector>
#include <string>
#include <iostream>
#include <boost/foreach.hpp>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
struct ParameterBase {
std::string m_name;
std::string m_desc;
virtual void addToBoost(po::options_description&) = 0;
};
template <typename T>
struct Parameter : ParameterBase {
T* m_value;
Parameter(std::string name, T* value, std::string desc) {
m_name = name;
m_value = value;
m_desc = desc;
}
void addToBoost(po::options_description& od) {
od.add_options()(m_name.c_str(), po::value(m_value)->default_value(*m_value), m_desc.c_str());
}
};
struct Config {
std::vector<ParameterBase*> params;
};
class Parser {
std::vector<Config> m_configs;
public:
void addGroup(Config config) {
m_configs.push_back(config);
}
void read(int argc, char* argv[]);
};
struct GeneralConfig : Config {
static int verbose;
static float scale;
GeneralConfig() : Config() {
params.push_back(new Parameter<int>("verbose", &verbose, "verbosity: 0: debug, 10000:info, 20000: warn, 30000: error"));
params.push_back(new Parameter<float>("scale", &scale, "scale factor applied to distances that are assumed to be in meters"));
}
};
#define METERS GeneralConfig::scale