From 455261a8dc24068586a718f98926183ad7397d45 Mon Sep 17 00:00:00 2001 From: nekobit Date: Sun, 2 Oct 2022 05:10:13 +0000 Subject: [PATCH] Config singleton FossilOrigin-Name: 49a2dd0e8e60f2fda887dd815ef38ad140c22ccffbd85338553aa17b033c882c --- src/config/config_http.h | 21 +++++++++++++++++++++ src/config/config_loader.cpp | 20 ++++++++++++++++++++ src/config/config_loader.h | 18 +++++++++++++++--- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/config/config_http.h diff --git a/src/config/config_http.h b/src/config/config_http.h new file mode 100644 index 0000000..f31cdc8 --- /dev/null +++ b/src/config/config_http.h @@ -0,0 +1,21 @@ +/* + * Wormhole - Federated social network + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#pragma once + + diff --git a/src/config/config_loader.cpp b/src/config/config_loader.cpp index 8ad7d29..3421e03 100644 --- a/src/config/config_loader.cpp +++ b/src/config/config_loader.cpp @@ -17,8 +17,28 @@ */ #include "config_loader.h" +#include "config_http.h" using namespace Config; +namespace +{ + // Global instance + ConfigLoader inst{}; +} + +ConfigLoader& instance() +{ + return inst; +} + ConfigLoader::ConfigLoader() {} + +void ConfigLoader::load_config(const std::filesystem::path& path) +{ + // Make sure it's loaded + YAML::Node node = YAML::LoadFile(path); + + +} diff --git a/src/config/config_loader.h b/src/config/config_loader.h index 5611bfb..d79f143 100644 --- a/src/config/config_loader.h +++ b/src/config/config_loader.h @@ -18,7 +18,9 @@ #pragma once +#include #include +#include namespace Config { @@ -27,8 +29,18 @@ namespace Config public: ConfigLoader(); ~ConfigLoader() = default; - private: - /** @brief Config parser for YAML */ - YAML::Node cfg; + + void load_config(const std::filesystem::path& path); + + /** + * @brief List of commonly used configuration options + */ + struct CommonConfig + { + Config::HTTP http; + } config; }; + + // Global instance of config + ConfigLoader& instance(); }