preloading_class_loader.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <string>
13 
16 
18 
19 /*
20  * In the classes where you need to use this classloader, insert the following code at the very beginning of the CPP
21  * file:
22  *
23 // HACK: we need to alter the private lowlever_class_loader_ of pluginlib::ClassLoader
24 #define private public
25 #include <pluginlib/class_loader.hpp>
26 #undef private
27  *
28  */
29 
36 template <typename Impl, typename Base>
38 {
39 protected:
45  {
46  const auto implType = cras::getTypeName<Impl>();
47  const auto baseType = cras::getTypeName<Base>();
48  auto metaObject = new class_loader::impl::MetaObject<Impl, Base>(implType, baseType);
49  metaObject->addOwningClassLoader(this);
50  class_loader::impl::getFactoryMapForBaseClass<Base>()[implType] = metaObject;
51  }
52 
53 public:
55  {
56  const auto implType = cras::getTypeName<Impl>();
57  auto metaObject = class_loader::impl::getFactoryMapForBaseClass<Base>()[implType];
58  metaObject->removeOwningClassLoader(this);
59  class_loader::impl::getFactoryMapForBaseClass<Base>().erase(implType);
60  delete metaObject;
61  }
62 
68  static void preload(const std::string& pluginlibType, pluginlib::ClassLoader<Base>& loader)
69  {
70  const auto implType = cras::getTypeName<Impl>();
71  const auto baseType = cras::getTypeName<Base>();
73  loader.classes_available_.insert({pluginlibType, {pluginlibType, implType, baseType, "", "", "", ""}});
74  loader.classes_available_.at(pluginlibType).resolved_library_path_ = implType;
75  }
76 
84  static void unPreload(const std::string& pluginlibType, pluginlib::ClassLoader<Base>& loader)
85  {
86  loader.unloadLibraryForClass(pluginlibType);
87  }
88 };
pluginlib::ClassLoader::unloadLibraryForClass
virtual int unloadLibraryForClass(const std::string &lookup_name)
PreloadingClassLoader::preload
static void preload(const std::string &pluginlibType, pluginlib::ClassLoader< Base > &loader)
"Install" the preloading classloader into the given classloader.
Definition: preloading_class_loader.hpp:68
PreloadingClassLoader
This pluginlib classloader alternative can load compiled-in classes and provide them as if they were ...
Definition: preloading_class_loader.hpp:37
class_loader::MultiLibraryClassLoader::active_class_loaders_
LibraryToClassLoaderMap active_class_loaders_
PreloadingClassLoader::PreloadingClassLoader
PreloadingClassLoader()
Construct the class loader.
Definition: preloading_class_loader.hpp:44
pluginlib::ClassLoader::classes_available_
std::map< std::string, ClassDesc > classes_available_
type_utils.hpp
Utilities for working with C++ types.
PreloadingClassLoader::~PreloadingClassLoader
~PreloadingClassLoader() override
Definition: preloading_class_loader.hpp:54
pluginlib::ClassLoader
class_loader.hpp
class_loader::ClassLoader
class_loader::impl::MetaObject
PreloadingClassLoader::unPreload
static void unPreload(const std::string &pluginlibType, pluginlib::ClassLoader< Base > &loader)
Revert the effect of preload().
Definition: preloading_class_loader.hpp:84
pluginlib::ClassLoader::lowlevel_class_loader_
class_loader::MultiLibraryClassLoader lowlevel_class_loader_
class_loader::ClassLoader::ClassLoader
CLASS_LOADER_PUBLIC ClassLoader(const std::string &library_path, bool ondemand_load_unload=false)


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sat Dec 14 2024 03:51:04