27 #ifndef INCLUDED_IntegerByteSwap_h_GUID_11841216_B020_47A7_D0A9_9B1CFFEB1C5C 28 #define INCLUDED_IntegerByteSwap_h_GUID_11841216_B020_47A7_D0A9_9B1CFFEB1C5C 32 #include <osvr/Common/ConfigByteSwapping.h> 35 #include <boost/integer.hpp> 38 #include <type_traits> 40 #if defined(OSVR_HAVE_INTRIN_H) && defined(OSVR_HAVE_WORKING_MS_BYTESWAPS) 44 #ifdef OSVR_HAVE_BYTESWAP_H 63 bool, std::is_base_of<UnspecializedByteSwapBase, T>::value>;
69 std::integral_constant<bool, !IsByteSwapperUnspecialized<T>::value>;
72 template <
typename ArgType>
static ArgType
apply(ArgType
const v) {
82 #if defined(OSVR_HAVE_WORKING_MS_BYTESWAPS) 83 template <>
struct ByteSwap<uint16_t> {
84 static uint16_t
apply(uint16_t
const v) {
85 return _byteswap_ushort(v);
89 template <>
struct ByteSwap<uint32_t> {
90 static uint32_t
apply(uint32_t
const v) {
91 return _byteswap_ulong(v);
94 template <>
struct ByteSwap<uint64_t> {
95 static uint64_t
apply(uint64_t
const v) {
96 return _byteswap_uint64(v);
99 #elif defined(OSVR_HAVE_BYTESWAP_H) && defined(OSVR_HAVE_WORKING_BSWAP) 100 template <>
struct ByteSwap<uint16_t> {
101 static uint16_t
apply(uint16_t
const v) {
return bswap16(v); }
103 template <>
struct ByteSwap<uint32_t> {
104 static uint32_t
apply(uint32_t
const v) {
return bswap32(v); }
106 template <>
struct ByteSwap<uint64_t> {
107 static uint64_t
apply(uint64_t
const v) {
return bswap64(v); }
109 #elif defined(OSVR_HAVE_BYTESWAP_H) && \ 110 defined(OSVR_HAVE_WORKING_BSWAP_UNDERSCORE) 111 template <>
struct ByteSwap<uint16_t> {
112 static uint16_t
apply(uint16_t
const v) {
return bswap_16(v); }
115 template <>
struct ByteSwap<uint32_t> {
116 static uint32_t
apply(uint32_t
const v) {
return bswap_32(v); }
118 template <>
struct ByteSwap<uint64_t> {
119 static uint64_t
apply(uint64_t
const v) {
return bswap_64(v); }
121 #elif defined(OSVR_HAVE_BYTESWAP_H) && \ 122 defined(OSVR_HAVE_WORKING_UNDERSCORES_BSWAP) 123 template <>
struct ByteSwap<uint16_t> {
124 static uint16_t
apply(uint16_t
const v) {
return __bswap_16(v); }
127 template <>
struct ByteSwap<uint32_t> {
128 static uint32_t
apply(uint32_t
const v) {
return __bswap_32(v); }
130 template <>
struct ByteSwap<uint64_t> {
131 static uint64_t
apply(uint64_t
const v) {
return __bswap_64(v); }
138 for (
size_t i = 0; i <
sizeof(
T); ++i) {
139 reinterpret_cast<char *
>(&ret)[i] =
140 reinterpret_cast<char const *>(&v)[
sizeof(
T) - 1 - i];
151 typedef typename boost::int_t<sizeof(T) * 8>::exact int_t;
152 typedef typename boost::uint_t<sizeof(T) * 8>::exact uint_t;
154 typename std::conditional<std::is_signed<T>::value, uint_t,
155 int_t>::type opposite_signedness_type;
156 typedef typename std::add_const<opposite_signedness_type>::type
157 const_opposite_signedness_type;
162 static const bool HAVE_BYTESWAPPER =
164 static const bool HAVE_OPPPOSITEBYTESWAPPER =
170 template <
typename T>
173 typename std::enable_if<
182 template <
typename T>
185 typename std::enable_if<
191 static_cast<typename Traits::const_opposite_signedness_type>(
198 template <
typename T>
201 typename std::enable_if<
216 static_assert(std::is_integral<Type>::value,
217 "Can only apply integerByteSwap to integers");
218 typedef typename std::remove_cv<
219 typename std::remove_reference<Type>::type>::type
T;
221 return detail::integerByteSwapImpl<T>(v);
226 #endif // INCLUDED_IntegerByteSwap_h_GUID_11841216_B020_47A7_D0A9_9B1CFFEB1C5C Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
Template for providing/describing optimized/intrinsic byte swap functions.
Definition: IntegerByteSwap.h:57
Header wrapping the C99 standard stdint header.
Definition: IntegerByteSwap.h:71
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
typename F::template apply< Args... > apply
Apply an alias class.
Definition: Apply.h:44
Definition: newuoa.h:1888
T integerByteSwapImpl(T const v, typename std::enable_if< IntegerByteSwapTraits< T >::HAVE_BYTESWAPPER >::type *=nullptr)
Implementation of integerByteSwap(): Gets called when we have an exact match to an explicit specializ...
Definition: IntegerByteSwap.h:171
Tag type used only for recognizing ByteSwap specializations that aren't explicitly specialized...
Definition: IntegerByteSwap.h:53
T genericByteSwap(T const v)
Universal byte-swap function that always works, but isn't necessarily optimized.
Definition: IntegerByteSwap.h:136
Traits assisting selection of optimized integer byte swapping.
Definition: IntegerByteSwap.h:149
Type integerByteSwap(Type const v)
Swap the order of bytes of an arbitrary integer type.
Definition: IntegerByteSwap.h:215
std::integral_constant< bool, std::is_base_of< UnspecializedByteSwapBase, T >::value > IsByteSwapperUnspecialized
Trait: For a given T=ByteSwap<ValueType> struct, is ByteSwap<ValueType> default/unspecialized?
Definition: IntegerByteSwap.h:63
std::integral_constant< bool, !IsByteSwapperUnspecialized< T >::value > IsByteSwapperSpecialized
Trait: For a given T=ByteSwap<ValueType> struct, is ByteSwap<ValueType> specialized?
Definition: IntegerByteSwap.h:69