From 549a58731f332e8056eb3b35f6110b92b3c25350 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Tue, 20 Jul 2021 08:19:00 +0100 Subject: Codechange: Remove (unused) ability to specify min/max of OverflowSafeInt --- src/core/overflowsafe_type.hpp | 45 +++++++++++++++++++++------------------ src/script/api/script_company.cpp | 4 ++-- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp index 3f2948551..01400df0a 100644 --- a/src/core/overflowsafe_type.hpp +++ b/src/core/overflowsafe_type.hpp @@ -12,6 +12,8 @@ #include "math_func.hpp" +#include + #ifdef __has_builtin # if __has_builtin(__builtin_add_overflow) && __has_builtin(__builtin_sub_overflow) && __has_builtin(__builtin_mul_overflow) # define HAS_OVERFLOW_BUILTINS @@ -23,13 +25,14 @@ * you multiply the maximum value with 2, or add 2, or subtract something from * the minimum value, etc. * @param T the type these integers are stored with. - * @param T_MAX the maximum value for the integers. - * @param T_MIN the minimum value for the integers. */ -template +template class OverflowSafeInt { private: + static constexpr T T_MAX = std::numeric_limits::max(); + static constexpr T T_MIN = std::numeric_limits::min(); + /** The non-overflow safe backend to store the value in. */ T m_value; public: @@ -175,31 +178,31 @@ public: }; /* Sometimes we got int64 operator OverflowSafeInt instead of vice versa. Handle that properly */ -template inline OverflowSafeInt operator + (int64 a, OverflowSafeInt b) { return b + a; } -template inline OverflowSafeInt operator - (int64 a, OverflowSafeInt b) { return -b + a; } -template inline OverflowSafeInt operator * (int64 a, OverflowSafeInt b) { return b * a; } -template inline OverflowSafeInt operator / (int64 a, OverflowSafeInt b) { return (OverflowSafeInt)a / (int)b; } +template inline OverflowSafeInt operator + (int64 a, OverflowSafeInt b) { return b + a; } +template inline OverflowSafeInt operator - (int64 a, OverflowSafeInt b) { return -b + a; } +template inline OverflowSafeInt operator * (int64 a, OverflowSafeInt b) { return b * a; } +template inline OverflowSafeInt operator / (int64 a, OverflowSafeInt b) { return (OverflowSafeInt)a / (int)b; } /* Sometimes we got int operator OverflowSafeInt instead of vice versa. Handle that properly */ -template inline OverflowSafeInt operator + (int a, OverflowSafeInt b) { return b + a; } -template inline OverflowSafeInt operator - (int a, OverflowSafeInt b) { return -b + a; } -template inline OverflowSafeInt operator * (int a, OverflowSafeInt b) { return b * a; } -template inline OverflowSafeInt operator / (int a, OverflowSafeInt b) { return (OverflowSafeInt)a / (int)b; } +template inline OverflowSafeInt operator + (int a, OverflowSafeInt b) { return b + a; } +template inline OverflowSafeInt operator - (int a, OverflowSafeInt b) { return -b + a; } +template inline OverflowSafeInt operator * (int a, OverflowSafeInt b) { return b * a; } +template inline OverflowSafeInt operator / (int a, OverflowSafeInt b) { return (OverflowSafeInt)a / (int)b; } /* Sometimes we got uint operator OverflowSafeInt instead of vice versa. Handle that properly */ -template inline OverflowSafeInt operator + (uint a, OverflowSafeInt b) { return b + a; } -template inline OverflowSafeInt operator - (uint a, OverflowSafeInt b) { return -b + a; } -template inline OverflowSafeInt operator * (uint a, OverflowSafeInt b) { return b * a; } -template inline OverflowSafeInt operator / (uint a, OverflowSafeInt b) { return (OverflowSafeInt)a / (int)b; } +template inline OverflowSafeInt operator + (uint a, OverflowSafeInt b) { return b + a; } +template inline OverflowSafeInt operator - (uint a, OverflowSafeInt b) { return -b + a; } +template inline OverflowSafeInt operator * (uint a, OverflowSafeInt b) { return b * a; } +template inline OverflowSafeInt operator / (uint a, OverflowSafeInt b) { return (OverflowSafeInt)a / (int)b; } /* Sometimes we got byte operator OverflowSafeInt instead of vice versa. Handle that properly */ -template inline OverflowSafeInt operator + (byte a, OverflowSafeInt b) { return b + (uint)a; } -template inline OverflowSafeInt operator - (byte a, OverflowSafeInt b) { return -b + (uint)a; } -template inline OverflowSafeInt operator * (byte a, OverflowSafeInt b) { return b * (uint)a; } -template inline OverflowSafeInt operator / (byte a, OverflowSafeInt b) { return (OverflowSafeInt)a / (int)b; } +template inline OverflowSafeInt operator + (byte a, OverflowSafeInt b) { return b + (uint)a; } +template inline OverflowSafeInt operator - (byte a, OverflowSafeInt b) { return -b + (uint)a; } +template inline OverflowSafeInt operator * (byte a, OverflowSafeInt b) { return b * (uint)a; } +template inline OverflowSafeInt operator / (byte a, OverflowSafeInt b) { return (OverflowSafeInt)a / (int)b; } -typedef OverflowSafeInt OverflowSafeInt64; -typedef OverflowSafeInt OverflowSafeInt32; +typedef OverflowSafeInt OverflowSafeInt64; +typedef OverflowSafeInt OverflowSafeInt32; #undef HAS_OVERFLOW_BUILTINS diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp index 9f5722c10..dddcc950c 100644 --- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -140,9 +140,9 @@ if (quarter > EARLIEST_QUARTER) return -1; if (quarter == CURRENT_QUARTER) { - return ::Company::Get(company)->cur_economy.delivered_cargo.GetSum >(); + return ::Company::Get(company)->cur_economy.delivered_cargo.GetSum(); } - return ::Company::Get(company)->old_economy[quarter - 1].delivered_cargo.GetSum >(); + return ::Company::Get(company)->old_economy[quarter - 1].delivered_cargo.GetSum(); } /* static */ int32 ScriptCompany::GetQuarterlyPerformanceRating(ScriptCompany::CompanyID company, uint32 quarter) -- cgit v1.2.3-54-g00ecf