Here is my code:
My Config.h
:
#include <string>
#include <boost/property_tree/ini_parser.hpp>
namespace pt = boost::property_tree;
class Config {
public:
Config(std::string conf);
template<typename T>
T GetConfigValue(std::string configKey, T value = 0){
pt::ptree tree;
pt::read_ini(_configFile, tree);
return tree.get<T>(configKey, value);
}
private:
std::string _configFile;
};
Here is how I call it:
#include "Logger.h"
#include "Config.h"
int main() {
Config * config = new Config("/WorldServer.conf.dist");
std::string def = "Nothing there.";
Logger::Log(config->GetConfigValue("WorldServer.MaxPingTime", def));
}
Here is the content of WorldServer.conf.dist
:
[WorldServer]
MaxPingTime = 30
MySQL.User = "root"
When I execute
Logger::Log(config->GetConfigValue("WorldServer.MaxPingTime", def));
I see 30
as result which is correct, however when I execute:
Logger::Log(config->GetConfigValue("WorldServer.MySQL.User", def));
i see as result Nothing there.
As far as I understand the .
in the MySQL.User
is causing the issue.
My question is can I somehow make it work with dot using boost property tree to parse the ini config?