mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Allow using EnumBitSet over network commands.
parent
fdb3555147
commit
6d1f56ce6b
|
@ -193,6 +193,15 @@ public:
|
||||||
return EnumBitSet{static_cast<Tstorage>(this->data & other.data)};
|
return EnumBitSet{static_cast<Tstorage>(this->data & other.data)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the raw value behind this EnumBitSet.
|
||||||
|
* @returns the raw value.
|
||||||
|
*/
|
||||||
|
inline constexpr Tstorage base() const noexcept
|
||||||
|
{
|
||||||
|
return this->data;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Tstorage data; ///< Bitmask of enum values.
|
Tstorage data; ///< Bitmask of enum values.
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#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"
|
#include "../core/overflowsafe_type.hpp"
|
||||||
|
|
||||||
struct StrongTypedefBase;
|
struct StrongTypedefBase;
|
||||||
|
@ -36,6 +37,9 @@ 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 Tenum, typename Tstorage>
|
||||||
|
EndianBufferWriter &operator <<(const EnumBitSet<Tenum, Tstorage> &data) { return *this << data.base(); }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
EndianBufferWriter &operator <<(const OverflowSafeInt<T> &data) { return *this << static_cast<T>(data); };
|
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 >>(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 Tenum, typename Tstorage>
|
||||||
|
EndianBufferReader &operator >>(EnumBitSet<Tenum, Tstorage> &data) { data = Tenum{this->Read<Tstorage>()}; return *this; }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
EndianBufferReader &operator >>(OverflowSafeInt<T> &data) { data = this->Read<T>(); return *this; };
|
EndianBufferReader &operator >>(OverflowSafeInt<T> &data) { data = this->Read<T>(); return *this; };
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue