:3
This commit is contained in:
parent
94d08a02d6
commit
4d1e69bbe5
8 changed files with 167 additions and 133 deletions
|
@ -1,7 +1,7 @@
|
|||
#include "config.h"
|
||||
|
||||
#define DEFINE_GETTER(class_name, type, name) \
|
||||
type class_name::get##name() const { return m_##name; }
|
||||
fn class_name::get##name() const->type { return m_##name; }
|
||||
|
||||
DEFINE_GETTER(Config, const General, General)
|
||||
DEFINE_GETTER(Config, const NowPlaying, NowPlaying)
|
||||
|
@ -12,7 +12,7 @@ DEFINE_GETTER(Weather, const Weather::Location, Location)
|
|||
DEFINE_GETTER(Weather, const std::string, ApiKey)
|
||||
DEFINE_GETTER(Weather, const std::string, Units)
|
||||
|
||||
const Config& Config::getInstance() {
|
||||
fn Config::getInstance() -> const Config& {
|
||||
static const auto* INSTANCE =
|
||||
new Config(rfl::toml::load<Config>("./config.toml").value());
|
||||
return *INSTANCE;
|
||||
|
@ -25,14 +25,14 @@ Config::Config(General general, NowPlaying now_playing, Weather weather)
|
|||
|
||||
General::General(std::string name) : m_Name(std::move(name)) {}
|
||||
|
||||
NowPlaying::NowPlaying(bool enable) : m_Enabled(enable) {}
|
||||
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)),
|
||||
m_Units(std::move(units)) {}
|
||||
|
||||
WeatherImpl WeatherImpl::from_class(const Weather& weather) noexcept {
|
||||
fn WeatherImpl::from_class(const Weather& weather) noexcept -> WeatherImpl {
|
||||
return {
|
||||
.location = weather.getLocation(),
|
||||
.api_key = weather.getApiKey(),
|
||||
|
@ -40,22 +40,27 @@ WeatherImpl WeatherImpl::from_class(const Weather& weather) noexcept {
|
|||
};
|
||||
}
|
||||
|
||||
Weather WeatherImpl::to_class() const { return {location, api_key, units}; }
|
||||
fn WeatherImpl::to_class() const -> Weather {
|
||||
return {location, api_key, units};
|
||||
}
|
||||
|
||||
GeneralImpl GeneralImpl::from_class(const General& general) noexcept {
|
||||
fn GeneralImpl::from_class(const General& general) noexcept -> GeneralImpl {
|
||||
return {general.getName()};
|
||||
}
|
||||
|
||||
General GeneralImpl::to_class() const { return {name}; }
|
||||
fn GeneralImpl::to_class() const -> General { return {name}; }
|
||||
|
||||
NowPlayingImpl NowPlayingImpl::from_class(
|
||||
const NowPlaying& now_playing) noexcept {
|
||||
// clang-format off
|
||||
fn NowPlayingImpl::from_class(
|
||||
const NowPlaying& now_playing
|
||||
) noexcept -> NowPlayingImpl {
|
||||
return {.enabled = now_playing.getEnabled()};
|
||||
}
|
||||
//clang-format on
|
||||
|
||||
NowPlaying NowPlayingImpl::to_class() const { return {enabled}; }
|
||||
fn NowPlayingImpl::to_class() const -> NowPlaying { return {enabled}; }
|
||||
|
||||
ConfigImpl ConfigImpl::from_class(const Config& config) noexcept {
|
||||
fn ConfigImpl::from_class(const Config& config) noexcept -> ConfigImpl {
|
||||
return {
|
||||
.general = config.getGeneral(),
|
||||
.now_playing = config.getNowPlaying(),
|
||||
|
@ -63,4 +68,6 @@ ConfigImpl ConfigImpl::from_class(const Config& config) noexcept {
|
|||
};
|
||||
}
|
||||
|
||||
Config ConfigImpl::to_class() const { return {general, now_playing, weather}; }
|
||||
fn ConfigImpl::to_class() const -> Config {
|
||||
return {general, now_playing, weather};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue