1
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
383
|
23 #if !defined (octave_unwind_prot_h) |
|
24 #define octave_unwind_prot_h 1 |
1
|
25 |
1297
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
1342
|
30 #include <cstddef> |
529
|
31 |
1755
|
32 #include <string> |
|
33 |
1
|
34 typedef void (*cleanup_func)(void *ptr); |
|
35 |
|
36 void add_unwind_protect (cleanup_func fptr, void *ptr); |
|
37 void run_unwind_protect (void); |
|
38 void discard_unwind_protect (void); |
1755
|
39 void begin_unwind_frame (const string& tag); |
|
40 void run_unwind_frame (const string& tag); |
|
41 void discard_unwind_frame (const string& tag); |
1
|
42 void run_all_unwind_protects (void); |
|
43 void discard_all_unwind_protects (void); |
|
44 |
|
45 void unwind_protect_int_internal (int *ptr, int value); |
1755
|
46 void unwind_protect_str_internal (string *ptr, const string& value); |
1
|
47 void unwind_protect_ptr_internal (void **ptr, void *value); |
|
48 void unwind_protect_var_internal (void *ptr, void *value, size_t size); |
|
49 |
|
50 #define unwind_protect_int(i) \ |
|
51 unwind_protect_int_internal (&(i), (i)) |
|
52 |
1755
|
53 #define unwind_protect_str(s) \ |
|
54 unwind_protect_str_internal (&(s), (s)) |
|
55 |
1
|
56 #define unwind_protect_ptr(p) \ |
|
57 unwind_protect_ptr_internal ((void **) &(p), (void *) (p)) |
|
58 |
453
|
59 class |
|
60 unwind_elem |
240
|
61 { |
|
62 public: |
1755
|
63 unwind_elem (void) |
|
64 : ue_tag (), ue_fptr (0), ue_ptr (0) { } |
|
65 |
|
66 unwind_elem (const string &t) |
|
67 : ue_tag (t), ue_fptr (0), ue_ptr (0) { } |
|
68 |
|
69 unwind_elem (cleanup_func f, void *p) |
|
70 : ue_tag (), ue_fptr (f), ue_ptr (p) { } |
|
71 |
|
72 unwind_elem (const unwind_elem& el) |
|
73 : ue_tag (el.ue_tag), ue_fptr (el.ue_fptr), ue_ptr (el.ue_ptr) { } |
|
74 |
|
75 ~unwind_elem (void) { } |
240
|
76 |
1755
|
77 unwind_elem& operator = (const unwind_elem& el) |
|
78 { |
|
79 ue_tag = el.ue_tag; |
|
80 ue_fptr = el.ue_fptr; |
|
81 ue_ptr = el.ue_ptr; |
240
|
82 |
1755
|
83 return *this; |
|
84 } |
|
85 |
|
86 string tag (void) { return ue_tag; } |
|
87 |
|
88 cleanup_func fptr (void) { return ue_fptr; } |
|
89 |
|
90 void *ptr (void) { return ue_ptr; } |
240
|
91 |
|
92 private: |
1755
|
93 string ue_tag; |
|
94 cleanup_func ue_fptr; |
|
95 void *ue_ptr; |
240
|
96 }; |
|
97 |
1
|
98 #endif |
|
99 |
|
100 /* |
|
101 ;;; Local Variables: *** |
|
102 ;;; mode: C++ *** |
|
103 ;;; End: *** |
|
104 */ |