OpenCPN Partial API docs
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 
71 class EventVar : public Observable {
72 public:
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); }
90  const void Notify(std::shared_ptr<void> p, const std::string& s, int n = 0) {
91  Observable::Notify(p, s, n, 0);
92  }
93 
94 private:
95  std::string Autokey() {
96  static std::atomic<unsigned long> last_ix(0);
97  return std::string("!@%/+") + std::to_string(last_ix++);
98  }
99 };
100 
101 #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(void *data)
Notify all listeners about variable change with ClientData.
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