OpenCPN Partial API docs
GlobalVar< T > Class Template Reference

Wrapper for global variable, supports notification events when value changes. More...

#include <observable_globvar.h>

Inheritance diagram for GlobalVar< T >:
Observable KeyProvider

Public Member Functions

 GlobalVar (T *ptr)
 
void Set (const T &arg)
 
const T Get ()
 
- Public Member Functions inherited from Observable
 Observable (const std::string &_key)
 
 Observable (const KeyProvider &kp)
 
virtual const void Notify ()
 Notify all listeners about variable change.
 
const void Notify (std::shared_ptr< const void > p)
 
bool Unlisten (wxEvtHandler *listener, wxEventType ev)
 Remove window listening to ev from list of listeners. More...
 
std::string GetKey () const
 

Additional Inherited Members

- Public Attributes inherited from Observable
const std::string key
 The key used to create and clone.
 
- 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() and/or GetClientData().
 
const void Notify (const std::string &s, void *client_data)
 

Detailed Description

template<typename T>
class GlobalVar< T >

Wrapper for global variable, supports notification events when value changes.

Client usage, writing a value + notifying listeners

GlobalVar<wxString> compat_os(&g_compatOS);
compat_os.Set("ubuntu-gtk3-x86_64");
Wrapper for global variable, supports notification events when value changes.

Client usage, modifying a value + notifying listeners:

GlobalVar<wxString> plugin_array_var(&plugin_array);
plugin_array.Add(new_pic);
plugin_array_var.Notify();

Client usage, listening to value changes:

class Foo: public wxEvtHandler {
public:
Foo(...) {
GlobalVar<wxString> compat_os(&g_compatOS);
auto action = [](wxCommandEvent&) { cout << "value has changed"; };
compat_os_listener.Init(compat_os, action);
}
private:
ObsListener compat_os_listener;
...
}
Define an action to be performed when a KeyProvider is notified.
Definition: observable.h:210

Definition at line 71 of file observable_globvar.h.


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