OpenCPN Partial API docs
ConfigVar< T > Class Template Reference

Wrapper for configuration variables which lives in a wxBaseConfig object. More...

#include <observable_confvar.h>

Inheritance diagram for ConfigVar< T >:
Observable KeyProvider

Public Member Functions

 ConfigVar (const std::string &section_, const std::string &key_, wxConfigBase *cb)
 
void Set (const T &arg)
 
const T Get (const T &default_val)
 
- 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 = std::string>
class ConfigVar< T >

Wrapper for configuration variables which lives in a wxBaseConfig object.

Supports int, bool, double, std::string and wxString. Besides basic set()/get() also provides notification events when value changes.

Client usage when reading, setting a value and notifying listeners:

ConfigVar<bool> expert("/PlugIns", "CatalogExpert", &g_pConfig);
bool old_value = expert.Get(false);
expert.Set(false);
Wrapper for configuration variables which lives in a wxBaseConfig object.

Client usage, listening to value changes.

class Foo: public wxEventHandler {
public:
Foo(...) {
ConfigVar<bool> expert("/PlugIns", "CatalogExpert", &g_pConfig);
auto action = [](wxCommandEvent&) { cout << "value has changed"; });
expert_listener.Init(expert, action);
...
}
private:
ObsListener expert_listener;
...
}
Define an action to be performed when a KeyProvider is notified.
Definition: observable.h:210

Definition at line 67 of file observable_confvar.h.


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