]> ncurses.scripts.mit.edu Git - ncurses.git/blob - c++/etip.h.in
ncurses 6.4 - patch 20240420
[ncurses.git] / c++ / etip.h.in
1 // * This makes emacs happy -*-Mode: C++;-*-
2 /****************************************************************************
3  * Copyright 2018-2020,2021 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.46 2021/04/17 17:59:57 tom 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   explicit NCursesException (const char* msg)
158     : message(msg), errorno (E_SYSTEM_ERROR)
159     {};
160
161   NCursesException& operator=(const NCursesException& rhs)
162   {
163     message = rhs.message;
164     errorno = rhs.errorno;
165     return *this;
166   }
167
168   NCursesException(const NCursesException& rhs)
169     : message(rhs.message), errorno(rhs.errorno)
170   {
171   }
172
173   virtual const char *classname() const {
174     return "NCursesWindow";
175   }
176
177   virtual ~NCursesException()
178   {
179   }
180 };
181
182 class NCURSES_CXX_IMPEXP NCursesPanelException : public NCursesException
183 {
184 public:
185   const NCursesPanel* p;
186
187   NCursesPanelException (const char *msg, int err) :
188     NCursesException (msg, err),
189     p (0)
190     {};
191
192   NCursesPanelException (const NCursesPanel* panel,
193                          const char *msg,
194                          int err) :
195     NCursesException (msg, err),
196     p (panel)
197     {};
198
199   explicit NCursesPanelException (int err) :
200     NCursesException ("panel library error", err),
201     p (0)
202     {};
203
204   NCursesPanelException (const NCursesPanel* panel,
205                          int err) :
206     NCursesException ("panel library error", err),
207     p (panel)
208     {};
209
210   NCursesPanelException& operator=(const NCursesPanelException& rhs)
211   {
212     if (this != &rhs) {
213       NCursesException::operator=(rhs);
214       p = rhs.p;
215     }
216     return *this;
217   }
218
219   NCursesPanelException(const NCursesPanelException& rhs)
220     : NCursesException(rhs), p(rhs.p)
221   {
222   }
223
224   virtual const char *classname() const {
225     return "NCursesPanel";
226   }
227
228   virtual ~NCursesPanelException()
229   {
230   }
231 };
232
233 class NCURSES_CXX_IMPEXP NCursesMenuException : public NCursesException
234 {
235 public:
236   const NCursesMenu* m;
237
238   NCursesMenuException (const char *msg, int err) :
239     NCursesException (msg, err),
240     m (0)
241     {};
242
243   NCursesMenuException (const NCursesMenu* menu,
244                         const char *msg,
245                         int err) :
246     NCursesException (msg, err),
247     m (menu)
248     {};
249
250   explicit NCursesMenuException (int err) :
251     NCursesException ("menu library error", err),
252     m (0)
253     {};
254
255   NCursesMenuException (const NCursesMenu* menu,
256                         int err) :
257     NCursesException ("menu library error", err),
258     m (menu)
259     {};
260
261   NCursesMenuException& operator=(const NCursesMenuException& rhs)
262   {
263     if (this != &rhs) {
264       NCursesException::operator=(rhs);
265       m = rhs.m;
266     }
267     return *this;
268   }
269
270   NCursesMenuException(const NCursesMenuException& rhs)
271     : NCursesException(rhs), m(rhs.m)
272   {
273   }
274
275   virtual const char *classname() const {
276     return "NCursesMenu";
277   }
278
279   virtual ~NCursesMenuException()
280   {
281   }
282 };
283
284 class NCURSES_CXX_IMPEXP NCursesFormException : public NCursesException
285 {
286 public:
287   const NCursesForm* f;
288
289   NCursesFormException (const char *msg, int err) :
290     NCursesException (msg, err),
291     f (0)
292     {};
293
294   NCursesFormException (const NCursesForm* form,
295                         const char *msg,
296                         int err) :
297     NCursesException (msg, err),
298     f (form)
299     {};
300
301   explicit NCursesFormException (int err) :
302     NCursesException ("form library error", err),
303     f (0)
304     {};
305
306   NCursesFormException (const NCursesForm* form,
307                         int err) :
308     NCursesException ("form library error", err),
309     f (form)
310     {};
311
312   NCursesFormException& operator=(const NCursesFormException& rhs)
313   {
314     if (this != &rhs) {
315       NCursesException::operator=(rhs);
316       f = rhs.f;
317     }
318     return *this;
319   }
320
321   NCursesFormException(const NCursesFormException& rhs)
322     : NCursesException(rhs), f(rhs.f)
323   {
324   }
325
326   virtual const char *classname() const {
327     return "NCursesForm";
328   }
329
330   virtual ~NCursesFormException()
331   {
332   }
333 };
334
335 #if !((defined(__GNUG__) && defined(__EXCEPTIONS) && (__GNUG__ < 7)) || defined(__SUNPRO_CC))
336 #  if HAVE_IOSTREAM
337 #     include <iostream>
338 #     if IOSTREAM_NAMESPACE
339 using std::cerr;
340 using std::endl;
341 #     endif
342 #  else
343 #     include <iostream.h>
344 #  endif
345 #endif
346
347 inline void THROW(const NCursesException *e) {
348 #if defined(__GNUG__) && defined(__EXCEPTIONS)
349 #  if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
350       (*lib_error_handler)(e ? e->classname() : "", e ? e->message : "");
351 #  elif (__GNUG__ >= 7)
352      // g++ 7.0 warns about deprecation, but lacks the predefined symbols
353       ::endwin();
354       std::cerr << "Found a problem - goodbye" << std::endl;
355       exit(EXIT_FAILURE);
356 #  else
357 #    define CPP_HAS_TRY_CATCH 1
358 #  endif
359 #elif defined(__SUNPRO_CC)
360 #  if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
361   genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
362 #  else
363 #    define CPP_HAS_TRY_CATCH 1
364 #  endif
365 #else
366   if (e)
367     cerr << e->message << endl;
368   exit(0);
369 #endif
370
371 #ifndef CPP_HAS_TRY_CATCH
372 #define CPP_HAS_TRY_CATCH 0
373 #define NCURSES_CPP_TRY         /* nothing */
374 #define NCURSES_CPP_CATCH(e)    if (false)
375 #define THROWS(s)               /* nothing */
376 #define THROW2(s,t)             /* nothing */
377 #elif CPP_HAS_TRY_CATCH
378   throw *e;
379 #define NCURSES_CPP_TRY         try
380 #define NCURSES_CPP_CATCH(e)    catch(e)
381 #if defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510)
382 // C++17 deprecates the usage of throw().
383 #define THROWS(s)               /* nothing */
384 #define THROW2(s,t)             /* nothing */
385 #else
386 #define THROWS(s)               throw(s)
387 #define THROW2(s,t)             throw(s,t)
388 #endif
389 #endif
390 }
391
392 #endif /* NCURSES_ETIP_H_incl */