Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / dti_excs / Unwind_Stack.hh
1 // $XConsortium: Unwind_Stack.hh /main/5 1996/10/04 09:34:56 drk $
2 class Destructable;
3
4 #define UNWIND_STACK_SIZE 512
5
6 class Unwind_Record
7 {
8 public:
9   Destructable *f_object;
10   unsigned short f_size;
11   void set (Destructable *object, unsigned int size)
12     { f_object = object; f_size = size; }
13   unsigned long object_start() const
14     { return ((unsigned long) f_object); }
15   unsigned long object_end() const
16     { return ((unsigned long) f_object + f_size); }
17 };
18
19
20 class Unwind_Stack
21 {
22 public:
23   Unwind_Stack()
24     { f_bottom = g_top;
25       PRINTF (("+++ New TOS = %d\n", f_bottom)); }
26
27   ~Unwind_Stack()
28     { g_top = f_bottom;
29       PRINTF (("--- Reset TOS = %d\n", g_top)); }
30
31   void push (Destructable *object, unsigned int size);
32
33   void pop()
34     { g_top--;
35       PRINTF (("  Pop [ %d ]\n", g_top)); }
36
37   int empty() const
38     { return (g_top == f_bottom); }
39
40   const Unwind_Record &top() const
41     { return (g_stack[g_top-1]); }
42   
43 private:
44   unsigned short f_bottom;
45
46   static unsigned short g_top;
47
48 #ifdef C_API
49   static Unwind_Record*  g_stack;
50
51   friend void initialize_exception();
52   friend void quit_exception();
53 #else
54   static Unwind_Record  g_stack[UNWIND_STACK_SIZE];
55 #endif
56 };
57
58
59 inline void
60 Unwind_Stack::push (Destructable *object, unsigned int size)
61 {
62   void terminate();
63   if (g_top > UNWIND_STACK_SIZE)
64     {
65       Exceptions::error (Exceptions::f_msg_out_of_obj_stack_memory,
66                          Exceptions::INTERNAL_ERROR);
67       terminate();
68     }
69   PRINTF (("  Push [ %d ] = %p\n", g_top, object));
70   g_stack[g_top++].set (object, size);
71 }