]> ncurses.scripts.mit.edu Git - ncurses.git/blob - c++/etip.h.in
ncurses 5.6 - patch 20070127
[ncurses.git] / c++ / etip.h.in
1 // * This makes emacs happy -*-Mode: C++;-*-
2 /****************************************************************************
3  * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc.              *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29
30 /****************************************************************************
31  *   Author: Juergen Pfeifer, 1997                                          *
32  ****************************************************************************/
33
34 // $Id: etip.h.in,v 1.34 2007/01/27 18:49:00 tom Exp $
35
36 #ifndef NCURSES_ETIP_H_incl
37 #define NCURSES_ETIP_H_incl 1
38
39 // These are substituted at configure/build time
40 #ifndef HAVE_BUILTIN_H
41 #define HAVE_BUILTIN_H 0
42 #endif
43
44 #ifndef HAVE_GXX_BUILTIN_H
45 #define HAVE_GXX_BUILTIN_H 0
46 #endif
47
48 #ifndef HAVE_GPP_BUILTIN_H
49 #define HAVE_GPP_BUILTIN_H 0
50 #endif
51
52 #ifndef HAVE_TYPEINFO
53 #define HAVE_TYPEINFO 0
54 #endif
55
56 #ifndef HAVE_VALUES_H
57 #define HAVE_VALUES_H 0
58 #endif
59
60 #ifndef ETIP_NEEDS_MATH_H
61 #define ETIP_NEEDS_MATH_H 0
62 #endif
63
64 #ifndef ETIP_NEEDS_MATH_EXCEPTION
65 #define ETIP_NEEDS_MATH_EXCEPTION 0
66 #endif
67
68 #ifndef CPP_HAS_PARAM_INIT
69 #define CPP_HAS_PARAM_INIT 0
70 #endif
71
72 #ifndef CPP_HAS_STATIC_CAST
73 #define CPP_HAS_STATIC_CAST 0   // workaround for g++ 2.95.3
74 #endif
75
76 #ifdef __GNUG__
77 #  if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
78 #    if HAVE_TYPEINFO
79 #      include <typeinfo>
80 #    endif
81 #  endif
82 #endif
83
84 #if defined(__GNUG__)
85 #  if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H
86 #    if ETIP_NEEDS_MATH_H
87 #      if ETIP_NEEDS_MATH_EXCEPTION
88 #        undef exception
89 #        define exception math_exception
90 #      endif
91 #      include <math.h>
92 #    endif
93 #    undef exception
94 #    define exception builtin_exception
95 #    if HAVE_GPP_BUILTIN_H
96 #     include <gpp/builtin.h>
97 #    elif HAVE_GXX_BUILTIN_H
98 #     include <g++/builtin.h>
99 #    else
100 #     include <builtin.h>
101 #    endif
102 #    undef exception
103 #  endif
104 #elif defined (__SUNPRO_CC)
105 #  include <generic.h>
106 #endif
107
108 #include <ncurses_dll.h>
109
110 extern "C" {
111 #if HAVE_VALUES_H
112 #  include <values.h>
113 #endif
114
115 #include <assert.h>
116 #include <eti.h>
117 #include <errno.h>
118 }
119
120 // Language features
121 #if CPP_HAS_PARAM_INIT
122 #define NCURSES_PARAM_INIT(value) = value
123 #else
124 #define NCURSES_PARAM_INIT(value) /*nothing*/
125 #endif
126
127 #if CPP_HAS_STATIC_CAST
128 #define STATIC_CAST(s) static_cast<s>
129 #else
130 #define STATIC_CAST(s) (s)
131 #endif
132
133 // Forward Declarations
134 class NCURSES_IMPEXP NCursesPanel;
135 class NCURSES_IMPEXP NCursesMenu;
136 class NCURSES_IMPEXP NCursesForm;
137
138 class NCURSES_IMPEXP NCursesException
139 {
140 public:
141   const char *message;
142   int errorno;
143
144   NCursesException (const char* msg, int err)
145     : message(msg), errorno (err)
146     {};
147
148   NCursesException (const char* msg)
149     : message(msg), errorno (E_SYSTEM_ERROR)
150     {};
151
152   NCursesException& operator=(const NCursesException& rhs)
153   {
154     errorno = rhs.errorno;
155     return *this;
156   }
157
158   NCursesException(const NCursesException& rhs)
159     : message(rhs.message), errorno(rhs.errorno)
160   {
161   }
162
163   virtual const char *classname() const {
164     return "NCursesWindow";
165   }
166
167   virtual ~NCursesException()
168   {
169   }
170 };
171
172 class NCURSES_IMPEXP NCursesPanelException : public NCursesException
173 {
174 public:
175   const NCursesPanel* p;
176
177   NCursesPanelException (const char *msg, int err) :
178     NCursesException (msg, err),
179     p (NULL)
180     {};
181
182   NCursesPanelException (const NCursesPanel* panel,
183                          const char *msg,
184                          int err) :
185     NCursesException (msg, err),
186     p (panel)
187     {};
188
189   NCursesPanelException (int err) :
190     NCursesException ("panel library error", err),
191     p (NULL)
192     {};
193
194   NCursesPanelException (const NCursesPanel* panel,
195                          int err) :
196     NCursesException ("panel library error", err),
197     p (panel)
198     {};
199
200   NCursesPanelException& operator=(const NCursesPanelException& rhs)
201   {
202     if (this != &rhs) {
203       NCursesException::operator=(rhs);
204       p = rhs.p;
205     }
206     return *this;
207   }
208
209   NCursesPanelException(const NCursesPanelException& rhs)
210     : NCursesException(rhs), p(rhs.p)
211   {
212   }
213
214   virtual const char *classname() const {
215     return "NCursesPanel";
216   }
217
218   virtual ~NCursesPanelException()
219   {
220   }
221 };
222
223 class NCURSES_IMPEXP NCursesMenuException : public NCursesException
224 {
225 public:
226   const NCursesMenu* m;
227
228   NCursesMenuException (const char *msg, int err) :
229     NCursesException (msg, err),
230     m (NULL)
231     {};
232
233   NCursesMenuException (const NCursesMenu* menu,
234                         const char *msg,
235                         int err) :
236     NCursesException (msg, err),
237     m (menu)
238     {};
239
240   NCursesMenuException (int err) :
241     NCursesException ("menu library error", err),
242     m (NULL)
243     {};
244
245   NCursesMenuException (const NCursesMenu* menu,
246                         int err) :
247     NCursesException ("menu library error", err),
248     m (menu)
249     {};
250
251   NCursesMenuException& operator=(const NCursesMenuException& rhs)
252   {
253     if (this != &rhs) {
254       NCursesException::operator=(rhs);
255       m = rhs.m;
256     }
257     return *this;
258   }
259
260   NCursesMenuException(const NCursesMenuException& rhs)
261     : NCursesException(rhs), m(rhs.m)
262   {
263   }
264
265   virtual const char *classname() const {
266     return "NCursesMenu";
267   }
268
269   virtual ~NCursesMenuException()
270   {
271   }
272 };
273
274 class NCURSES_IMPEXP NCursesFormException : public NCursesException
275 {
276 public:
277   const NCursesForm* f;
278
279   NCursesFormException (const char *msg, int err) :
280     NCursesException (msg, err),
281     f (NULL)
282     {};
283
284   NCursesFormException (const NCursesForm* form,
285                         const char *msg,
286                         int err) :
287     NCursesException (msg, err),
288     f (form)
289     {};
290
291   NCursesFormException (int err) :
292     NCursesException ("form library error", err),
293     f (NULL)
294     {};
295
296   NCursesFormException (const NCursesForm* form,
297                         int err) :
298     NCursesException ("form library error", err),
299     f (form)
300     {};
301
302   NCursesFormException& operator=(const NCursesFormException& rhs)
303   {
304     if (this != &rhs) {
305       NCursesException::operator=(rhs);
306       f = rhs.f;
307     }
308     return *this;
309   }
310
311   NCursesFormException(const NCursesFormException& rhs)
312     : NCursesException(rhs), f(rhs.f)
313   {
314   }
315
316   virtual const char *classname() const {
317     return "NCursesForm";
318   }
319
320   virtual ~NCursesFormException()
321   {
322   }
323 };
324
325 #if !((defined(__GNUG__) && defined(__EXCEPTIONS)) || defined(__SUNPRO_CC))
326 #  include <iostream.h>
327    extern "C" void exit(int);
328 #endif
329
330 inline void THROW(const NCursesException *e) {
331 #if defined(__GNUG__) && defined(__EXCEPTIONS)
332 #  if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
333       (*lib_error_handler)(e?e->classname():"",e?e->message:"");
334 #else
335       throw *e;
336 #endif
337 #elif defined(__SUNPRO_CC)
338 #  if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
339   genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
340 #else
341   throw *e;
342 #endif
343 #else
344   if (e)
345     cerr << e->message << endl;
346   exit(0);
347 #endif
348 }
349
350 #define THROWS(s)
351
352 #endif /* NCURSES_ETIP_H_incl */