@@ -11,7 +11,20 @@ struct freeNDArray {
1111 void operator ()(dataType *data) { array->release (); }
1212};
1313
14- NTNDArrayConverter::NTNDArrayConverter (pvxs::Value value) : m_value(value) {}
14+ NTNDArrayConverter::NTNDArrayConverter (pvxs::Value value) : m_value(value) {
15+ m_typeMap = {
16+ {typeid (int8_t ), NDAttrDataType_t::NDAttrInt8},
17+ {typeid (uint8_t ), NDAttrDataType_t::NDAttrUInt8},
18+ {typeid (int16_t ), NDAttrDataType_t::NDAttrInt16},
19+ {typeid (uint16_t ), NDAttrDataType_t::NDAttrUInt16},
20+ {typeid (int32_t ), NDAttrDataType_t::NDAttrInt32},
21+ {typeid (uint32_t ), NDAttrDataType_t::NDAttrUInt32},
22+ {typeid (int64_t ), NDAttrDataType_t::NDAttrInt64},
23+ {typeid (uint64_t ), NDAttrDataType_t::NDAttrUInt64},
24+ {typeid (float_t ), NDAttrDataType_t::NDAttrFloat32},
25+ {typeid (double_t ), NDAttrDataType_t::NDAttrFloat64}
26+ };
27+ }
1528
1629NDColorMode_t NTNDArrayConverter::getColorMode (void )
1730{
@@ -221,14 +234,14 @@ void NTNDArrayConverter::toDataTimeStamp (NDArray *dest)
221234}
222235
223236template <typename valueType>
224- void NTNDArrayConverter::toAttribute (NDArray *dest, pvxs::Value attribute, NDAttrDataType_t dataType )
237+ void NTNDArrayConverter::toAttribute (NDArray *dest, pvxs::Value attribute)
225238{
226- // TODO, can we make dataType a template parameter?
227239 auto name = attribute[" name" ].as <std::string>();
228240 auto desc = attribute[" descriptor" ].as <std::string>();
229241 auto source = attribute[" source" ].as <std::string>();
230242 NDAttrSource_t sourceType = (NDAttrSource_t) attribute[" sourceType" ].as <int32_t >();
231243 valueType value = attribute[" value" ].as <valueType>();
244+ NDAttrDataType_t dataType = m_typeMap[typeid (valueType)];
232245
233246 NDAttribute *attr = new NDAttribute (name.c_str (), desc.c_str (), sourceType, source.c_str (), dataType, (void *)&value);
234247 dest->pAttributeList ->add (attr);
@@ -264,16 +277,16 @@ void NTNDArrayConverter::toAttributes (NDArray *dest)
264277 pvxs::Value value = attributes[i][" value" ];
265278 switch (attributes[i][" value->" ].type ().code ) {
266279 // use indirection on Any container to get specified type
267- case pvxs::TypeCode::Int8: toAttribute<int8_t > (dest, attributes[i], NDAttrDataType_t::NDAttrInt8 ); break ;
268- case pvxs::TypeCode::UInt8: toAttribute<uint8_t > (dest, attributes[i], NDAttrDataType_t::NDAttrUInt8 ); break ;
269- case pvxs::TypeCode::Int16: toAttribute<int16_t > (dest, attributes[i], NDAttrDataType_t::NDAttrInt16 ); break ;
270- case pvxs::TypeCode::UInt16: toAttribute<uint16_t > (dest, attributes[i], NDAttrDataType_t::NDAttrUInt16 ); break ;
271- case pvxs::TypeCode::Int32: toAttribute<int32_t > (dest, attributes[i], NDAttrDataType_t::NDAttrInt32 ); break ;
272- case pvxs::TypeCode::UInt32: toAttribute<uint32_t > (dest, attributes[i], NDAttrDataType_t::NDAttrUInt32 ); break ;
273- case pvxs::TypeCode::Int64: toAttribute<int64_t > (dest, attributes[i], NDAttrDataType_t::NDAttrInt64 ); break ;
274- case pvxs::TypeCode::UInt64: toAttribute<uint64_t > (dest, attributes[i], NDAttrDataType_t::NDAttrUInt64 ); break ;
275- case pvxs::TypeCode::Float32: toAttribute<float_t > (dest, attributes[i], NDAttrDataType_t::NDAttrFloat32 ); break ;
276- case pvxs::TypeCode::Float64: toAttribute<double_t > (dest, attributes[i], NDAttrDataType_t::NDAttrFloat64 ); break ;
280+ case pvxs::TypeCode::Int8: toAttribute<int8_t > (dest, attributes[i]); break ;
281+ case pvxs::TypeCode::UInt8: toAttribute<uint8_t > (dest, attributes[i]); break ;
282+ case pvxs::TypeCode::Int16: toAttribute<int16_t > (dest, attributes[i]); break ;
283+ case pvxs::TypeCode::UInt16: toAttribute<uint16_t > (dest, attributes[i]); break ;
284+ case pvxs::TypeCode::Int32: toAttribute<int32_t > (dest, attributes[i]); break ;
285+ case pvxs::TypeCode::UInt32: toAttribute<uint32_t > (dest, attributes[i]); break ;
286+ case pvxs::TypeCode::Int64: toAttribute<int64_t > (dest, attributes[i]); break ;
287+ case pvxs::TypeCode::UInt64: toAttribute<uint64_t > (dest, attributes[i]); break ;
288+ case pvxs::TypeCode::Float32: toAttribute<float_t > (dest, attributes[i]); break ;
289+ case pvxs::TypeCode::Float64: toAttribute<double_t > (dest, attributes[i]); break ;
277290 case pvxs::TypeCode::String: toStringAttribute (dest, attributes[i]); break ;
278291 case pvxs::TypeCode::Null: toUndefinedAttribute (dest, attributes[i]); break ;
279292 default : throw std::runtime_error (" invalid value data type" );
0 commit comments