From 0f35c53cf98a9ae7791b6a52793d0fece35b9aac Mon Sep 17 00:00:00 2001 From: Stefan Fabian Date: Wed, 29 Jan 2025 12:32:39 +0100 Subject: [PATCH] Apply required changes due to change of array template parameters in ros_babel_fish. --- src/message_conversions.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/message_conversions.cpp b/src/message_conversions.cpp index 44a6e95..bbba731 100644 --- a/src/message_conversions.cpp +++ b/src/message_conversions.cpp @@ -747,13 +747,14 @@ bool fillMessage( Message &msg, const QVariant &value ) namespace { -template +template size_t limitCount( const ArrayMessageBase &array, int count ) { - if ( BOUNDED && static_cast( count ) > array.maxSize() ) { - QML_ROS2_PLUGIN_WARN( "Too many values for fixed size array (%d vs %lu)! Only using first %lu.", - count, array.size(), array.size() ); - return array.size(); + if ( ( BOUNDED || FIXED_LENGTH ) && static_cast( count ) > array.maxSize() ) { + QML_ROS2_PLUGIN_WARN( + "Too many values for bounded or fixed size array (%d vs %lu)! Only using first %lu.", count, + array.maxSize(), array.maxSize() ); + return array.maxSize(); } return count; } @@ -762,7 +763,7 @@ struct QVariantListToMessageConverter { template bool operator()( ArrayMessage_ &array, BabelFish &, const ArrayType &list ) { - int count = limitCount( array, list.size() ); + int count = limitCount( array, list.size() ); bool no_error = count == list.size(); if ( !FIXED_LENGTH ) array.clear(); @@ -787,7 +788,7 @@ struct QVariantListToMessageConverter { bool operator()( CompoundArrayMessage_ &array, BabelFish &fish, const Array &list ) { - const int count = limitCount( array, list.size() ); + const int count = limitCount( array, list.size() ); bool no_error = count == list.size(); if ( !FIXED_LENGTH ) array.clear(); @@ -836,7 +837,7 @@ struct QAbstractListModelToMessageConverter { bool operator()( ArrayMessage_ &array, BabelFish &, const QAbstractListModel &list ) { - int count = limitCount( array, list.rowCount() ); + int count = limitCount( array, list.rowCount() ); bool no_error = count == list.rowCount(); if ( !FIXED_LENGTH ) array.clear(); @@ -862,7 +863,7 @@ struct QAbstractListModelToMessageConverter { bool operator()( CompoundArrayMessage_ &array, BabelFish &fish, const QAbstractListModel &list ) { - int count = limitCount( array, list.rowCount() ); + int count = limitCount( array, list.rowCount() ); QHash roleNames = list.roleNames(); if ( roleNames.empty() ) return true;