This repository has been archived on 2023-10-28. You can view files and clone it, but cannot push or open issues or pull requests.
frostbite/snowlib/DataUtil.h
2021-04-01 23:49:11 +01:00

58 lines
942 B
C++

#pragma once
#include <stdint.h>
class DataUtil
{
public:
DataUtil(const unsigned char* p_in, int offset_in) : p(p_in), offset(offset_in)
{
}
float getLEFloat()
{
const float f = *(float*)(p + offset);
offset += 4;
return f;
}
int getLEInt()
{
const int i = *(int32_t*)(p + offset);
offset += 4;
return i;
}
unsigned short getLEUShort()
{
const unsigned short s = *(uint16_t*)(p + offset);
offset += 2;
return s;
}
static int getLEInt(const unsigned char* data, int offset)
{
return *(int32_t *)(data + offset);
}
static short getLEShort(const unsigned char* data, int offset)
{
return *(int16_t *)(data + offset);
}
static unsigned short getLEUShort(const unsigned char* data, int offset)
{
return *(uint16_t *)(data + offset);
}
static float getLEFloat(const unsigned char* data, int offset)
{
return *(float*)(data + offset);
}
private:
const unsigned char* p;
int offset;
};