13 #ifndef ML_EVENT_SOURCE_H
14 #define ML_EVENT_SOURCE_H
64 struct ListenerEntry {
65 ListenerEntry() : cb(nullptr), userData(nullptr) {}
66 ListenerEntry(
BaseEventCallback* aCB,
void* aUserData) : cb(aCB), userData(aUserData) {}
67 void sendEvent(BaseEvent* event)
const { (*cb)(userData, event); }
68 bool isValid()
const {
return (cb !=
nullptr); }
69 bool operator==(
const ListenerEntry& b)
const {
return cb == b.cb && userData == b.userData; }
76 std::vector<ListenerEntry> _eventListeners;
77 bool _inEventListenerIteration;
78 bool _eventListenersRemovedInIteration;
122 template<
typename ToTypePtr>
125 if (from->getTypeId()->isDerivedFrom((
static_cast<ToTypePtr
>(0))->getClassTypeId())) {
126 return static_cast<ToTypePtr
>(from);
136 template<
typename ToTypePtr>
139 if (from->getTypeId()->isDerivedFrom((
static_cast<ToTypePtr
>(0))->getClassTypeId())) {
140 return static_cast<ToTypePtr
>(from);
BaseEvent is the base class for all events emitted from EventSourceBase.
EventSource * source() const
Returns the Base object emitting this event.
Class representing general ML objects that support import/export via strings (setPersistentState() an...
EventSourceRemovedEvent is used to indicate when the EventSourceBase object is removed.
EventSourceDeletedEvent()
EventSourceBase class adds event listener handling to Base.
EventSource(const EventSource &evSource)
void addEventListener(BaseEventCallback *cb, void *userData)
Adds event listener callback to this Base object.
void sendEvent(BaseEvent *event, void *skipListener=nullptr)
Macro for the declaration of the runtime type system methods, defined in mlRuntimeSubClass....
bool hasEventListeners() const
Checks whether any event listeners have been added to this Base object; this can be used to skip the ...
void removeEventListener(BaseEventCallback *cb, void *userData)
Removes event listener callback from this Base object.
#define ML_ABSTRACT_CLASS_HEADER(className)
Similar to ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non-existing export symbol.
ToTypePtr mlbaseevent_cast(ml::BaseEvent *from)
Cast operation for safely casting BaseEvents to derived types.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non-existing export symbol.
#define ML_ABSTRACT_ROOT_CLASS_HEADER(className)
bool operator==(const Tmat2< DT > &a, const Tmat2< DT > &b)
a == b ? Returns true if yes.
void BaseEventCallback(void *, BaseEvent *)