Skip to content

Commit

Permalink
shared_ptr<X> -> X::SharedPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
bmagyar committed Oct 5, 2024
1 parent fbc6e3a commit 730e91b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ class ChainableControllerInterface : public ControllerInterfaceBase
bool is_chainable() const final;

CONTROLLER_INTERFACE_PUBLIC
std::vector<std::shared_ptr<hardware_interface::StateInterface>> export_state_interfaces() final;
std::vector<hardware_interface::StateInterface::SharedPtr> export_state_interfaces() final;

CONTROLLER_INTERFACE_PUBLIC
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> export_reference_interfaces()
final;
std::vector<hardware_interface::CommandInterface::SharedPtr> export_reference_interfaces() final;

CONTROLLER_INTERFACE_PUBLIC
bool set_chained_mode(bool chained_mode) final;
Expand Down Expand Up @@ -134,9 +133,8 @@ class ChainableControllerInterface : public ControllerInterfaceBase

/// Storage of values for state interfaces
std::vector<std::string> exported_state_interface_names_;
std::vector<std::shared_ptr<hardware_interface::StateInterface>>
ordered_exported_state_interfaces_;
std::unordered_map<std::string, std::shared_ptr<hardware_interface::StateInterface>>
std::vector<hardware_interface::StateInterface::SharedPtr> ordered_exported_state_interfaces_;
std::unordered_map<std::string, hardware_interface::StateInterface::SharedPtr>
exported_state_interfaces_;
// BEGIN (Handle export change): for backward compatibility
std::vector<double> state_interfaces_values_;
Expand All @@ -147,8 +145,8 @@ class ChainableControllerInterface : public ControllerInterfaceBase
// BEGIN (Handle export change): for backward compatibility
std::vector<double> reference_interfaces_;
// END
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> ordered_reference_interfaces_;
std::unordered_map<std::string, std::shared_ptr<hardware_interface::CommandInterface>>
std::vector<hardware_interface::CommandInterface::SharedPtr> ordered_reference_interfaces_;
std::unordered_map<std::string, hardware_interface::CommandInterface::SharedPtr>
reference_interfaces_ptrs_;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ class ControllerInterface : public controller_interface::ControllerInterfaceBase
* \returns empty list.
*/
CONTROLLER_INTERFACE_PUBLIC
std::vector<std::shared_ptr<hardware_interface::StateInterface>> export_state_interfaces() final;
std::vector<hardware_interface::StateInterface::SharedPtr> export_state_interfaces() final;

/**
* Controller has no reference interfaces.
*
* \returns empty list.
*/
CONTROLLER_INTERFACE_PUBLIC
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> export_reference_interfaces()
final;
std::vector<hardware_interface::CommandInterface::SharedPtr> export_reference_interfaces() final;

/**
* Controller is not chainable, therefore no chained mode can be set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class ControllerInterfaceBase : public rclcpp_lifecycle::node_interfaces::Lifecy
* \returns list of command interfaces for preceding controllers.
*/
CONTROLLER_INTERFACE_PUBLIC
virtual std::vector<std::shared_ptr<hardware_interface::CommandInterface>>
virtual std::vector<hardware_interface::CommandInterface::SharedPtr>
export_reference_interfaces() = 0;

/**
Expand All @@ -245,8 +245,7 @@ class ControllerInterfaceBase : public rclcpp_lifecycle::node_interfaces::Lifecy
* \returns list of state interfaces for preceding controllers.
*/
CONTROLLER_INTERFACE_PUBLIC
virtual std::vector<std::shared_ptr<hardware_interface::StateInterface>>
export_state_interfaces() = 0;
virtual std::vector<hardware_interface::StateInterface::SharedPtr> export_state_interfaces() = 0;

/**
* Set chained mode of a chainable controller. This method triggers internal processes to switch
Expand Down
10 changes: 5 additions & 5 deletions controller_interface/src/chainable_controller_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ return_type ChainableControllerInterface::update(
return ret;
}

std::vector<std::shared_ptr<hardware_interface::StateInterface>>
std::vector<hardware_interface::StateInterface::SharedPtr>
ChainableControllerInterface::export_state_interfaces()
{
auto state_interfaces = on_export_state_interfaces();
std::vector<std::shared_ptr<hardware_interface::StateInterface>> state_interfaces_ptrs_vec;
std::vector<hardware_interface::StateInterface::SharedPtr> state_interfaces_ptrs_vec;
state_interfaces_ptrs_vec.reserve(state_interfaces.size());
ordered_exported_state_interfaces_.reserve(state_interfaces.size());
exported_state_interface_names_.reserve(state_interfaces.size());
Expand Down Expand Up @@ -94,11 +94,11 @@ ChainableControllerInterface::export_state_interfaces()
return state_interfaces_ptrs_vec;
}

std::vector<std::shared_ptr<hardware_interface::CommandInterface>>
std::vector<hardware_interface::CommandInterface::SharedPtr>
ChainableControllerInterface::export_reference_interfaces()
{
auto reference_interfaces = on_export_reference_interfaces();
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> reference_interfaces_ptrs_vec;
std::vector<hardware_interface::CommandInterface::SharedPtr> reference_interfaces_ptrs_vec;
reference_interfaces_ptrs_vec.reserve(reference_interfaces.size());
exported_reference_interface_names_.reserve(reference_interfaces.size());
ordered_reference_interfaces_.reserve(reference_interfaces.size());
Expand Down Expand Up @@ -134,7 +134,7 @@ ChainableControllerInterface::export_reference_interfaces()
throw std::runtime_error(error_msg);
}

std::shared_ptr<hardware_interface::CommandInterface> reference_interface =
hardware_interface::CommandInterface::SharedPtr reference_interface =
std::make_shared<hardware_interface::CommandInterface>(std::move(interface));
const auto inteface_name = reference_interface->get_name();
// check the exported interface name is unique
Expand Down
4 changes: 2 additions & 2 deletions controller_interface/src/controller_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ ControllerInterface::ControllerInterface() : ControllerInterfaceBase() {}

bool ControllerInterface::is_chainable() const { return false; }

std::vector<std::shared_ptr<hardware_interface::StateInterface>>
std::vector<hardware_interface::StateInterface::SharedPtr>
ControllerInterface::export_state_interfaces()
{
return {};
}

std::vector<std::shared_ptr<hardware_interface::CommandInterface>>
std::vector<hardware_interface::CommandInterface::SharedPtr>
ControllerInterface::export_reference_interfaces()
{
return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ TEST_F(ChainableControllerInterfaceTest, interfaces_prefix_is_not_node_name)
controller.set_name_prefix_of_reference_interfaces("some_not_correct_interface_prefix");

// expect empty return because interface prefix is not equal to the node name
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> exported_reference_interfaces;
std::vector<hardware_interface::CommandInterface::SharedPtr> exported_reference_interfaces;
EXPECT_THROW(
{ exported_reference_interfaces = controller.export_reference_interfaces(); },
std::runtime_error);
ASSERT_THAT(exported_reference_interfaces, IsEmpty());
// expect empty return because interface prefix is not equal to the node name
std::vector<std::shared_ptr<hardware_interface::StateInterface>> exported_state_interfaces;
std::vector<hardware_interface::StateInterface::SharedPtr> exported_state_interfaces;
EXPECT_THROW(
{ exported_state_interfaces = controller.export_state_interfaces(); }, std::runtime_error);
ASSERT_THAT(exported_state_interfaces, IsEmpty());
Expand Down
4 changes: 2 additions & 2 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,8 @@ controller_interface::return_type ControllerManager::configure_controller(
get_logger(),
"Controller '%s' is chainable. Interfaces are being exported to resource manager.",
controller_name.c_str());
std::vector<std::shared_ptr<hardware_interface::StateInterface>> state_interfaces;
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> ref_interfaces;
std::vector<hardware_interface::StateInterface::SharedPtr> state_interfaces;
std::vector<hardware_interface::CommandInterface::SharedPtr> ref_interfaces;
try
{
state_interfaces = controller->export_state_interfaces();
Expand Down
2 changes: 1 addition & 1 deletion hardware_interface_testing/test/test_resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ TEST_F(ResourceManagerTest, managing_controllers_reference_interfaces)
CONTROLLER_NAME + "/" + REFERENCE_INTERFACE_NAMES[1],
CONTROLLER_NAME + "/" + REFERENCE_INTERFACE_NAMES[2]};

std::vector<std::shared_ptr<hardware_interface::CommandInterface>> reference_interfaces;
std::vector<hardware_interface::CommandInterface::SharedPtr> reference_interfaces;
std::vector<double> reference_interface_values = {1.0, 2.0, 3.0};

for (size_t i = 0; i < REFERENCE_INTERFACE_NAMES.size(); ++i)
Expand Down

0 comments on commit 730e91b

Please sign in to comment.