Nameless Engine
|
#include <NodeFunction.hpp>
Public Member Functions | |
NodeFunction (size_t iNodeId, const std::function< FunctionReturnType(FunctionArgs...)> &callback) | |
NodeFunction (const NodeFunction &other)=default | |
NodeFunction & | operator= (const NodeFunction &other)=default |
NodeFunction (NodeFunction &&other) noexcept=default | |
NodeFunction & | operator= (NodeFunction &&other) noexcept=default |
bool | operator() (FunctionArgs &&... args) |
bool | isNodeSpawned () |
Private Attributes | |
std::function< FunctionReturnType(FunctionArgs...)> | callback |
size_t | iNodeId = 0 |
std::function
wrapper used for Node functions/lambdas with an additional check (compared to the usual std::function
): once the callback is called this class will first check if the node, the callback function points to, is still spawned or not, and if not spawned then the callback function will not be called to avoid running functions on despawned nodes or hitting deleted memory.
|
inline |
Constructor.
gc
pointers in std::function
(as it's used under the hood).iNodeId | ID of the spawned node that "contains" the callback. |
callback | Points to the function/lambda of the spawned node with ID that was specified as the previous argument. |
|
default |
Copy constructor.
other | Other object. |
|
defaultnoexcept |
Move constructor.
other | Other object. |
|
inline |
Checks if the node, the callback function points to, is still spawned or not.
true
if the node is still spawned, false
otherwise.
|
inline |
Calls the stores callback function with the specified arguments.
args | Arguments to pass to callback function call. |
true
if the node, the callback function points to, was despawned and the callback was not called to avoid running logic on despawned/deleted node, otherwise false
.
|
default |
Copy assignment.
other | Other object. |
|
defaultnoexcept |
Move assignment.
other | Other object. |
|
private |
Points to the function of the spawned node with ID iNodeId.
|
private |
ID of the spawned node that contains callback function.