Mercurial > octave
annotate liboctave/util/action-container.h @ 27177:8498dccc15c7
minor style fixes
* action-container.h, functor.h, oct-binmap.h, oct-refcount.h,
sparse-sort.cc, sparse-sort.h, str-vec.h, unwind-prot.h:
Use m_ prefix for class data members and s_ prefix for static data
members. Minor style fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 12 Jun 2019 11:03:06 -0500 |
parents | fff643eb3514 |
children | 829d9efb7730 |
rev | line source |
---|---|
15396 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25653
diff
changeset
|
3 Copyright (C) 1993-2019 John W. Eaton |
15396 | 4 Copyright (C) 2009-2010 VZLU Prague |
5 | |
6 This file is part of Octave. | |
7 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24397
diff
changeset
|
8 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24397
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
11 (at your option) any later version. |
15396 | 12 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
16 GNU General Public License for more details. |
15396 | 17 |
18 You should have received a copy of the GNU General Public License | |
19 along with Octave; see the file COPYING. If not, see | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24397
diff
changeset
|
20 <https://www.gnu.org/licenses/>. |
15396 | 21 |
22 */ | |
23 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
24 #if ! defined (octave_action_container_h) |
15396 | 25 #define octave_action_container_h 1 |
26 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
27 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
28 |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
29 #include <functional> |
23442
53f5f8231c37
allow most header files to be compiled separately
John W. Eaton <jwe@octave.org>
parents:
23437
diff
changeset
|
30 |
15396 | 31 // This class allows registering actions in a list for later |
32 // execution, either explicitly or when the container goes out of | |
33 // scope. | |
34 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
35 // FIXME: is there a better name for this class? |
15396 | 36 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
37 namespace octave |
15396 | 38 { |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
39 class |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
40 action_container |
15396 | 41 { |
42 public: | |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
43 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
44 // A generic unwind_protect element. Knows how to run itself and |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
45 // discard itself. Also, contains a pointer to the next element. |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
46 class elem |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
47 { |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
48 public: |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
49 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
50 friend class action_container; |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
51 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
52 elem (void) { } |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
53 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
54 // No copying! |
15396 | 55 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
56 elem (const elem&) = delete; |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
57 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
58 elem& operator = (const elem&) = delete; |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
59 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
60 virtual ~elem (void) = default; |
15396 | 61 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
62 virtual void run (void) { } |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
63 }; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
64 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
65 // An element that merely runs a void (*)(void) function. |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
66 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
67 class fcn_elem : public elem |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
68 { |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
69 public: |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
70 |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
71 template <typename F, typename... Args> |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
72 fcn_elem (F&& fcn, Args&&... args) |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
73 : m_fcn (std::bind (fcn, args...)) |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
74 { } |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
75 |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
76 void run (void) { m_fcn (); } |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
77 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
78 private: |
15396 | 79 |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
80 std::function<void (void)> m_fcn; |
23927
e3a36f84d01d
provide variable-editor widget for the GUI
Michael Barnes <mjbcode@runbox.com>
parents:
23747
diff
changeset
|
81 }; |
e3a36f84d01d
provide variable-editor widget for the GUI
Michael Barnes <mjbcode@runbox.com>
parents:
23747
diff
changeset
|
82 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
83 // An element that stores arbitrary variable, and restores it. |
15396 | 84 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
85 template <typename T> |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
86 class restore_var_elem : public elem |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
87 { |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
88 public: |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
89 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
90 restore_var_elem (T& ref, const T& val) |
27177 | 91 : m_ptr (&ref), m_val (val) { } |
15396 | 92 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
93 // No copying! |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
94 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
95 restore_var_elem (const restore_var_elem&) = delete; |
15396 | 96 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
97 restore_var_elem& operator = (const restore_var_elem&) = delete; |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
98 |
27177 | 99 void run (void) { *m_ptr = m_val; } |
15396 | 100 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
101 private: |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
102 |
27177 | 103 T *m_ptr, m_val; |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
104 }; |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
105 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
106 // Deletes a class allocated using new. |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
107 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
108 template <typename T> |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
109 class delete_ptr_elem : public elem |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
110 { |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
111 public: |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
112 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
113 delete_ptr_elem (T *ptr) |
27177 | 114 : m_ptr (ptr) { } |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
115 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
116 // No copying! |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
117 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
118 delete_ptr_elem (const delete_ptr_elem&) = delete; |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
119 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
120 delete_ptr_elem operator = (const delete_ptr_elem&) = delete; |
15396 | 121 |
27177 | 122 void run (void) { delete m_ptr; } |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
123 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
124 private: |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
125 |
27177 | 126 T *m_ptr; |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
127 }; |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
128 |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
129 action_container (void) { } |
23437
442fe5b5afb5
new action_container constructors for unwind_protect
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
130 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
131 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
132 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
133 action_container (const action_container&) = delete; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
134 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
135 action_container& operator = (const action_container&) = delete; |
15396 | 136 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
137 virtual ~action_container (void) = default; |
15396 | 138 |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
139 template <typename F, typename... Args> |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
140 void add (F&& fcn, Args&&... args) |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
141 { |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
142 add_action (new fcn_elem (std::forward<F> (fcn), |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
143 std::forward<Args> (args)...)); |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
144 } |
15396 | 145 |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
146 // Use separate template types for function pointer parameter |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
147 // declarations and captured arguments so that differences in |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
148 // const are handled properly. |
15396 | 149 |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
150 template <typename... Params, typename... Args> |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
151 void add_fcn (void (*fcn) (Params...), Args&&... args) |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
152 { |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
153 add_action (new fcn_elem (fcn, std::forward<Args> (args)...)); |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
154 } |
15396 | 155 |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
156 template <typename T, typename... Params, typename... Args> |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
157 void add_method (T *obj, void (T::*method) (Params...), Args&&... args) |
23927
e3a36f84d01d
provide variable-editor widget for the GUI
Michael Barnes <mjbcode@runbox.com>
parents:
23747
diff
changeset
|
158 { |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
159 add_action (new fcn_elem (method, obj, std::forward<Args> (args)...)); |
23927
e3a36f84d01d
provide variable-editor widget for the GUI
Michael Barnes <mjbcode@runbox.com>
parents:
23747
diff
changeset
|
160 } |
e3a36f84d01d
provide variable-editor widget for the GUI
Michael Barnes <mjbcode@runbox.com>
parents:
23747
diff
changeset
|
161 |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
162 template <typename T, typename... Params, typename... Args> |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
163 void add_method (T& obj, void (T::*method) (Params...), Args&&... args) |
23927
e3a36f84d01d
provide variable-editor widget for the GUI
Michael Barnes <mjbcode@runbox.com>
parents:
23747
diff
changeset
|
164 { |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
165 add_action (new fcn_elem (method, &obj, std::forward<Args> (args)...)); |
23927
e3a36f84d01d
provide variable-editor widget for the GUI
Michael Barnes <mjbcode@runbox.com>
parents:
23747
diff
changeset
|
166 } |
e3a36f84d01d
provide variable-editor widget for the GUI
Michael Barnes <mjbcode@runbox.com>
parents:
23747
diff
changeset
|
167 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
168 // Call to delete (T*). |
23437
442fe5b5afb5
new action_container constructors for unwind_protect
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
169 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
170 template <typename T> |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
171 void add_delete (T *obj) |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
172 { |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
173 add_action (new delete_ptr_elem<T> (obj)); |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
174 } |
15396 | 175 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
176 // Protect any variable. |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
177 template <typename T> |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
178 void protect_var (T& var) |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
179 { |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
180 add_action (new restore_var_elem<T> (var, var)); |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
181 } |
15396 | 182 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
183 // Protect any variable, value given. |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
184 template <typename T> |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
185 void protect_var (T& var, const T& val) |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
186 { |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
187 add_action (new restore_var_elem<T> (var, val)); |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
188 } |
23437
442fe5b5afb5
new action_container constructors for unwind_protect
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
189 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
190 operator bool (void) const { return ! empty (); } |
15396 | 191 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
192 virtual void run_first (void) = 0; |
15396 | 193 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
194 void run (size_t num) |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
195 { |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
196 if (num > size ()) |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
197 num = size (); |
15396 | 198 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
199 for (size_t i = 0; i < num; i++) |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
200 run_first (); |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
201 } |
15396 | 202 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
203 void run (void) { run (size ()); } |
15396 | 204 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
205 virtual void discard_first (void) = 0; |
15396 | 206 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
207 void discard (size_t num) |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
208 { |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
209 if (num > size ()) |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
210 num = size (); |
15396 | 211 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
212 for (size_t i = 0; i < num; i++) |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
213 discard_first (); |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
214 } |
15396 | 215 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
216 void discard (void) { discard (size ()); } |
15396 | 217 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
218 virtual size_t size (void) const = 0; |
15396 | 219 |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
220 bool empty (void) const { return size () == 0; } |
25653
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
221 |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
222 protected: |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
223 |
b3d357990b52
better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
224 virtual void add_action (elem *new_elem) = 0; |
23747
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
225 }; |
0b4d1575a2e2
move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23442
diff
changeset
|
226 } |
15396 | 227 |
228 #endif |