Skip to content

Commit 97a4313

Browse files
committed
Added comments and docs
Signed-off-by: ahcorde <ahcorde@gmail.com>
1 parent 6a800a4 commit 97a4313

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

include/class_loader/class_loader.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ std::string systemLibraryFormat(const std::string & library_name);
7575
* @brief This class allows loading and unloading of dynamically linked libraries which contain class
7676
* definitions from which objects can be created/destroyed during runtime (i.e. class_loader).
7777
* Libraries loaded by a ClassLoader are only accessible within scope of that ClassLoader object.
78+
* This class inherit from enable_shared_from_this which means we must used smart pointers,
79+
* otherwise the code might work but it may run into a leak.
7880
*/
7981
class ClassLoader : public std::enable_shared_from_this<ClassLoader>
8082
{
@@ -130,6 +132,8 @@ class ClassLoader : public std::enable_shared_from_this<ClassLoader>
130132
std::bind(&ClassLoader::onPluginDeletion<Base>, shared_from_this(), std::placeholders::_1)
131133
);
132134
} catch (std::bad_weak_ptr & e) { // This is not a shared_ptr
135+
CONSOLE_BRIDGE_logWarn("class_loader::ClassLoader::createUniqueInstance "
136+
"This class must be used with smart pointer");
133137
return std::shared_ptr<Base>(
134138
createRawInstance<Base>(derived_class_name, true),
135139
std::bind(&ClassLoader::onPluginDeletion<Base>, this, std::placeholders::_1)
@@ -160,6 +164,8 @@ class ClassLoader : public std::enable_shared_from_this<ClassLoader>
160164
std::bind(&ClassLoader::onPluginDeletion<Base>, shared_from_this(), std::placeholders::_1)
161165
);
162166
} catch (std::bad_weak_ptr & e) { // This is not a shared_ptr
167+
CONSOLE_BRIDGE_logWarn("class_loader::ClassLoader::createUniqueInstance "
168+
"This class must be used with smart pointer");
163169
return std::unique_ptr<Base, DeleterType<Base>>(
164170
raw,
165171
std::bind(&ClassLoader::onPluginDeletion<Base>, this, std::placeholders::_1)

0 commit comments

Comments
 (0)