#pragma once #include #include #include "utils.h" template class be_val { public: static_assert(!std::is_array::value, "be_val invalid type: array"); static_assert(!std::is_pointer::value, "be_val invalid type: pointer"); static_assert(sizeof(Type) == 1 || sizeof(Type) == 2 || sizeof(Type) == 4 || sizeof(Type) == 8, "be_val invalid type size"); be_val() { } be_val(Type value) { *this = value; } Type value() const { return byte_swap(mValue); } operator Type() const { return value(); } template std::enable_if_t::value, be_val&> operator =(const Other &rhs) { mValue = byte_swap(static_cast(rhs)); return *this; } be_val &operator++() { *this = value() + 1; return *this; } be_val &operator--() { *this = value() - 1; return *this; } be_val operator--(int) { auto old = *this; *this = value() - 1; return old; } be_val operator++(int) { auto old = *this; *this = value() + 1; return old; } template bool operator == (const Other &rhs) const { return value() == static_cast(rhs); } template bool operator != (const Other &rhs) const { return value() != static_cast(rhs); } template bool operator >= (const Other &rhs) const { return value() >= static_cast(rhs); } template bool operator <= (const Other &rhs) const { return value() <= static_cast(rhs); } template bool operator > (const Other &rhs) const { return value() > static_cast(rhs); } template bool operator < (const Other &rhs) const { return value() < static_cast(rhs); } template be_val &operator+=(const Other &rhs) { *this = static_cast(value() + rhs); return *this; } template be_val &operator-=(const Other &rhs) { *this = static_cast(value() - rhs); return *this; } template be_val &operator*=(const Other &rhs) { *this = static_cast(value() * rhs); return *this; } template be_val &operator/=(const Other &rhs) { *this = static_cast(value() / rhs); return *this; } template be_val &operator%=(const Other &rhs) { *this = static_cast(value() % rhs); return *this; } template be_val &operator|=(const Other &rhs) { *this = static_cast(value() | rhs); return *this; } template be_val &operator&=(const Other &rhs) { *this = static_cast(value() & rhs); return *this; } template be_val &operator^=(const Other &rhs) { *this = static_cast(value() ^ rhs); return *this; } template Type operator+(const Other &rhs) const { return static_cast(value() + rhs); } template Type operator-(const Other &rhs) const { return static_cast(value() - rhs); } template Type operator*(const Other &rhs) const { return static_cast(value() * rhs); } template Type operator/(const Other &rhs) const { return static_cast(value() / rhs); } template Type operator%(const Other &rhs) const { return static_cast(value() % rhs); } template Type operator|(const Other &rhs) const { return static_cast(value() | rhs); } template Type operator&(const Other &rhs) const { return static_cast(value() & rhs); } template Type operator^(const Other &rhs) const { return static_cast(value() ^ rhs); } protected: Type mValue {}; };