Converting HID API to use be<> auto swapping type.
This commit is contained in:
@@ -35,6 +35,8 @@ namespace poly {
|
||||
#define POLY_BYTE_SWAP_64 __bswap_64
|
||||
#endif // XE_COMPILER_MSVC
|
||||
|
||||
inline int8_t byte_swap(int8_t value) { return value; }
|
||||
inline uint8_t byte_swap(uint8_t value) { return value; }
|
||||
inline int16_t byte_swap(int16_t value) {
|
||||
return static_cast<int16_t>(POLY_BYTE_SWAP_16(static_cast<int16_t>(value)));
|
||||
}
|
||||
|
||||
@@ -245,6 +245,19 @@ inline void store_and_swap<double>(void* mem, double value) {
|
||||
*reinterpret_cast<double*>(mem) = byte_swap(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct be {
|
||||
be() = default;
|
||||
be(const T& src) : value(poly::byte_swap(src)) {}
|
||||
be(const be& other) {
|
||||
value = other.value;
|
||||
}
|
||||
operator T() const {
|
||||
return poly::byte_swap(value);
|
||||
}
|
||||
T value;
|
||||
};
|
||||
|
||||
} // namespace poly
|
||||
|
||||
#endif // POLY_MEMORY_H_
|
||||
|
||||
Reference in New Issue
Block a user