class_loader
master
The class_loader package is a ROS-independent package for loading plugins during runtime.
|
Go to the documentation of this file.
32 #ifndef CLASS_LOADER__MULTI_LIBRARY_CLASS_LOADER_HPP_
33 #define CLASS_LOADER__MULTI_LIBRARY_CLASS_LOADER_HPP_
44 # pragma clang diagnostic push
45 # pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
47 #include "console_bridge/console.h"
49 # pragma clang diagnostic pop
62 class MultiLibraryClassLoaderImpl;
95 CONSOLE_BRIDGE_logDebug(
96 "class_loader::MultiLibraryClassLoader: "
97 "Attempting to create instance of class type %s.",
99 ClassLoader * loader = getClassLoaderForClass<Base>(class_name);
100 if (
nullptr == loader) {
102 "MultiLibraryClassLoader: Could not create object of class type " +
104 " as no factory exists for it. Make sure that the library exists and " +
105 "was explicitly loaded through MultiLibraryClassLoader::loadLibrary()");
124 ClassLoader * loader = getClassLoaderForLibrary(library_path);
125 if (
nullptr == loader) {
127 "Could not create instance as there is no ClassLoader in "
128 "MultiLibraryClassLoader bound to library " + library_path +
129 " Ensure you called MultiLibraryClassLoader::loadLibrary()");
146 CONSOLE_BRIDGE_logDebug(
147 "class_loader::MultiLibraryClassLoader: Attempting to create instance of class type %s.",
149 ClassLoader * loader = getClassLoaderForClass<Base>(class_name);
150 if (
nullptr == loader) {
152 "MultiLibraryClassLoader: Could not create object of class type " + class_name +
153 " as no factory exists for it. "
154 "Make sure that the library exists and was explicitly loaded through "
155 "MultiLibraryClassLoader::loadLibrary()");
173 ClassLoader * loader = getClassLoaderForLibrary(library_path);
174 if (
nullptr == loader) {
176 "Could not create instance as there is no ClassLoader in "
177 "MultiLibraryClassLoader bound to library " + library_path +
178 " Ensure you called MultiLibraryClassLoader::loadLibrary()");
196 ClassLoader * loader = getClassLoaderForClass<Base>(class_name);
197 if (
nullptr == loader) {
199 "MultiLibraryClassLoader: Could not create class of type " + class_name);
216 ClassLoader * loader = getClassLoaderForLibrary(library_path);
217 if (
nullptr == loader) {
219 "Could not create instance as there is no ClassLoader in MultiLibraryClassLoader "
220 "bound to library " + library_path +
221 " Ensure you called MultiLibraryClassLoader::loadLibrary()");
238 available_classes.
begin(), available_classes.
end(), class_name);
247 bool isLibraryAvailable(
const std::string & library_path)
const;
259 for (
auto & loader : getAllAvailableClassLoaders()) {
262 available_classes.
end(), loader_classes.
begin(), loader_classes.
end());
264 return available_classes;
276 ClassLoader * loader = getClassLoaderForLibrary(library_path);
277 if (
nullptr == loader) {
279 "There is no ClassLoader in MultiLibraryClassLoader bound to library " +
281 " Ensure you called MultiLibraryClassLoader::loadLibrary()");
316 bool isOnDemandLoadUnloadEnabled()
const;
331 template<
typename Base>
335 for (ClassLoaderVector::iterator i = loaders.
begin(); i != loaders.
end(); ++i) {
336 if (!(*i)->isLibraryLoaded()) {
339 if ((*i)->isClassAvailable<Base>(class_name)) {
356 void shutdownAllClassLoaders();
358 MultiLibraryClassLoaderImpl * impl_;
363 #endif // CLASS_LOADER__MULTI_LIBRARY_CLASS_LOADER_HPP_
void loadLibrary(const std::string &library_path, ClassLoader *loader)
Loads a library into memory if it has not already been done so. Attempting to load an already loaded ...
Definition: class_loader.hpp:59
Base * createUnmanagedInstance(const std::string &derived_class_name)
Generates an instance of loadable classes (i.e. class_loader).
Definition: class_loader.hpp:170
Base * createUnmanagedInstance(const std::string &class_name)
Creates an instance of an object of given class name with ancestor class Base This version does not l...
Definition: multi_library_class_loader.hpp:194
A ClassLoader that can bind more than one runtime library.
Definition: multi_library_class_loader.hpp:68
std::shared_ptr< Base > createInstance(const std::string &derived_class_name)
Generates an instance of loadable classes (i.e. class_loader).
Definition: class_loader.hpp:125
Base * createUnmanagedInstance(const std::string &class_name, const std::string &library_path)
Creates an instance of an object of given class name with ancestor class Base This version takes a sp...
Definition: multi_library_class_loader.hpp:214
std::vector< std::string > getAvailableClasses() const
Indicates which classes (i.e. class_loader) that can be loaded by this object.
Definition: class_loader.hpp:110
std::map< LibraryPath, class_loader::ClassLoader * > LibraryToClassLoaderMap
Definition: multi_library_class_loader.hpp:59
bool isClassAvailable(const std::string &class_name) const
Indicates if a class has been loaded and can be instantiated.
Definition: multi_library_class_loader.hpp:234
std::vector< std::string > getAvailableClasses() const
Gets a list of all classes that are loaded by the class loader.
Definition: multi_library_class_loader.hpp:256
std::vector< ClassLoader * > ClassLoaderVector
Definition: multi_library_class_loader.hpp:60
ClassLoader::UniquePtr< Base > createUniqueInstance(const std::string &class_name, const std::string &library_path)
Creates an instance of an object of given class name with ancestor class Base.
Definition: multi_library_class_loader.hpp:171
std::shared_ptr< Base > createInstance(const std::string &class_name, const std::string &library_path)
Creates an instance of an object of given class name with ancestor class Base This version takes a sp...
Definition: multi_library_class_loader.hpp:121
std::vector< std::string > getAvailableClassesForLibrary(const std::string &library_path)
Gets a list of all classes loaded for a particular library.
Definition: multi_library_class_loader.hpp:274
This class allows loading and unloading of dynamically linked libraries which contain class definitio...
Definition: class_loader.hpp:79
#define CLASS_LOADER_PUBLIC
Definition: visibility_control.hpp:58
UniquePtr< Base > createUniqueInstance(const std::string &derived_class_name)
Generates an instance of loadable classes (i.e. class_loader).
Definition: class_loader.hpp:147
ClassLoader::UniquePtr< Base > createUniqueInstance(const std::string &class_name)
Creates an instance of an object of given class name with ancestor class Base.
Definition: multi_library_class_loader.hpp:144
std::string LibraryPath
Definition: multi_library_class_loader.hpp:58
std::shared_ptr< Base > createInstance(const std::string &class_name)
Creates an instance of an object of given class name with ancestor class Base This version does not l...
Definition: multi_library_class_loader.hpp:93
An exception class thrown when a multilibrary class loader does not have a ClassLoader bound to it.
Definition: exceptions.hpp:96
void unloadLibrary(const std::string &library_path, ClassLoader *loader)
Unloads a library if it loaded in memory and cleans up its corresponding class factories....
An exception class thrown when class_loader is unable to create a plugin.
Definition: exceptions.hpp:83