/* This file is part of FediPotato. * Copyright © 2020 tastytea * * 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, version 3. * * 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 . */ #ifndef FEDIPOTATO_CONFIG_HPP #define FEDIPOTATO_CONFIG_HPP #include #if __has_include() # include #else # include #endif #include #include namespace FediPotato { using json = nlohmann::json; namespace fs = std::filesystem; using std::string; using std::string_view; /*! * @brief Read and write the configuration. * * @since 0.1.0 * * @headerfile config.hpp FediPotato/config.hpp */ class Config { public: /*! * @brief Construct a Config object. * * @param application_name The name of your application. * @param filename The filename to open. * * @since 0.1.0 */ explicit Config(string_view application_name, string_view filename); //! Copy constructor Config(const Config &other) = default; //! Move constructor Config(Config &&other) noexcept = default; //! Destructor virtual ~Config() noexcept = default; //! Copy assignment operator Config& operator=(const Config &other) = delete; //! Move assignment operator Config& operator=(Config &&other) noexcept = delete; public: /*! * @brief Read and parse the configuration file. * * @since 0.1.0 */ void read(); /*! * @brief Set a configuration setting. * * @param key The key of the setting. * @param value The value of the setting. * * @since 0.1.0 */ void set(string_view key, string_view value); private: const string _filename; const fs::path _filepath; json _configfile; }; } // namespace FediPotato #endif // FEDIPOTATO_CONFIG_HPP