some cleanup and stuff
This commit is contained in:
parent
138191227f
commit
afbba70f92
13 changed files with 203 additions and 160 deletions
|
@ -1,32 +1,12 @@
|
|||
#include "config.h"
|
||||
|
||||
#define DEFINE_GETTER(class_name, type, name) \
|
||||
fn class_name::get##name() const->type { return m_##name; }
|
||||
|
||||
DEFINE_GETTER(Config, const General, General)
|
||||
DEFINE_GETTER(Config, const NowPlaying, NowPlaying)
|
||||
DEFINE_GETTER(Config, const Weather, Weather)
|
||||
DEFINE_GETTER(General, const std::string, Name)
|
||||
DEFINE_GETTER(NowPlaying, bool, Enabled)
|
||||
// -------------
|
||||
// -- Weather --
|
||||
// -------------
|
||||
DEFINE_GETTER(Weather, const Weather::Location, Location)
|
||||
DEFINE_GETTER(Weather, const std::string, ApiKey)
|
||||
DEFINE_GETTER(Weather, const std::string, Units)
|
||||
|
||||
fn Config::getInstance() -> const Config& {
|
||||
static const auto* INSTANCE =
|
||||
new Config(rfl::toml::load<Config>("./config.toml").value());
|
||||
return *INSTANCE;
|
||||
}
|
||||
|
||||
Config::Config(General general, NowPlaying now_playing, Weather weather)
|
||||
: m_General(std::move(general)),
|
||||
m_NowPlaying(now_playing),
|
||||
m_Weather(std::move(weather)) {}
|
||||
|
||||
General::General(std::string name) : m_Name(std::move(name)) {}
|
||||
|
||||
NowPlaying::NowPlaying(bool enabled) : m_Enabled(enabled) {}
|
||||
|
||||
Weather::Weather(Location location, std::string api_key, std::string units)
|
||||
: m_Location(std::move(location)),
|
||||
m_ApiKey(std::move(api_key)),
|
||||
|
@ -43,22 +23,56 @@ fn WeatherImpl::from_class(const Weather& weather) noexcept -> WeatherImpl {
|
|||
fn WeatherImpl::to_class() const -> Weather {
|
||||
return {location, api_key, units};
|
||||
}
|
||||
// ------------
|
||||
|
||||
// -------------
|
||||
// -- General --
|
||||
// -------------
|
||||
DEFINE_GETTER(General, const std::string, Name)
|
||||
|
||||
General::General(std::string name) : m_Name(std::move(name)) {}
|
||||
|
||||
fn GeneralImpl::from_class(const General& general) noexcept -> GeneralImpl {
|
||||
return {general.getName()};
|
||||
}
|
||||
|
||||
fn GeneralImpl::to_class() const -> General { return {name}; }
|
||||
// -------------
|
||||
|
||||
// clang-format off
|
||||
fn NowPlayingImpl::from_class(
|
||||
const NowPlaying& now_playing
|
||||
// ----------------
|
||||
// -- NowPlaying --
|
||||
// ----------------
|
||||
DEFINE_GETTER(NowPlaying, bool, Enabled)
|
||||
|
||||
NowPlaying::NowPlaying(bool enabled) : m_Enabled(enabled) {}
|
||||
|
||||
fn NowPlayingImpl::from_class(const NowPlaying& now_playing
|
||||
) noexcept -> NowPlayingImpl {
|
||||
return {.enabled = now_playing.getEnabled()};
|
||||
}
|
||||
//clang-format on
|
||||
|
||||
fn NowPlayingImpl::to_class() const -> NowPlaying { return {enabled.value_or(false)}; }
|
||||
fn NowPlayingImpl::to_class() const -> NowPlaying {
|
||||
return {enabled.value_or(false)};
|
||||
}
|
||||
// ----------------
|
||||
|
||||
// ------------
|
||||
// -- Config --
|
||||
// ------------
|
||||
DEFINE_GETTER(Config, const General, General)
|
||||
DEFINE_GETTER(Config, const NowPlaying, NowPlaying)
|
||||
DEFINE_GETTER(Config, const Weather, Weather)
|
||||
|
||||
Config::Config(General general, NowPlaying now_playing, Weather weather)
|
||||
: m_General(std::move(general)),
|
||||
m_NowPlaying(now_playing),
|
||||
m_Weather(std::move(weather)) {}
|
||||
|
||||
fn Config::getInstance() -> const Config& {
|
||||
static const auto* INSTANCE =
|
||||
new Config(rfl::toml::load<Config>("./config.toml").value());
|
||||
return *INSTANCE;
|
||||
}
|
||||
|
||||
fn ConfigImpl::from_class(const Config& config) noexcept -> ConfigImpl {
|
||||
return {
|
||||
|
@ -71,3 +85,4 @@ fn ConfigImpl::from_class(const Config& config) noexcept -> ConfigImpl {
|
|||
fn ConfigImpl::to_class() const -> Config {
|
||||
return {general, now_playing, weather};
|
||||
}
|
||||
// ------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue