3939#include < ros/ros.h>
4040#include < pluginlib/class_loader.h>
4141#include < boost/shared_ptr.hpp>
42+ #include < algorithm>
4243#include < fstream>
4344
4445namespace urdf {
@@ -86,7 +87,7 @@ SensorMap parseSensors(const std::string &xml_string, const SensorParserMap &par
8687 return parseSensors (xml_doc, parsers);
8788}
8889
89- const SensorParserMap& getDefaultSensorParserMap ( )
90+ SensorParserMap getSensorParsers ( const std::vector<std::string> &allowed )
9091{
9192 static boost::mutex PARSER_PLUGIN_LOCK;
9293 static boost::shared_ptr<pluginlib::ClassLoader<urdf::SensorParser> > PARSER_PLUGIN_LOADER;
@@ -101,24 +102,35 @@ const SensorParserMap& getDefaultSensorParserMap()
101102 const std::vector<std::string> &classes = PARSER_PLUGIN_LOADER->getDeclaredClasses ();
102103 for (std::size_t i = 0 ; i < classes.size () ; ++i)
103104 {
104- urdf::SensorParserSharedPtr parser;
105- try {
106- parser = PARSER_PLUGIN_LOADER->createInstance (classes[i]);
107- } catch (const pluginlib::PluginlibException& ex) {
108- ROS_ERROR_STREAM (" Failed to create sensor parser: " << classes[i] << " \n " << ex.what ());
109- }
110- defaultParserMap.insert (std::make_pair (classes[i], parser));
111- ROS_DEBUG_STREAM (" added sensor parser: " << classes[i]);
105+ // skip this class if not listed in allowed
106+ if (!allowed.empty () && std::find (allowed.begin (), allowed.end (), classes[i]) == allowed.end ())
107+ continue ;
108+
109+ urdf::SensorParserSharedPtr parser;
110+ try {
111+ parser = PARSER_PLUGIN_LOADER->createInstance (classes[i]);
112+ } catch (const pluginlib::PluginlibException& ex) {
113+ ROS_ERROR_STREAM (" Failed to create sensor parser: " << classes[i] << " \n " << ex.what ());
114+ }
115+ defaultParserMap.insert (std::make_pair (classes[i], parser));
116+ ROS_DEBUG_STREAM (" added sensor parser: " << classes[i]);
112117 }
113118 if (defaultParserMap.empty ())
114119 ROS_WARN_STREAM (" No sensor parsers found" );
115120 }
116121 }
117122 catch (const pluginlib::PluginlibException& ex)
118123 {
119- ROS_ERROR_STREAM (" Exception while creating sensor plugin loader " << ex.what ());
124+ ROS_ERROR_STREAM (" Exception while creating sensor plugin loader " << ex.what ());
120125 }
121126 return defaultParserMap;
122127}
123128
129+ SensorParserMap getSensorParser (const std::string &name)
130+ {
131+ std::vector<std::string> allowed;
132+ allowed.push_back (name);
133+ return getSensorParsers (allowed);
134+ }
135+
124136} // namespace
0 commit comments