diff --git a/.clang-format b/.clang-format index 6843477..441c990 100644 --- a/.clang-format +++ b/.clang-format @@ -10,10 +10,12 @@ AllowShortLoopsOnASingleLine: true BasedOnStyle: Chromium BinPackArguments: false BinPackParameters: false +ColumnLimit: 100 FixNamespaceComments: false IndentAccessModifiers: false IndentExternBlock: Indent NamespaceIndentation: All +SkipMacroDefinitionBody: true SpaceBeforeCpp11BracedList: true SpacesBeforeTrailingComments: 1 diff --git a/include/util/macros.h b/include/util/macros.h index f5fe51b..4a2e07a 100644 --- a/include/util/macros.h +++ b/include/util/macros.h @@ -1,3 +1,13 @@ +#pragma once + #define fn auto + #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; } + +#define DEF_IMPL(struct_name, lower_name, ...) \ + struct struct_name##Impl { \ + __VA_ARGS__; \ + static fn from_class(const struct_name& lower_name) -> struct_name##Impl; \ + [[nodiscard]] fn to_class() const -> struct_name; \ + }; diff --git a/meson.build b/meson.build index 87989f9..eb0e6bb 100644 --- a/meson.build +++ b/meson.build @@ -98,7 +98,7 @@ if host_machine.system() == 'linux' endif incdir = include_directories( - 'include', + ['include', '/nix/store/pp85qmfpf239b75sm23hhx6cvxfrr4p9-fmt-10.2.1-dev/include'], is_system: true # Ignores warnings from include dir ) diff --git a/src/config/config.cpp b/src/config/config.cpp index 6c59238..df02270 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -32,7 +32,7 @@ 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 { +fn GeneralImpl::from_class(const General& general) -> GeneralImpl { return {general.getName()}; } @@ -46,8 +46,7 @@ DEFINE_GETTER(NowPlaying, bool, Enabled) NowPlaying::NowPlaying(bool enabled) : m_Enabled(enabled) {} -fn NowPlayingImpl::from_class(const NowPlaying& now_playing -) noexcept -> NowPlayingImpl { +fn NowPlayingImpl::from_class(const NowPlaying& now_playing) -> NowPlayingImpl { return {.enabled = now_playing.getEnabled()}; } @@ -74,7 +73,7 @@ fn Config::getInstance() -> const Config& { return *INSTANCE; } -fn ConfigImpl::from_class(const Config& config) noexcept -> ConfigImpl { +fn ConfigImpl::from_class(const Config& config) -> ConfigImpl { return { .general = config.getGeneral(), .now_playing = config.getNowPlaying(), diff --git a/src/config/config.h b/src/config/config.h index 940e8b4..fe34a54 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -20,14 +20,6 @@ class General { [[nodiscard]] fn getName() const -> const std::string; }; -struct GeneralImpl { - std::string name; - - static fn from_class(const General& general) noexcept -> GeneralImpl; - - [[nodiscard]] fn to_class() const -> General; -}; - class NowPlaying { private: bool m_Enabled; @@ -38,15 +30,6 @@ class NowPlaying { [[nodiscard]] fn getEnabled() const -> bool; }; -struct NowPlayingImpl { - std::optional enabled; - - static fn from_class(const NowPlaying& now_playing - ) noexcept -> NowPlayingImpl; - - [[nodiscard]] fn to_class() const -> NowPlaying; -}; - class Config { private: General m_General; @@ -63,42 +46,21 @@ class Config { [[nodiscard]] fn getNowPlaying() const -> const NowPlaying; }; -struct ConfigImpl { - General general; - NowPlaying now_playing; - Weather weather; +// Reflect-CPP Stuff +DEF_IMPL(General, general, std::string name) +DEF_IMPL(NowPlaying, now_playing, std::optional enabled) +DEF_IMPL(Config, config, General general; NowPlaying now_playing; Weather weather) - static fn from_class(const Config& config) noexcept -> ConfigImpl; - - [[nodiscard]] fn to_class() const -> Config; -}; - -// Parsers for Config classes namespace rfl::parsing { template struct Parser - : public CustomParser< - ReaderType, - WriterType, - ProcessorsType, - General, - GeneralImpl> {}; + : public CustomParser {}; template struct Parser - : public CustomParser< - ReaderType, - WriterType, - ProcessorsType, - NowPlaying, - NowPlayingImpl> {}; + : public CustomParser {}; template struct Parser - : public CustomParser< - ReaderType, - WriterType, - ProcessorsType, - Config, - ConfigImpl> {}; + : public CustomParser {}; }