Skip to content
Snippets Groups Projects
Commit ce50778a authored by Martin Stump's avatar Martin Stump
Browse files

Replace the comparison of `IControllerConfig`

parent f2447b55
No related branches found
No related tags found
1 merge request!153Replace the comparison of `IControllerConfig`
/*******************************************************************************
* Copyright (c) 2022-2023, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2024, Mercedes-Benz Tech Innovation GmbH
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
......@@ -17,10 +18,13 @@
#include <MantleAPI/Common/vector.h>
#include <units.h>
#include <tuple>
#include <vector>
namespace mantle_api
{
/// Defines how a route should be calculated
enum class RouteStrategy
{
......@@ -36,9 +40,29 @@ struct RouteWaypoint
/// Reference position used to form a route
mantle_api::Vec3<units::length::meter_t> waypoint{};
/// Defines how a route should be calculated
RouteStrategy route_strategy{RouteStrategy::kUndefined};
RouteStrategy route_strategy{};
};
/// @brief Equality comparison for RouteWaypoint
///
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are equal
inline bool operator==(const RouteWaypoint& lhs, const RouteWaypoint& rhs) noexcept
{
return std::tie(lhs.waypoint, lhs.route_strategy) == std::tie(rhs.waypoint, rhs.route_strategy);
}
/// @brief Inequality comparison for RouteWaypoint
///
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are not equal
inline bool operator!=(const RouteWaypoint& lhs, const RouteWaypoint& rhs) noexcept
{
return !(lhs == rhs);
}
/// Serves as a raw set of global coordinates and information for
/// linking them, from which the actual route can be calculated
struct RouteDefinition
......@@ -47,5 +71,26 @@ struct RouteDefinition
std::vector<mantle_api::RouteWaypoint> waypoints{};
};
/// @brief Equality comparison for RouteDefinition.
///
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are equal
inline bool operator==(const RouteDefinition& lhs, const RouteDefinition& rhs) noexcept
{
return lhs.waypoints == rhs.waypoints;
}
/// @brief Inequality comparison for RouteDefinition.
///
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are not equal
inline bool operator!=(const RouteDefinition& lhs, const RouteDefinition& rhs) noexcept
{
return !(lhs == rhs);
}
} // namespace mantle_api
#endif // MANTLEAPI_COMMON_ROUTE_DEFINITION_H
/*******************************************************************************
* Copyright (c) 2021-2023, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2024, Mercedes-Benz Tech Innovation GmbH
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
......@@ -38,7 +39,7 @@ struct IControllerConfig
std::string name;
/// Pointer to the map query service
/// @todo: Check why map_query_service is part of the interface because it is not set from engine side but only in the environment on calling AddController()
ILaneLocationQueryService* map_query_service{nullptr};
ILaneLocationQueryService* map_query_service{};
/// List of active control strategies
std::vector<std::shared_ptr<mantle_api::ControlStrategy>> control_strategies;
/// Specifies the route behavior for the control stratgies
......@@ -47,63 +48,37 @@ struct IControllerConfig
/// @brief Equality comparison for IControllerConfig.
///
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are equal
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are equal
inline bool operator==(const IControllerConfig& lhs, const IControllerConfig& rhs) noexcept
{
// Check if the objects are the same
if (&lhs == &rhs)
{
return true;
}
const auto compare_control_strategies = [](const auto& lhs, const auto& rhs)
const auto compare_control_strategy = [](const auto& lhs, const auto& rhs)
{
if (lhs.size() != rhs.size())
// Compare the objects pointed to by the shared_ptrs, handling the case where either is null
if (!lhs || !rhs)
{
return false;
return lhs == rhs; // Both are null (equal) or one is null (not equal)
}
else
{
for (size_t i = 0; i < lhs.size(); i++)
{
if (*(lhs[i]) != *(rhs[i]))
{
return false;
}
}
}
return true;
};
const auto compare_route_definition = [](const auto& lhs, const auto& rhs)
{
if (lhs.waypoints.size() != rhs.waypoints.size())
{
return false;
}
for (size_t i = 0; i < lhs.waypoints.size(); ++i)
{
if (lhs.waypoints[i].route_strategy != rhs.waypoints[i].route_strategy ||
lhs.waypoints[i].waypoint != rhs.waypoints[i].waypoint)
{
return false;
}
}
return true;
return *lhs == *rhs; // Both are non-null, compare the objects
};
return lhs.name == rhs.name &&
lhs.map_query_service == rhs.map_query_service &&
compare_control_strategies(lhs.control_strategies, rhs.control_strategies) &&
compare_route_definition(lhs.route_definition, rhs.route_definition);
std::equal(lhs.control_strategies.begin(), lhs.control_strategies.end(), rhs.control_strategies.begin(), rhs.control_strategies.end(), compare_control_strategy) &&
lhs.route_definition == rhs.route_definition;
}
/// @brief Check for not equal
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are not equal
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are not equal
inline bool operator!=(const IControllerConfig& lhs, const IControllerConfig& rhs) noexcept
{
return !(lhs == rhs);
......@@ -128,24 +103,20 @@ struct ExternalControllerConfig : public IControllerConfig
/// @brief Check for equality
///
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are equal
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are equal
inline bool operator==(const ExternalControllerConfig& lhs, const ExternalControllerConfig& rhs) noexcept
{
auto compare_base = [](const IControllerConfig& lhs, const IControllerConfig& rhs)
{
return lhs == rhs;
};
return compare_base(lhs, rhs) && lhs.parameters == rhs.parameters;
return static_cast<const IControllerConfig&>(lhs) == static_cast<const IControllerConfig&>(rhs) &&
lhs.parameters == rhs.parameters;
}
/// @brief Check for not equal
///
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are not equal
/// @param[in] lhs The left-hand side value for the comparison
/// @param[in] rhs The right-hand side value for the comparison
/// @returns true if the values of lhs and rhs are not equal
inline bool operator!=(const ExternalControllerConfig& lhs, const ExternalControllerConfig& rhs) noexcept
{
return !(lhs == rhs);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment