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

Adapter class that wraps a callback function as an EventReceiver. More...

#include <EngineEvent.h>

Inheritance diagram for UCILoader::FunctionCallbackEventReceiver:
UCILoader::EventReceiver

Public Member Functions

 FunctionCallbackEventReceiver (std::function< void(const EngineEvent *)> callback, uint32_t allowedEvents)
 Constructor for callbacks that receive the full event.
 
 FunctionCallbackEventReceiver (std::function< void()> callback, uint32_t allowedEvents)
 Constructor for simple parameterless callbacks.
 
virtual void receiveEvent (const EngineEvent *event) override
 Handle the event by invoking the stored callback.
 
virtual uint32_t eventFilter () override
 Get the event filter bitmask.
 
- Public Member Functions inherited from UCILoader::EventReceiver
virtual ~EventReceiver ()
 Virtual destructor that disconnects from all connected emitters.
 
void unlinkAll ()
 Disconnect this receiver from all connected emitters.
 
virtual uint32_t eventFilter ()=0
 Get the event filter bitmask for this receiver.
 
virtual void receiveEvent (const EngineEvent *event)=0
 Handle an incoming event.
 

Detailed Description

Adapter class that wraps a callback function as an EventReceiver.

FunctionCallbackEventReceiver allows simple function or lambda callbacks to be used with the event system without creating a full EventReceiver subclass.

Typically used via EventEmitter::connect() overloads:

emitter->connect(
[](const EngineEvent* event) {
if (event->getType() == NamedEngineEvents::SearchCompleted) {
std::cout << "Search finished!" << std::endl;
}
},
NamedEngineEvents::SearchCompleted | NamedEngineEvents::EngineCrashed
);
Base class for events emitted by an EngineInstance.
Definition: EngineEvent.h:42
virtual uint32_t getType() const =0
Get the type code of this event.
See also
EventEmitter::connect() for usage

Constructor & Destructor Documentation

◆ FunctionCallbackEventReceiver() [1/2]

UCILoader::FunctionCallbackEventReceiver::FunctionCallbackEventReceiver ( std::function< void(const EngineEvent *)>  callback,
uint32_t  allowedEvents 
)
inline

Constructor for callbacks that receive the full event.

Parameters
callbackFunction to invoke for each matching event (receives EngineEvent*)
allowedEventsBitmask of event types to pass to the callback

◆ FunctionCallbackEventReceiver() [2/2]

UCILoader::FunctionCallbackEventReceiver::FunctionCallbackEventReceiver ( std::function< void()>  callback,
uint32_t  allowedEvents 
)
inline

Constructor for simple parameterless callbacks.

Parameters
callbackFunction to invoke for each matching event (receives no parameters)
allowedEventsBitmask of event types to trigger the callback

Member Function Documentation

◆ eventFilter()

virtual uint32_t UCILoader::FunctionCallbackEventReceiver::eventFilter ( )
inlineoverridevirtual

Get the event filter bitmask.

Returns
The allowedEvents bitmask passed at construction

Implements UCILoader::EventReceiver.

◆ receiveEvent()

void UCILoader::FunctionCallbackEventReceiver::receiveEvent ( const EngineEvent event)
overridevirtual

Handle the event by invoking the stored callback.

Parameters
eventThe EngineEvent to process

Implements UCILoader::EventReceiver.


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