From ee2079ec3541f365a2d216591ba798d43136cb8c Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" <277429+mackal@users.noreply.github.com> Date: Tue, 17 Jan 2023 16:21:01 -0500 Subject: [PATCH] [C++20] Arithmetic on different enums is deprecated (#2752) Just do some casts and add some constants to make life easier --- common/rulesys.cpp | 22 +++++++++++----------- common/rulesys.h | 28 +++++++++++++++++----------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/common/rulesys.cpp b/common/rulesys.cpp index b58e83e6a..ce35b7c09 100644 --- a/common/rulesys.cpp +++ b/common/rulesys.cpp @@ -34,7 +34,7 @@ const char *RuleManager::s_categoryNames[_CatCount + 1] = { "InvalidCategory" }; -const RuleManager::RuleInfo RuleManager::s_RuleInfo[_IntRuleCount + _RealRuleCount + _BoolRuleCount + 1] = { +const RuleManager::RuleInfo RuleManager::s_RuleInfo[IntRuleCount + RealRuleCount + BoolRuleCount + 1] = { /* this is done in three steps so we can reliably get to them by index*/ #define RULE_INT(category_name, rule_name, default_value, notes) \ { #category_name ":" #rule_name, Category__##category_name, IntRule, Int__##rule_name, notes }, @@ -212,14 +212,14 @@ std::string RuleManager::_GetRuleName(RuleType type, uint16 index) { case IntRule: return s_RuleInfo[index].name; case RealRule: - return s_RuleInfo[index + _IntRuleCount].name; + return s_RuleInfo[index + IntRuleCount].name; case BoolRule: - return s_RuleInfo[index + _IntRuleCount + _RealRuleCount].name; + return s_RuleInfo[index + IntRuleCount + RealRuleCount].name; default: break; } - return s_RuleInfo[_IntRuleCount + _RealRuleCount + _BoolRuleCount].name; + return s_RuleInfo[IntRuleCount + RealRuleCount + BoolRuleCount].name; } //assumes index is valid! @@ -228,14 +228,14 @@ const std::string &RuleManager::_GetRuleNotes(RuleType type, uint16 index) { case IntRule: return s_RuleInfo[index].notes; case RealRule: - return s_RuleInfo[index + _IntRuleCount].notes; + return s_RuleInfo[index + IntRuleCount].notes; case BoolRule: - return s_RuleInfo[index + _IntRuleCount + _RealRuleCount].notes; + return s_RuleInfo[index + IntRuleCount + RealRuleCount].notes; default: break; } - return s_RuleInfo[_IntRuleCount + _RealRuleCount + _BoolRuleCount].notes; + return s_RuleInfo[IntRuleCount + RealRuleCount + BoolRuleCount].notes; } bool RuleManager::LoadRules(Database *db, const std::string &rule_set_name, bool reload) { @@ -325,15 +325,15 @@ void RuleManager::SaveRules(Database *db, const std::string &rule_set_name) { } int i; - for (i = 0; i < _IntRuleCount; i++) { + for (i = 0; i < IntRuleCount; i++) { _SaveRule(db, IntRule, i); } - for (i = 0; i < _RealRuleCount; i++) { + for (i = 0; i < RealRuleCount; i++) { _SaveRule(db, RealRule, i); } - for (i = 0; i < _BoolRuleCount; i++) { + for (i = 0; i < BoolRuleCount; i++) { _SaveRule(db, BoolRule, i); } } @@ -536,7 +536,7 @@ bool RuleManager::RestoreRuleNotes(Database *db) } } - return s_RuleInfo[_IntRuleCount + _RealRuleCount + _BoolRuleCount]; + return s_RuleInfo[IntRuleCount + RealRuleCount + BoolRuleCount]; }(e.rule_name); if (Strings::Contains(rule.name, e.rule_name)) { diff --git a/common/rulesys.h b/common/rulesys.h index 28e66f105..403f611e4 100644 --- a/common/rulesys.h +++ b/common/rulesys.h @@ -57,6 +57,8 @@ public: _IntRuleCount } IntType; + static const int IntRuleCount = static_cast(_IntRuleCount); + typedef enum { #define RULE_REAL(category_name, rule_name, default_value, notes) \ Real__##rule_name, @@ -66,6 +68,8 @@ public: _RealRuleCount } RealType; + static const int RealRuleCount = static_cast(_RealRuleCount); + typedef enum { #define RULE_BOOL(category_name, rule_name, default_value, notes) \ Bool__##rule_name, @@ -75,6 +79,8 @@ public: _BoolRuleCount } BoolType; + static const int BoolRuleCount = static_cast(_BoolRuleCount); + typedef enum { #define RULE_CATEGORY(category_name) \ Category__##category_name, @@ -95,7 +101,7 @@ public: static const BoolType InvalidBool = _BoolRuleCount; static const CategoryType InvalidCategory = _CatCount; - static const uint32 _RulesCount = _IntRuleCount + _RealRuleCount + _BoolRuleCount; + static const uint32 RulesCount = IntRuleCount + RealRuleCount + BoolRuleCount; //fetch routines, you should generally use the Rule* macros instead of this int GetIntRule(IntType t) const; @@ -103,13 +109,13 @@ public: bool GetBoolRule(BoolType t) const; //management routines - static std::string GetRuleName(IntType t) { return s_RuleInfo[t].name; } - static std::string GetRuleName(RealType t) { return s_RuleInfo[t + _IntRuleCount].name; } - static std::string GetRuleName(BoolType t) { return s_RuleInfo[t + _IntRuleCount + _RealRuleCount].name; } - static const std::string &GetRuleNotes(IntType t) { return s_RuleInfo[t].notes; } - static const std::string &GetRuleNotes(RealType t) { return s_RuleInfo[t + _IntRuleCount].notes; } - static const std::string &GetRuleNotes(BoolType t) { return s_RuleInfo[t + _IntRuleCount + _RealRuleCount].notes; } - static uint32 CountRules() { return _RulesCount; } + static std::string GetRuleName(IntType t) { return s_RuleInfo[static_cast(t)].name; } + static std::string GetRuleName(RealType t) { return s_RuleInfo[static_cast(t) + IntRuleCount].name; } + static std::string GetRuleName(BoolType t) { return s_RuleInfo[static_cast(t) + IntRuleCount + RealRuleCount].name; } + static const std::string &GetRuleNotes(IntType t) { return s_RuleInfo[static_cast(t)].notes; } + static const std::string &GetRuleNotes(RealType t) { return s_RuleInfo[static_cast(t) + IntRuleCount].notes; } + static const std::string &GetRuleNotes(BoolType t) { return s_RuleInfo[static_cast(t) + IntRuleCount + RealRuleCount].notes; } + static uint32 CountRules() { return RulesCount; } static CategoryType FindCategory(const std::string &category_name); bool ListRules(const std::string &category_name, std::vector &l); bool ListCategories(std::vector &l); @@ -141,9 +147,9 @@ private: int m_activeRuleset; std::string m_activeName; - int m_RuleIntValues[_IntRuleCount]; - float m_RuleRealValues[_RealRuleCount]; - uint32 m_RuleBoolValues[_BoolRuleCount]; + int m_RuleIntValues[IntRuleCount]; + float m_RuleRealValues[RealRuleCount]; + uint32 m_RuleBoolValues[BoolRuleCount]; typedef enum { IntRule,