23#include "auto_apms_util/container.hpp"
24#include "auto_apms_util/exceptions.hpp"
25#include "auto_apms_util/string.hpp"
26#include "pluginlib/class_loader.hpp"
45 const std::string & resource_type,
const std::set<std::string> & exclude_packages = {});
110template <
typename BaseT>
129 const std::string & base_package,
const std::string & base_class,
130 const std::set<std::string> & exclude_packages = {});
156 const std::string & base_package,
const std::string & base_class,
157 const std::set<std::string> & exclude_packages = {},
158 const std::map<std::string, std::string> & reserved_names = {});
179 const std::string & base_package,
const std::string & base_class,
180 const std::set<std::string> & exclude_packages = {},
181 const std::map<std::string, std::string> & reserved_names = {});
194template <
typename BaseT>
196 const std::string & base_package,
const std::string & base_class,
const std::set<std::string> & exclude_packages)
197: pluginlib::ClassLoader<BaseT>(base_package, base_class,
"",
collectPluginXMLPaths(exclude_packages))
201template <
typename BaseT>
203 const std::string & base_package,
const std::string & base_class,
const std::set<std::string> & exclude_packages,
204 const std::map<std::string, std::string> & reserved_names)
207 return {base_package, base_class, exclude_packages};
210template <
typename BaseT>
212 const std::string & base_package,
const std::string & base_class,
const std::set<std::string> & exclude_packages,
213 const std::map<std::string, std::string> & reserved_names)
215 std::map<std::string, std::vector<std::string>> packages_for_class_name;
217 for (
const auto & package : packages) {
218 auto single_package_loader =
219 pluginlib::ClassLoader<BaseT>(base_package, base_class,
"", {
getPluginXMLPath(package)});
220 for (
const auto & class_name : single_package_loader.getDeclaredClasses()) {
221 packages_for_class_name[class_name].push_back(package);
226 for (
const auto & [class_name, package] : reserved_names) {
227 packages_for_class_name[class_name].push_back(package);
231 std::vector<std::string> error_details;
232 for (
const auto & [class_name, packages] : packages_for_class_name) {
233 if (packages.size() > 1) {
234 error_details.push_back(
235 "- Class '" + class_name +
"' found in packages ['" + auto_apms_util::join(packages,
"', '") +
"'].");
238 if (!error_details.empty()) {
239 throw exceptions::ResourceError(
240 "Ambiguous class names found! PluginClassLoader (Base: " + base_class +
241 ") verified with verifyUnambiguousClassNames() won't register resources from packages "
242 "that use already existing lookup names. Found the following duplicates:\n" +
243 auto_apms_util::join(error_details,
"\n"));
247template <
typename BaseT>
250 std::map<std::string, std::string> map;
251 for (
const std::string & class_name : this->getDeclaredClasses()) {
252 map[class_name] = this->getClassPackage(class_name);
static PluginClassLoader makeUnambiguousPluginClassLoader(const std::string &base_package, const std::string &base_class, const std::set< std::string > &exclude_packages={}, const std::map< std::string, std::string > &reserved_names={})
Parse all associated plugin manifest files registered with the ament resource index and instantiate a...
static void verifyUnambiguousClassNames(const std::string &base_package, const std::string &base_class, const std::set< std::string > &exclude_packages={}, const std::map< std::string, std::string > &reserved_names={})
Perform the ambiguity check of makeUnambiguousPluginClassLoader without creating a PluginClassLoader.
std::map< std::string, std::string > getClassPackageMap()
Retrieve a map that contains information about which package a plugin class belongs to.
PluginClassLoader(const std::string &base_package, const std::string &base_class, const std::set< std::string > &exclude_packages={})
Standard PluginClassLoader constructor.
std::vector< std::string > collectPluginXMLPaths(const std::set< std::string > &exclude_packages={})
Collect the paths of plugins.xml manifest files generated by AutoAPMS.
std::string getPluginXMLPath(const std::string &package)
Get the path of a specific plugins.xml manifest file generated by AutoAPMS.
std::set< std::string > getPackagesWithResourceType(const std::string &resource_type, const std::set< std::string > &exclude_packages={})
Get a list of all package names that register a certain type of ament_index resources.
std::set< std::string > getPackagesWithPluginResources(const std::set< std::string > &exclude_packages={})
Get a list of all package names that register AutoAPMS plugin resources.
Fundamental helper classes and utility functions.