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