1
0
Fork 0

Codechange: Allow using EnumBitSet over network commands.

pull/11338/merge
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

@ -193,6 +193,15 @@ public:
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:
Tstorage data; ///< Bitmask of enum values.
};

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; };