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

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

#include <configvar.h>

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

Public Member Functions

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

Client usage, listening to value changes.

class Foo: public wxEventHandler {
public:
Foo(...) {
auto action = [](wxCommandEvent&) { cout << "value has changed"; });
m_expert_listener.Init(expert, action);
...
}
private:
obs::Listener m_expert_listener;
...
}

Definition at line 68 of file configvar.h.

Constructor & Destructor Documentation

◆ ConfigVar()

template<typename T >
obs::ConfigVar< T >::ConfigVar ( const std::string &  section_,
const std::string &  key_,
wxConfigBase *  cb 
)

Definition at line 48 of file observable_confvar.cpp.

Member Function Documentation

◆ Get()

template<typename T >
T obs::ConfigVar< T >::Get ( const T &  default_val)

Definition at line 56 of file observable_confvar.cpp.

◆ Set()

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

Definition at line 67 of file observable_confvar.cpp.


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