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