Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00030
00031 #ifndef HARDWARE_INTERFACE_INTERFACE_MANAGER_H
00032 #define HARDWARE_INTERFACE_INTERFACE_MANAGER_H
00033
00034 #include <map>
00035 #include <string>
00036
00037 #include <ros/console.h>
00038
00039 #include <hardware_interface/internal/demangle_symbol.h>
00040
00041 namespace hardware_interface
00042 {
00043
00044 class InterfaceManager
00045 {
00046 public:
00056 template<class T>
00057 void registerInterface(T* iface)
00058 {
00059 const std::string iface_name = internal::demangledTypeName<T>();
00060 if (interfaces_.find(iface_name) != interfaces_.end())
00061 {
00062 ROS_WARN_STREAM("Replacing previously registered interface '" << iface_name << "'.");
00063 }
00064 interfaces_[internal::demangledTypeName<T>()] = iface;
00065 }
00066
00077 template<class T>
00078 T* get()
00079 {
00080 InterfaceMap::iterator it = interfaces_.find(internal::demangledTypeName<T>());
00081 if (it == interfaces_.end())
00082 return NULL;
00083
00084 T* iface = static_cast<T*>(it->second);
00085 if (!iface)
00086 {
00087 ROS_ERROR_STREAM("Failed reconstructing type T = '" << internal::demangledTypeName<T>().c_str() <<
00088 "'. This should never happen");
00089 return NULL;
00090 }
00091 return iface;
00092 }
00093
00094 protected:
00095 typedef std::map<std::string, void*> InterfaceMap;
00096 InterfaceMap interfaces_;
00097 };
00098
00099 }
00100
00101 #endif // header guard