Mercurial > octave
annotate liboctave/util/singleton-cleanup.h @ 33658:b1d6e40ac737 stable tip
NEWS.9.md: Fix typo and minor formatting changes.
* etc/NEWS.9.md: Fix typo. Adjust whitespace. Use markdown syntax for code
snippets.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Wed, 05 Jun 2024 11:27:35 +0200 |
parents | 2e484f9f1f18 |
children | 4b601ca024d5 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31837
diff
changeset
|
3 // Copyright (C) 2011-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
22799
592fa741e0aa
add missing copyright notices (bug #49624)
John W. Eaton <jwe@octave.org>
parents:
22402
diff
changeset
|
25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
26 #if ! defined (octave_singleton_cleanup_h) |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #define octave_singleton_cleanup_h 1 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
30 |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include <set> |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 class |
13989
b4d399c975de
Export new added functions/classes (Woe32)
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13983
diff
changeset
|
34 OCTAVE_API |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 singleton_cleanup_list |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 protected: |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
39 singleton_cleanup_list () : m_fcn_list () { } |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 public: |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
43 typedef void (*fptr) (); |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 |
31837
febd82d1a8de
use new macros to consistently delete copy and move member functions
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
45 OCTAVE_DISABLE_COPY_MOVE (singleton_cleanup_list) |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
46 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
47 ~singleton_cleanup_list (); |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 static void add (fptr f) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 if (instance_ok ()) |
27379
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
52 s_instance->do_add (f); |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
55 static void cleanup () |
27379
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
56 { |
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
57 delete s_instance; |
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
58 s_instance = nullptr; |
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
59 } |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 private: |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 |
27379
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
63 static singleton_cleanup_list *s_instance; |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
65 static bool instance_ok (); |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
67 static void cleanup_instance () |
27379
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
68 { |
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
69 delete s_instance; |
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
70 s_instance = nullptr; |
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
71 } |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 |
27379
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
73 std::set<fptr> m_fcn_list; |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 void do_add (fptr f) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 { |
27379
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
77 m_fcn_list.insert (f); |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 }; |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 #endif |