class_loader.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef PLUGINLIB__CLASS_LOADER_HPP_
31 #define PLUGINLIB__CLASS_LOADER_HPP_
32 
33 #include <map>
34 #include <string>
35 #include <vector>
36 
37 #include "boost/algorithm/string.hpp"
39 #include "pluginlib/class_desc.hpp"
41 #include "pluginlib/exceptions.hpp"
42 #include "ros/console.h"
43 #include "ros/package.h"
44 #include "tinyxml2.h" // NOLINT
45 
46 // Note: pluginlib has traditionally utilized a "lookup name" for classes that does not match its
47 // real C++ name.
48 // This was done due to limitations of how pluginlib was implemented.
49 // As of version 1.9, a lookup name is no longer necessary and an attempt to the merge two concepts
50 // is underway.
51 
52 namespace pluginlib
53 {
54 
55 #if __cplusplus >= 201103L
56 template<typename T>
58 #endif
59 template<class T>
62 {
63 public:
64  typedef typename std::map<std::string, ClassDesc>::iterator ClassMapIterator;
65 
66 public:
76  std::string package, std::string base_class,
77  std::string attrib_name = std::string("plugin"),
78  std::vector<std::string> plugin_xml_paths = std::vector<std::string>());
79 
81 
84  ~ClassLoader() override;
85 
87 
97  [[deprecated]] T * createClassInstance(
98  const std::string & lookup_name,
99  bool auto_load = true);
100 
102 
113  boost::shared_ptr<T> createInstance(const std::string & lookup_name);
114 
115 #if __cplusplus >= 201103L
116 
132  UniquePtr<T> createUniqueInstance(const std::string & lookup_name);
133 #endif
134 
136 
149  T * createUnmanagedInstance(const std::string & lookup_name);
150 
152 
155  std::vector<std::string> getPluginXmlPaths();
156 
158 
161  std::vector<std::string> getDeclaredClasses();
162 
164 
168  virtual std::string getName(const std::string & lookup_name);
169 
171 
174  virtual std::string getBaseClassType() const;
175 
177 
181  virtual std::string getClassType(const std::string & lookup_name);
182 
184 
188  virtual std::string getClassDescription(const std::string & lookup_name);
189 
191 
195  virtual std::string getClassLibraryPath(const std::string & lookup_name);
196 
198 
202  virtual std::string getClassPackage(const std::string & lookup_name);
203 
205 
209  virtual std::string getPluginManifestPath(const std::string & lookup_name);
210 
212 
215  virtual std::vector<std::string> getRegisteredLibraries();
216 
218 
222  bool isClassLoaded(const std::string & lookup_name);
223 
225 
229  virtual bool isClassAvailable(const std::string & lookup_name);
230 
232 
239  virtual void loadLibraryForClass(const std::string & lookup_name);
240 
242 
245  virtual void refreshDeclaredClasses();
246 
248 
256  virtual int unloadLibraryForClass(const std::string & lookup_name);
257 
258 private:
260 
264  std::vector<std::string> getPluginXmlPaths(
265  const std::string & package,
266  const std::string & attrib_name,
267  bool force_recrawl = false);
268 
270 
275  std::map<std::string, ClassDesc> determineAvailableClasses(
276  const std::vector<std::string> & plugin_xml_paths);
277 
279 
283  std::string extractPackageNameFromPackageXML(const std::string & package_xml_path);
284 
286 
291  std::vector<std::string> getAllLibraryPathsToTry(
292  const std::string & library_name,
293  const std::string & exporting_package_name);
294 
296  std::vector<std::string> getCatkinLibraryPaths();
297 
299 
303  std::string getErrorStringForUnknownClass(const std::string & lookup_name);
304 
306  std::string getPathSeparator();
307 
309  std::string getROSBuildLibraryPath(const std::string & exporting_package_name);
310 
312  std::string getPackageFromPluginXMLFilePath(const std::string & path);
313 
315  std::string joinPaths(const std::string & path1, const std::string & path2);
316 
318 
323  const std::string & xml_file, std::map<std::string,
324  ClassDesc> & class_available);
325 
327 
331  std::string stripAllButFileFromPath(const std::string & path);
332 
333 
335 
339  int unloadClassLibraryInternal(const std::string & library_path);
340 
341 private:
342  std::vector<std::string> plugin_xml_paths_;
343  // Map from library to class's descriptions described in XML.
344  std::map<std::string, ClassDesc> classes_available_;
345  std::string package_;
346  std::string base_class_;
347  std::string attrib_name_;
349 };
350 
351 } // namespace pluginlib
352 
353 // Note: The implementation of the methods is in a separate file for clarity.
354 #include "./class_loader_imp.hpp"
355 
356 #endif // PLUGINLIB__CLASS_LOADER_HPP_
pluginlib::ClassLoader::getBaseClassType
virtual std::string getBaseClassType() const
Given the lookup name of a class, return the type of the associated base class.
Definition: class_loader_imp.hpp:386
exceptions.hpp
pluginlib::ClassLoader::getCatkinLibraryPaths
std::vector< std::string > getCatkinLibraryPaths()
Return the paths where libraries are installed according to the Catkin build system.
Definition: class_loader_imp.hpp:310
pluginlib::ClassLoader::unloadLibraryForClass
virtual int unloadLibraryForClass(const std::string &lookup_name)
Decrement the counter for the library containing a class with a given name.
Definition: class_loader_imp.hpp:815
pluginlib::ClassLoader::isClassAvailable
virtual bool isClassAvailable(const std::string &lookup_name)
Check if the class associated with a plugin name is available to be loaded.
Definition: class_loader_imp.hpp:603
pluginlib::ClassLoader::attrib_name_
std::string attrib_name_
Definition: class_loader.hpp:347
boost::shared_ptr
pluginlib::ClassLoader::getClassType
virtual std::string getClassType(const std::string &lookup_name)
Given the lookup name of a class, return the type of the derived class associated with it.
Definition: class_loader_imp.hpp:404
pluginlib::ClassLoader::ClassMapIterator
std::map< std::string, ClassDesc >::iterator ClassMapIterator
Definition: class_loader.hpp:64
pluginlib::ClassLoader::stripAllButFileFromPath
std::string stripAllButFileFromPath(const std::string &path)
Strip all but the filename from an explicit file path.
Definition: class_loader_imp.hpp:802
pluginlib::ClassLoaderBase
Pure virtual base class of pluginlib::ClassLoader which is not templated.
Definition: class_loader_base.hpp:45
pluginlib::ClassLoader::unloadClassLibraryInternal
int unloadClassLibraryInternal(const std::string &library_path)
Helper function for unloading a shared library.
Definition: class_loader_imp.hpp:830
pluginlib::ClassLoader::getPluginManifestPath
virtual std::string getPluginManifestPath(const std::string &lookup_name)
Given the name of a class, return the path of the associated plugin manifest.
Definition: class_loader_imp.hpp:577
class_loader::MultiLibraryClassLoader
pluginlib::ClassLoader::getPluginXmlPaths
std::vector< std::string > getPluginXmlPaths()
Return a list of all available plugin manifest paths for this ClassLoader's base class type.
Definition: class_loader_imp.hpp:462
class_desc.hpp
class_loader_base.hpp
pluginlib::ClassLoader::classes_available_
std::map< std::string, ClassDesc > classes_available_
Definition: class_loader.hpp:344
console.h
multi_library_class_loader.hpp
pluginlib::ClassLoader::getPathSeparator
std::string getPathSeparator()
Get the standard path separator for the native OS (e.g. "/" on *nix, "\" on Windows).
Definition: class_loader_imp.hpp:561
pluginlib::ClassLoader::package_
std::string package_
Definition: class_loader.hpp:345
pluginlib::ClassLoader::getClassLibraryPath
virtual std::string getClassLibraryPath(const std::string &lookup_name)
Given the name of a class, return the path to its associated library.
Definition: class_loader_imp.hpp:415
pluginlib::ClassLoader::determineAvailableClasses
std::map< std::string, ClassDesc > determineAvailableClasses(const std::vector< std::string > &plugin_xml_paths)
Return the available classes.
Definition: class_loader_imp.hpp:243
pluginlib::ClassLoader::~ClassLoader
~ClassLoader() override
The destructor attempts to unload all libraries which are still loaded.
Definition: class_loader_imp.hpp:98
class_loader::ClassLoader::UniquePtr
std::unique_ptr< Base, DeleterType< Base > > UniquePtr
pluginlib::ClassDesc
Storage for information about a given class.
Definition: class_desc.hpp:80
pluginlib
Definition: class_desc.hpp:42
pluginlib::ClassLoader
A class to help manage and load classes.
Definition: class_loader.hpp:61
package.h
class_loader_imp.hpp
pluginlib::ClassLoader::getClassDescription
virtual std::string getClassDescription(const std::string &lookup_name)
Given the lookup name of a class, return its description.
Definition: class_loader_imp.hpp:393
pluginlib::ClassLoader::getClassPackage
virtual std::string getClassPackage(const std::string &lookup_name)
Given the name of a class, return name of the containing package.
Definition: class_loader_imp.hpp:451
pluginlib::ClassLoader::ClassLoader
ClassLoader(std::string package, std::string base_class, std::string attrib_name=std::string("plugin"), std::vector< std::string > plugin_xml_paths=std::vector< std::string >())
Definition: class_loader_imp.hpp:68
pluginlib::ClassLoader::createInstance
boost::shared_ptr< T > createInstance(const std::string &lookup_name)
Create an instance of a desired class.
Definition: class_loader_imp.hpp:136
pluginlib::ClassLoader::loadLibraryForClass
virtual void loadLibraryForClass(const std::string &lookup_name)
Attempt to load the library containing a class with a given name.
Definition: class_loader_imp.hpp:618
pluginlib::ClassLoader::getName
virtual std::string getName(const std::string &lookup_name)
Strip the package name off of a lookup name.
Definition: class_loader_imp.hpp:495
pluginlib::ClassLoader::plugin_xml_paths_
std::vector< std::string > plugin_xml_paths_
Definition: class_loader.hpp:342
pluginlib::ClassLoader::getErrorStringForUnknownClass
std::string getErrorStringForUnknownClass(const std::string &lookup_name)
Return an error message for an unknown class.
Definition: class_loader_imp.hpp:481
pluginlib::ClassLoader::createUnmanagedInstance
T * createUnmanagedInstance(const std::string &lookup_name)
Create an instance of a desired class.
Definition: class_loader_imp.hpp:200
pluginlib::ClassLoader::base_class_
std::string base_class_
Definition: class_loader.hpp:346
pluginlib::ClassLoader::processSingleXMLPluginFile
void processSingleXMLPluginFile(const std::string &xml_file, std::map< std::string, ClassDesc > &class_available)
Parse a plugin XML file.
Definition: class_loader_imp.hpp:653
pluginlib::ClassLoader::lowlevel_class_loader_
class_loader::MultiLibraryClassLoader lowlevel_class_loader_
Definition: class_loader.hpp:348
pluginlib::ClassLoader::getRegisteredLibraries
virtual std::vector< std::string > getRegisteredLibraries()
Return the libraries that are registered and can be loaded.
Definition: class_loader_imp.hpp:589
pluginlib::ClassLoader::isClassLoaded
bool isClassLoaded(const std::string &lookup_name)
Check if the library for a given class is currently loaded.
Definition: class_loader_imp.hpp:379
pluginlib::ClassLoader::refreshDeclaredClasses
virtual void refreshDeclaredClasses()
Refresh the list of all available classes for this ClassLoader's base class type.
Definition: class_loader_imp.hpp:768
pluginlib::ClassLoader::joinPaths
std::string joinPaths(const std::string &path1, const std::string &path2)
Join two filesystem paths together utilzing appropriate path separator.
Definition: class_loader_imp.hpp:610
pluginlib::ClassLoader::getPackageFromPluginXMLFilePath
std::string getPackageFromPluginXMLFilePath(const std::string &path)
Get the package name from a path to a plugin XML file.
Definition: class_loader_imp.hpp:506
pluginlib::ClassLoader::getROSBuildLibraryPath
std::string getROSBuildLibraryPath(const std::string &exporting_package_name)
Given a package name, return the path where rosbuild thinks plugins are installed.
Definition: class_loader_imp.hpp:596
pluginlib::ClassLoader::extractPackageNameFromPackageXML
std::string extractPackageNameFromPackageXML(const std::string &package_xml_path)
Open a package.xml file and extract the package name (i.e. contents of <name> tag).
Definition: class_loader_imp.hpp:273
pluginlib::ClassLoader::createClassInstance
T * createClassInstance(const std::string &lookup_name, bool auto_load=true)
Create an instance of a desired class, optionally loading the associated library too.
Definition: class_loader_imp.hpp:107
pluginlib::ClassLoader::getAllLibraryPathsToTry
std::vector< std::string > getAllLibraryPathsToTry(const std::string &library_name, const std::string &exporting_package_name)
Get a list of paths to try to find a library.
Definition: class_loader_imp.hpp:333
pluginlib::ClassLoader::getDeclaredClasses
std::vector< std::string > getDeclaredClasses()
Return a list of all available classes for this ClassLoader's base class type.
Definition: class_loader_imp.hpp:469


pluginlib
Author(s): Eitan Marder-Eppstein, Tully Foote, Dirk Thomas, Mirza Shah
autogenerated on Tue Jul 9 2024 02:50:20