Ask Your Question
1

PluginLib declaring template classes

asked 2012-10-01 22:10:17 -0500

Hi! Using template classes with the PluginLib looks interesting. However I've found several problems when I tried it. Firstly the macro PLUGINLIB_DECLARE_CLASS does not look to work with template classes, even using the typical "parameter pareteses for macros" [See Code 1], it finally worked using typedefs [See Code 2]. I would like to automate this mechanism to easily generate plugin classes.

I would like to declare a plugin for each template class instantiation in the code. For that I though two alternatives: - using the PLUGINLIB_DECLARE_CLASS in the class scope -> it didn't worked. The internal pocolib complains about it. - using metaprograming to generate in the root scope all the possible combinations of template class instantiation. Any Idea?(I think PCL do things like that). Finally I think it would be necesary a macro for stringfy a template classname for the 2nd parameter of the PLUGINLIB_DECLARE_CLASS. Any Idea about how to do this?

CODE 1

 #include <pluginlib class_list_macros.h=""> 
 //----- wrong plugin declaration --------
 PLUGINLIB_DECLARE_CLASS(rtcus_navigation, default_ds_twist,
(DefaultStateEstimation<DynamicState2D,Twist2D>),
(StateEstimtion<DynamicState2D,Twist2D>))

CODE 2

 //---- working template class plugin declaration -------- 
 typedef StateEstimtion<DynamicState2D,Twist2D> base;
 typedef DefaultStateEstimation<DynamicState2D,Twist2D> default_ds_twist;
 PLUGINLIB_DECLARE_CLASS(rtcus_navigation, default_DynamicState2D_Twist2D,default_ds_twist,base)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2012-10-02 02:22:36 -0500

I have found a partial solution. The plugin-base-class should inherit from an auxiliar-untemplated-base-class. After this you can use a dynamic_pointer_cast to the templated plugin-base-class. This is not bad given the dynamic load is itself dynamic, no additional and unexpected runtime errors should occur. given "NavigationNodeComponent" the auxiliar untemplated base class and state_estimator_name the name of the plugin we want to load.

pluginlib::ClassLoader<navigationnodecomponent> loader("rtcus_navigation","rtcus_navigation::NavigationNodeComponent");
shared_ptr<StateEstimation<StateType, ActionType, TimeModel> > new_state_estimation = 
   dynamic_pointer_cast<rtcus_navigation::StateEstimation<StateType, ActionType, TimeModel> >( 
    loader.createInstance(state_estimator_name));

However this is only for the loading stage. How to declare plugin in a more automated way and not manually remains unsolved.

edit flag offensive delete link more
0

answered 2012-10-02 01:53:50 -0500

dornhege gravatar image

I think that it should work in principle with one template parameter. The problem with two parameters is the ',' between them which the macro instantiation interprets as the separator between macro arguments (macros are "dumb" in the sense that they do not understand c++). So, you won't get around typedefs for this.

edit flag offensive delete link more

Comments

Yeah, the comma is the main problem.

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2012-10-02 02:14:09 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-10-01 22:10:17 -0500

Seen: 637 times

Last updated: Oct 02 '12