OpenCPN Partial API docs
Loading...
Searching...
No Matches
obs::Listener Class Reference

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

#include <observable.h>

Inheritance diagram for obs::Listener:

Public Member Functions

 Listener ()
 Create an object which does not listen until Init();.
 Listener (Listener &&other) noexcept
 std::move support
Listener & operator= (Listener &&other) noexcept
 std::move support
 Listener (const Listener &)=delete
 ObsListener is non-copyable and can only be assigned using std::move.
Listener & operator= (Listener &)=delete
 ObsListener is non-copyable and can only be assigned using std::move.
 Listener (const KeyProvider &kp, const std::function< void(ObservedEvt &ev)> &action)
 Create object which invokes action when the kp key is notified.
 Listener (const KeyProvider &kp, const std::function< void()> &action)
 Create object which invokes action when the kp key is notified.
void Init (const KeyProvider &kp, const std::function< void(ObservedEvt &ev)> &action)
 Initiate an object yet not listening so it invokes action when the kp key is notified.

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 usually 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:
obs::Listener change_listener;
}
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:293

Or, using Init():

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

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

std::vector<ObsListener> v;
ObsListener l;
v[0] = std::move(l);

Definition at line 293 of file observable.h.

Constructor & Destructor Documentation

◆ Listener() [1/4]

obs::Listener::Listener ( )
inline

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

Definition at line 296 of file observable.h.

◆ Listener() [2/4]

obs::Listener::Listener ( Listener && other)
inlinenoexcept

std::move support

Definition at line 299 of file observable.h.

◆ Listener() [3/4]

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

Create object which invokes action when the kp key is notified.

Definition at line 324 of file observable.h.

◆ Listener() [4/4]

obs::Listener::Listener ( const KeyProvider & kp,
const std::function< void()> & action )
inline

Create object which invokes action when the kp key is notified.

Definition at line 331 of file observable.h.

Member Function Documentation

◆ Init()

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

Initiate an object yet not listening so it invokes action when the kp key is notified.

Definition at line 338 of file observable.h.

◆ operator=()

Listener & obs::Listener::operator= ( Listener && other)
inlinenoexcept

std::move support

Definition at line 308 of file observable.h.


The documentation for this class was generated from the following file:
  • /home/runner/work/main/main/opencpn/libs/observable/include/observable/observable.h