8 #include "EndianSwapper.h"
9 #include "IException.h"
23 EndianSwapper::EndianSwapper(QString inputEndian) {
25 if(inputEndian !=
"LSB" && inputEndian !=
"MSB") {
26 string message =
"Invalid parameter-InputEndian must be LSB or MSB";
27 throw IException(IException::Programmer, message, _FILEINFO_);
46 EndianSwapper::~EndianSwapper() {
55 double EndianSwapper::Double(
void *buf) {
56 double result = *(
double *)buf;
59 char *ptr = (
char *)buf + (
sizeof(
double) - 1) * p_needSwap;
61 for(
unsigned int i = 0; i <
sizeof(double); i++) {
62 p_swapper.p_char[i] = *ptr;
63 ptr += p_swapDirection;
66 result = p_swapper.p_double;
78 float EndianSwapper::Float(
void *buf) {
79 float result = *(
float *)buf;
82 char *ptr = (
char *)buf + (
sizeof(
float) - 1) * p_needSwap;
84 for(
unsigned int i = 0; i <
sizeof(float); i++) {
85 p_swapper.p_char[i] = *ptr;
86 ptr += p_swapDirection;
89 result = p_swapper.p_float;
99 int EndianSwapper::ExportFloat(
void *buf) {
108 int EndianSwapper::Int(
void *buf) {
109 int result = *(
int *)buf;
112 char *ptr = (
char *)buf + (
sizeof(
int) - 1) * p_needSwap;
114 for(
unsigned int i = 0; i <
sizeof(int); i++) {
115 p_swapper.p_char[i] = *ptr;
116 ptr += p_swapDirection;
119 result = p_swapper.p_int;
130 uint32_t EndianSwapper::Uint32_t(
void *buf) {
131 uint32_t result = *(uint32_t *)buf;
134 char *ptr = (
char *)buf + (
sizeof(uint32_t) - 1) * p_needSwap;
136 for(
unsigned int i = 0; i <
sizeof(uint32_t); i++) {
137 p_swapper.p_char[i] = *ptr;
138 ptr += p_swapDirection;
141 result = p_swapper.p_uint32;
152 long long int EndianSwapper::LongLongInt(
void *buf) {
153 long long int result = *(
long long int *)buf;
156 char *ptr = (
char *)buf + (
sizeof(
long long int) - 1) * p_needSwap;
158 for(
unsigned int i = 0; i <
sizeof(
long long int); i++) {
159 p_swapper.p_char[i] = *ptr;
160 ptr += p_swapDirection;
163 result = p_swapper.p_longLongInt;
174 short int EndianSwapper::ShortInt(
void *buf) {
175 short int result = *(
short int *)buf;
178 char *ptr = (
char *)buf + (
sizeof(
short int) - 1) * p_needSwap;
180 for(
unsigned int i = 0; i <
sizeof(
short int); i++) {
181 p_swapper.p_char[i] = *ptr;
182 ptr += p_swapDirection;
185 result = p_swapper.p_shortInt;
197 unsigned short int EndianSwapper::UnsignedShortInt(
void *buf) {
198 unsigned short int result = *(
unsigned short int *)buf;
200 char *ptr = (
char *)buf + (
sizeof(
unsigned short int) - 1) * p_needSwap;
202 for(
unsigned int i = 0; i <
sizeof(
unsigned short int); i++) {
203 p_swapper.p_char[i] = *ptr;
204 ptr += p_swapDirection;
207 result = p_swapper.p_uShortInt;