OpenCPN Partial API docs
ObsListener Class Reference

Define an action to be performed when a KeyProvider is notified. More...

#include <observable.h>

Inheritance diagram for ObsListener:

Public Member Functions

 ObsListener ()
 Create an object which does not listen until Init();.
 
 ObsListener (const KeyProvider &kp, std::function< void(ObservedEvt &ev)> action)
 Create object which invokes action when kp is notified.
 
 ObsListener (const KeyProvider &kp, std::function< void()> action)
 Create object which invokes action when kp is notified.
 
void Init (const KeyProvider &kp, std::function< void(ObservedEvt &ev)> action)
 Initiate an object yet not listening.
 

Detailed Description

Define an action to be performed when a KeyProvider is notified.

Convenience container hiding the Bind(), wxEVENT_TYPE and listening details. The action function is in most use cases a lambda expression.

Controller/GUI example usage, listening to the EventVar model.change:

class Gui: public SomeBaseClass {
public:
Gui:Gui(Model& model):
change_listener(model.change, [&](ObservableEvt& ev) {
auto s = ev.GetString();
.... do something
})
{}
private:
EvtVarListener change_listener;
}

Or, using Init():

Gui:Gui(Model& model) {
auto action = [&](ObservableEvt& ev) {
auto s = ev.GetString();
.... do something
});
change_listener.Init(model.change, action);
}

Definition at line 210 of file observable.h.


The documentation for this class was generated from the following file: