OpenCPN Partial API docs
Loading...
Searching...
No Matches
observable_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, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
20
29#ifndef OBSERVABLE___EVTVAR__H
30#define OBSERVABLE___EVTVAR__H
31
32#include <atomic>
33#include <memory>
34#include <string>
35
36#include "observable.h"
37
73class EventVar : public Observable {
74public:
75 EventVar() : Observable(Autokey()) {}
76
78 void Notify() override { Observable::Notify("", nullptr)
79 ; }
80
82 void Notify(void* data) { Observable::Notify("", data); }
83
85 void Notify(const std::string& s) { Observable::Notify(s, nullptr); }
86
88 void Notify(int n, const std::string& s) { Observable::Notify(nullptr, s, n, nullptr); }
89
91 void Notify(int n, void* p) { Observable::Notify(nullptr, "", n, p); }
92
97 void Notify(const std::shared_ptr<void>& p, const std::string& s, int n = 0) {
98 Observable::Notify(p, s, n, nullptr);
99 }
100
102 void Notify(const std::shared_ptr<const void>& p) {
103 Observable::Notify(p, "", 0, nullptr);
104 }
105
106private:
107 std::string Autokey() {
108 static std::atomic<unsigned long> last_ix(0);
109 return std::string("!@%/+") + std::to_string(last_ix++);
110 }
111};
112
113#endif // OBSERVABLE___EVTVAR__H
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
void Notify(int n, const std::string &s)
Notify all listeners about variable change with a string and an int.
void Notify() override
Notify all listeners, no data supplied.
void Notify(const std::shared_ptr< const void > &p)
Notify all listeners about variable change with const* shared_ptr,.
void Notify(const std::string &s)
Notify all listeners about variable change with a string.
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.
void Notify(void *data)
Notify all listeners about variable change with ClientData.
void Notify(int n, void *p)
Notify all listeners about variable change with an int and ClientData.
The observable notify/listen basic nuts and bolts.
Definition observable.h:100
virtual void Notify()
Notify all listeners about variable change.
General observable implementation with several specializations.