[nostalgia/studio] Change configio functions to take auto string type

This commit is contained in:
Gary Talent 2022-07-10 15:51:04 -05:00
parent fdc57ce7b8
commit 6908199428

View File

@ -36,8 +36,8 @@ constexpr auto ConfigDir = [] {
}(); }();
template<typename T> template<typename T>
ox::Result<T> readConfig(core::Context *ctx, const ox::String &name) noexcept { ox::Result<T> readConfig(core::Context *ctx, const char *name) noexcept {
oxAssert(name != "", "Config type has no TypeName"); oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
const auto homeDir = std::getenv("HOME"); const auto homeDir = std::getenv("HOME");
const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString(); const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString();
const auto path = ox::sfmt("{}/{}.json", configPath, name).toStdString(); const auto path = ox::sfmt("{}/{}.json", configPath, name).toStdString();
@ -65,8 +65,8 @@ ox::Result<T> readConfig(core::Context *ctx) noexcept {
} }
template<typename T> template<typename T>
ox::Error writeConfig(core::Context *ctx, const ox::String &name, T *data) noexcept { ox::Error writeConfig(core::Context *ctx, const auto &name, T *data) noexcept {
oxAssert(name != "", "Config type has no TypeName"); oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
const auto homeDir = std::getenv("HOME"); const auto homeDir = std::getenv("HOME");
const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString(); const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString();
const auto path = ox::sfmt("{}/{}.json", configPath, name).toStdString(); const auto path = ox::sfmt("{}/{}.json", configPath, name).toStdString();
@ -98,7 +98,7 @@ ox::Error writeConfig(core::Context *ctx, T *data) noexcept {
} }
template<typename T, typename Func> template<typename T, typename Func>
void openConfig(core::Context *ctx, const ox::String &name, Func f) noexcept { void openConfig(core::Context *ctx, const auto &name, Func f) noexcept {
oxAssert(name != "", "Config type has no TypeName"); oxAssert(name != "", "Config type has no TypeName");
const auto c = readConfig<T>(ctx, name); const auto c = readConfig<T>(ctx, name);
f(&c.value); f(&c.value);
@ -111,8 +111,8 @@ void openConfig(core::Context *ctx, Func f) noexcept {
} }
template<typename T, typename Func> template<typename T, typename Func>
void editConfig(core::Context *ctx, const ox::String &name, Func f) noexcept { void editConfig(core::Context *ctx, const auto &name, Func f) noexcept {
oxAssert(name != "", "Config type has no TypeName"); oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
auto c = readConfig<T>(ctx, name); auto c = readConfig<T>(ctx, name);
f(&c.value); f(&c.value);
oxLogError(writeConfig(ctx, name, &c.value)); oxLogError(writeConfig(ctx, name, &c.value));