JX Application Framework
|
#include <JBroadcaster.h>
Classes | |
struct | ClearPointer |
class | Message |
Public Member Functions | |
JBroadcaster () | |
virtual | ~JBroadcaster () |
JBroadcaster & | operator= (const JBroadcaster &source) |
bool | HasSenders () const |
JSize | GetSenderCount () const |
bool | HasRecipients () const |
JSize | GetRecipientCount () const |
virtual JString | ToString () const |
template<class T > | |
void | ListenTo (const JBroadcaster *sender, const std::function< void(const T &)> &f) |
Protected Member Functions | |
JBroadcaster (const JBroadcaster &source) | |
void | ListenTo (const JBroadcaster *sender) |
void | StopListening (const JBroadcaster *sender) |
void | ClearWhenGoingAway (const JBroadcaster *sender, void *pointerToMember) |
void | StopListening (const JBroadcaster *sender, const std::type_info &messageType) |
template<class T > | |
void | Send (JBroadcaster *recipient, const T &message) |
template<class T > | |
void | Broadcast (const T &message) |
virtual void | Receive (JBroadcaster *sender, const Message &message) |
void | SendWithFeedback (JBroadcaster *recipient, Message *message) |
void | BroadcastWithFeedback (Message *message) |
virtual void | ReceiveWithFeedback (JBroadcaster *sender, Message *message) |
virtual void | ReceiveGoingAway (JBroadcaster *sender) |
Mixin class to allow objects to send messages to each other. A JBroadcaster maintains a list of objects that send it messages (senders) and a list of objects to which it sends messages (recipients). To send a message, call Broadcast(). The Receive() method is then called for each recipient that called ListenTo(obj). For every recipient that called ListenTo(obj,fn), the given function will be invoked. ListenTo(obj,fn) should only be used in leaf classes. Base classes should use ListenTo(obj) in case derived classes need to intercept messages in Receive(). To send a message that requires feedback, call BroadcastWithFeedback(). The ReceiveWithFeedback() method is then called for each recipient. To listen for the death of a sender, override ReceiveGoingAway(). Be sure to read the warnings associated with using this function! Because the overhead is so low if there is nobody to broadcast to or nobody to listen to, there is no point in making a separate JListener class. Since this is a mixin class, all classes that wish to inherit from it must use "virtual public" inheritance.
JBroadcaster::JBroadcaster | ( | ) |
|
virtual |
Close all connections.
|
protected |
Don't copy the connections. We want this to be identical to the default constructor so nobody has to worry about calling us. (Otherwise, they would because we are linked in via virtual inheritance.)
|
inlineprotected |
Send the given message to all recipients. It is the responsibility of derived classes to implement a set of useful messages. Every message must be derived from JBroadcaster::Message and should contain all the information necessary to process the message.
By inlining this part of the function, we avoid the overhead of a function call unless somebody is actually listening.
|
inlineprotected |
Send the given message to all recipients and expect a reply. The reply is message dependent and therefore stored in the message, so we simply send the message as a non-const object and let the receiver who understands the message deal with it.
By inlining this part of the function, we avoid the overhead of a function call unless somebody is actually listening.
|
protected |
Register an object that needs to be forgotten when it is deleted.
JSize JBroadcaster::GetRecipientCount | ( | ) | const |
JSize JBroadcaster::GetSenderCount | ( | ) | const |
bool JBroadcaster::HasRecipients | ( | ) | const |
bool JBroadcaster::HasSenders | ( | ) | const |
|
protected |
Open a connection by adding the given object to this object's sender list, and adding this object to the given object's recipient list.
If the connection already exists, then we do nothing.
void JBroadcaster::ListenTo | ( | const JBroadcaster * | csender, |
const std::function< void(const T &)> & | f | ||
) |
Open a connection by adding the given object to this object's sender list, and adding this object & function to the given object's recipient list.
If the connection already exists, then we replace the previous function.
NOTE: This cannot be used if you intend to use ReceiveWithFeedback().
JBroadcaster & JBroadcaster::operator= | ( | const JBroadcaster & | source | ) |
Don't copy the connections.
|
protectedvirtual |
Process the given message from the given sender. This function is not pure virtual because not all classes will want to implement it.
Reimplemented in JAuxTableData< T >, JAuxTableData< bool >, JAuxTableData< JFontStyle >, JAliasArray< T >, JAliasArray< JString * >, JBroadcastSnooper, JBroadcastTester, JContainer, JFloatBufferTableData, JMemoryManager, JMMMonitor, JNamedTreeList, JSimpleProcess, JTable, JTableSelection, JTableSelectionIterator, JTextEditor, JTreeList, JTreeNode, JXCardFile, JXCheckboxGroup, JXChooseColorDialog, JXChooseFileDialog, JXChooseMonoFont, JXChoosePathDialog, JXColHeaderWidget, JXColorWheel, JXCSFDialogBase, JXDirTable, JXDisplayMenu, JXDockWidget, JXDockWindowTask, JXDocumentMenu, JXEPSPrintSetupDialog, JXFileListTable, JXFileNameDisplay, JXFontNameMenu, JXFontSizeMenu, JXFSInputBase, JXHistoryMenuBase, JXImageMenuTable, JXMenu, JXModalDialogDirector, JXNamedTreeListWidget, JXPGMessageDirector, JXProgressDisplay, JXPSPrintSetupDialog, JXPTPageSetupDialog, JXPTPrintSetupDialog, JXRowHeaderWidget, JXSaveFileDialog, JXScrollableWidget, JXSearchTextDialog, JXSharedPrefObject, JXSliderBase, JXSpellCheckerDialog, JXStringCompletionMenu, JXStringList, JXStyleMenu, JXTable, JXTEBase, JXTextEditor, JXTextMenuTable, JXToolBar, JXTreeListWidget, and JXWDMenu.
|
protectedvirtual |
The given sender has been deleted.
Warning: Since this function may be called from within a -chain- of destructors, it is not usually safe to do anything inside this function other than directly changing instance variables (e.g. setting pointers to nullptr).
This function is not pure virtual because not all classes will want to implement it.
Reimplemented in JAliasArray< T >, JAliasArray< JString * >, JBroadcastSnooper, JBroadcastTester, JTableSelectionIterator, JTextEditor, JXCheckboxGroup, JXDNDManager, JXDockWidget, JXSelectionData, and JXStringList.
|
protectedvirtual |
Process the given message from the given sender and provide feedback via the message as appropriate. This function is not pure virtual because not all classes will want to implement it.
Reimplemented in JXApplication, JXDNDManager, JXSearchTextDialog, and JXSelectionManager.
|
protected |
Send the given message to the specified recipient. It is the responsibility of derived classes to implement a set of useful messages. Every message must be derived from JBroadcaster::Message and should contain all the information necessary to process the message.
This function allows messages to be sent to an object in a way that is safe but that does not require the C++ type safety mechanism of dynamic_cast. Essentially, this feature is equivalent to the object methods provided by Objective C.
|
protected |
Send the given message to the specified recipients. It is the responsibility of derived classes to implement a set of useful messages. Every message must be derived from JBroadcaster::Message and should contain all the information necessary to process the message.
This function allows messages to be sent to an object in a way that is safe but that does not require the C++ type safety mechanism of dynamic_cast. Essentially, this feature is equivalent to the object methods provided by Objective C.
|
protected |
Close a connection by removing the given object from this object's sender list, and removing this object from the given objects's recipient list.
|
protected |
Close a connection by removing the given object from this object's sender list, and removing this object from the given objects's recipient list.
|
virtual |
Reimplemented in JCollection, JXFTCCell, JXInputField, JXStaticText, JXTextButton, JXTextCheckbox, JXTextRadioButton, and JXWidget.