Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | |
2 | * Implementation of a cleanup stack for exception handling on platforms |
||
3 | * that don't clean up the stack automatically after an exception |
||
4 | * occurs. The macro's SAFEPUSH and SAFEPOP as defined in |
||
5 | * plat/ |
||
6 | * to use, so it can be configured differently for different platforms. |
||
7 | * |
||
8 | */ |
||
9 | |||
10 | |||
11 | #define __lispcleanupstack_h__ |
||
12 | |||
13 | |||
14 | #include "grower.h" |
||
15 | |||
16 | |||
17 | * Only classes derived from this one can be pushed onto |
||
18 | * a cleanup stack. This in order to assure the cleanup code |
||
19 | * knows where to find the destructor. |
||
20 | * |
||
21 | * Typical candidates for cleanup include places in the code that |
||
22 | * have temporal global side effects that need to be finalized on, |
||
23 | * Like opening a file for reading, reading and then closing. If |
||
24 | * reading prematurely finishes through an exception, the file |
||
25 | * should be closed. |
||
26 | */ |
||
27 | class LispBase : public YacasBase |
||
28 | { |
||
29 | public: |
||
30 | virtual void Delete()=0; |
||
31 | virtual ~LispBase(){}; |
||
32 | }; |
||
33 | |||
34 | |||
35 | * Use this clean up stack if the compiler generates |
||
36 | * cleanup code itself (particularly for newer c++ compilers). |
||
37 | * Alternatively SAFEPUSH and SAFEPOP can then be defined to do nothing. |
||
38 | */ |
||
39 | class LispCleanup : public YacasBase |
||
40 | { |
||
41 | public: |
||
42 | inline LispCleanup() : iObjects() {} |
||
43 | virtual ~LispCleanup(); |
||
44 | /// Push an object onto the cleanup stack for guarding |
||
45 | virtual void Push(LispBase& aObject); |
||
46 | /// Pop an object from the cleanup stack (the system is finished using it) |
||
47 | virtual void Pop(); |
||
48 | /// Exception occurred: delete all objects on the stack, back to front. |
||
49 | virtual void Delete(); |
||
50 | /** For testing purposes, verify that all places that pushed an object |
||
51 | * popped it too. |
||
52 | */ |
||
53 | void CheckStackEmpty(); |
||
54 | |||
55 | |||
56 | CArrayGrower |
||
57 | }; |
||
58 | |||
59 | |||
60 | * Use this clean up stack if the compiler doesn't generate |
||
61 | * cleanup code itself (particularly for older c++ compilers). |
||
62 | */ |
||
63 | class DeletingLispCleanup : public LispCleanup |
||
64 | { |
||
65 | public: |
||
66 | virtual ~DeletingLispCleanup(); |
||
67 | virtual void Push(LispBase& aObject); |
||
68 | virtual void Pop(); |
||
69 | virtual void Delete(); |
||
70 | }; |
||
71 | |||
72 | |||
73 | |||
74 |