GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
singleton-cleanup.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2011-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_singleton_cleanup_h)
27 #define octave_singleton_cleanup_h 1
28 
29 #include "octave-config.h"
30 
31 #include <set>
32 
33 class
36 {
37 protected:
38 
39  singleton_cleanup_list (void) : m_fcn_list () { }
40 
41 public:
42 
43  typedef void (*fptr) (void);
44 
45  // No copying!
46 
48 
49  singleton_cleanup_list& operator = (const singleton_cleanup_list&) = delete;
50 
51  ~singleton_cleanup_list (void);
52 
53  static void add (fptr f)
54  {
55  if (instance_ok ())
56  s_instance->do_add (f);
57  }
58 
59  static void cleanup (void)
60  {
61  delete s_instance;
62  s_instance = nullptr;
63  }
64 
65 private:
66 
68 
69  static bool instance_ok (void);
70 
71  static void cleanup_instance (void)
72  {
73  delete s_instance;
74  s_instance = nullptr;
75  }
76 
77  std::set<fptr> m_fcn_list;
78 
79  void do_add (fptr f)
80  {
81  m_fcn_list.insert (f);
82  }
83 };
84 
85 #endif
static void cleanup_instance(void)
std::set< fptr > m_fcn_list
static void add(fptr f)
singleton_cleanup_list(const singleton_cleanup_list &)=delete
static void cleanup(void)
static singleton_cleanup_list * s_instance
F77_RET_T const F77_DBLE const F77_DBLE * f
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
Definition: lo-specfun.cc:1102
#define OCTAVE_API
Definition: main.in.cc:55