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