29 #ifndef PLUGINLIB_FACTORY_H 30 #define PLUGINLIB_FACTORY_H 34 #include <QStringList> 59 Type*(*factory_function_)();
76 for(
size_t i = 0; i < std_ids.size(); i++ )
78 ids.push_back( QString::fromStdString( std_ids[ i ]));
80 typename QHash<QString, BuiltInClassRecord>::const_iterator iter;
83 ids.push_back( iter.key() );
90 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find( class_id );
93 return iter->description_;
100 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find( class_id );
110 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find( class_id );
113 return iter->package_;
120 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find( class_id );
128 virtual QIcon
getIcon(
const QString& class_id )
const 130 QString
package = getClassPackage( class_id );
132 QIcon icon =
loadPixmap(
"package://"+
package+
"/icons/classes/"+class_name+
".svg" );
138 icon =
loadPixmap(
"package://rviz/icons/default_class_icon.png");
144 virtual void addBuiltInClass(
const QString& package,
const QString& name,
const QString& description,
145 Type* (*factory_function)() )
147 BuiltInClassRecord record;
148 record.class_id_ =
package + "/" + name;
149 record.package_ = package;
151 record.description_ = description;
152 record.factory_function_ = factory_function;
168 virtual Type*
makeRaw(
const QString& class_id, QString* error_return =
NULL )
170 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find( class_id );
173 Type* instance = iter->factory_function_();
174 if( instance ==
NULL && error_return !=
NULL )
176 *error_return =
"Factory function for built-in class '" + class_id +
"' returned NULL.";
186 ROS_ERROR(
"PluginlibFactory: The plugin for class '%s' failed to load. Error: %s",
187 qPrintable( class_id ), ex.what() );
190 *error_return = QString::fromStdString( ex.what() );
203 #endif // PLUGINLIB_FACTORY_H virtual std::string getPluginManifestPath(const std::string &lookup_name)
pluginlib::ClassLoader< Type > * class_loader_
virtual Type * makeRaw(const QString &class_id, QString *error_return=NULL)
Instantiate and return a instance of a subclass of Type using our pluginlib::ClassLoader.
virtual std::string getClassDescription(const std::string &lookup_name)
virtual void addBuiltInClass(const QString &package, const QString &name, const QString &description, Type *(*factory_function)())
Templated factory which informs objects created by it what their class identifier string was...
T * createUnmanagedInstance(const std::string &lookup_name)
virtual QString getClassName(const QString &class_id) const
virtual QIcon getIcon(const QString &class_id) const
virtual std::string getClassPackage(const std::string &lookup_name)
virtual QStringList getDeclaredClassIds()
virtual QString getClassPackage(const QString &class_id) const
std::vector< std::string > getDeclaredClasses()
virtual ~PluginlibFactory()
QHash< QString, BuiltInClassRecord > built_ins_
virtual std::string getName(const std::string &lookup_name)
virtual QString getClassDescription(const QString &class_id) const
QPixmap loadPixmap(QString url, bool fill_cache)
PluginlibFactory(const QString &package, const QString &base_class_type)
virtual QString getPluginManifestPath(const QString &class_id) const