add ScalarTypeFunc::allocArray

This commit is contained in:
Michael Davidsaver
2013-05-07 13:22:50 -04:00
parent b137b32fc6
commit 79cd374f16
2 changed files with 39 additions and 0 deletions

View File

@@ -78,6 +78,28 @@ namespace ScalarTypeFunc {
*buf += name(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);
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
}}

View File

@@ -16,6 +16,7 @@
#include <pv/pvType.h>
#include <pv/byteBuffer.h>
#include <pv/serialize.h>
#include <pv/sharedVector.h>
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<void> allocArray(ScalarType id, size_t len);
//! Allocate an untyped array based on ScalarType
template<ScalarType ID>
inline
shared_vector<typename ScalarTypeTraits<ID>::type>
allocArray(size_t len)
{
shared_vector<void> raw(allocArray(ID, len));
return static_shared_vector_cast<typename ScalarTypeTraits<ID>::type>(raw);
}
}
}}
#endif /* PVINTROSPECT_H */