From 8062fadbd4a2b7b5f67a201423add40b86ddff0c Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 27 Apr 2025 19:45:50 +0200 Subject: [PATCH] App: Replace C macros with lambda expression --- src/App/PreCompiled.h | 1 + src/App/Property.cpp | 45 ++++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/App/PreCompiled.h b/src/App/PreCompiled.h index 8b32f51627..973723687d 100644 --- a/src/App/PreCompiled.h +++ b/src/App/PreCompiled.h @@ -50,6 +50,7 @@ #include // STL +#include #include #include #if defined(FC_OS_WIN32) diff --git a/src/App/Property.cpp b/src/App/Property.cpp index 491e060b35..a00a6e6ab9 100644 --- a/src/App/Property.cpp +++ b/src/App/Property.cpp @@ -23,6 +23,8 @@ ***************************************************************************/ #include +#include +#include #include #include @@ -114,36 +116,35 @@ std::string Property::getFileName(const char* postfix, const char* prefix) const return ss.str(); } +// clang-format off +static constexpr auto mapProps = std::to_array>({ + {App::Property::PropReadOnly, Prop_ReadOnly}, + {App::Property::PropHidden, Prop_Hidden}, + {App::Property::PropOutput, Prop_Output}, + {App::Property::PropTransient, Prop_Transient}, + {App::Property::PropNoRecompute, Prop_NoRecompute}, + {App::Property::PropNoPersist, Prop_NoPersist} +}); +// clang-format on + short Property::getType() const { short type = 0; -#define GET_PTYPE(_name) \ - do { \ - if (testStatus(App::Property::Prop##_name)) \ - type |= Prop_##_name; \ - } while (0) - GET_PTYPE(ReadOnly); - GET_PTYPE(Hidden); - GET_PTYPE(Output); - GET_PTYPE(Transient); - GET_PTYPE(NoRecompute); - GET_PTYPE(NoPersist); + for (const auto& [propertyStatus, propertyType] : mapProps) { + if (testStatus(propertyStatus)) { + type |= propertyType; + } + } return type; } void Property::syncType(unsigned type) { -#define SYNC_PTYPE(_name) \ - do { \ - if (type & Prop_##_name) \ - StatusBits.set((size_t)Prop##_name); \ - } while (0) - SYNC_PTYPE(ReadOnly); - SYNC_PTYPE(Transient); - SYNC_PTYPE(Hidden); - SYNC_PTYPE(Output); - SYNC_PTYPE(NoRecompute); - SYNC_PTYPE(NoPersist); + for (const auto& [propertyStatus, propertyType] : mapProps) { + if (type & propertyType) { + StatusBits.set((size_t)propertyStatus); + } + } } const char* Property::getGroup() const