39
39
#include < ros/ros.h>
40
40
#include < pluginlib/class_loader.h>
41
41
#include < boost/shared_ptr.hpp>
42
+ #include < algorithm>
42
43
#include < fstream>
43
44
44
45
namespace urdf {
@@ -86,7 +87,7 @@ SensorMap parseSensors(const std::string &xml_string, const SensorParserMap &par
86
87
return parseSensors (xml_doc, parsers);
87
88
}
88
89
89
- const SensorParserMap& getDefaultSensorParserMap ( )
90
+ SensorParserMap getSensorParsers ( const std::vector<std::string> &allowed )
90
91
{
91
92
static boost::mutex PARSER_PLUGIN_LOCK;
92
93
static boost::shared_ptr<pluginlib::ClassLoader<urdf::SensorParser> > PARSER_PLUGIN_LOADER;
@@ -101,24 +102,35 @@ const SensorParserMap& getDefaultSensorParserMap()
101
102
const std::vector<std::string> &classes = PARSER_PLUGIN_LOADER->getDeclaredClasses ();
102
103
for (std::size_t i = 0 ; i < classes.size () ; ++i)
103
104
{
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]);
112
117
}
113
118
if (defaultParserMap.empty ())
114
119
ROS_WARN_STREAM (" No sensor parsers found" );
115
120
}
116
121
}
117
122
catch (const pluginlib::PluginlibException& ex)
118
123
{
119
- ROS_ERROR_STREAM (" Exception while creating sensor plugin loader " << ex.what ());
124
+ ROS_ERROR_STREAM (" Exception while creating sensor plugin loader " << ex.what ());
120
125
}
121
126
return defaultParserMap;
122
127
}
123
128
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
+
124
136
} // namespace
0 commit comments