OpenCPN Partial API docs
Loading...
Searching...
No Matches
evtvar.h
Go to the documentation of this file.
1/*************************************************************************
2 *
3 * Copyright (C) 2022 - 2025 Alec Leamas
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
17 **************************************************************************/
18
26#ifndef Observable_EVTVAR_H
27#define Observable_EVTVAR_H
28
29#include <atomic>
30#include <memory>
31#include <string>
32
33#include "observable.h"
34
35namespace obs {
78class EventVar : public Observable {
79public:
80 EventVar() : Observable(Autokey()) {}
81
83 void Notify() override { Observable::Notify("", nullptr); }
84
86 void Notify(void* data) { Observable::Notify("", data); }
87
89 void Notify(const std::string& s) { Observable::Notify(s, nullptr); }
90
92 void Notify(int n, const std::string& s) {
93 Observable::Notify(nullptr, s, n, nullptr);
94 }
95
97 void Notify(int n, void* p) { Observable::Notify(nullptr, "", n, p); }
98
103 void Notify(const std::shared_ptr<void>& p, const std::string& s, int n = 0) {
104 Observable::Notify(p, s, n, nullptr);
105 }
106
108 void Notify(const std::shared_ptr<const void>& p) override {
109 Observable::Notify(p, "", 0, nullptr);
110 }
111
112private:
113 static std::string Autokey() {
114 static std::atomic<unsigned long> last_ix(0);
115 return std::string("!@%/+") + std::to_string(last_ix++);
116 }
117};
118
119} // namespace obs
120
121#endif // Observable_EVTVAR_H
Generic event handling between for example MVC Model and Controller based on a shared EventVar variab...
Definition evtvar.h:78
void Notify(int n, const std::string &s)
Notify all listeners about variable change with a string and an int.
Definition evtvar.h:92
void Notify(int n, void *p)
Notify all listeners about variable change with an int and ClientData.
Definition evtvar.h:97
void Notify(const std::string &s)
Notify all listeners about variable change with a string.
Definition evtvar.h:89
void Notify() override
Notify all listeners, no data supplied.
Definition evtvar.h:83
void Notify(const std::shared_ptr< void > &p, const std::string &s, int n=0)
Notify all listeners about variable change with shared_ptr, a string and an optional number.
Definition evtvar.h:103
void Notify(void *data)
Notify all listeners about variable change with ClientData.
Definition evtvar.h:86
void Notify(const std::shared_ptr< const void > &p) override
Notify all listeners about variable change with const* shared_ptr,.
Definition evtvar.h:108
The observable notify/listen basic nuts and bolts.
Definition observable.h:100
virtual void Notify()
Notify all listeners to configured key about variable change.
General observable pattern implementation built on top of wxWidgets event handling.