Mercurial > hg > octave-nkf
annotate src/unwind-prot.h @ 9112:f5b51f54f44e
Remove obsolete comments from test scripts in test
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Sun, 12 Apr 2009 22:30:00 +0200 |
parents | eb63fbe60fab |
children | d58086453171 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2004, |
8920 | 4 2005, 2006, 2007, 2008 John W. Eaton |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
383 | 24 #if !defined (octave_unwind_prot_h) |
25 #define octave_unwind_prot_h 1 | |
1 | 26 |
1342 | 27 #include <cstddef> |
529 | 28 |
1755 | 29 #include <string> |
4214 | 30 #include <stack> |
1 | 31 |
453 | 32 class |
6109 | 33 OCTINTERP_API |
453 | 34 unwind_elem |
240 | 35 { |
2985 | 36 public: |
37 | |
38 typedef void (*cleanup_func) (void *ptr); | |
39 | |
1755 | 40 unwind_elem (void) |
41 : ue_tag (), ue_fptr (0), ue_ptr (0) { } | |
42 | |
3523 | 43 unwind_elem (const std::string &t) |
1755 | 44 : ue_tag (t), ue_fptr (0), ue_ptr (0) { } |
45 | |
46 unwind_elem (cleanup_func f, void *p) | |
47 : ue_tag (), ue_fptr (f), ue_ptr (p) { } | |
48 | |
49 unwind_elem (const unwind_elem& el) | |
50 : ue_tag (el.ue_tag), ue_fptr (el.ue_fptr), ue_ptr (el.ue_ptr) { } | |
51 | |
52 ~unwind_elem (void) { } | |
240 | 53 |
1755 | 54 unwind_elem& operator = (const unwind_elem& el) |
55 { | |
56 ue_tag = el.ue_tag; | |
57 ue_fptr = el.ue_fptr; | |
58 ue_ptr = el.ue_ptr; | |
240 | 59 |
1755 | 60 return *this; |
61 } | |
62 | |
3523 | 63 std::string tag (void) { return ue_tag; } |
1755 | 64 |
65 cleanup_func fptr (void) { return ue_fptr; } | |
66 | |
67 void *ptr (void) { return ue_ptr; } | |
240 | 68 |
2985 | 69 private: |
70 | |
3523 | 71 std::string ue_tag; |
2985 | 72 |
1755 | 73 cleanup_func ue_fptr; |
2985 | 74 |
1755 | 75 void *ue_ptr; |
240 | 76 }; |
77 | |
2985 | 78 class |
6109 | 79 OCTINTERP_API |
2985 | 80 unwind_protect |
81 { | |
82 public: | |
83 | |
7336 | 84 static void add (unwind_elem::cleanup_func fptr, void *ptr = 0); |
2985 | 85 |
86 static void run (void); | |
87 | |
88 static void discard (void); | |
89 | |
3523 | 90 static void begin_frame (const std::string& tag); |
2985 | 91 |
3523 | 92 static void run_frame (const std::string& tag); |
2985 | 93 |
3523 | 94 static void discard_frame (const std::string& tag); |
2985 | 95 |
96 static void run_all (void); | |
97 | |
98 static void discard_all (void); | |
99 | |
100 // Ways to save variables. | |
101 | |
102 static void save_bool (bool *ptr, bool value); | |
103 | |
104 static void save_int (int *ptr, int value); | |
105 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
106 static void save_size_t (size_t *ptr, size_t value); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
107 |
3523 | 108 static void save_str (std::string *ptr, const std::string& value); |
2985 | 109 |
110 static void save_ptr (void **ptr, void *value); | |
111 | |
112 static void save_var (void *ptr, void *value, size_t size); | |
113 | |
4214 | 114 static std::stack<unwind_elem> elt_list; |
2985 | 115 }; |
116 | |
117 // We could get by without these macros, but they are nice to have... | |
118 | |
119 #define unwind_protect_bool(b) \ | |
120 unwind_protect::save_bool (&(b), (b)) | |
121 | |
122 #define unwind_protect_int(i) \ | |
123 unwind_protect::save_int (&(i), (i)) | |
124 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
125 #define unwind_protect_size_t(i) \ |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
126 unwind_protect::save_size_t (&(i), (i)) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
127 |
2985 | 128 #define unwind_protect_str(s) \ |
129 unwind_protect::save_str (&(s), (s)) | |
130 | |
131 #define unwind_protect_ptr(p) \ | |
5760 | 132 unwind_protect::save_ptr (reinterpret_cast<void **> (&(p)), \ |
133 reinterpret_cast<void *> (p)) | |
134 | |
5854 | 135 #define unwind_protect_fptr(p) \ |
136 unwind_protect::save_ptr (reinterpret_cast<void **> (&(p)), \ | |
137 FCN_PTR_CAST (void *, p)) | |
138 | |
5760 | 139 #define unwind_protect_const_ptr(p) \ |
140 unwind_protect::save_ptr (const_cast<void **> (reinterpret_cast<const void **> (&(p))), \ | |
141 const_cast<void *> (reinterpret_cast<const void *> (p))) | |
2985 | 142 |
1 | 143 #endif |
144 | |
145 /* | |
146 ;;; Local Variables: *** | |
147 ;;; mode: C++ *** | |
148 ;;; End: *** | |
149 */ |