150 lines
4.0 KiB
C++
150 lines
4.0 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: Data.hpp
|
|
Date: 2021-6-10
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::Data
|
|
{
|
|
enum class DataType
|
|
{
|
|
kTypeUInt, // Human friendly types, used by parse, inherited by struct type members
|
|
kTypeSInt,
|
|
kTypeNumber,
|
|
kTypeString,
|
|
kTypeBoolean,
|
|
kTypeUUID,
|
|
kTypeVec3,
|
|
kTypeVec4,
|
|
|
|
kTypeGenericMax, // Binary serialization, inherit pare types
|
|
|
|
kTypeStructFloat,
|
|
kTypeStructUInt8,
|
|
kTypeStructInt8,
|
|
kTypeStructUInt16,
|
|
kTypeStructInt16,
|
|
kTypeStructUInt32,
|
|
kTypeStructInt32,
|
|
|
|
kTypeSpecialComponent, // Special QST types
|
|
kTypeSpecialArray, //
|
|
kTypeSpecialObject, //
|
|
kTypeSpecialReserved1, // User definable
|
|
kTypeSpecialReserved2 = kTypeSpecialReserved1 + 20, //
|
|
kTypeSpecialReserved3 = kTypeSpecialReserved2 + 20, //
|
|
kTypeSpecialReserved4 = kTypeSpecialReserved3 + 20, //
|
|
|
|
kTypeEND,
|
|
|
|
// Out of order
|
|
kTypeStructDouble = kTypeNumber, // overlap bin serial with human friendly aliases
|
|
kTypeStructUInt64 = kTypeUInt, //
|
|
kTypeStructInt64 = kTypeSInt, //
|
|
};
|
|
|
|
union PrimitiveValue
|
|
{
|
|
AuUInt64 uint;
|
|
AuInt64 sint;
|
|
double number;
|
|
bool boolean;
|
|
AuVec3 vec3;
|
|
AuVec4 vec4;
|
|
};
|
|
|
|
struct Value
|
|
{
|
|
#define CONSTRUCTOR(type, member)\
|
|
Value(type val)\
|
|
{\
|
|
primitive.member = val;\
|
|
}
|
|
CONSTRUCTOR(const AuVec3 &, vec3);
|
|
CONSTRUCTOR(const AuVec4 &, vec4);
|
|
CONSTRUCTOR(bool, boolean);
|
|
CONSTRUCTOR(double, number);
|
|
CONSTRUCTOR(AuInt64, sint);
|
|
CONSTRUCTOR(AuUInt64, uint);
|
|
#undef CONSTRUCTOR
|
|
|
|
Value(uuids::uuid val)
|
|
{
|
|
UUID = val;
|
|
}
|
|
|
|
Value(const AuString &val)
|
|
{
|
|
string = val;
|
|
}
|
|
|
|
Value(const char *val)
|
|
{
|
|
string = val;
|
|
}
|
|
|
|
Value()
|
|
{
|
|
|
|
}
|
|
|
|
PrimitiveValue primitive;
|
|
uuids::uuid UUID;
|
|
AuString string;
|
|
};
|
|
|
|
struct TypedValue
|
|
{
|
|
DataType type;
|
|
Value value;
|
|
};
|
|
|
|
#if !defined(_CPPSHARP)
|
|
template<DataType type>
|
|
static constexpr AuUInt GetDatatypeLength()
|
|
{
|
|
switch /*constexpr*/ (type)
|
|
{
|
|
case DataType::kTypeBoolean: return 1;
|
|
case DataType::kTypeStructFloat: return 4;
|
|
case DataType::kTypeStructDouble: return 8;
|
|
case DataType::kTypeVec3: return 3 * 4;
|
|
case DataType::kTypeVec4: return 4 * 4;
|
|
case DataType::kTypeStructUInt8: return 1;
|
|
case DataType::kTypeStructInt8: return 1;
|
|
case DataType::kTypeStructUInt16: return 2;
|
|
case DataType::kTypeStructInt16: return 2;
|
|
case DataType::kTypeStructUInt32: return 4;
|
|
case DataType::kTypeStructInt32: return 4;
|
|
case DataType::kTypeStructUInt64: return 8;
|
|
case DataType::kTypeStructInt64: return 8;
|
|
default: return 0;//static_assert(false, "invalid datatype");
|
|
}
|
|
}
|
|
|
|
static AuUInt GetDatatypeLength(Data::DataType type)
|
|
{
|
|
switch /*constexpr*/ (type)
|
|
{
|
|
case DataType::kTypeBoolean: return 1;
|
|
case DataType::kTypeStructFloat: return 4;
|
|
case DataType::kTypeStructDouble: return 8;
|
|
case DataType::kTypeVec3: return 3 * 4;
|
|
case DataType::kTypeVec4: return 4 * 4;
|
|
case DataType::kTypeStructUInt8: return 1;
|
|
case DataType::kTypeStructInt8: return 1;
|
|
case DataType::kTypeStructUInt16: return 2;
|
|
case DataType::kTypeStructInt16: return 2;
|
|
case DataType::kTypeStructUInt32: return 4;
|
|
case DataType::kTypeStructInt32: return 4;
|
|
case DataType::kTypeStructUInt64: return 8;
|
|
case DataType::kTypeStructInt64: return 8;
|
|
default: return 0;
|
|
}
|
|
}
|
|
#endif
|
|
}
|