mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
mal_toolkit::CallbackSystem< F > Class Template Reference

A system for managing and invoking callback functions. More...

#include "callback-system.hpp"

Collaboration diagram for mal_toolkit::CallbackSystem< F >:
[legend]

Public Types

using CallbackFunction = F
 
using CallbackId = uint32_t
 
using CallbackAddress = size_t
 

Public Member Functions

CallbackId AddCallback (CallbackFunction const &callback)
 Add a new callback function.
 
void RemoveCallback (CallbackId id)
 Remove a callback by its ID.
 
void RemoveCallback (CallbackFunction const &callback)
 Remove a callback by its function object.
 
void InvokeCallbacks (T const &data)
 Invoke all registered callbacks with the provided data.
 

Private Attributes

std::unordered_map< CallbackId, Callback > callbacks_
 
std::unordered_map< CallbackId, CallbackAddresscallback_addresses_
 
CallbackId next_id_ = 0
 

Detailed Description

template<typename F>
class mal_toolkit::CallbackSystem< F >

A system for managing and invoking callback functions.

Template Parameters
FType of the callback function.

Definition at line 34 of file callback-system.hpp.

Member Typedef Documentation

◆ CallbackAddress

template<typename F >
using mal_toolkit::CallbackSystem< F >::CallbackAddress = size_t

Definition at line 39 of file callback-system.hpp.

◆ CallbackFunction

template<typename F >
using mal_toolkit::CallbackSystem< F >::CallbackFunction = F

Definition at line 37 of file callback-system.hpp.

◆ CallbackId

template<typename F >
using mal_toolkit::CallbackSystem< F >::CallbackId = uint32_t

Definition at line 38 of file callback-system.hpp.

Member Function Documentation

◆ AddCallback()

template<typename F >
CallbackId mal_toolkit::CallbackSystem< F >::AddCallback ( CallbackFunction const & callback)
inline

Add a new callback function.

Parameters
callbackThe callback function to add.
Returns
CallbackId The ID of the added callback.

Definition at line 47 of file callback-system.hpp.

Here is the call graph for this function:

◆ InvokeCallbacks()

template<typename F >
void mal_toolkit::CallbackSystem< F >::InvokeCallbacks ( T const & data)
inline

Invoke all registered callbacks with the provided data.

Parameters
dataThe data to be passed to the callbacks.

Definition at line 89 of file callback-system.hpp.

◆ RemoveCallback() [1/2]

template<typename F >
void mal_toolkit::CallbackSystem< F >::RemoveCallback ( CallbackFunction const & callback)
inline

Remove a callback by its function object.

Parameters
callbackThe callback function to remove.

Definition at line 71 of file callback-system.hpp.

Here is the call graph for this function:

◆ RemoveCallback() [2/2]

template<typename F >
void mal_toolkit::CallbackSystem< F >::RemoveCallback ( CallbackId id)
inline

Remove a callback by its ID.

Parameters
idThe ID of the callback to remove.

Definition at line 60 of file callback-system.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ callback_addresses_

template<typename F >
std::unordered_map<CallbackId, CallbackAddress> mal_toolkit::CallbackSystem< F >::callback_addresses_
private

Definition at line 99 of file callback-system.hpp.

◆ callbacks_

template<typename F >
std::unordered_map<CallbackId, Callback> mal_toolkit::CallbackSystem< F >::callbacks_
private

Definition at line 98 of file callback-system.hpp.

◆ next_id_

template<typename F >
CallbackId mal_toolkit::CallbackSystem< F >::next_id_ = 0
private

Definition at line 100 of file callback-system.hpp.


The documentation for this class was generated from the following file: