Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / dti_excs / Exception.hh
1
2 #include <ctype.h>
3
4 #define G_TEMP_SPACE_SIZE 1024
5
6 #define CASTEXCEPT
7
8 class Exception : public Destructable
9 {
10 public:
11 #ifdef NATIVE_EXCEPTIONS
12
13 #if defined(hpux)
14   Exception() { }
15 #endif
16
17 #else
18   Exception();
19
20 #if defined(linux) && defined(EXC_DEBUG)
21 ~Exception()
22 {
23     PRINTF (("Destroying Exception @ %p\n", this));
24 }
25 #elif defined(EXC_DEBUG)
26 ~Exception()
27 {
28     PRINTF (("Destroying Exception @ %p\n", this));
29 }
30 #endif
31
32   // For printing debugging info. Can be overloaded by derived classes.
33   virtual void print_exception()
34     { }
35   
36   virtual const char *class_name()
37     { return ("Exception"); }
38
39   Exception *prepare_to_throw();
40
41   // This operator invoked if this is thrown as an object/reference
42   Exception *operator ->()
43     { if (!f_thrown) f_thrown_as_pointer = 0;
44       return (this); }
45
46   operator Exception *()
47     { return (this); }
48
49   virtual int isa (const char *type)
50     { return (is (type, "Exception")); }
51
52   int is (const char *type, const char *this_class);
53
54   static Exception &current_exception();
55
56   const char *file()
57     { return (f_file); }
58   unsigned short line()
59     { return (f_line); }
60
61   // Need to provide a plain operator new definition because we
62   // have a definition of the other one below.  (See the ARM.) 
63
64 #ifndef USL    
65   static void *operator new (size_t size)
66     { return (::operator new (size)); }
67 #endif
68
69   static void operator delete (void *place);
70
71   // For initial throw.  Redefined by decendents.
72   // Makes temporaries for stack based objects and calls do_throw. 
73   void throw_it (unsigned int line, const char *file, int debugging);
74
75   // Actual throw code.  Also used for rethrows. 
76   void do_throw (unsigned int line = 0,
77                  const char *file = "(unknown)",
78                  int debugging = 0);
79
80   // Length is only valid for exceptions at the top of the stack! 
81   int length() { return (g_next_avail - (char *) this); }
82   void unmake_current();
83   void make_current();
84   static void relocate (Exception **exception, int length);
85
86 protected:
87 friend class Jump_Environment;
88 friend class Exceptions;
89
90 #if defined(hpux)||defined(__uxp__)
91 #define MakeOperatorNewPublic
92 #endif
93
94 #ifdef MakeOperatorNewPublic
95 // A problem with the HP-UX 3.65 compiler requires us to make this public.
96 // And, since we gen the Templates.nd.c file on a non-HPUX platform, we need
97 // a second way to trigger the change.
98 public:
99 #endif
100   static void *operator new (size_t size, int);
101 #ifdef MakeOperatorNewPublic
102 protected:
103 #endif
104
105 // f_thrown flag is a safty feature to make sure that the f_throw_as_pointer
106 // flag can't be reset accidently by the user calling operator -> 
107   
108 #ifdef PURIFY
109   unsigned char f_thrown;
110   unsigned char f_thrown_as_pointer;
111   unsigned char f_temporary;
112 #else
113   unsigned char f_thrown : 1;
114   unsigned char f_thrown_as_pointer : 1;
115   unsigned char f_temporary : 1;
116 #endif
117
118 private:
119   // Line and file where exception was originally thrown from. 
120   const char     *f_file;
121   unsigned short  f_line;
122   Exception      *f_previous_exception;
123
124   static Exception *g_current_exception;
125
126 #ifdef C_API
127   static char      *g_temp_space;
128 #else
129   static char       g_temp_space[G_TEMP_SPACE_SIZE];
130 #endif
131
132   static char      *g_next_avail;
133
134 #ifdef C_API
135   friend void initialize_exception();
136   friend void quit_exception();
137 #endif
138
139 #endif /* NATIVE_EXCEPTIONS */
140 };
141
142
143 // /////////////////////////////////////////////////////////////////
144 // DECLARE_EXCEPTION - macros for derived classes
145 // /////////////////////////////////////////////////////////////////
146
147 #ifndef NATIVE_EXCEPTIONS
148 // NOTE: class_name, is, and isa should be renamed to _exc_... 
149
150 #define _DECL_START(NAME) \
151   const char *class_name() \
152     { return (STRINGIFY(NAME)); } \
153   void throw_it (unsigned int line, const char *file, int dbg) \
154     { Exception *temp; \
155       if (in_stack()) { \
156         temp = new (0) NAME (*this); \
157         ((NAME *)temp)->f_temporary = 1; \
158       } else \
159         temp = this; \
160       temp->do_throw (line, file, dbg); } \
161   NAME *operator ->() { if (!f_thrown) f_thrown_as_pointer = 0; \
162                         return (this); } \
163   operator NAME *() { return (this); } \
164   int isa (const char *type) \
165     { return (is (type, STRINGIFY(NAME)) ||
166
167 #define _DECL_END \
168               ); } \
169
170 // MUST be the first thing in a subclass or protections get screwed up.
171
172 #define DECLARE_EXCEPTION DECLARE_EXCEPTION1
173
174 #define DECLARE_EXCEPTION1(NAME,SUPER1) \
175   _DECL_START (NAME) \
176   SUPER1::isa (type) \
177   _DECL_END
178
179 #define DECLARE_EXCEPTION2(NAME,SUPER1,SUPER2) \
180   _DECL_START (NAME) \
181   SUPER1::isa (type) || \
182   SUPER2::isa (type) \
183   _DECL_END
184
185 #define DECLARE_EXCEPTION3(NAME,SUPER1,SUPER2,SUPER3) \
186   _DECL_START (NAME) \
187   SUPER1::isa (type) || \
188   SUPER2::isa (type) || \
189   SUPER3::isa (type) \
190   _DECL_END
191
192 #else
193
194 #define DECLARE_EXCEPTION(NAME,SUPER1)
195 #define DECLARE_EXCEPTION1(NAME,SUPER1)
196 #define DECLARE_EXCEPTION2(NAME,SUPER1,SUPER2)
197 #define DECLARE_EXCEPTION3(NAME,SUPER1,SUPER2)
198
199 #endif /* NATIVE_EXCEPTIONS */
200
201 // Users can define more if they need to...