40 lines
864 B
C++
40 lines
864 B
C++
#include "config.h"
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
|
|
Config::Config(const std::string &filepath)
|
|
{
|
|
load(filepath);
|
|
}
|
|
|
|
void Config::load(const std::string &filepath)
|
|
{
|
|
std::ifstream file(filepath);
|
|
if (!file)
|
|
{
|
|
throw std::runtime_error("Konfigurationsdatei konnte nicht geöffnet werden.");
|
|
}
|
|
|
|
std::string line;
|
|
while (std::getline(file, line))
|
|
{
|
|
std::istringstream iss(line);
|
|
std::string key, value;
|
|
if (std::getline(iss, key, '=') && std::getline(iss, value))
|
|
{
|
|
config_map[key] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
std::string Config::get(const std::string &key) const
|
|
{
|
|
auto it = config_map.find(key);
|
|
if (it != config_map.end())
|
|
{
|
|
return it->second;
|
|
}
|
|
throw std::runtime_error("Konfigurationsschlüssel nicht gefunden: " + key);
|
|
}
|