OpenCPN Partial API docs
Loading...
Searching...
No Matches
observable_evtvar.h
1/*************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: General observable implementation with several specializations.
5 *
6 * Copyright (C) 2022 Alec Leamas
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the
20 * Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 **************************************************************************/
23
24#ifndef _OBSERVABLE_EVTVAR_H
25#define _OBSERVABLE_EVTVAR_H
26
27#include <atomic>
28#include <memory>
29#include <string>
30#include <vector>
31
32#include <wx/event.h>
33
34#include "observable.h"
35
71class EventVar : public Observable {
72public:
73 EventVar() : Observable(Autokey()) {}
74
76 const void Notify() { Observable::Notify("", 0); }
77
79 const void Notify(void* data) { Observable::Notify("", data); }
80
82 const void Notify(const std::string& s) { Observable::Notify(s, 0); }
83
85 const void Notify(int n, const std::string& s) { Observable::Notify(0, s, n, 0); }
86
88 const void Notify(int n, void* p) { Observable::Notify(0, "", n, p); }
89
94 const void Notify(std::shared_ptr<void> p, const std::string& s, int n = 0) {
95 Observable::Notify(p, s, n, 0);
96 }
97
98private:
99 std::string Autokey() {
100 static std::atomic<unsigned long> last_ix(0);
101 return std::string("!@%/+") + std::to_string(last_ix++);
102 }
103};
104
105#endif // _OBSERVABLE_EVTVAR_H
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
const void Notify(int n, const std::string &s)
Notify all listeners about variable change with a string and an int.
const void Notify(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.
const void Notify()
Notify all listeners, no data supplied.
const void Notify(const std::string &s)
Notify all listeners about variable change with a string.
const void Notify(int n, void *p)
Notify all listeners about variable change with an int and ClientData.
const void Notify(void *data)
Notify all listeners about variable change with ClientData.
The observable notify/listen basic nuts and bolts.
Definition observable.h:81
virtual const void Notify()
Notify all listeners about variable change.