OpenCPN Partial API docs
Loading...
Searching...
No Matches
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 (ObsListener &&other)
 ObsListener can only be assigned using std::move.
 
ObsListeneroperator= (ObsListener &&other)
 
 ObsListener (const ObsListener &)=delete
 
ObsListeneroperator= (ObsListener &)=delete
 
 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);
}

ObsListener is non-copyable, but can be created and assigned using std::move like in

std::vector<ObsListener> v;
v[0] = std::move(l);
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:228

Definition at line 228 of file observable.h.

Constructor & Destructor Documentation

◆ ObsListener() [1/4]

ObsListener::ObsListener ( )
inline

Create an object which does not listen until Init();.

Definition at line 231 of file observable.h.

◆ ObsListener() [2/4]

ObsListener::ObsListener ( ObsListener &&  other)
inline

ObsListener can only be assigned using std::move.

Definition at line 234 of file observable.h.

◆ ObsListener() [3/4]

ObsListener::ObsListener ( const KeyProvider kp,
std::function< void(ObservedEvt &ev)>  action 
)
inline

Create object which invokes action when kp is notified.

Definition at line 245 of file observable.h.

◆ ObsListener() [4/4]

ObsListener::ObsListener ( const KeyProvider kp,
std::function< void()>  action 
)
inline

Create object which invokes action when kp is notified.

Definition at line 251 of file observable.h.

Member Function Documentation

◆ Init()

void ObsListener::Init ( const KeyProvider kp,
std::function< void(ObservedEvt &ev)>  action 
)
inline

Initiate an object yet not listening.

Definition at line 255 of file observable.h.

◆ operator=()

ObsListener & ObsListener::operator= ( ObsListener &&  other)
inline

Definition at line 237 of file observable.h.


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