From 5f4ca240b4467dc9327e59fd60aa6c2a883a708f Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 7 May 2013 16:51:48 -0400 Subject: [PATCH] add ScalarTypeFunc::elementSize --- pvDataApp/factory/TypeFunc.cpp | 26 ++++++++++++++++++++++++-- pvDataApp/pv/pvIntrospect.h | 3 +++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pvDataApp/factory/TypeFunc.cpp b/pvDataApp/factory/TypeFunc.cpp index 2685d3c..0d38b6c 100644 --- a/pvDataApp/factory/TypeFunc.cpp +++ b/pvDataApp/factory/TypeFunc.cpp @@ -78,11 +78,33 @@ namespace ScalarTypeFunc { *buf += name(scalarType); } + size_t elementSize(ScalarType id) + { + switch(id) { +#define OP(ENUM, TYPE) case ENUM: return sizeof(TYPE) + OP(pvBoolean, boolean); + OP(pvUByte, uint8); + OP(pvByte, int8); + OP(pvUShort, uint16); + OP(pvShort, int16); + OP(pvUInt, uint32); + OP(pvInt, int32); + OP(pvULong, uint64); + OP(pvLong, int64); + OP(pvFloat, float); + OP(pvDouble, double); + OP(pvString, String); +#undef OP + default: + THROW_EXCEPTION2(std::invalid_argument, "error unknown ScalarType"); + } + } + shared_vector allocArray(ScalarType id, size_t len) { switch(id) { -#define OP(ENUM, TYPE) case ENUM: return static_shared_vector_cast(shared_vector(len)) - OP(pvBoolean, uint8); +#define OP(ENUM, TYPE) case ENUM: return static_shared_vector_cast(shared_vector(len)) + OP(pvBoolean, boolean); OP(pvUByte, uint8); OP(pvByte, int8); OP(pvUShort, uint16); diff --git a/pvDataApp/pv/pvIntrospect.h b/pvDataApp/pv/pvIntrospect.h index bedd97f..51d1015 100644 --- a/pvDataApp/pv/pvIntrospect.h +++ b/pvDataApp/pv/pvIntrospect.h @@ -192,6 +192,9 @@ namespace ScalarTypeFunc { * @param scalarType The type. */ void toString(StringBuilder builder,ScalarType scalarType); + + //! gives sizeof(T) where T depends on the scalar type id. + size_t elementSize(ScalarType id); }; /**