xentara-plugin v2.0.3
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::process::ExtendedEvent Class Referencefinal

A reference to an event published by a Xentara element, including change events for attributes. More...

#include <xentara/process/ExtendedEvent.hpp>

Public Member Functions

 ExtendedEvent ()=default
 Constructor for a null reference.
 
 ExtendedEvent (std::weak_ptr< const Event > event)
 Creates a reference to a free-standing event.
 
 ExtendedEvent (const model::ElementAttribute &attribute)
 Creates a reference to an attribute change event.
 
 ExtendedEvent (data::ReadHandle readHandle)
 Creates a reference to an attribute change event.
 
 ExtendedEvent (model::ElementAttribute attribute, UnpreparedTag tag)
 Creates a reference to an attribute change event during loading of the model.
 
 operator bool () const noexcept
 Boolean operator.
 
auto prepare () -> void
 Prepares a reference created during loading.
 
auto addHandler (std::reference_wrapper< EventHandler > handler) const -> void
 Adds an event handler.
 
auto removeHandler (std::reference_wrapper< EventHandler > handler) const -> void
 Removes an event handler.
 

Related Symbols

(Note that these are not member symbols.)

constexpr UnpreparedTag kUnprepared
 A marker to specify that an extended event still needs to be prepared.
 

Detailed Description

A reference to an event published by a Xentara element, including change events for attributes.

This is a convenience class that contains a weak reference to a free-standing event or to a change event for an attribute. You can use this class to add and remove event handler to and from events without having to worry about the type of event.

See also
proces::Event
data::ReadHandle
model::Element::extendedEvent()

Constructor & Destructor Documentation

◆ ExtendedEvent() [1/5]

xentara::process::ExtendedEvent::ExtendedEvent ( )
default

Constructor for a null reference.

This constructor contstruct a null object that does not contain a reference to any event. You must assign avalid object to this object before using it.

◆ ExtendedEvent() [2/5]

xentara::process::ExtendedEvent::ExtendedEvent ( std::weak_ptr< const Event event)

Creates a reference to a free-standing event.

Parameters
eventThe event to reference. Must not be a null pointer (but may be expired).

◆ ExtendedEvent() [3/5]

xentara::process::ExtendedEvent::ExtendedEvent ( const model::ElementAttribute attribute)

Creates a reference to an attribute change event.

Parameters
attributeA reference to attribute whose change event you want to reference. Must be a valid reference.
Exceptions
std::runtime_errorThe attribute does not support change events
See also
data::ReadHandle::hasChangeEvent()

◆ ExtendedEvent() [4/5]

xentara::process::ExtendedEvent::ExtendedEvent ( data::ReadHandle  readHandle)

Creates a reference to an attribute change event.

Parameters
readHandleA read handle to attribute whose change event you want to reference. Must be a valid handle.
Exceptions
std::runtime_errorThe read handle does not support change events
See also
data::ReadHandle::hasChangeEvent()

◆ ExtendedEvent() [5/5]

xentara::process::ExtendedEvent::ExtendedEvent ( model::ElementAttribute  attribute,
UnpreparedTag  tag 
)

Creates a reference to an attribute change event during loading of the model.

This constructor is used to create an event reference is being during the loading process, before realize() has been call on the model’s elements.

Before using a reference created with this constructor, you must call prepare(). prepare() must be called at the earliest during the prepare() phase of loading, usually from within the prepare() callback of a Xentara element.

Parameters
attributeA reference to attribute whose change event you want to reference. Must be a valid reference.
tagAlways pass kUnprepared as this parameter

Member Function Documentation

◆ addHandler()

auto xentara::process::ExtendedEvent::addHandler ( std::reference_wrapper< EventHandler handler) const -> void

Adds an event handler.

This function adds the given handler to the contained event. It is safe to call this function on a null (default constructed) reference. For a null reference, the function simply does nothing.

If the reference was created during loading, either by passing kUnprepared to the [constructor()](ExtendedEvent(model::ElementAttribute, UnpreparedTag), or by resolving it using config::Resolver, then prepare() must be called befor calling addHandler().

Parameters
handlerThe handler
Exceptions
std::logic_errorThe reference was created using kUnprepared, but prepare() was not called.

◆ operator bool()

xentara::process::ExtendedEvent::operator bool ( ) const
explicitnoexcept

Boolean operator.

This operator checks whether the object is not a null reference.

Returns
Returns true if the object contains a reference to an event, or false if the object is a null (default constructed) reference.

◆ prepare()

auto xentara::process::ExtendedEvent::prepare ( ) -> void

Prepares a reference created during loading.

This function is used to prepare a reference that was created during loading, either by passing kUnprepared to the [constructor()](ExtendedEvent(model::ElementAttribute, UnpreparedTag), or by resolving it using config::Resolver. The function must be called at the earliest during the prepare() phase of loading, and should normally be called from within the prepare() callback of a Xentara element.

It is safe to call this function an any reference, even one that was not created using kUnprepared. For references that have already been prepared, or for references that do not need to be prepared, this function simple does nothing.

Exceptions
std::runtime_errorThe event references an attribute that does not support change events
See also
data::ReadHandle::hasChangeEvent()

◆ removeHandler()

auto xentara::process::ExtendedEvent::removeHandler ( std::reference_wrapper< EventHandler handler) const -> void

Removes an event handler.

This function removes the given handler from the contained event. It is safe to call this function on a null (default constructed) reference. For a null reference, the function simply does nothing.

Parameters
handlerThe handler. If the handler is not attached to the event, this function does nothing.

Friends And Related Symbol Documentation

◆ kUnprepared

constexpr UnpreparedTag kUnprepared
related

A marker to specify that an extended event still needs to be prepared.

This marker is used to specify that an extended event reference is being created during the loading process, before realize() has been call on the model’s elements.