Codechange: make TimerGameCalendar Date and Year types strongly typed (#10761)

This commit is contained in:
Patric Stout
2023-08-12 20:14:21 +02:00
committed by GitHub
parent 0238a2b567
commit 299570b2c1
55 changed files with 390 additions and 203 deletions

View File

@@ -81,36 +81,13 @@ enum TropicZone {
/**
* The index/ID of a Tile.
*
* It is compatible with int32 / int64 for easy math throughout the code.
*/
struct TileIndex : StrongIntegralTypedef<uint32_t, TileIndex> {
using StrongIntegralTypedef<uint32_t, TileIndex>::StrongIntegralTypedef;
using TileIndex = StrongType::Typedef<uint32_t, struct TileIndexTag, StrongType::Implicit, StrongType::Compare, StrongType::Integer, StrongType::Compatible<int32_t>, StrongType::Compatible<int64_t>>;
debug_inline constexpr TileIndex() = default;
debug_inline constexpr TileIndex(const TileIndex &o) = default;
debug_inline constexpr TileIndex(TileIndex &&o) = default;
debug_inline constexpr TileIndex(const uint32_t &value) : StrongIntegralTypedef<uint32_t, TileIndex>(value) {}
debug_inline constexpr TileIndex &operator =(const TileIndex &rhs) { this->value = rhs.value; return *this; }
debug_inline constexpr TileIndex &operator =(TileIndex &&rhs) { this->value = std::move(rhs.value); return *this; }
debug_inline constexpr TileIndex &operator =(const uint32_t &rhs) { this->value = rhs; return *this; }
/** Implicit conversion to the base type for e.g. array indexing. */
debug_inline constexpr operator uint32_t() const { return this->value; }
/* Import operators from the base class into our overload set. */
using StrongIntegralTypedef::operator ==;
using StrongIntegralTypedef::operator !=;
using StrongIntegralTypedef::operator +;
using StrongIntegralTypedef::operator -;
/* Add comparison and add/sub for signed ints as e.g. 0 is signed and will
* match ambiguously when only unsigned overloads are present. */
constexpr bool operator ==(int rhs) const { return this->value == (uint32_t)rhs; }
constexpr bool operator !=(int rhs) const { return this->value != (uint32_t)rhs; }
constexpr TileIndex operator +(int rhs) const { return { (uint32_t)(this->value + rhs) }; }
constexpr TileIndex operator -(int rhs) const { return { (uint32_t)(this->value - rhs) }; }
};
/* Make sure the size is as expected. */
static_assert(sizeof(TileIndex) == 4);
/**
* The very nice invalid tile marker