Skip to content

Commit

Permalink
Apply required changes due to change of array template parameters in …
Browse files Browse the repository at this point in the history
…ros_babel_fish.
  • Loading branch information
StefanFabian committed Jan 29, 2025
1 parent 756fd3a commit 0f35c53
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/message_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,14 @@ bool fillMessage( Message &msg, const QVariant &value )
namespace
{

template<bool BOUNDED>
template<bool BOUNDED, bool FIXED_LENGTH>
size_t limitCount( const ArrayMessageBase &array, int count )
{
if ( BOUNDED && static_cast<size_t>( 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<size_t>( 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;
}
Expand All @@ -762,7 +763,7 @@ struct QVariantListToMessageConverter {
template<typename T, bool BOUNDED, bool FIXED_LENGTH, typename ArrayType>
bool operator()( ArrayMessage_<T, BOUNDED, FIXED_LENGTH> &array, BabelFish &, const ArrayType &list )
{
int count = limitCount<BOUNDED>( array, list.size() );
int count = limitCount<BOUNDED, FIXED_LENGTH>( array, list.size() );
bool no_error = count == list.size();
if ( !FIXED_LENGTH )
array.clear();
Expand All @@ -787,7 +788,7 @@ struct QVariantListToMessageConverter {
bool operator()( CompoundArrayMessage_<BOUNDED, FIXED_LENGTH> &array, BabelFish &fish,
const Array &list )
{
const int count = limitCount<BOUNDED>( array, list.size() );
const int count = limitCount<BOUNDED, FIXED_LENGTH>( array, list.size() );
bool no_error = count == list.size();
if ( !FIXED_LENGTH )
array.clear();
Expand Down Expand Up @@ -836,7 +837,7 @@ struct QAbstractListModelToMessageConverter {
bool operator()( ArrayMessage_<T, BOUNDED, FIXED_LENGTH> &array, BabelFish &,
const QAbstractListModel &list )
{
int count = limitCount<BOUNDED>( array, list.rowCount() );
int count = limitCount<BOUNDED, FIXED_LENGTH>( array, list.rowCount() );
bool no_error = count == list.rowCount();
if ( !FIXED_LENGTH )
array.clear();
Expand All @@ -862,7 +863,7 @@ struct QAbstractListModelToMessageConverter {
bool operator()( CompoundArrayMessage_<BOUNDED, FIXED_LENGTH> &array, BabelFish &fish,
const QAbstractListModel &list )
{
int count = limitCount<BOUNDED>( array, list.rowCount() );
int count = limitCount<BOUNDED, FIXED_LENGTH>( array, list.rowCount() );
QHash<int, QByteArray> roleNames = list.roleNames();
if ( roleNames.empty() )
return true;
Expand Down

0 comments on commit 0f35c53

Please sign in to comment.