OpenCPN Partial API docs
|
Generic event handling between between two parties like MVC Model and Controller using a shared EventVar variable. More...
#include <observable_evtvar.h>
Public Member Functions | |
const void | Notify () |
Notify all listeners, no data supplied. More... | |
const void | Notify (void *data) |
Notify all listeners about variable change with ClientData. More... | |
const void | Notify (const std::string &s) |
Notify all listeners about variable change with a string. More... | |
const void | Notify (int n, const std::string &s) |
Notify all listeners about variable change with a string and an int. More... | |
const void | Notify (std::shared_ptr< void > p, const std::string &s, int n=0) |
Notify all listeners about variable change with shared_ptr, a string and an optional number. More... | |
Public Member Functions inherited from Observable | |
Observable (const std::string &_key) | |
Create an instance listening to given key. More... | |
Observable (const KeyProvider &kp) | |
Create an instance listening to key provided by kp.GetKey(). More... | |
virtual const void | Notify () |
Notify all listeners about variable change. More... | |
const void | Notify (std::shared_ptr< const void > p) |
Notify all listeners about variable change with a shared_ptr payload. More... | |
bool | Unlisten (wxEvtHandler *listener, wxEventType ev) |
Remove window listening to ev from list of listeners. More... | |
std::string | GetKey () const |
Retrieve the actual listening key: More... | |
virtual std::string | GetKey () const =0 |
Return key used to listen and notify. More... | |
Additional Inherited Members | |
Public Attributes inherited from Observable | |
const std::string | key |
The key used to create and clone. More... | |
Protected Member Functions inherited from Observable | |
const void | Notify (std::shared_ptr< const void > ptr, const std::string &s, int num, void *client_data) |
Notify all listeners: send them a 'type' ObservedEvt message as defined by listen() with optional data available using GetString(), getInt(), GetSharedPtr() and/or GetClientData(). More... | |
const void | Notify (const std::string &s, void *client_data) |
Notify all listeners: send them a 'type' ObservedEvt message as defined by listen() with optional data available using GetString() and/or GetClientData(). More... | |
Generic event handling between between two parties like MVC Model and Controller using a shared EventVar variable.
Notifying, for example in Model code:
class Model: ... public: EventVar change; void some_method() { ... change.Notify("new value") }
Listening, for example in Controller/GUI:
class Gui: public wxEvtHandler { public: Gui:Gui(Model& model) { wxDEFINE_EVENT(EVT_FOO, wxCommandEvent); change_listener.Listen(model.change, this, EVT_FOO); Bind(EVT_FOO, [&](wxCommandEvent ev) { auto s = ev.GetString(); s -> "new value" ... do something; }); } private: ObservableListener change_listener; }
Definition at line 69 of file observable_evtvar.h.
|
inline |
Definition at line 71 of file observable_evtvar.h.
|
inlinevirtual |
Notify all listeners, no data supplied.
Reimplemented from Observable.
Definition at line 74 of file observable_evtvar.h.
|
inline |
Notify all listeners about variable change with a string.
Definition at line 80 of file observable_evtvar.h.
|
inline |
Notify all listeners about variable change with a string and an int.
Definition at line 83 of file observable_evtvar.h.
|
inline |
Notify all listeners about variable change with shared_ptr, a string and an optional number.
Definition at line 88 of file observable_evtvar.h.
|
inline |
Notify all listeners about variable change with ClientData.
Definition at line 77 of file observable_evtvar.h.