-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cpp
More file actions
45 lines (40 loc) · 972 Bytes
/
Config.cpp
File metadata and controls
45 lines (40 loc) · 972 Bytes
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
#include "Config.h"
#include <sstream>
namespace bo = boost::program_options;
Config::Config()
:_options("Options")
{
_options.add_options()
("MAIN.VOLUME", bo::value<std::string>(), "Volume between 0.0 to 1.0")
("PLAYING.LIST", bo::value<std::string>(), "playlist file")
;
}
bool Config::load(const std::string& configFile)
{
std::ifstream ifs(configFile.c_str());
if (!ifs)
{
std::cout << "can not open config file: " << configFile << "\n";
return false;
}
else
{
bo::store(bo::parse_config_file(ifs, _options), _vm);
bo::notify(_vm);
}
}
void Config::dump()
{
for(auto it = _vm.begin(); it != _vm.end(); it++)
{
std::cout << (*it).first << "=" << get<std::string>((*it).first) << std::endl;
}
}
template<typename RET>
RET Config::get(const std::string& opt) const
{
std::istringstream os(_vm[opt].as< std::string >());
RET ret;
os >> ret;
return ret;
}