-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.h
73 lines (64 loc) · 2.87 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef CRYPTOCENSUS_CONFIG_H
#define CRYPTOCENSUS_CONFIG_H
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_map>
class Config {
public:
/**
* Default constructor.
*
* Reads from "config.txt", and creates a map of key-value pairs from the text file.
* Each key-value pair is represented by a line in the text file, and keys and values are
* deliniated by the '=' character.
*/
Config();
/**
* Gets a string configuration.
*
* @param configKey the name of the configuration key to search for.
* @param defaultValue the value to return by default.
* @return the configuration value if it is valid; defaultValue otherwise.
*/
std::string getConfig(std::string configKey, std::string defaultValue);
/**
* Gets a int configuration.
*
* @param configKey the name of the configuration key to search for.
* @param defaultValue the value to return by default.
* @return the configuration value if it is valid; defaultValue otherwise.
*/
int getIntConfig(std::string configKey, int defaultValue);
/**
* Gets a int configuration if it falls within a specified minimum and maximum value.
*
* @param configKey the name of the configuration key to search for.
* @param defaultValue the value to return by default.
* @param min the minimum number to accept.
* @param max the maximum number to accept.
* @return the configuration value if it is valid, and is between the min and max values; defaultValue otherwise.
*/
int getIntConfig(std::string configKey, int defaultValue, int min, int max);
/**
* Gets a long configuration.
*
* @param configKey the name of the configuration key to search for.
* @param defaultValue the value to return by default.
* @return the configuration value if it is valid; defaultValue otherwise.
*/
long getLongConfig(std::string configKey, long defaultValue);
/**
* Gets a long configuration if it falls within a specified minimum and maximum value.
*
* @param configKey the name of the configuration key to search for.
* @param defaultValue the value to return by default.
* @param min the minimum number to accept.
* @param max the maximum number to accept.
* @return the configuration value if it is valid, and is between the min and max values; defaultValue otherwise.
*/
long getLongConfig(std::string configKey, long defaultValue, int min, int max);
private:
std::unordered_map<std::string, std::string> configMap;
};
#endif