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

58 lines
942 B
C
Raw Permalink Normal View History

2020-02-06 13:23:46 +13:00
#pragma once
#include <stdint.h>
class DataUtil
{
public:
2021-04-02 11:49:11 +13:00
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)
{
2020-02-06 13:23:46 +13:00
return *(int32_t *)(data + offset);
}
2021-04-02 11:49:11 +13:00
static short getLEShort(const unsigned char* data, int offset)
{
2020-02-06 13:23:46 +13:00
return *(int16_t *)(data + offset);
}
2021-04-02 11:49:11 +13:00
static unsigned short getLEUShort(const unsigned char* data, int offset)
{
2020-02-06 13:23:46 +13:00
return *(uint16_t *)(data + offset);
}
2021-04-02 11:49:11 +13:00
static float getLEFloat(const unsigned char* data, int offset)
{
return *(float*)(data + offset);
}
private:
const unsigned char* p;
int offset;
2020-02-06 13:23:46 +13:00
};