Skip to content

Commit

Permalink
Change compile time check for ParamsType in API::spawn
Browse files Browse the repository at this point in the history
Change behavior from not matching the templated function to matching to everything, but then asserting the correct types. This better reflects the intention, as we do not want to match some other function for different types, but to terminate the compilation

Signed-off-by: Mateusz Palczuk <mateusz.palczuk@robotec.ai>
  • Loading branch information
TauTheLepton committed Feb 19, 2025
1 parent 28f3177 commit 0350572
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ class API
auto updateFrame() -> bool;

// entities, ego - spawn
template <
typename PoseType, typename ParamsType,
typename = std::enable_if_t<std::disjunction_v<
std::is_same<std::decay_t<ParamsType>, traffic_simulator_msgs::msg::VehicleParameters>,
std::is_same<std::decay_t<ParamsType>, traffic_simulator_msgs::msg::PedestrianParameters>,
std::is_same<std::decay_t<ParamsType>, traffic_simulator_msgs::msg::MiscObjectParameters>>>>
template <typename PoseType, typename ParamsType>
auto spawn(
const std::string & name, const PoseType & pose, const ParamsType & parameters,
const std::string & behavior = "", const std::string & model3d = "") -> entity::EntityBase &
Expand All @@ -124,6 +119,14 @@ class API
using PedestrianParameters = traffic_simulator_msgs::msg::PedestrianParameters;
using MiscObjectParameters = traffic_simulator_msgs::msg::MiscObjectParameters;

static_assert(
std::disjunction_v<
std::is_same<std::decay_t<ParamsType>, VehicleParameters>,
std::is_same<std::decay_t<ParamsType>, PedestrianParameters>,
std::is_same<std::decay_t<ParamsType>, MiscObjectParameters>>,
"ParamsType must be either a VehicleParameters, a PedestrianParameters, or a "
"MiscObjectParameters");

auto register_to_entity_manager = [&]() -> entity::EntityBase & {
if constexpr (std::is_same_v<ParamsType, VehicleParameters>) {
if (behavior == VehicleBehavior::autoware()) {
Expand Down

0 comments on commit 0350572

Please sign in to comment.