Polyphase Game Engine
Loading...
Searching...
No Matches
Swap.h
Go to the documentation of this file.
1#pragma once
2
3template<typename T>
4void Swap32(T& dst)
5{
6 OCT_ASSERT(sizeof(T) == 4);
7
8 uint8_t* charArray = reinterpret_cast<uint8_t*>(&dst);
9 uint8_t c0 = charArray[0];
10 uint8_t c1 = charArray[1];
11 uint8_t c2 = charArray[2];
12 uint8_t c3 = charArray[3];
13
14 charArray[0] = c3;
15 charArray[1] = c2;
16 charArray[2] = c1;
17 charArray[3] = c0;
18}
19
20template<typename T>
21void Swap16(T& dst)
22{
23 OCT_ASSERT(sizeof(T) == 2);
24
25 uint8_t* charArray = reinterpret_cast<uint8_t*>(&dst);
26 uint8_t c0 = charArray[0];
27 uint8_t c1 = charArray[1];
28
29 charArray[0] = c1;
30 charArray[1] = c0;
31}
#define OCT_ASSERT(expr)
Definition Assertion.h:12
void Swap32(T &dst)
Definition Swap.h:4
void Swap16(T &dst)
Definition Swap.h:21