OpenWalker Project
Documentation of the ROS Packages
class_loader.h
Go to the documentation of this file.
1 
34 #ifndef OPEN_WALKER_PLUGIN_LOADER_CLASS_LOADER_H
35 #define OPEN_WALKER_PLUGIN_LOADER_CLASS_LOADER_H
36 
37 #include <string>
38 #include <memory>
39 
41 
42 namespace ow_plugin_loader
43 {
44 
52 {
53 public:
55 
56 protected:
57  void* handle_;
58  bool opened_;
59  std::string libFilePath_;
60 
61 public:
65  ClassLoader(const std::string& libFilePath = "");
66 
70  virtual ~ClassLoader();
71 
77  bool open(const std::string& libFilePath = "");
78 
84  bool close();
85 
86  bool isOpened() const;
87  bool isClosed() const;
88 
92  IGenericClass* createClassGeneric();
93 
104  template<class IClass>
105  IClass* createClass()
106  {
107  return static_cast<IClass*>(createClassGeneric());
108  }
109 
110 
117  void destroyClass(IGenericClass* ptr);
118 
119 private:
123  ClassLoader(const ClassLoader& other);
124 
128  ClassLoader& operator=(const ClassLoader& other);
129 };
130 
131 } // namespace ow_plugin_loader
132 
133 #endif // OPEN_WALKER_PLUGIN_LOADER_CLASS_LOADER_H
Definition: class_creator.h:42
The IGenericClass class.
Definition: i_generic_class.h:54
virtual ~ClassLoader()
Deconstructor.
IClass * createClass()
Create a new class of the loaded library with the specified type.
Definition: class_loader.h:105
The ClassLoader class.
Definition: class_loader.h:51
void destroyClass(IGenericClass *ptr)
Destroy a created class using the loaded lib to avoid memory leaks.
void * handle_
the handle for shared library
Definition: class_loader.h:57
IGenericClass * createClassGeneric()
Create a new class of the loaded library and return a generic pointer.
bool open(const std::string &libFilePath="")
Open and load the shared lib which contains the desired class to create.
bool close()
Unload and close the shared lib.
std::string libFilePath_
file path to .so library
Definition: class_loader.h:59
ClassLoader(const std::string &libFilePath="")
Default constructor.
bool opened_
opened/closed flag
Definition: class_loader.h:58