add TypeCode::arrayType()

This commit is contained in:
Michael Davidsaver
2020-07-16 12:37:48 -07:00
parent 290a2689fc
commit 01ff23f5b3
2 changed files with 28 additions and 0 deletions
+3
View File
@@ -121,6 +121,8 @@ enum struct Kind : uint8_t {
Null = 0xe0,
};
enum class ArrayType : uint8_t;
/** Possible Field types.
*
* eg. String is scalar string, StringA is array of strings.
@@ -183,6 +185,7 @@ struct TypeCode {
constexpr TypeCode(code_t c) :code(c) {}
PVXS_API StoreType storedAs() const;
PVXS_API ArrayType arrayType() const;
//! associated array of type
constexpr TypeCode arrayOf() const {return TypeCode{uint8_t(code|0x08)};}
+25
View File
@@ -80,6 +80,31 @@ StoreType TypeCode::storedAs() const
}
}
ArrayType TypeCode::arrayType() const
{
switch(code) {
#define CASE(ATYPE, TYPE) case TypeCode::TYPE: return ArrayType::ATYPE
CASE(Bool, BoolA);
CASE(Int8, Int8A);
CASE(Int16, Int16A);
CASE(Int32, Int32A);
CASE(Int64, Int64A);
CASE(UInt8, UInt8A);
CASE(UInt16, UInt16A);
CASE(UInt32, UInt32A);
CASE(UInt64, UInt64A);
CASE(Float32, Float32A);
CASE(Float64, Float64A);
CASE(String, StringA);
CASE(Value, StructA);
CASE(Value, UnionA);
CASE(Value, AnyA);
#undef CASE
default:
throw std::logic_error("TypeCode can not be mapped to ArrayType");
}
}
const char* TypeCode::name() const
{
switch(code) {