Finished the first pass of moving everything around and cleaning up as much as possible.
This commit is contained in:
parent
d47f6f996d
commit
adfb6367d7
9 changed files with 163 additions and 87 deletions
32
config.cpp
Normal file
32
config.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "config.hpp"
|
||||
#include "dbc.hpp"
|
||||
#include <fmt/core.h>
|
||||
|
||||
using nlohmann::json;
|
||||
using fmt::format;
|
||||
|
||||
Config::Config(const std::string src_path) : $src_path(src_path) {
|
||||
std::ifstream infile($src_path);
|
||||
$config = json::parse(infile);
|
||||
}
|
||||
|
||||
json &Config::operator[](const std::string &key) {
|
||||
dbc::check($config.contains(key), format("ERROR in config, key {} doesn't exist.", key));
|
||||
return $config[key];
|
||||
}
|
||||
|
||||
std::wstring Config::wstring(const std::string key) {
|
||||
dbc::check($config.contains(key), format("ERROR wstring in config, key {} doesn't exist.", key));
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||
const std::string& str_val = $config[key];
|
||||
return $converter.from_bytes(str_val);
|
||||
}
|
||||
|
||||
std::wstring Config::wstring(const std::string main_key, const std::string sub_key) {
|
||||
dbc::check($config.contains(main_key), format("ERROR wstring main/key in config, main_key {} doesn't exist.", main_key));
|
||||
dbc::check($config[main_key].contains(sub_key), format("ERROR wstring in config, main_key/key {}/{} doesn't exist.", main_key, sub_key));
|
||||
|
||||
const std::string& str_val = $config[main_key][sub_key];
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||
return $converter.from_bytes(str_val);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue