48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#ifndef GERMANAIRLINESVA_GACONNECTOR_CONFIG_H
|
|
#define GERMANAIRLINESVA_GACONNECTOR_CONFIG_H
|
|
|
|
#include "stringExtensions.hpp"
|
|
|
|
#include <map>
|
|
|
|
#include <fstream>
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace config
|
|
{
|
|
static inline std::map<std::string, std::string>
|
|
readConfig(const std::string &file)
|
|
{
|
|
std::ifstream config(file);
|
|
std::map<std::string, std::string> settings;
|
|
|
|
std::string line;
|
|
while (std::getline(config, line)) {
|
|
std::vector<std::string> fields = split(line, '=');
|
|
if (fields.size() >= 2) {
|
|
trim(fields[0]);
|
|
trim(fields[1]);
|
|
settings[fields[0]] = fields[1];
|
|
}
|
|
}
|
|
|
|
config.close();
|
|
return settings;
|
|
}
|
|
|
|
|
|
static inline void
|
|
writeConfig(const std::map<std::string, std::string> &config,
|
|
const std::string &file)
|
|
{
|
|
std::ofstream cfg(file);
|
|
for (const std::pair<const std::string, std::string> &entry : config) {
|
|
cfg << entry.first << '=' << entry.second << '\n';
|
|
}
|
|
cfg.close();
|
|
}
|
|
} // namespace config
|
|
#endif
|