mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Make OverflowSafeInt ConvertibleThroughBase. (#13449)
parent
5f4f78574f
commit
64724b8893
|
@ -35,6 +35,8 @@ private:
|
||||||
/** The non-overflow safe backend to store the value in. */
|
/** The non-overflow safe backend to store the value in. */
|
||||||
T m_value;
|
T m_value;
|
||||||
public:
|
public:
|
||||||
|
using BaseType = T;
|
||||||
|
|
||||||
constexpr OverflowSafeInt() : m_value(0) { }
|
constexpr OverflowSafeInt() : m_value(0) { }
|
||||||
|
|
||||||
constexpr OverflowSafeInt(const OverflowSafeInt &other) : m_value(other.m_value) { }
|
constexpr OverflowSafeInt(const OverflowSafeInt &other) : m_value(other.m_value) { }
|
||||||
|
@ -178,6 +180,8 @@ public:
|
||||||
|
|
||||||
static inline constexpr OverflowSafeInt<T> max() { return T_MAX; }
|
static inline constexpr OverflowSafeInt<T> max() { return T_MAX; }
|
||||||
static inline constexpr OverflowSafeInt<T> min() { return T_MIN; }
|
static inline constexpr OverflowSafeInt<T> min() { return T_MIN; }
|
||||||
|
|
||||||
|
BaseType base() const noexcept { return this->m_value; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include "../core/bitmath_func.hpp"
|
#include "../core/bitmath_func.hpp"
|
||||||
#include "../core/enum_type.hpp"
|
|
||||||
#include "../core/overflowsafe_type.hpp"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Endian-aware buffer adapter that always writes values in little endian order.
|
* Endian-aware buffer adapter that always writes values in little endian order.
|
||||||
|
@ -35,9 +33,6 @@ public:
|
||||||
EndianBufferWriter &operator <<(std::string_view data) { this->Write(data); return *this; }
|
EndianBufferWriter &operator <<(std::string_view data) { this->Write(data); return *this; }
|
||||||
EndianBufferWriter &operator <<(bool data) { return *this << static_cast<uint8_t>(data ? 1 : 0); }
|
EndianBufferWriter &operator <<(bool data) { return *this << static_cast<uint8_t>(data ? 1 : 0); }
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
EndianBufferWriter &operator <<(const OverflowSafeInt<T> &data) { return *this << static_cast<T>(data); };
|
|
||||||
|
|
||||||
template <typename... Targs>
|
template <typename... Targs>
|
||||||
EndianBufferWriter &operator <<(const std::tuple<Targs...> &data)
|
EndianBufferWriter &operator <<(const std::tuple<Targs...> &data)
|
||||||
{
|
{
|
||||||
|
@ -133,9 +128,6 @@ public:
|
||||||
EndianBufferReader &operator >>(std::string &data) { data = this->ReadStr(); return *this; }
|
EndianBufferReader &operator >>(std::string &data) { data = this->ReadStr(); return *this; }
|
||||||
EndianBufferReader &operator >>(bool &data) { data = this->Read<uint8_t>() != 0; return *this; }
|
EndianBufferReader &operator >>(bool &data) { data = this->Read<uint8_t>() != 0; return *this; }
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
EndianBufferReader &operator >>(OverflowSafeInt<T> &data) { data = this->Read<T>(); return *this; };
|
|
||||||
|
|
||||||
template <typename... Targs>
|
template <typename... Targs>
|
||||||
EndianBufferReader &operator >>(std::tuple<Targs...> &data)
|
EndianBufferReader &operator >>(std::tuple<Targs...> &data)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue