OpenCPN Partial API docs
Loading...
Searching...
No Matches
obs::GlobalVar< T > Class Template Reference

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

#include <global_var.h>

Inheritance diagram for obs::GlobalVar< T >:
obs::Observable obs::KeyProvider

Public Member Functions

 GlobalVar (T *ptr)
 
void Set (const T &arg)
 
Get ()
 
- Public Member Functions inherited from obs::Observable
 Observable (const std::string &_key)
 Initiate an object which can apply Notify() and Listen() to given key.
 
 Observable (const KeyProvider &kp)
 Initiate an object which can apply Notify() and Listen() to given key.
 
virtual void Notify ()
 Notify all listeners to configured key about variable change.
 
virtual void Notify (const std::shared_ptr< const void > &p)
 Notify all listeners to configured key about variable change.
 
bool Unlisten (wxEvtHandler *listener, wxEventType ev)
 Remove window listening to ev from list of listeners.
 
std::string GetKey () const override
 Return the key given to the constructor.
 

Additional Inherited Members

- Public Attributes inherited from obs::Observable
const std::string key
 The key used to create and clone.
 
- Protected Member Functions inherited from obs::Observable
void Notify (const 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(), GetClientData(), GetInt() and/or GetSharedPtr()
 
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().
 

Detailed Description

template<typename T>
class obs::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.
Definition global_var.h:69

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:
obs::Listener compat_os_listener;
...
}

Definition at line 69 of file global_var.h.

Constructor & Destructor Documentation

◆ GlobalVar()

template<typename T >
obs::GlobalVar< T >::GlobalVar ( T *  ptr)
inlineexplicit

Definition at line 71 of file global_var.h.

Member Function Documentation

◆ Get()

template<typename T >
T obs::GlobalVar< T >::Get ( )
inline

Definition at line 80 of file global_var.h.

◆ Set()

template<typename T >
void obs::GlobalVar< T >::Set ( const T &  arg)
inline

Definition at line 75 of file global_var.h.


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