35#include "observable_evt.h"
38#if defined(_MSC_VER) || defined(__CYGWIN__)
39#define DECL_EXP __declspec(dllexport)
40#elif defined(__GNUC__) || defined(__clang__)
41#define DECL_EXP __attribute__((visibility("default")))
48std::string ptr_key(
const void* ptr);
58 virtual std::string
GetKey()
const = 0;
79 std::vector<std::pair<wxEvtHandler*, wxEventType>> listeners;
95 virtual const void Notify();
98 const void Notify(std::shared_ptr<const void> p) {
Notify(p,
"", 0, 0); }
104 bool Unlisten(wxEvtHandler* listener, wxEventType ev);
118 const void Notify(std::shared_ptr<const void> ptr,
const std::string& s,
119 int num,
void* client_data);
126 const void Notify(
const std::string& s,
void* client_data) {
127 Notify(
nullptr, s, 0, client_data);
133 void Listen(wxEvtHandler* listener, wxEventType ev_type);
137 mutable std::mutex m_mutex;
150 : key(k), listener(l), ev_type(e) {
160 : key(other.key), listener(other.listener), ev_type(other.ev_type) {
171 void Listen(
const std::string& key, wxEvtHandler* listener, wxEventType evt);
178 Listen(kp.
GetKey(), l, evt);
186 wxEvtHandler* listener;
192std::shared_ptr<const T> UnpackEvtPointer(
ObservedEvt ev) {
193 return std::static_pointer_cast<const T>(ev.GetSharedPtr());
Interface implemented by classes which listens.
virtual std::string GetKey() const =0
Return key used to listen and notify.
Keeps listening over it's lifespan, removes itself on destruction.
ObservableListener(ObservableListener &&other)
A listener can only be transferred using std::move().
ObservableListener(const KeyProvider &kp, wxEvtHandler *l, wxEventType e)
Construct a listening object listening to kp.GetKey()
ObservableListener(const std::string &k, wxEvtHandler *l, wxEventType e)
Construct a listening object listening to key k.
void Listen(const KeyProvider &kp, wxEvtHandler *l, wxEventType evt)
Set object to send wxEventType ev to listener on changes in a KeyProvider.
ObservableListener()
Default constructor, does not listen to anything.
The observable notify/listen basic nuts and bolts.
std::string GetKey() const
Retrieve the actual listening key:
const std::string key
The key used to create and clone.
const void Notify(std::shared_ptr< const void > p)
Notify all listeners about variable change with a shared_ptr payload.
Observable(const std::string &_key)
Create an instance listening to given key.
Observable(const KeyProvider &kp)
Create an instance listening to key provided by kp.GetKey().
const void Notify(const std::string &s, void *client_data)
Notify all listeners: send them a 'type' ObservedEvt message as defined by listen() with optional dat...
bool Unlisten(wxEvtHandler *listener, wxEventType ev)
Remove window listening to ev from list of listeners.
virtual const void Notify()
Notify all listeners about variable change.
Adds a std::shared<void> element to wxCommandEvent.