UCILoader 1.1.2
Small C++ library that allows user to connect to a chess engines via UCI protocol.
Loading...
Searching...
No Matches
UCILoader::EngineEvent Class Referenceabstract

Base class for events emitted by an EngineInstance. More...

#include <EngineEvent.h>

Inheritance diagram for UCILoader::EngineEvent:
UCILoader::ConcreteEvent< Payload, EventCode > UCILoader::NoPayloadEvent

Public Member Functions

virtual ~EngineEvent ()
 Virtual destructor for proper cleanup of derived classes.
 
virtual uint32_t getType () const =0
 Get the type code of this event.
 
virtual const void * getPayload () const =0
 Get the payload data associated with this event.
 

Detailed Description

Base class for events emitted by an EngineInstance.

EngineEvent is the foundation of the asynchronous event system. Each event has a unique type code with exactly one bit set (power of 2), enabling efficient filtering and matching using bitwise operations.

Event Type Codes: All event type codes are defined in the NamedEngineEvents namespace as powers of 2, allowing safe bitwise OR operations to create event filters.

Event Payloads: Some events carry associated data (payload) accessible via getPayload(). Others have no payload and return nullptr. The specific event type determines both whether a payload exists and its data type.

Typical Usage:

uint32_t myFilter = (NamedEngineEvents::SearchCompleted |
NamedEngineEvents::EngineCrashed);
if (event->getType() & myFilter) {
// Handle search completion or engine crash
}
See also
NamedEngineEvents for predefined event types
EventReceiver for handling events
EventEmitter for emitting events

Member Function Documentation

◆ getPayload()

virtual const void * UCILoader::EngineEvent::getPayload ( ) const
pure virtual

Get the payload data associated with this event.

Returns
Const void pointer to the event payload, or nullptr if no payload exists

Different event types carry different payload types. When a non-null pointer is returned, it points to an internally managed payload object. The caller must:

  1. Know the expected type based on getType()
  2. Cast the pointer to the appropriate type using C-style cast
  3. NOT attempt to delete or modify the payload

Payload Type Reference: See NamedEngineEvents namespace documentation for which events have payloads and their types. For example:

  • InfoReceived: payload is Info<Move>*
  • InfoClampReceived: payload is std::vector<Info<Move>>*
  • EngineSynchronized, SearchStarted, etc.: payload is nullptr

Example Usage:

if (event->getType() == NamedEngineEvents::InfoReceived) {
auto info = (Info<StandardChessMove>*) event->getPayload();
std::cout << "Engine depth: " << info->getDepth() << std::endl;
}

Implemented in UCILoader::ConcreteEvent< Payload, EventCode >, and UCILoader::NoPayloadEvent.

◆ getType()

virtual uint32_t UCILoader::EngineEvent::getType ( ) const
pure virtual

Get the type code of this event.

Returns
A uint32_t type code with exactly one bit set (power of 2)

Each event type is represented by a unique power-of-2 value, enabling efficient bitwise filtering. Type codes are defined in the NamedEngineEvents namespace.

Bitwise Filtering Example:

// Check if event is either SearchCompleted or EngineCrashed
uint32_t filter = (NamedEngineEvents::SearchCompleted |
NamedEngineEvents::EngineCrashed);
if (event->getType() & filter) {
// Handle the matched event
}
See also
NamedEngineEvents for available event types

Implemented in UCILoader::ConcreteEvent< Payload, EventCode >, and UCILoader::NoPayloadEvent.


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