29 #ifndef PLUGINLIB_FACTORY_H 30 #define PLUGINLIB_FACTORY_H 34 #include <QStringList> 60 Type* (*factory_function_)();
78 for (
size_t i = 0; i < std_ids.size(); i++)
80 ids.push_back(QString::fromStdString(std_ids[i]));
82 typename QHash<QString, BuiltInClassRecord>::const_iterator iter;
85 ids.push_back(iter.key());
92 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find(class_id);
95 return iter->description_;
102 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find(class_id);
112 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find(class_id);
115 return iter->package_;
122 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find(class_id);
130 QIcon
getIcon(
const QString& class_id)
const override 132 QString
package = getClassPackage(class_id);
134 QIcon icon =
loadPixmap(
"package://" +
package +
"/icons/classes/" + class_name +
".svg");
137 icon =
loadPixmap(
"package://" +
package +
"/icons/classes/" + class_name +
".png");
140 icon =
loadPixmap(
"package://rviz/icons/default_class_icon.png");
148 const QString& description,
149 Type* (*factory_function)())
151 BuiltInClassRecord record;
152 record.class_id_ =
package + "/" + name;
153 record.package_ = package;
155 record.description_ = description;
156 record.factory_function_ = factory_function;
173 Type*
makeRaw(
const QString& class_id, QString* error_return =
nullptr)
override 175 typename QHash<QString, BuiltInClassRecord>::const_iterator iter =
built_ins_.find(class_id);
178 Type* instance = iter->factory_function_();
179 if (instance ==
nullptr && error_return !=
nullptr)
181 *error_return =
"Factory function for built-in class '" + class_id +
"' returned NULL.";
191 ROS_ERROR(
"PluginlibFactory: The plugin for class '%s' failed to load. Error: %s",
192 qPrintable(class_id), ex.what());
195 *error_return = QString::fromStdString(ex.what());
208 #endif // PLUGINLIB_FACTORY_H virtual std::string getPluginManifestPath(const std::string &lookup_name)
pluginlib::ClassLoader< Type > * class_loader_
QStringList getDeclaredClassIds() override
QString getClassDescription(const QString &class_id) const override
virtual std::string getClassDescription(const std::string &lookup_name)
QString getClassPackage(const QString &class_id) const override
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 std::string getClassPackage(const std::string &lookup_name)
virtual QString getPluginManifestPath(const QString &class_id) const
std::vector< std::string > getDeclaredClasses()
QString getClassName(const QString &class_id) const override
QHash< QString, BuiltInClassRecord > built_ins_
virtual std::string getName(const std::string &lookup_name)
Type * makeRaw(const QString &class_id, QString *error_return=nullptr) override
Instantiate and return a instance of a subclass of Type using our pluginlib::ClassLoader.
QPixmap loadPixmap(QString url, bool fill_cache)
QIcon getIcon(const QString &class_id) const override
~PluginlibFactory() override
PluginlibFactory(const QString &package, const QString &base_class_type)