1 #include "JSONSettingsLoader.h"
6 #include <config/Config.h>
10 JSONSettingsLoader::JSONSettingsLoader(std::string_view filename)
15 JSONSettingsLoader::JSONSettingsLoader(std::string_view filename, std::string_view path,
bool relative )
20 void JSONSettingsLoader::getValue(
const std::string& name,
int* value)
const {
21 if (this->hasValue(name)) {
22 *value = this->settings[name];
26 void JSONSettingsLoader::getValue(
const std::string& name,
double* value)
const {
27 if (this->hasValue(name)) {
28 *value = this->settings[name];
32 void JSONSettingsLoader::getValue(
const std::string& name, std::string* value)
const {
33 if (this->hasValue(name)) {
34 *value = this->settings[name];
38 void JSONSettingsLoader::getValue(
const std::string& name,
bool* value)
const {
39 if (this->hasValue(name)) {
40 *value = this->settings[name];
44 void JSONSettingsLoader::setValue(
const std::string& name,
int value,
bool overwrite,
bool save) {
45 if (!overwrite && this->hasValue(name)) {
48 this->settings[name] = value;
54 void JSONSettingsLoader::setValue(
const std::string& name,
double value,
bool overwrite,
bool save) {
55 if (!overwrite && this->hasValue(name)) {
58 this->settings[name] = value;
64 void JSONSettingsLoader::setValue(
const std::string& name,
const std::string& value,
bool overwrite,
bool save) {
65 if (!overwrite && this->hasValue(name)) {
68 this->settings[name] = value;
74 void JSONSettingsLoader::setValue(
const std::string& name,
bool value,
bool overwrite,
bool save) {
75 if (!overwrite && this->hasValue(name)) {
78 this->settings[name] = value;
84 bool JSONSettingsLoader::hasValue(
const std::string& name)
const {
85 return this->settings.contains(name);
88 void JSONSettingsLoader::load() {
89 std::ifstream fileCheck{this->getFilePath().data()};
90 if (!fileCheck.good()) {
92 std::fstream fs{this->getFilePath().data(), std::fstream::out};
96 std::ifstream inputFile{this->getFilePath().data()};
100 for (
auto element = input.begin(); element != input.end(); ++element) {
101 this->settings[element.key()] = element.value();
105 void JSONSettingsLoader::save() {
106 std::ofstream output{this->getFilePath().data()};
107 output << std::setw(4) << this->settings << std::endl;