24#include <boost/functional/hash.hpp>
28#include <unordered_map>
35 std::unordered_map<std::pair<std::string, std::string>, std::string, boost::hash<std::pair<std::string, std::string>>> values;
54Config::Config(std::string
const& iniFile) :
Config() {
59 auto valueHandler = [](
void* obj,
char const* section,
char const* name,
char const* value) ->
int {
60 auto _this = (
Config*) obj;
61 pair<string, string> keyToInsert(section, name);
62 pair<pair<string, string>,
string> pairToInsert(keyToInsert, value);
63 _this->data->values.insert(pairToInsert);
66 if (ini_parse(iniFile.c_str(), valueHandler,
this) < 0) {
67 throw Exception(__PRETTY_FUNCTION__, 1,
"Could not read config file.");
71void Config::insert(std::initializer_list<std::pair<std::pair<std::string, std::string>, std::string>>
init) {
72 data->values.insert(
init.begin(),
init.end());
75void Config::override(std::vector<std::pair<std::pair<std::string, std::string>, std::string>>
const& overrides) {
76 for (
auto& [k, v] : overrides) {
81bool Config::isSet(std::pair<std::string, std::string>
const& key)
const {
82 return (data->values.count(key) == 1);
86 if (data->values.count(key) == 1) {
87 return data->values.at(key);
94void Config::set(std::pair<string, string> key, std::string value) {
95 data->values[std::move(key)] = std::move(value);
98void Config::set(std::string section, std::string key, std::string value) {
99 set(pair<string, string>(std::move(section), std::move(key)), std::move(value));
Reader for config files and accessor to config values.
Exception class that can be used by apps to catch errors resulting from nawa function calls.
int init(nawa::AppInit &appInit)
std::string operator[](std::pair< std::string, std::string > const &key) const
bool isSet(std::pair< std::string, std::string > const &key) const
void insert(std::initializer_list< std::pair< std::pair< std::string, std::string >, std::string > > init)
void read(std::string const &iniFile)
void set(std::pair< std::string, std::string > key, std::string value)
void override(std::vector< std::pair< std::pair< std::string, std::string >, std::string > > const &overrides)
#define NAWA_DEFAULT_DESTRUCTOR_IMPL(Class)
#define NAWA_COPY_CONSTRUCTOR_IMPL(Class)
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_IMPL(Class)
#define NAWA_DEFAULT_CONSTRUCTOR_IMPL(Class)
#define NAWA_COPY_ASSIGNMENT_OPERATOR_IMPL(Class)
#define NAWA_MOVE_CONSTRUCTOR_IMPL(Class)