1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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) \ |
2800
|
57 unwind_protect_ptr_internal (static_cast<void **> (&(p)), \ |
|
58 static_cast<void *> (p)) |
1
|
59 |
453
|
60 class |
|
61 unwind_elem |
240
|
62 { |
|
63 public: |
1755
|
64 unwind_elem (void) |
|
65 : ue_tag (), ue_fptr (0), ue_ptr (0) { } |
|
66 |
|
67 unwind_elem (const string &t) |
|
68 : ue_tag (t), ue_fptr (0), ue_ptr (0) { } |
|
69 |
|
70 unwind_elem (cleanup_func f, void *p) |
|
71 : ue_tag (), ue_fptr (f), ue_ptr (p) { } |
|
72 |
|
73 unwind_elem (const unwind_elem& el) |
|
74 : ue_tag (el.ue_tag), ue_fptr (el.ue_fptr), ue_ptr (el.ue_ptr) { } |
|
75 |
|
76 ~unwind_elem (void) { } |
240
|
77 |
1755
|
78 unwind_elem& operator = (const unwind_elem& el) |
|
79 { |
|
80 ue_tag = el.ue_tag; |
|
81 ue_fptr = el.ue_fptr; |
|
82 ue_ptr = el.ue_ptr; |
240
|
83 |
1755
|
84 return *this; |
|
85 } |
|
86 |
|
87 string tag (void) { return ue_tag; } |
|
88 |
|
89 cleanup_func fptr (void) { return ue_fptr; } |
|
90 |
|
91 void *ptr (void) { return ue_ptr; } |
240
|
92 |
|
93 private: |
1755
|
94 string ue_tag; |
|
95 cleanup_func ue_fptr; |
|
96 void *ue_ptr; |
240
|
97 }; |
|
98 |
1
|
99 #endif |
|
100 |
|
101 /* |
|
102 ;;; Local Variables: *** |
|
103 ;;; mode: C++ *** |
|
104 ;;; End: *** |
|
105 */ |