add ScalarTypeFunc::allocArray
This commit is contained in:
@@ -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
|
||||
|
||||
}}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user