-
Notifications
You must be signed in to change notification settings - Fork 25
/
configuration.hpp
49 lines (40 loc) · 1.18 KB
/
configuration.hpp
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
#pragma once
#include <cstdlib>
#include <cstdint>
#include <thread>
#include <boost/lexical_cast.hpp>
namespace ds2i {
class configuration {
public:
static configuration const& get() {
static configuration instance;
return instance;
}
double eps1;
double eps2;
uint64_t fix_cost;
size_t log_partition_size;
size_t worker_threads;
bool heuristic_greedy;
private:
configuration()
{
fillvar("DS2I_EPS1", eps1, 0.03);
fillvar("DS2I_EPS2", eps2, 0.3);
fillvar("DS2I_FIXCOST", fix_cost, 64);
fillvar("DS2I_LOG_PART", log_partition_size, 7);
fillvar("DS2I_THREADS", worker_threads, std::thread::hardware_concurrency());
fillvar("DS2I_HEURISTIC_GREEDY", heuristic_greedy, false);
}
template <typename T, typename T2>
void fillvar(const char* envvar, T& var, T2 def)
{
const char* val = std::getenv(envvar);
if (!val || !strlen(val)) {
var = def;
} else {
var = boost::lexical_cast<T>(val);
}
}
};
}