Skip to content

Commit

Permalink
Refs #21745. Make lambda a reusable public method
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
  • Loading branch information
juanlofer-eprosima committed Oct 3, 2024
1 parent 04fa7d2 commit 8a3fd08
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
30 changes: 10 additions & 20 deletions include/fastdds/dds/domain/qos/DomainParticipantQos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,6 @@ class DomainParticipantQos
virtual bool operator ==(
const DomainParticipantQos& b) const
{
auto compare_flow_controllers = [](const DomainParticipantQos& lhs, const DomainParticipantQos& rhs) -> bool
{
const auto& lhs_flow_controllers = lhs.flow_controllers();
const auto& rhs_flow_controllers = rhs.flow_controllers();

if (lhs_flow_controllers.size() != rhs_flow_controllers.size())
{
return false;
}

return std::equal(lhs_flow_controllers.begin(), lhs_flow_controllers.end(),
rhs_flow_controllers.begin(),
[](const std::shared_ptr<fastdds::rtps::FlowControllerDescriptor>& a,
const std::shared_ptr<fastdds::rtps::FlowControllerDescriptor>& b)
{
return *a == *b;
});
};

return (this->user_data_ == b.user_data()) &&
(this->entity_factory_ == b.entity_factory()) &&
(this->allocation_ == b.allocation()) &&
Expand All @@ -111,7 +92,7 @@ class DomainParticipantQos
#if HAVE_SECURITY
(this->security_log_thread_ == b.security_log_thread()) &&
#endif // if HAVE_SECURITY
(compare_flow_controllers(*this, b));
(compare_flow_controllers(b));
}

/**
Expand Down Expand Up @@ -341,6 +322,15 @@ class DomainParticipantQos
return flow_controllers_;
}

/**
* Compares the flow controllers of two DomainParticipantQos element-wise.
*
* @param qos The DomainParticipantQos to compare with.
* @return true if the flow controllers are the same, false otherwise.
*/
FASTDDS_EXPORTED_API bool compare_flow_controllers(
const DomainParticipantQos& qos) const;

/**
* Getter for FlowControllerDescriptorList
*
Expand Down
20 changes: 20 additions & 0 deletions src/cpp/fastdds/domain/qos/DomainParticipantQos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ void DomainParticipantQos::setup_transports(
utils::set_qos_from_attributes(*this, attr);
}

bool DomainParticipantQos::compare_flow_controllers(
const DomainParticipantQos& qos) const
{
const auto& lhs_flow_controllers = flow_controllers();
const auto& rhs_flow_controllers = qos.flow_controllers();

if (lhs_flow_controllers.size() != rhs_flow_controllers.size())
{
return false;
}

return std::equal(lhs_flow_controllers.begin(), lhs_flow_controllers.end(),
rhs_flow_controllers.begin(),
[](const std::shared_ptr<fastdds::rtps::FlowControllerDescriptor>& a,
const std::shared_ptr<fastdds::rtps::FlowControllerDescriptor>& b)
{
return *a == *b;
});
}

} /* namespace dds */
} /* namespace fastdds */
} /* namespace eprosima */
21 changes: 1 addition & 20 deletions test/unittest/dds/participant/ParticipantTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,26 +500,7 @@ void check_equivalent_qos(
ASSERT_EQ(qos_1.security_log_thread(), qos_2.security_log_thread());
#endif // if HAVE_SECURITY

auto compare_flow_controllers = [](const DomainParticipantQos& lhs, const DomainParticipantQos& rhs) -> bool
{
const auto& lhs_flow_controllers = lhs.flow_controllers();
const auto& rhs_flow_controllers = rhs.flow_controllers();

if (lhs_flow_controllers.size() != rhs_flow_controllers.size())
{
return false;
}

return std::equal(lhs_flow_controllers.begin(), lhs_flow_controllers.end(),
rhs_flow_controllers.begin(),
[](const std::shared_ptr<fastdds::rtps::FlowControllerDescriptor>& a,
const std::shared_ptr<fastdds::rtps::FlowControllerDescriptor>& b)
{
return *a == *b;
});
};

ASSERT_TRUE(compare_flow_controllers(qos_1, qos_2));
ASSERT_TRUE(qos_1.compare_flow_controllers(qos_2));
}

void check_participant_with_profile(
Expand Down

0 comments on commit 8a3fd08

Please sign in to comment.