libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Slot< Args > Class Template Reference

Type-safe callback slot that wraps a callable with optional ownership tracking. More...

#include <slot.h>

Classes

struct  removeConstAndRef
 Helper trait that strips const qualification and references from a type. More...
 

Public Types

using Function = std::function< void(Args...)>
 Callable type that the slot wraps.
 
template<typename T >
using RemoveConstAndRef = typename removeConstAndRef< T >::type
 Convenience alias for removeConstAndRef.
 

Public Member Functions

 Slot (const Function &func, void *owner=nullptr, const char *prototype=nullptr, int id=-1)
 Constructs a Slot with the given callable and optional metadata.
 
voidowner () const
 Returns the owner pointer associated with this slot.
 
const charprototype () const
 Returns the prototype string associated with this slot.
 
int id () const
 Returns the numeric identifier for this slot.
 
void setID (int val)
 Sets the numeric identifier for this slot.
 
void exec (Args... args)
 Executes the slot's callable with the given typed arguments.
 
void exec (const VariantList &variantList)
 Executes the slot's callable by unpacking arguments from a VariantList.
 

Static Public Member Functions

static VariantList pack (Args... args)
 Packs the given arguments into a VariantList.
 

Detailed Description

template<typename... Args>
class Slot< Args >

Type-safe callback slot that wraps a callable with optional ownership tracking.

Slot provides a mechanism for storing and invoking callbacks with a fixed argument signature. It supports direct invocation with typed arguments as well as deferred invocation from a VariantList, enabling type-erased signal/slot communication.

Template Parameters
ArgsThe argument types that the slot's callable accepts.

Constructor & Destructor Documentation

◆ Slot()

template<typename... Args>
Slot< Args >::Slot ( const Function func,
void owner = nullptr,
const char prototype = nullptr,
int  id = -1 
)
inline

Constructs a Slot with the given callable and optional metadata.

Parameters
funcThe callable to invoke when the slot is executed.
ownerOptional pointer to the object that owns this slot.
prototypeOptional human-readable prototype string for introspection.
idOptional numeric identifier for the slot, defaults to -1 (unset).

Member Function Documentation

◆ exec() [1/2]

template<typename... Args>
void Slot< Args >::exec ( Args...  args)
inline

Executes the slot's callable with the given typed arguments.

Parameters
argsThe arguments to forward to the callable.

◆ exec() [2/2]

template<typename... Args>
void Slot< Args >::exec ( const VariantList variantList)
inline

Executes the slot's callable by unpacking arguments from a VariantList.

Each element in the VariantList is converted back to the corresponding typed argument and forwarded to the underlying callable.

Parameters
variantListThe list of Variant values to unpack as arguments.

◆ pack()

template<typename... Args>
static VariantList Slot< Args >::pack ( Args...  args)
inlinestatic

Packs the given arguments into a VariantList.

Each argument is converted to a Variant after stripping const and reference qualifiers. This is useful for serializing a set of arguments for later deferred invocation via exec(const VariantList &).

Parameters
argsThe arguments to pack.
Returns
A VariantList containing each argument as a Variant.

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