This commit is contained in:
Mars 2024-06-15 16:57:16 -04:00
parent 81cb6b5d4a
commit f668a2eb4c
Signed by: pupbrained
GPG key ID: 874E22DF2F9DFCB5
4 changed files with 26 additions and 21 deletions

View file

@ -14,6 +14,7 @@ ColumnLimit: 100
FixNamespaceComments: false FixNamespaceComments: false
IndentAccessModifiers: false IndentAccessModifiers: false
IndentExternBlock: Indent IndentExternBlock: Indent
IndentPPDirectives: BeforeHash
NamespaceIndentation: All NamespaceIndentation: All
SkipMacroDefinitionBody: true SkipMacroDefinitionBody: true
SpaceBeforeCpp11BracedList: true SpaceBeforeCpp11BracedList: true

View file

@ -1,10 +1,27 @@
#pragma once #pragma once
/**
* @brief Allows for rust-style function definitions
*/
#define fn auto #define fn auto
/**
* @brief Allows for easy getter creation
*
* @param class_name The class to use
* @param type Type of the getter
* @param name Name of the getter
*/
#define DEFINE_GETTER(class_name, type, name) \ #define DEFINE_GETTER(class_name, type, name) \
fn class_name::get##name() const -> type { return m_##name; } fn class_name::get##name() const -> type { return m_##name; }
/**
* @brief Helper for making reflect-cpp impls
*
* @param struct_name The struct name
* @param lower_name The arg name
* @param ... Values of the class to convert
*/
#define DEF_IMPL(struct_name, lower_name, ...) \ #define DEF_IMPL(struct_name, lower_name, ...) \
struct struct_name##Impl { \ struct struct_name##Impl { \
__VA_ARGS__; \ __VA_ARGS__; \

View file

@ -8,9 +8,7 @@ DEFINE_GETTER(Weather, const std::string, ApiKey)
DEFINE_GETTER(Weather, const std::string, Units) DEFINE_GETTER(Weather, const std::string, Units)
Weather::Weather(Location location, std::string api_key, std::string units) Weather::Weather(Location location, std::string api_key, std::string units)
: m_Location(std::move(location)), : m_Location(std::move(location)), m_ApiKey(std::move(api_key)), m_Units(std::move(units)) {}
m_ApiKey(std::move(api_key)),
m_Units(std::move(units)) {}
fn WeatherImpl::from_class(const Weather& weather) noexcept -> WeatherImpl { fn WeatherImpl::from_class(const Weather& weather) noexcept -> WeatherImpl {
return { return {
@ -20,9 +18,7 @@ fn WeatherImpl::from_class(const Weather& weather) noexcept -> WeatherImpl {
}; };
} }
fn WeatherImpl::to_class() const -> Weather { fn WeatherImpl::to_class() const -> Weather { return {location, api_key, units}; }
return {location, api_key, units};
}
// ------------ // ------------
// ------------- // -------------
@ -32,9 +28,7 @@ DEFINE_GETTER(General, const std::string, Name)
General::General(std::string name) : m_Name(std::move(name)) {} General::General(std::string name) : m_Name(std::move(name)) {}
fn GeneralImpl::from_class(const General& general) -> GeneralImpl { fn GeneralImpl::from_class(const General& general) -> GeneralImpl { return {general.getName()}; }
return {general.getName()};
}
fn GeneralImpl::to_class() const -> General { return {name}; } fn GeneralImpl::to_class() const -> General { return {name}; }
// ------------- // -------------
@ -50,9 +44,7 @@ fn NowPlayingImpl::from_class(const NowPlaying& now_playing) -> NowPlayingImpl {
return {.enabled = now_playing.getEnabled()}; return {.enabled = now_playing.getEnabled()};
} }
fn NowPlayingImpl::to_class() const -> NowPlaying { fn NowPlayingImpl::to_class() const -> NowPlaying { return {enabled.value_or(false)}; }
return {enabled.value_or(false)};
}
// ---------------- // ----------------
// ------------ // ------------
@ -63,13 +55,10 @@ DEFINE_GETTER(Config, const NowPlaying, NowPlaying)
DEFINE_GETTER(Config, const Weather, Weather) DEFINE_GETTER(Config, const Weather, Weather)
Config::Config(General general, NowPlaying now_playing, Weather weather) Config::Config(General general, NowPlaying now_playing, Weather weather)
: m_General(std::move(general)), : m_General(std::move(general)), m_NowPlaying(now_playing), m_Weather(std::move(weather)) {}
m_NowPlaying(now_playing),
m_Weather(std::move(weather)) {}
fn Config::getInstance() -> const Config& { fn Config::getInstance() -> const Config& {
static const auto* INSTANCE = static const auto* INSTANCE = new Config(rfl::toml::load<Config>("./config.toml").value());
new Config(rfl::toml::load<Config>("./config.toml").value());
return *INSTANCE; return *INSTANCE;
} }
@ -81,7 +70,5 @@ fn ConfigImpl::from_class(const Config& config) -> ConfigImpl {
}; };
} }
fn ConfigImpl::to_class() const -> Config { fn ConfigImpl::to_class() const -> Config { return {general, now_playing, weather}; }
return {general, now_playing, weather};
}
// ------------ // ------------

View file

@ -46,7 +46,7 @@ class Config {
[[nodiscard]] fn getNowPlaying() const -> const NowPlaying; [[nodiscard]] fn getNowPlaying() const -> const NowPlaying;
}; };
// Reflect-CPP Stuff // reflect-cpp Stuff
DEF_IMPL(General, general, std::string name) DEF_IMPL(General, general, std::string name)
DEF_IMPL(NowPlaying, now_playing, std::optional<bool> enabled) DEF_IMPL(NowPlaying, now_playing, std::optional<bool> enabled)
DEF_IMPL(Config, config, General general; NowPlaying now_playing; Weather weather) DEF_IMPL(Config, config, General general; NowPlaying now_playing; Weather weather)