3#include "Exceptions/FileDoesNotExistException.h"
11 template<ranges::range T>
12 Config& Config::overrideConfigurationArray(string_view key,
const T& value,
bool recursive)
14 vector<json::utility::jsonObject> data;
16 data.reserve(distance(value.begin(), value.end()));
18 for (
const auto& temp : value)
20 json::utility::appendArray(temp, data);
23 currentConfiguration.overrideValue(key, data, recursive);
28 Config::Config(
const filesystem::path& configPath) :
29 basePath(filesystem::absolute(configPath))
31 if (!filesystem::exists(configPath))
33 throw file_manager::exceptions::FileDoesNotExistException(configPath.string());
36 basePath = basePath.parent_path();
38 currentConfiguration.setJSONData(ifstream(configPath));
41 Config::Config(string_view serverConfiguration, string_view applicationDirectory) :
42 currentConfiguration(serverConfiguration),
43 basePath(filesystem::absolute(applicationDirectory))
48 Config& Config::overrideConfiguration(string_view key,
const json::utility::jsonObject::variantType& value,
bool recursive)
50 currentConfiguration.overrideValue(key, value, recursive);
55 Config& Config::overrideConfiguration(string_view key,
const vector<int64_t>& value,
bool recursive)
57 return this->overrideConfigurationArray(key, value, recursive);
60 Config& Config::overrideConfiguration(string_view key,
const vector<string>& value,
bool recursive)
62 return this->overrideConfigurationArray(key, value, recursive);
65 Config& Config::overrideBasePath(
const filesystem::path& basePath)
67 if (!filesystem::exists(basePath))
69 throw file_manager::exceptions::FileDoesNotExistException(basePath.string());
72 this->basePath = basePath;
77 const string& Config::getConfigurationString(string_view key,
bool recursive)
const
79 return currentConfiguration.getString(key, recursive);
82 int64_t Config::getConfigurationInteger(string_view key,
bool recursive)
const
84 return currentConfiguration.getInt(key, recursive);
87 bool Config::getConfigurationBoolean(string_view key,
bool recursive)
const
89 return currentConfiguration.getBool(key, recursive);
92 const filesystem::path& Config::getBasePath()
const
97 string Config::getConfiguration()
const
99 return (ostringstream() << currentConfiguration).str();
102 string_view Config::getRawConfiguration()
const
104 return currentConfiguration.getRawData();
107 const json::JSONParser& Config::operator * ()
const
109 return currentConfiguration;
Config file representation.