forked from petermilne/ACQ420FMC
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Env.h
55 lines (45 loc) · 831 Bytes
/
Env.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
55
/*
* Env.h
*
* Created on: 19 Sep 2019
* Author: pgm
*/
#ifndef ENV_H_
#define ENV_H_
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <map>
class Env {
std::map<std::string,std::string> _env;
public:
Env(const char* fname);
std::string& operator() (std::string key);
static int getenv(const char* key, int def) {
const char* sv = ::getenv(key);
if (sv){
return strtol(sv, 0, 0);
}else{
return def;
}
}
static double getenv(const char* key, double def) {
const char* sv = ::getenv(key);
if (sv){
return strtod(sv, 0);
}else{
return def;
}
}
static const char* getenv(const char* key, const char* def) {
const char* sv = ::getenv(key);
if (sv){
return sv;
}else{
return def;
}
}
};
#endif /* ENV_H_ */