1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-21 03:12:41 +01:00

Codechange: Allow using EnumBitSet over network commands.

This commit is contained in:
Peter Nelson
2025-01-29 17:47:47 +00:00
committed by Peter Nelson
parent fdb3555147
commit 6d1f56ce6b
2 changed files with 16 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
#include <string_view>
#include "../core/bitmath_func.hpp"
#include "../core/enum_type.hpp"
#include "../core/overflowsafe_type.hpp"
struct StrongTypedefBase;
@@ -36,6 +37,9 @@ public:
EndianBufferWriter &operator <<(std::string_view data) { this->Write(data); return *this; }
EndianBufferWriter &operator <<(bool data) { return *this << static_cast<uint8_t>(data ? 1 : 0); }
template <typename Tenum, typename Tstorage>
EndianBufferWriter &operator <<(const EnumBitSet<Tenum, Tstorage> &data) { return *this << data.base(); }
template <typename T>
EndianBufferWriter &operator <<(const OverflowSafeInt<T> &data) { return *this << static_cast<T>(data); };
@@ -130,6 +134,9 @@ public:
EndianBufferReader &operator >>(std::string &data) { data = this->ReadStr(); return *this; }
EndianBufferReader &operator >>(bool &data) { data = this->Read<uint8_t>() != 0; return *this; }
template <typename Tenum, typename Tstorage>
EndianBufferReader &operator >>(EnumBitSet<Tenum, Tstorage> &data) { data = Tenum{this->Read<Tstorage>()}; return *this; }
template <typename T>
EndianBufferReader &operator >>(OverflowSafeInt<T> &data) { data = this->Read<T>(); return *this; };