From 26bfdc82113c8ef9a826b883b58a3ea0a24e2ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20L=C3=BCdtke?= Date: Sat, 21 Oct 2017 18:17:57 +0200 Subject: [PATCH] do not require default constructors for HardwareInterface classes ResourceManager-based interfaces still need a default constructor. --- .../internal/interface_manager.h | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/hardware_interface/include/hardware_interface/internal/interface_manager.h b/hardware_interface/include/hardware_interface/internal/interface_manager.h index dad46e09f..b65053747 100644 --- a/hardware_interface/include/hardware_interface/internal/interface_manager.h +++ b/hardware_interface/include/hardware_interface/internal/interface_manager.h @@ -95,6 +95,31 @@ struct CheckIsResourceManager { // calls ResourceManager::concatManagers if C is a ResourceManager static void callGetResources(std::vector &resources, T* iface) { return callGR(resources, iface, 0); } + + template + static T* newCI(boost::ptr_vector &guards, typename C::resource_manager_type*) + { + T* iface_combo = new T; + // save the new interface pointer to allow for its correct destruction + guards.push_back(static_cast(iface_combo)); + return iface_combo; + } + + // method called if C is not a ResourceManager + template + static T* newCI(boost::ptr_vector &guards, ...) { + // it is not a ResourceManager + ROS_ERROR("You cannot register multiple interfaces of the same type which are " + "not of type ResourceManager. There is no established protocol " + "for combining them."); + return NULL; + } + + static T* newCombinedInterface(boost::ptr_vector &guards) + { + return newCI(guards, 0); + } + }; class InterfaceManager @@ -180,13 +205,8 @@ class InterfaceManager iface_combo = static_cast(it_combo->second); } else { // no existing combined interface - if(CheckIsResourceManager::value) { - // it is a ResourceManager - - // create a new combined interface - iface_combo = new T; - // save the new interface pointer to allow for its correct destruction - interface_destruction_list_.push_back(reinterpret_cast(iface_combo)); + iface_combo = CheckIsResourceManager::newCombinedInterface(interface_destruction_list_); + if(iface_combo) { // concat all of the resource managers together CheckIsResourceManager::callConcatManagers(iface_list, iface_combo); // save the combined interface for if this is called again