OpenCPN Partial API docs
observable_globvar.h
1 /*************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: global variables listen/notify wrapper.
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_GLOBVAR_H
25 #define _OBSERVABLE_GLOBVAR_H
26 
27 #include <memory>
28 #include <string>
29 #include <vector>
30 
31 #include <wx/event.h>
32 
33 #include "observable.h"
34 
70 template <typename T>
71 class GlobalVar : public Observable {
72 public:
73  GlobalVar(T* ptr) : Observable(ptr_key(ptr)), variable(ptr) {}
74 
75  void Set(const T& arg) {
76  *variable = arg;
78  }
79 
80  const T Get() { return *variable; }
81 
82 private:
83  GlobalVar(); // not implemented
84 
85  T* const variable;
86 };
87 
88 #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:82
virtual const void Notify()
Notify all listeners about variable change.
Definition: observable.cpp:94