Workspace 6.21.5
Public Member Functions | List of all members
ForwardNotifications Class Reference

Allows one Observable object to mimic another for a specific event type. More...

#include <Workspace/DataExecution/Events/forwardnotifications.h>

Public Member Functions

 ForwardNotifications ()
 
 ForwardNotifications (const ForwardNotifications &fw)
 
 ForwardNotifications (Observable &src, Observable &dest, const EventID &eventID=AllObservableEvents::eventID())
 
 ~ForwardNotifications ()
 
ForwardNotificationsoperator= (const ForwardNotifications &fw)
 

Detailed Description

The class allows one Observable object to notify events raised on another. The main use of this is to make one object's events appear to come from another, which is particularly useful when creating wrapper classes around other objects with Observable components. If you want to forward all events from the source to the destination, not just one event type, then use the EventID from the AllObservableEvents class.

The most useful way to use a ForwardNotifications object is to make it a local data member of the destination object. If this is done, then either the source or destination object can be deleted at any time and the event forwarding mechanism does the right thing to ensure that no attempt is made to use an object that has been deleted.

Constructor & Destructor Documentation

◆ ForwardNotifications() [1/3]

Creates a do-nothing event forwarder. This is only really useful if you intend to later assign a new forwarding relationship to it with the assignment operator.

◆ ForwardNotifications() [2/3]

ForwardNotifications ( Observable src,
Observable dest,
const EventID eventID = AllObservableEvents::eventID() 
)
Parameters
srcThe observable object to forward the specified event type from.
destThe observable object to forward the specified event type to.
eventIDThe event type to forward.

Attaches this object as an observer to src for the specified event type. Any matching event src subsequently initiates will be forwarded to dest as well.

◆ ForwardNotifications() [3/3]

Duplicates the forwarding relationship in fw. This constructor mostly only exists to allow temporaries to be created, since duplicating a forwarding relationship will result in events effectively being raised more than once.

◆ ~ForwardNotifications()

Removes the forwarding relationship. If the source has already been deleted, this destructor still does the right thing and will not attempt to access the source (the observer used internally will already have been deleted).

Member Function Documentation

◆ operator=()

ForwardNotifications & operator= ( const ForwardNotifications fw)
Parameters
fwThe forwarding object to assign to this one.

The assignment operator allows an object to change what it is forwarding between. The old and new fowarding relationships need not have anything in common. The main reason for providing an assignment operator is to allow a ForwardNotifications object to be created as a data member of an object but still allow it to change what objects it forwards between. The alternative is to store a pointer to a dynamically allocated ForwardNotifications object and then destroy and recreate it with the new forwarding relationship. This also requires the class holding the ForwardNotifications pointer to remember to delete the object when it is itself deleted, which can be avoided by storing a ForwardNotifications object as a data member directly and using the assignment operator to change the forwarding relationship.