add allocArray()

This commit is contained in:
Michael Davidsaver
2020-07-15 20:40:53 -07:00
parent 01ff23f5b3
commit c8c12d9c54
2 changed files with 28 additions and 0 deletions
+25
View File
@@ -62,6 +62,31 @@ size_t elementSize(ArrayType type)
throw std::logic_error("Invalid ArrayType");
}
shared_array<void> allocArray(ArrayType type, size_t count)
{
switch(type) {
#define CASE(CODE, TYPE) case ArrayType::CODE: return shared_array<TYPE>(count).castTo<void>()
CASE(Bool, bool);
CASE(UInt8, uint8_t);
CASE(UInt16, uint16_t);
CASE(UInt32, uint32_t);
CASE(UInt64, uint64_t);
CASE(Int8, int8_t);
CASE(Int16, int16_t);
CASE(Int32, int32_t);
CASE(Int64, int64_t);
CASE(Float32, float);
CASE(Float64, double);
CASE(String, std::string);
CASE(Value, Value);
#undef CASE
case ArrayType::Null:
break;
}
throw std::logic_error("Invalid ArrayType");
}
namespace detail {
namespace {