SW Task Event Loop Framework v1.0.0
High-performance C++ asynchronous event loop framework with timer management and promise-based programming
Loading...
Searching...
No Matches
swt::EventQueue::QueueItem Struct Reference

Unified queue item supporting both messages and function tasks. More...

#include <EventQueue.h>

Collaboration diagram for swt::EventQueue::QueueItem:
Collaboration graph

Public Member Functions

 QueueItem (std::shared_ptr< Message > msg, int64_t when)
 Constructor for message queue items.
 
 QueueItem (std::packaged_task< void()> &&t, int64_t when)
 Constructor for function queue items.
 
 QueueItem (QueueItem &&other) noexcept
 Move constructor - transfers ownership of queue item.
 
QueueItemoperator= (QueueItem &&other) noexcept
 Move assignment operator - transfers ownership.
 
 QueueItem (const QueueItem &)=delete
 Copy constructor - deleted (move-only semantics)
 
QueueItemoperator= (const QueueItem &)=delete
 Copy assignment - deleted (move-only semantics)
 

Public Attributes

QueueItemType type
 Type discriminator for queue item.
 
int64_t whenUs
 Execution time in microseconds (absolute)
 
std::shared_ptr< Messagemessage
 Message payload (for MESSAGE type)
 
std::packaged_task< void()> task
 Function task (for FUNCTION type)
 

Detailed Description

Unified queue item supporting both messages and function tasks.

QueueItem provides a variant-like structure that can hold either traditional messages or modern function tasks while maintaining uniform timing and ordering semantics. Uses move-only semantics for optimal performance with function objects.

Key design principles:

  • Type discrimination: QueueItemType enum for runtime type safety
  • Unified timing: int64_t whenUs for consistent execution scheduling
  • Move-only: Prevents accidental copying of expensive function objects
  • Memory efficiency: Uses shared_ptr for messages, move semantics for tasks

Definition at line 115 of file EventQueue.h.

Constructor & Destructor Documentation

◆ QueueItem() [1/4]

swt::EventQueue::QueueItem::QueueItem ( std::shared_ptr< Message msg,
int64_t  when 
)
inline

Constructor for message queue items.

Parameters
msgShared pointer to message object
whenAbsolute execution time in microseconds

Creates a queue item containing a traditional message for handler-based processing with specified execution timing.

Definition at line 130 of file EventQueue.h.

◆ QueueItem() [2/4]

swt::EventQueue::QueueItem::QueueItem ( std::packaged_task< void()> &&  t,
int64_t  when 
)
inline

Constructor for function queue items.

Parameters
tPackaged task to execute (moved)
whenAbsolute execution time in microseconds

Creates a queue item containing a function task for direct execution with specified timing.

Definition at line 141 of file EventQueue.h.

◆ QueueItem() [3/4]

swt::EventQueue::QueueItem::QueueItem ( QueueItem &&  other)
inlinenoexcept

Move constructor - transfers ownership of queue item.

Parameters
otherQueue item to move from

Efficiently transfers ownership of either message or task without copying expensive function objects.

Definition at line 151 of file EventQueue.h.

◆ QueueItem() [4/4]

swt::EventQueue::QueueItem::QueueItem ( const QueueItem )
delete

Copy constructor - deleted (move-only semantics)

Queue items cannot be copied to prevent expensive function object duplication and ensure unique ownership.

Member Function Documentation

◆ operator=() [1/2]

QueueItem & swt::EventQueue::QueueItem::operator= ( const QueueItem )
delete

Copy assignment - deleted (move-only semantics)

Queue items cannot be copy-assigned to maintain move-only semantics and prevent accidental expensive copies.

◆ operator=() [2/2]

QueueItem & swt::EventQueue::QueueItem::operator= ( QueueItem &&  other)
inlinenoexcept

Move assignment operator - transfers ownership.

Parameters
otherQueue item to move from
Returns
Reference to this queue item

Handles self-assignment safely and transfers ownership of contained message or task.

Definition at line 163 of file EventQueue.h.

References message, task, type, and whenUs.

Member Data Documentation

◆ message

std::shared_ptr<Message> swt::EventQueue::QueueItem::message

Message payload (for MESSAGE type)

Definition at line 119 of file EventQueue.h.

Referenced by operator=().

◆ task

std::packaged_task<void()> swt::EventQueue::QueueItem::task

Function task (for FUNCTION type)

Definition at line 120 of file EventQueue.h.

Referenced by operator=().

◆ type

QueueItemType swt::EventQueue::QueueItem::type

Type discriminator for queue item.

Definition at line 116 of file EventQueue.h.

Referenced by operator=().

◆ whenUs

int64_t swt::EventQueue::QueueItem::whenUs

Execution time in microseconds (absolute)

Definition at line 117 of file EventQueue.h.

Referenced by operator=().


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