|
|
|
@ -5,6 +5,52 @@
|
|
|
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
|
|
|
|
|
template<typename Type, uint Lo, uint Hi> struct BitField {
|
|
|
|
|
static_assert(Lo <= Hi, "");
|
|
|
|
|
static_assert(Hi < sizeof(Type) * 8, "");
|
|
|
|
|
|
|
|
|
|
inline BitField() = default;
|
|
|
|
|
inline BitField(const BitField& value) { set(value.data); }
|
|
|
|
|
template<typename T> inline BitField(const T& value) { set(value << Lo); }
|
|
|
|
|
|
|
|
|
|
//inline explicit operator bool() const { return data & Mask; }
|
|
|
|
|
inline operator Type() const { return get(); }
|
|
|
|
|
|
|
|
|
|
inline auto& operator=(const BitField& value) { return set(value.data); }
|
|
|
|
|
template<typename T> inline auto& operator=(const T& value) { return set(value << Lo); }
|
|
|
|
|
|
|
|
|
|
inline auto operator++(int) { Type value = get(); set(data + (1 << Lo)); return value; }
|
|
|
|
|
inline auto operator--(int) { Type value = get(); set(data - (1 << Lo)); return value; }
|
|
|
|
|
|
|
|
|
|
inline auto& operator++() { return set(data + (1 << Lo)); }
|
|
|
|
|
inline auto& operator--() { return set(data - (1 << Lo)); }
|
|
|
|
|
|
|
|
|
|
inline auto& operator &=(const Type value) { return set(data & (value << Lo)); }
|
|
|
|
|
inline auto& operator |=(const Type value) { return set(data | (value << Lo)); }
|
|
|
|
|
inline auto& operator ^=(const Type value) { return set(data ^ (value << Lo)); }
|
|
|
|
|
inline auto& operator<<=(const Type value) { return set(data << value); }
|
|
|
|
|
inline auto& operator>>=(const Type value) { return set(data >> value); }
|
|
|
|
|
inline auto& operator +=(const Type value) { return set(data + (value << Lo)); }
|
|
|
|
|
inline auto& operator -=(const Type value) { return set(data - (value << Lo)); }
|
|
|
|
|
inline auto& operator *=(const Type value) { return set((get() * value) << Lo); }
|
|
|
|
|
inline auto& operator /=(const Type value) { return set((get() / value) << Lo); }
|
|
|
|
|
inline auto& operator %=(const Type value) { return set((get() % value) << Lo); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
enum : uint { Bits = Hi - Lo + 1 };
|
|
|
|
|
enum : uint { Mask = ((1ull << Bits) - 1) << Lo };
|
|
|
|
|
Type data;
|
|
|
|
|
|
|
|
|
|
inline auto get() const -> Type {
|
|
|
|
|
return (data & Mask) >> Lo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline auto set(Type value) -> BitField& {
|
|
|
|
|
data = (data & ~Mask) | (value & Mask);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Boolean {
|
|
|
|
|
inline Boolean() : data(false) {}
|
|
|
|
|
template<typename T> inline Boolean(const T& value) : data(value) {}
|
|
|
|
@ -29,27 +75,27 @@ template<uint Bits> struct Natural {
|
|
|
|
|
enum : type { Mask = ~0ull >> (64 - Bits) };
|
|
|
|
|
|
|
|
|
|
inline Natural() : data(0) {}
|
|
|
|
|
template<typename T> inline Natural(const T& value) { assign(value); }
|
|
|
|
|
template<typename T> inline Natural(const T& value) { set(value); }
|
|
|
|
|
|
|
|
|
|
inline operator type() const { return data; }
|
|
|
|
|
template<typename T> inline auto& operator=(const T& value) { assign(value); return *this; }
|
|
|
|
|
template<typename T> inline auto& operator=(const T& value) { set(value); return *this; }
|
|
|
|
|
|
|
|
|
|
inline auto operator++(int) { type value = data; assign(data + 1); return value; }
|
|
|
|
|
inline auto operator--(int) { type value = data; assign(data - 1); return value; }
|
|
|
|
|
inline auto operator++(int) { type value = data; set(data + 1); return value; }
|
|
|
|
|
inline auto operator--(int) { type value = data; set(data - 1); return value; }
|
|
|
|
|
|
|
|
|
|
inline auto& operator++() { assign(data + 1); return *this; }
|
|
|
|
|
inline auto& operator--() { assign(data - 1); return *this; }
|
|
|
|
|
inline auto& operator++() { set(data + 1); return *this; }
|
|
|
|
|
inline auto& operator--() { set(data - 1); return *this; }
|
|
|
|
|
|
|
|
|
|
inline auto& operator &=(const type value) { assign(data & value); return *this; }
|
|
|
|
|
inline auto& operator |=(const type value) { assign(data | value); return *this; }
|
|
|
|
|
inline auto& operator ^=(const type value) { assign(data ^ value); return *this; }
|
|
|
|
|
inline auto& operator<<=(const type value) { assign(data << value); return *this; }
|
|
|
|
|
inline auto& operator>>=(const type value) { assign(data >> value); return *this; }
|
|
|
|
|
inline auto& operator +=(const type value) { assign(data + value); return *this; }
|
|
|
|
|
inline auto& operator -=(const type value) { assign(data - value); return *this; }
|
|
|
|
|
inline auto& operator *=(const type value) { assign(data * value); return *this; }
|
|
|
|
|
inline auto& operator /=(const type value) { assign(data / value); return *this; }
|
|
|
|
|
inline auto& operator %=(const type value) { assign(data % value); return *this; }
|
|
|
|
|
inline auto& operator &=(const type value) { set(data & value); return *this; }
|
|
|
|
|
inline auto& operator |=(const type value) { set(data | value); return *this; }
|
|
|
|
|
inline auto& operator ^=(const type value) { set(data ^ value); return *this; }
|
|
|
|
|
inline auto& operator<<=(const type value) { set(data << value); return *this; }
|
|
|
|
|
inline auto& operator>>=(const type value) { set(data >> value); return *this; }
|
|
|
|
|
inline auto& operator +=(const type value) { set(data + value); return *this; }
|
|
|
|
|
inline auto& operator -=(const type value) { set(data - value); return *this; }
|
|
|
|
|
inline auto& operator *=(const type value) { set(data * value); return *this; }
|
|
|
|
|
inline auto& operator /=(const type value) { set(data / value); return *this; }
|
|
|
|
|
inline auto& operator %=(const type value) { set(data % value); return *this; }
|
|
|
|
|
|
|
|
|
|
inline auto serialize(serializer& s) { s(data); }
|
|
|
|
|
|
|
|
|
@ -92,7 +138,7 @@ template<uint Bits> struct Natural {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
auto assign(type value) -> void {
|
|
|
|
|
auto set(type value) -> void {
|
|
|
|
|
data = value & Mask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -111,27 +157,27 @@ template<uint Bits> struct Integer {
|
|
|
|
|
enum : utype { Mask = ~0ull >> (64 - Bits), Sign = 1ull << (Bits - 1) };
|
|
|
|
|
|
|
|
|
|
inline Integer() : data(0) {}
|
|
|
|
|
template<typename T> inline Integer(const T& value) { assign(value); }
|
|
|
|
|
template<typename T> inline Integer(const T& value) { set(value); }
|
|
|
|
|
|
|
|
|
|
inline operator type() const { return data; }
|
|
|
|
|
template<typename T> inline auto& operator=(const T& value) { assign(value); return *this; }
|
|
|
|
|
template<typename T> inline auto& operator=(const T& value) { set(value); return *this; }
|
|
|
|
|
|
|
|
|
|
inline auto operator++(int) { type value = data; assign(data + 1); return value; }
|
|
|
|
|
inline auto operator--(int) { type value = data; assign(data - 1); return value; }
|
|
|
|
|
inline auto operator++(int) { type value = data; set(data + 1); return value; }
|
|
|
|
|
inline auto operator--(int) { type value = data; set(data - 1); return value; }
|
|
|
|
|
|
|
|
|
|
inline auto& operator++() { assign(data + 1); return *this; }
|
|
|
|
|
inline auto& operator--() { assign(data - 1); return *this; }
|
|
|
|
|
inline auto& operator++() { set(data + 1); return *this; }
|
|
|
|
|
inline auto& operator--() { set(data - 1); return *this; }
|
|
|
|
|
|
|
|
|
|
inline auto& operator &=(const type value) { assign(data & value); return *this; }
|
|
|
|
|
inline auto& operator |=(const type value) { assign(data | value); return *this; }
|
|
|
|
|
inline auto& operator ^=(const type value) { assign(data ^ value); return *this; }
|
|
|
|
|
inline auto& operator<<=(const type value) { assign(data << value); return *this; }
|
|
|
|
|
inline auto& operator>>=(const type value) { assign(data >> value); return *this; }
|
|
|
|
|
inline auto& operator +=(const type value) { assign(data + value); return *this; }
|
|
|
|
|
inline auto& operator -=(const type value) { assign(data - value); return *this; }
|
|
|
|
|
inline auto& operator *=(const type value) { assign(data * value); return *this; }
|
|
|
|
|
inline auto& operator /=(const type value) { assign(data / value); return *this; }
|
|
|
|
|
inline auto& operator %=(const type value) { assign(data % value); return *this; }
|
|
|
|
|
inline auto& operator &=(const type value) { set(data & value); return *this; }
|
|
|
|
|
inline auto& operator |=(const type value) { set(data | value); return *this; }
|
|
|
|
|
inline auto& operator ^=(const type value) { set(data ^ value); return *this; }
|
|
|
|
|
inline auto& operator<<=(const type value) { set(data << value); return *this; }
|
|
|
|
|
inline auto& operator>>=(const type value) { set(data >> value); return *this; }
|
|
|
|
|
inline auto& operator +=(const type value) { set(data + value); return *this; }
|
|
|
|
|
inline auto& operator -=(const type value) { set(data - value); return *this; }
|
|
|
|
|
inline auto& operator *=(const type value) { set(data * value); return *this; }
|
|
|
|
|
inline auto& operator /=(const type value) { set(data / value); return *this; }
|
|
|
|
|
inline auto& operator %=(const type value) { set(data % value); return *this; }
|
|
|
|
|
|
|
|
|
|
inline auto serialize(serializer& s) { s(data); }
|
|
|
|
|
|
|
|
|
@ -174,7 +220,7 @@ template<uint Bits> struct Integer {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
auto assign(type value) -> void {
|
|
|
|
|
auto set(type value) -> void {
|
|
|
|
|
data = ((value & Mask) ^ Sign) - Sign;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -208,6 +254,7 @@ template<uint Bits> struct Real {
|
|
|
|
|
|
|
|
|
|
inline auto serialize(serializer& s) { s(data); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
type data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|