11 #ifndef EVIO_6_0_BYTEORDER_H
12 #define EVIO_6_0_BYTEORDER_H
24 ((uint16_t)((((uint16_t)(x)) >> 8) | \
25 (((uint16_t)(x)) << 8)))
29 ((uint32_t)((((uint32_t)(x)) >> 24) | \
30 (((uint32_t)(x) & 0x00ff0000) >> 8) | \
31 (((uint32_t)(x) & 0x0000ff00) << 8) | \
32 (((uint32_t)(x)) << 24)))
36 ((uint64_t)((((uint64_t)(x)) >> 56) | \
37 (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
38 (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
39 (((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
40 (((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
41 (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
42 (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
43 (((uint64_t)(x)) << 56)))
76 ByteOrder(
int val, std::string name) : value(val), name(std::move(name)) {}
84 std::string
getName()
const {
return name;}
143 return !*((
char *) &i);
162 template <
typename T>
171 template <
typename T>
181 template <
typename T>
189 static uint16_t*
byteSwap16(uint16_t* src,
size_t elements, uint16_t* dst);
190 static uint32_t*
byteSwap32(uint32_t* src,
size_t elements, uint32_t* dst);
191 static uint64_t*
byteSwap64(uint64_t* src,
size_t elements, uint64_t* dst);
192 static void byteNoSwap32(
const uint32_t* src,
size_t elements, uint32_t* dst);
199 #endif //EVIO_6_0_BYTEORDER_H
static const ByteOrder ENDIAN_LITTLE
Little endian byte order.
Definition: ByteOrder.h:57
Numerical values associated with endian byte order.
Definition: ByteOrder.h:53
static uint64_t * byteSwap64(uint64_t *src, size_t elements, uint64_t *dst)
This method swaps an array of 8-byte data.
Definition: ByteOrder.cpp:132
bool isBigEndian() const
Is this big endian?
Definition: ByteOrder.h:90
static ByteOrder const & nativeOrder()
Get the byte order of the local host.
Definition: ByteOrder.h:133
bool operator==(const ByteOrder &rhs) const
Definition: ByteOrder.cpp:180
static void byteNoSwap32(const uint32_t *src, size_t elements, uint32_t *dst)
This routine swaps nothing, it just copies the given number of 32 bit ints.
Definition: ByteOrder.cpp:155
bool isLittleEndian() const
Is this little endian?
Definition: ByteOrder.h:96
bool isLocalEndian() const
Is this endian same as the local host?
Definition: ByteOrder.h:102
static float byteSwap(float var)
Convenience method to return swapped float.
Definition: ByteOrder.cpp:29
static const ByteOrder ENDIAN_UNKNOWN
Unknown endian byte order.
Definition: ByteOrder.h:60
ByteOrder getOppositeEndian() const
Get the oppposite endian (little if this is big and vice versa).
Definition: ByteOrder.h:108
static uint32_t * byteSwap32(uint32_t *src, size_t elements, uint32_t *dst)
This method swaps an array of 4-byte data.
Definition: ByteOrder.cpp:109
std::string getName() const
Get the object name.
Definition: ByteOrder.h:84
static bool isLocalHostBigEndian()
Is the local host big endian?
Definition: ByteOrder.h:141
static void byteSwapInPlace(T &var)
Templated method to swap data in place.
Definition: ByteOrder.cpp:18
static ByteOrder const & getLocalByteOrder()
Get the byte order of the local host.
Definition: ByteOrder.h:122
static uint16_t * byteSwap16(uint16_t *src, size_t elements, uint16_t *dst)
This method swaps an array of 2-byte data.
Definition: ByteOrder.cpp:86
bool operator!=(const ByteOrder &rhs) const
Definition: ByteOrder.cpp:184
static const ByteOrder ENDIAN_BIG
Big endian byte order.
Definition: ByteOrder.h:58
static bool needToSwap(ByteOrder &order)
Is the argument the opposite of the local host's endian?
Definition: ByteOrder.h:151
static const ByteOrder ENDIAN_LOCAL
Local host's byte order.
Definition: ByteOrder.h:61