OpenCPN Partial API docs
Loading...
Searching...
No Matches
global_var.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
25#ifndef OBSERVABLE_GLOBVAR_H
26#define OBSERVABLE_GLOBVAR_H
27
28#include "observable.h"
29
30namespace obs {
68template <typename T>
69class GlobalVar : public Observable {
70public:
71 explicit GlobalVar(T* ptr) : Observable(PtrKey(ptr)), variable(ptr) {}
72
73 GlobalVar() = delete;
74
75 void Set(const T& arg) {
76 *variable = arg;
78 }
79
80 T Get() { return *variable; }
81
82private:
83 T* const variable;
84};
85
86} // namespace obs
87
88#endif // OBSERVABLE_GLOBVAR_H
Wrapper for global variable, supports notification events when value changes.
Definition global_var.h:69
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.
std::string PtrKey(const void *ptr)
Return address as printable string.