draconisplusplus/src/config/config.h

143 lines
3.4 KiB
C
Raw Normal View History

2024-05-31 22:59:00 -04:00
#pragma once
2024-06-02 01:24:33 -04:00
#include <cpr/cpr.h>
2024-06-01 06:59:01 -04:00
#include <fmt/core.h>
2024-06-02 01:24:33 -04:00
#include <fmtlog.h>
2024-05-31 22:59:00 -04:00
#include <toml++/toml.h>
2024-06-01 06:59:01 -04:00
#include <unistd.h>
2024-06-02 01:24:33 -04:00
#include <boost/json.hpp>
2024-06-01 06:59:01 -04:00
#include <rfl.hpp>
2024-05-31 22:59:00 -04:00
#include <string>
2024-06-01 06:59:01 -04:00
#include <toml++/impl/parser.hpp>
#include <variant>
2024-05-31 22:59:00 -04:00
using std::string;
2024-06-01 06:59:01 -04:00
struct Coords {
double lat;
double lon;
};
using Location = std::variant<string, Coords>;
2024-05-31 22:59:00 -04:00
class Weather {
private:
2024-06-01 06:59:01 -04:00
Location m_Location;
string m_ApiKey;
string m_Units;
2024-05-31 22:59:00 -04:00
public:
2024-06-01 06:59:01 -04:00
Weather(Location location, string api_key, string units);
2024-06-02 01:24:33 -04:00
[[nodiscard]] boost::json::object getWeatherInfo() const;
2024-06-01 06:59:01 -04:00
[[nodiscard]] const Location getLocation() const;
[[nodiscard]] const string getApiKey() const;
[[nodiscard]] const string getUnits() const;
};
struct WeatherImpl {
Location location;
string api_key;
string units;
2024-05-31 22:59:00 -04:00
2024-06-01 06:59:01 -04:00
static WeatherImpl from_class(const Weather& weather) noexcept;
2024-05-31 22:59:00 -04:00
2024-06-01 06:59:01 -04:00
[[nodiscard]] Weather to_class() const;
2024-05-31 22:59:00 -04:00
};
class General {
private:
2024-06-01 06:59:01 -04:00
string m_Name;
2024-05-31 22:59:00 -04:00
public:
2024-06-01 06:59:01 -04:00
General(string name);
2024-05-31 22:59:00 -04:00
2024-06-01 06:59:01 -04:00
[[nodiscard]] const string getName() const;
};
struct GeneralImpl {
string name;
static GeneralImpl from_class(const General& general) noexcept;
[[nodiscard]] General to_class() const;
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-01 06:59:01 -04:00
NowPlaying(bool enable);
2024-05-31 22:59:00 -04:00
2024-06-01 06:59:01 -04:00
[[nodiscard]] bool getEnabled() const;
};
struct NowPlayingImpl {
bool enabled;
static NowPlayingImpl from_class(const NowPlaying& now_playing) noexcept;
[[nodiscard]] NowPlaying to_class() const;
2024-05-31 22:59:00 -04:00
};
class Config {
private:
2024-06-01 06:59:01 -04:00
General m_General;
NowPlaying m_NowPlaying;
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);
static const Config& getInstance();
2024-05-31 22:59:00 -04:00
2024-06-01 06:59:01 -04:00
[[nodiscard]] const Weather getWeather() const;
[[nodiscard]] const General getGeneral() const;
[[nodiscard]] const NowPlaying getNowPlaying() const;
2024-05-31 22:59:00 -04:00
};
2024-06-01 06:59:01 -04:00
struct ConfigImpl {
General general;
NowPlaying now_playing;
Weather weather;
static ConfigImpl from_class(const Config& config) noexcept;
[[nodiscard]] Config to_class() const;
};
namespace rfl::parsing {
template <class ReaderType, class WriterType, class ProcessorsType>
struct Parser<ReaderType, WriterType, Weather, ProcessorsType>
: public CustomParser<ReaderType,
WriterType,
ProcessorsType,
Weather,
WeatherImpl> {};
template <class ReaderType, class WriterType, class ProcessorsType>
struct Parser<ReaderType, WriterType, General, ProcessorsType>
: public CustomParser<ReaderType,
WriterType,
ProcessorsType,
General,
GeneralImpl> {};
template <class ReaderType, class WriterType, class ProcessorsType>
struct Parser<ReaderType, WriterType, NowPlaying, ProcessorsType>
: public CustomParser<ReaderType,
WriterType,
ProcessorsType,
NowPlaying,
NowPlayingImpl> {};
template <class ReaderType, class WriterType, class ProcessorsType>
struct Parser<ReaderType, WriterType, Config, ProcessorsType>
: public CustomParser<ReaderType,
WriterType,
ProcessorsType,
Config,
ConfigImpl> {};
} // namespace rfl::parsing