IOCore/include/JsonConfigFile.hpp
S David 98e672042d
Some checks failed
buildbot/IOCore-linux-builder Build done.
buildbot/IOCore-macos-builder Build done.
Fix namespace for JsonConfigFile; Add missing dependencies (how was this working?)
2024-06-06 08:09:31 -04:00

56 lines
1.1 KiB
C++

/* JsonConfigFile.hpp
* Copyright © 2024 Saul D. Beniquez
* License: Mozilla Public License v. 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v.2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "FileResource.hpp"
#include "types.hpp"
#include <filesystem>
#include <nlohmann/json.hpp>
namespace IOCore {
class JsonConfigFile : public FileResource {
public:
JsonConfigFile(
const std::filesystem::path& file_path,
CreateDirs mode = CreateDirs::Disable
);
~JsonConfigFile() override;
auto read() -> nlohmann::json&;
void write();
template<typename T_>
[[nodiscard]] auto get() const -> T_
{
return config_json.get<T_>();
}
template<typename T_>
void set(const T_& value)
{
config_json = value;
}
auto getJsonData() -> nlohmann::json& { return this->config_json; };
protected:
nlohmann::json config_json;
private:
};
} // namespace IOCore
// clang-format off
// vim: set foldmethod=syntax foldlevel=1 foldminlines=12 textwidth=80 ts=8 sts=0 sw=8 noexpandtab ft=cpp.doxygen :