-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cpp
67 lines (54 loc) · 1.2 KB
/
Config.cpp
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
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <fstream>
#include <boost/config.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include "Config.hpp"
using namespace std;
namespace pod = boost::program_options::detail;
/* --------------------------------------------------------
GLOBALS
-------------------------------------------------------- */
const string g_sConfigFile = "mcsrv-tools.ini";
cConfig::cConfig()
{
}
cConfig::~cConfig()
{
}
void cConfig::init()
{
read();
}
void cConfig::read()
{
ifstream config(g_sConfigFile.c_str());
if( !config )
{
cerr<<"Error: could not open config file '"<<g_sConfigFile<<"'"<<endl;
exit(-1);
}
m_vOptions.insert("*");
try
{
for( pod::config_file_iterator it(config, m_vOptions), e ; it != e; ++it )
{
m_mParameters[it->string_key] = it->value[0];
}
}
catch(std::exception& e)
{
std::cerr<<"Exception: "<<e.what()<<std::endl;
}
}
string cConfig::get(const string arg_param)
{
return m_mParameters[arg_param];
}
string cConfig::get(const char* arg_param)
{
return get(string(arg_param));
}