diff --git a/pvDataApp/factory/TypeFunc.cpp b/pvDataApp/factory/TypeFunc.cpp index 68075b3..2685d3c 100644 --- a/pvDataApp/factory/TypeFunc.cpp +++ b/pvDataApp/factory/TypeFunc.cpp @@ -78,6 +78,28 @@ namespace ScalarTypeFunc { *buf += name(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); + 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 std::bad_alloc(); + } + } + } // namespace ScalarTypeFunc }} diff --git a/pvDataApp/pv/pvIntrospect.h b/pvDataApp/pv/pvIntrospect.h index 9f3179d..bedd97f 100644 --- a/pvDataApp/pv/pvIntrospect.h +++ b/pvDataApp/pv/pvIntrospect.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace epics { namespace pvData { @@ -579,5 +580,21 @@ OP(pvDouble, double); OP(pvString, String); #undef OP + +namespace ScalarTypeFunc { + //! Allocate an untyped array based on ScalarType + shared_vector allocArray(ScalarType id, size_t len); + + //! Allocate an untyped array based on ScalarType + template + inline + shared_vector::type> + allocArray(size_t len) + { + shared_vector raw(allocArray(ID, len)); + return static_shared_vector_cast::type>(raw); + } +} + }} #endif /* PVINTROSPECT_H */