add ScalarTypeFunc::elementSize

This commit is contained in:
Michael Davidsaver
2013-05-07 16:51:48 -04:00
parent 79cd374f16
commit 5f4ca240b4
2 changed files with 27 additions and 2 deletions

View File

@@ -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<void> allocArray(ScalarType id, size_t len)
{
switch(id) {
#define OP(ENUM, TYPE) case ENUM: return static_shared_vector_cast<TYPE>(shared_vector<TYPE>(len))
OP(pvBoolean, uint8);
#define OP(ENUM, TYPE) case ENUM: return static_shared_vector_cast<void>(shared_vector<TYPE>(len))
OP(pvBoolean, boolean);
OP(pvUByte, uint8);
OP(pvByte, int8);
OP(pvUShort, uint16);

View File

@@ -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);
};
/**