draconisplusplus/src/config/config.h

105 lines
2.3 KiB
C
Raw Normal View History

2024-06-07 04:23:11 -04:00
#pragma once
2024-06-01 06:59:01 -04:00
#include <fmt/core.h>
#include <rfl.hpp>
2024-06-05 19:04:53 -04:00
#include <rfl/toml.hpp>
2024-05-31 22:59:00 -04:00
#include <string>
2024-06-14 01:41:59 -04:00
#include "util/macros.h"
#include "weather.h"
2024-05-31 22:59:00 -04:00
2024-06-14 01:41:59 -04:00
// TODO: Make config values optional and supply defaults
2024-05-31 22:59:00 -04:00
class General {
private:
2024-06-07 04:23:11 -04:00
std::string m_Name;
2024-05-31 22:59:00 -04:00
public:
2024-06-07 04:23:11 -04:00
General(std::string name);
2024-05-31 22:59:00 -04:00
2024-06-09 20:14:51 -04:00
[[nodiscard]] fn getName() const -> const std::string;
2024-06-01 06:59:01 -04:00
};
struct GeneralImpl {
2024-06-07 04:23:11 -04:00
std::string name;
2024-06-01 06:59:01 -04:00
2024-06-09 20:14:51 -04:00
static fn from_class(const General& general) noexcept -> GeneralImpl;
2024-06-01 06:59:01 -04:00
2024-06-09 20:14:51 -04:00
[[nodiscard]] fn to_class() const -> General;
2024-05-31 22:59:00 -04:00
};
class NowPlaying {
private:
2024-06-01 06:59:01 -04:00
bool m_Enabled;
2024-05-31 22:59:00 -04:00
public:
2024-06-02 06:03:21 -04:00
NowPlaying(bool enabled);
2024-05-31 22:59:00 -04:00
2024-06-09 20:14:51 -04:00
[[nodiscard]] fn getEnabled() const -> bool;
2024-06-01 06:59:01 -04:00
};
struct NowPlayingImpl {
2024-06-14 00:48:32 -04:00
std::optional<bool> enabled;
2024-06-01 06:59:01 -04:00
2024-06-09 20:14:51 -04:00
static fn from_class(const NowPlaying& now_playing
) noexcept -> NowPlayingImpl;
2024-06-01 06:59:01 -04:00
2024-06-09 20:14:51 -04:00
[[nodiscard]] fn to_class() const -> NowPlaying;
2024-05-31 22:59:00 -04:00
};
class Config {
private:
2024-06-09 20:14:51 -04:00
General m_General;
2024-06-01 06:59:01 -04:00
NowPlaying m_NowPlaying;
2024-06-09 20:14:51 -04:00
Weather m_Weather;
2024-05-31 22:59:00 -04:00
2024-06-01 06:59:01 -04:00
public:
Config(General general, NowPlaying now_playing, Weather weather);
2024-06-09 20:14:51 -04:00
static fn getInstance() -> const Config&;
2024-05-31 22:59:00 -04:00
2024-06-09 20:14:51 -04:00
[[nodiscard]] fn getWeather() const -> const Weather;
[[nodiscard]] fn getGeneral() const -> const General;
[[nodiscard]] fn getNowPlaying() const -> const NowPlaying;
2024-05-31 22:59:00 -04:00
};
2024-06-01 06:59:01 -04:00
struct ConfigImpl {
2024-06-09 20:14:51 -04:00
General general;
2024-06-01 06:59:01 -04:00
NowPlaying now_playing;
2024-06-09 20:14:51 -04:00
Weather weather;
2024-06-01 06:59:01 -04:00
2024-06-09 20:14:51 -04:00
static fn from_class(const Config& config) noexcept -> ConfigImpl;
2024-06-01 06:59:01 -04:00
2024-06-09 20:14:51 -04:00
[[nodiscard]] fn to_class() const -> Config;
2024-06-01 06:59:01 -04:00
};
2024-06-02 06:03:21 -04:00
// Parsers for Config classes
2024-06-01 06:59:01 -04:00
namespace rfl::parsing {
template <class ReaderType, class WriterType, class ProcessorsType>
struct Parser<ReaderType, WriterType, General, ProcessorsType>
2024-06-09 20:14:51 -04:00
: public CustomParser<
ReaderType,
WriterType,
ProcessorsType,
General,
GeneralImpl> {};
2024-06-01 06:59:01 -04:00
template <class ReaderType, class WriterType, class ProcessorsType>
struct Parser<ReaderType, WriterType, NowPlaying, ProcessorsType>
2024-06-09 20:14:51 -04:00
: public CustomParser<
ReaderType,
WriterType,
ProcessorsType,
NowPlaying,
NowPlayingImpl> {};
2024-06-01 06:59:01 -04:00
template <class ReaderType, class WriterType, class ProcessorsType>
struct Parser<ReaderType, WriterType, Config, ProcessorsType>
2024-06-09 20:14:51 -04:00
: public CustomParser<
ReaderType,
WriterType,
ProcessorsType,
Config,
ConfigImpl> {};
2024-06-14 01:41:59 -04:00
}