implement enum and fix double/float byte order
This commit is contained in:
33
src/abr.h
33
src/abr.h
@@ -40,12 +40,12 @@ public:
|
|||||||
uint16_t ru16() { return m_swap ? swap(read<uint16_t>()) : read<uint16_t>(); }
|
uint16_t ru16() { return m_swap ? swap(read<uint16_t>()) : read<uint16_t>(); }
|
||||||
uint32_t ru32() { return m_swap ? swap(read<uint32_t>()) : read<uint32_t>(); }
|
uint32_t ru32() { return m_swap ? swap(read<uint32_t>()) : read<uint32_t>(); }
|
||||||
uint64_t ru64() { return m_swap ? swap(read<uint64_t>()) : read<uint64_t>(); }
|
uint64_t ru64() { return m_swap ? swap(read<uint64_t>()) : read<uint64_t>(); }
|
||||||
int8_t ri8() { return read<int8_t>(); }
|
int8_t ri8() { return read<int8_t>(); }
|
||||||
int16_t ri16() { return m_swap ? swap(read<int16_t>()) : read<int16_t>(); }
|
int16_t ri16() { return m_swap ? swap(read<int16_t>()) : read<int16_t>(); }
|
||||||
int32_t ri32() { return m_swap ? swap(read<int32_t>()) : read<int32_t>(); }
|
int32_t ri32() { return m_swap ? swap(read<int32_t>()) : read<int32_t>(); }
|
||||||
int64_t ri64() { return m_swap ? swap(read<int64_t>()) : read<int64_t>(); }
|
int64_t ri64() { return m_swap ? swap(read<int64_t>()) : read<int64_t>(); }
|
||||||
float rflt() { return read<float>(); }
|
float rflt() { return m_swap ? swap(read<float>()) : read<float>(); }
|
||||||
double rdbl() { return read<double>(); }
|
double rdbl() { return m_swap ? swap(read<double>()) : read<double>(); }
|
||||||
std::string pick(size_t chars) { return { (char*)m_cur, chars }; }
|
std::string pick(size_t chars) { return { (char*)m_cur, chars }; }
|
||||||
std::string rstring()
|
std::string rstring()
|
||||||
{
|
{
|
||||||
@@ -92,12 +92,22 @@ protected:
|
|||||||
template<typename T> T swap(T x)
|
template<typename T> T swap(T x)
|
||||||
{
|
{
|
||||||
#if _MSC_VER >= 1400
|
#if _MSC_VER >= 1400
|
||||||
|
|
||||||
if (sizeof(T) == 2)
|
if (sizeof(T) == 2)
|
||||||
return _byteswap_ushort(x);
|
{
|
||||||
|
auto y = _byteswap_ushort(*reinterpret_cast<uint16_t*>(&x));
|
||||||
|
return *reinterpret_cast<T*>(&y);
|
||||||
|
}
|
||||||
else if (sizeof(T) == 4)
|
else if (sizeof(T) == 4)
|
||||||
return _byteswap_ulong(x);
|
{
|
||||||
|
auto y = _byteswap_ulong(*reinterpret_cast<uint32_t*>(&x));
|
||||||
|
return *reinterpret_cast<T*>(&y);
|
||||||
|
}
|
||||||
else if (sizeof(T) == 8)
|
else if (sizeof(T) == 8)
|
||||||
return _byteswap_uint64(x);
|
{
|
||||||
|
auto y = _byteswap_uint64(*reinterpret_cast<uint64_t*>(&x));
|
||||||
|
return *reinterpret_cast<T*>(&y);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
auto p = reinterpret_cast<uint16_t*>(&x);
|
auto p = reinterpret_cast<uint16_t*>(&x);
|
||||||
if (sizeof(T) == 2)
|
if (sizeof(T) == 2)
|
||||||
@@ -179,7 +189,10 @@ class ABR : public BinaryStream
|
|||||||
};
|
};
|
||||||
struct Enum : public Type
|
struct Enum : public Type
|
||||||
{
|
{
|
||||||
|
std::string type;
|
||||||
|
std::string value;
|
||||||
|
virtual std::string str(int indent, const std::string& prefix) const override
|
||||||
|
{ return std::string(indent, '-') + prefix + fmt::format("enum {}: {}", type, value); }
|
||||||
};
|
};
|
||||||
struct EnumRef : public Type { };
|
struct EnumRef : public Type { };
|
||||||
struct Offset : public Type { };
|
struct Offset : public Type { };
|
||||||
|
|||||||
Reference in New Issue
Block a user