OpenCPN Partial API docs
observable_evt.h
1 /*************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: wxCommandEvt subclass which can carry also a shared_ptr<void>
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_EVT_H // Guard also used in ocpn_plugin.h
25 #define OBSERVABLE_EVT_H
26 
27 #include <memory>
28 
29 #include <wx/event.h>
30 
32 class ObservedEvt;
33 
34 wxDECLARE_EVENT(obsNOTIFY, ObservedEvt);
35 
37 class ObservedEvt : public wxCommandEvent {
38 public:
39  ObservedEvt(wxEventType commandType = obsNOTIFY, int id = 0)
40  : wxCommandEvent(commandType, id) {}
41 
42  ObservedEvt(const ObservedEvt& event) : wxCommandEvent(event) {
43  this->m_shared_ptr = event.m_shared_ptr;
44  }
45 
46  wxEvent* Clone() const { return new ObservedEvt(*this); }
47 
48  std::shared_ptr<const void> GetSharedPtr() const { return m_shared_ptr; }
49 
50  void SetSharedPtr(std::shared_ptr<const void> p) { m_shared_ptr = p; }
51 
52 private:
53  std::shared_ptr<const void> m_shared_ptr;
54 };
55 
56 #endif // OBSERVABLE_EVT_H
Adds a std::shared<void> element to wxCommandEvent.
Definition: ocpn_plugin.h:1652