|
@ -35,21 +35,55 @@ struct endian_wrapper { |
|
|
gp::array<uint8_t, sizeof(T)> bytes; |
|
|
gp::array<uint8_t, sizeof(T)> bytes; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
endian_wrapper() {} |
|
|
|
|
|
|
|
|
endian_wrapper() noexcept |
|
|
|
|
|
: value{0} {} |
|
|
|
|
|
|
|
|
endian_wrapper(T v) |
|
|
|
|
|
: value{mode == endian::native ? v : swap_endian(v)} {} |
|
|
|
|
|
|
|
|
endian_wrapper(T v) noexcept |
|
|
|
|
|
: value{adjust(v)} {} |
|
|
|
|
|
|
|
|
endian_wrapper(endian_wrapper& v) |
|
|
|
|
|
|
|
|
endian_wrapper(k">const endian_wrapper& v) noexcept |
|
|
: value{v.value} {} |
|
|
: value{v.value} {} |
|
|
|
|
|
|
|
|
endian_wrapper& operator=(T p) { |
|
|
|
|
|
value = mode == endian::native ? p : swap_endian(p); |
|
|
|
|
|
|
|
|
endian_wrapper& operator=(T v) noexcept { |
|
|
|
|
|
value = adjust(v); |
|
|
|
|
|
return *this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
endian_wrapper& operator=(const endian_wrapper& v) noexcept { |
|
|
|
|
|
value = v.value; |
|
|
return *this; |
|
|
return *this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
operator T() const noexcept { |
|
|
operator T() const noexcept { |
|
|
return mode == endian::native ? value : swap_endian(value); |
|
|
|
|
|
|
|
|
return adjust(value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// arithmetic assignment operators
|
|
|
|
|
|
|
|
|
|
|
|
endian_wrapper& operator+=(T rhs) noexcept { |
|
|
|
|
|
value = adjust(adjust(value) + rhs); |
|
|
|
|
|
return *this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
endian_wrapper& operator+=(endian_wrapper rhs) noexcept { |
|
|
|
|
|
value = adjust(adjust(value) + adjust(rhs.value)); |
|
|
|
|
|
return *this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
endian_wrapper& operator-=(T rhs) noexcept { |
|
|
|
|
|
value = adjust(adjust(value) - rhs); |
|
|
|
|
|
return *this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
endian_wrapper& operator-=(endian_wrapper rhs) noexcept { |
|
|
|
|
|
value = adjust(adjust(value) - adjust(rhs.value)); |
|
|
|
|
|
return *this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
T adjust(T x) const noexcept { |
|
|
|
|
|
return (mode == endian::native ? x : swap_endian(x)); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|