Converting HID API to use be<> auto swapping type.

This commit is contained in:
Ben Vanik
2014-08-19 22:50:21 -07:00
parent 48a0e5c601
commit fb98683ed3
24 changed files with 325 additions and 518 deletions

View File

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

View File

@@ -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_