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 
80  ~ClassLoader();
81 
83 
93  [[deprecated]] T * createClassInstance(
94  const std::string & lookup_name,
95  bool auto_load = true);
96 
98 
109  boost::shared_ptr<T> createInstance(const std::string & lookup_name);
110 
111 #if __cplusplus >= 201103L
112 
128  UniquePtr<T> createUniqueInstance(const std::string & lookup_name);
129 #endif
130 
132 
145  T * createUnmanagedInstance(const std::string & lookup_name);
146 
148 
151  std::vector<std::string> getPluginXmlPaths();
152 
154 
157  std::vector<std::string> getDeclaredClasses();
158 
160 
164  virtual std::string getName(const std::string & lookup_name);
165 
167 
170  virtual std::string getBaseClassType() const;
171 
173 
177  virtual std::string getClassType(const std::string & lookup_name);
178 
180 
184  virtual std::string getClassDescription(const std::string & lookup_name);
185 
187 
191  virtual std::string getClassLibraryPath(const std::string & lookup_name);
192 
194 
198  virtual std::string getClassPackage(const std::string & lookup_name);
199 
201 
205  virtual std::string getPluginManifestPath(const std::string & lookup_name);
206 
208 
211  virtual std::vector<std::string> getRegisteredLibraries();
212 
214 
218  bool isClassLoaded(const std::string & lookup_name);
219 
221 
225  virtual bool isClassAvailable(const std::string & lookup_name);
226 
228 
235  virtual void loadLibraryForClass(const std::string & lookup_name);
236 
238 
241  virtual void refreshDeclaredClasses();
242 
244 
252  virtual int unloadLibraryForClass(const std::string & lookup_name);
253 
254 private:
256 
260  std::vector<std::string> getPluginXmlPaths(
261  const std::string & package,
262  const std::string & attrib_name,
263  bool force_recrawl = false);
264 
266 
271  std::map<std::string, ClassDesc> determineAvailableClasses(
272  const std::vector<std::string> & plugin_xml_paths);
273 
275 
279  std::string extractPackageNameFromPackageXML(const std::string & package_xml_path);
280 
282 
287  std::vector<std::string> getAllLibraryPathsToTry(
288  const std::string & library_name,
289  const std::string & exporting_package_name);
290 
292  std::vector<std::string> getCatkinLibraryPaths();
293 
295 
299  std::string getErrorStringForUnknownClass(const std::string & lookup_name);
300 
302  std::string getPathSeparator();
303 
305  std::string getROSBuildLibraryPath(const std::string & exporting_package_name);
306 
308  std::string getPackageFromPluginXMLFilePath(const std::string & path);
309 
311  std::string joinPaths(const std::string & path1, const std::string & path2);
312 
314 
319  const std::string & xml_file, std::map<std::string,
320  ClassDesc> & class_available);
321 
323 
327  std::string stripAllButFileFromPath(const std::string & path);
328 
329 
331 
335  int unloadClassLibraryInternal(const std::string & library_path);
336 
337 private:
338  std::vector<std::string> plugin_xml_paths_;
339  // Map from library to class's descriptions described in XML.
340  std::map<std::string, ClassDesc> classes_available_;
341  std::string package_;
342  std::string base_class_;
343  std::string attrib_name_;
345 };
346 
347 } // namespace pluginlib
348 
349 // Note: The implementation of the methods is in a separate file for clarity.
350 #include "./class_loader_imp.hpp"
351 
352 #endif // PLUGINLIB__CLASS_LOADER_HPP_
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...
virtual std::string getPluginManifestPath(const std::string &lookup_name)
Given the name of a class, return the path of the associated plugin manifest.
std::map< std::string, ClassDesc > determineAvailableClasses(const std::vector< std::string > &plugin_xml_paths)
Return the available classes.
class_loader::MultiLibraryClassLoader lowlevel_class_loader_
std::string getPathSeparator()
Get the standard path separator for the native OS (e.g. "/" on *nix, "\" on Windows).
std::string getPackageFromPluginXMLFilePath(const std::string &path)
Get the package name from a path to a plugin XML file.
std::string getROSBuildLibraryPath(const std::string &exporting_package_name)
Given a package name, return the path where rosbuild thinks plugins are installed.
virtual int unloadLibraryForClass(const std::string &lookup_name)
Decrement the counter for the library containing a class with a given name.
virtual std::string getClassDescription(const std::string &lookup_name)
Given the lookup name of a class, return its description.
boost::shared_ptr< T > createInstance(const std::string &lookup_name)
Create an instance of a desired class.
T * createClassInstance(const std::string &lookup_name, bool auto_load=true)
Create an instance of a desired class, optionally loading the associated library too.
virtual void loadLibraryForClass(const std::string &lookup_name)
Attempt to load the library containing a class with a given name.
virtual std::string getClassLibraryPath(const std::string &lookup_name)
Given the name of a class, return the path to its associated library.
Pure virtual base class of pluginlib::ClassLoader which is not templated.
T * createUnmanagedInstance(const std::string &lookup_name)
Create an instance of a desired class.
std::vector< std::string > plugin_xml_paths_
virtual std::string getBaseClassType() const
Given the lookup name of a class, return the type of the associated base class.
virtual std::string getClassPackage(const std::string &lookup_name)
Given the name of a class, return name of the containing package.
bool isClassLoaded(const std::string &lookup_name)
Check if the library for a given class is currently loaded.
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).
std::map< std::string, ClassDesc >::iterator ClassMapIterator
Storage for information about a given class.
Definition: class_desc.hpp:46
virtual void refreshDeclaredClasses()
Refresh the list of all available classes for this ClassLoader&#39;s base class type. ...
std::string joinPaths(const std::string &path1, const std::string &path2)
Join two filesystem paths together utilzing appropriate path separator.
std::vector< std::string > getDeclaredClasses()
Return a list of all available classes for this ClassLoader&#39;s base class type.
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.
std::unique_ptr< Base, DeleterType< Base > > UniquePtr
std::vector< std::string > getCatkinLibraryPaths()
Return the paths where libraries are installed according to the Catkin build system.
virtual std::vector< std::string > getRegisteredLibraries()
Return the libraries that are registered and can be loaded.
virtual std::string getName(const std::string &lookup_name)
Strip the package name off of a lookup name.
std::vector< std::string > getPluginXmlPaths()
Return a list of all available plugin manifest paths for this ClassLoader&#39;s base class type...
std::string stripAllButFileFromPath(const std::string &path)
Strip all but the filename from an explicit file path.
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 >())
A class to help manage and load classes.
virtual bool isClassAvailable(const std::string &lookup_name)
Check if the class associated with a plugin name is available to be loaded.
std::map< std::string, ClassDesc > classes_available_
int unloadClassLibraryInternal(const std::string &library_path)
Helper function for unloading a shared library.
std::string getErrorStringForUnknownClass(const std::string &lookup_name)
Return an error message for an unknown class.
void processSingleXMLPluginFile(const std::string &xml_file, std::map< std::string, ClassDesc > &class_available)
Parse a plugin XML file.


pluginlib
Author(s): Eitan Marder-Eppstein, Tully Foote, Dirk Thomas, Mirza Shah
autogenerated on Thu Jun 6 2019 22:03:47