Event

An event. To add event handlers to the event use ~= or += followed by your event delegate. (use EventHandler for an easy signature for the delegate)

The delegate should take an void* sender and EventArgs argument.

Use -= to remove an event handler delegate from the event.

Members

Functions

clear
void clear()

Clears all handlers from the event

count
size_t count()

Gets the amount of handlers that are bound to this event

opCall
void opCall(void* sender, EventData data)

Call all event handlers bound to this event

opCall
void opCall(void* sender)

Call all event handlers bound to this event

opOpAssign
deprecated Event opOpAssign(EventHandler handler)

Add a new handler

opOpAssign
Event opOpAssign(EventHandler handler)

Add a new handler

opOpAssign
Event opOpAssign(EventHandler handler)

Deletes a handler

Examples

Test the creation and execution of an event

struct TestEventData { string name; }
bool wasRun;

// Test creation
auto eventHandler = (void* sender, TestEventData args) {
	assert(args.name == "test", "Expected value of event args to be \"Test\"");
	wasRun = true;
};

Event!TestEventData testEvent = new Event!TestEventData;
testEvent ~= eventHandler;

// Test execution
testEvent(null, TestEventData("test"));
assert(wasRun, "Expected event to be executed!");

// Test deletion of event handler
testEvent -= eventHandler;
assert(testEvent.count == 0, "Expected event to have no handlers!");

Meta