• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// * This makes emacs happy -*-Mode: C++;-*-
2/****************************************************************************
3 * Copyright 2018-2021,2022 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.50 2022/08/20 20:50:00 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_OVERRIDE
74#define CPP_HAS_OVERRIDE 0
75#endif
76
77#ifndef CPP_HAS_PARAM_INIT
78#define CPP_HAS_PARAM_INIT 0
79#endif
80
81#ifndef CPP_HAS_STATIC_CAST
82#define CPP_HAS_STATIC_CAST 0	// workaround for g++ 2.95.3
83#endif
84
85#ifndef IOSTREAM_NAMESPACE
86#define IOSTREAM_NAMESPACE 0
87#endif
88
89#ifdef __GNUG__
90#  if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
91#    if HAVE_TYPEINFO
92#      include <typeinfo>
93#    endif
94#  endif
95#endif
96
97#if defined(__GNUG__)
98#  if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H
99#    if ETIP_NEEDS_MATH_H
100#      if ETIP_NEEDS_MATH_EXCEPTION
101#        undef exception
102#        define exception math_exception
103#      endif
104#      include <math.h>
105#    endif
106#    undef exception
107#    define exception builtin_exception
108#    if HAVE_GPP_BUILTIN_H
109#     include <gpp/builtin.h>
110#    elif HAVE_GXX_BUILTIN_H
111#     include <g++/builtin.h>
112#    else
113#     include <builtin.h>
114#    endif
115#    undef exception
116#  endif
117#elif defined (__SUNPRO_CC)
118#  include <generic.h>
119#endif
120
121#include <curses.h>
122
123extern "C" {
124#if HAVE_VALUES_H
125#  include <values.h>
126#endif
127
128#include <assert.h>
129#include <eti.h>
130#include <errno.h>
131}
132
133// Language features
134#if CPP_HAS_OVERRIDE
135#define NCURSES_OVERRIDE override
136#else
137#define NCURSES_OVERRIDE /*nothing*/
138#endif
139
140#if CPP_HAS_PARAM_INIT
141#define NCURSES_PARAM_INIT(value) = value
142#else
143#define NCURSES_PARAM_INIT(value) /*nothing*/
144#endif
145
146#if CPP_HAS_STATIC_CAST
147#define STATIC_CAST(s) static_cast<s>
148#else
149#define STATIC_CAST(s) (s)
150#endif
151
152#ifndef NCURSES_CXX_IMPEXP
153#define NCURSES_CXX_IMPEXP  /* nothing */
154#endif
155
156// Forward Declarations
157class NCURSES_CXX_IMPEXP NCursesPanel;
158class NCURSES_CXX_IMPEXP NCursesMenu;
159class NCURSES_CXX_IMPEXP NCursesForm;
160
161class NCURSES_CXX_IMPEXP NCursesException
162{
163public:
164  const char *message;
165  int errorno;
166
167  NCursesException (const char* msg, int err)
168    : message(msg), errorno (err)
169    {};
170
171  explicit NCursesException (const char* msg)
172    : message(msg), errorno (E_SYSTEM_ERROR)
173    {};
174
175  NCursesException& operator=(const NCursesException& rhs)
176  {
177    message = rhs.message;
178    errorno = rhs.errorno;
179    return *this;
180  }
181
182  NCursesException(const NCursesException& rhs)
183    : message(rhs.message), errorno(rhs.errorno)
184  {
185  }
186
187  virtual const char *classname() const {
188    return "NCursesWindow";
189  }
190
191  virtual ~NCursesException()
192  {
193  }
194};
195
196class NCURSES_CXX_IMPEXP NCursesPanelException : public NCursesException
197{
198public:
199  const NCursesPanel* p;
200
201  NCursesPanelException (const char *msg, int err) :
202    NCursesException (msg, err),
203    p (0)
204    {};
205
206  NCursesPanelException (const NCursesPanel* panel,
207			 const char *msg,
208			 int err) :
209    NCursesException (msg, err),
210    p (panel)
211    {};
212
213  explicit NCursesPanelException (int err) :
214    NCursesException ("panel library error", err),
215    p (0)
216    {};
217
218  NCursesPanelException (const NCursesPanel* panel,
219			 int err) :
220    NCursesException ("panel library error", err),
221    p (panel)
222    {};
223
224  NCursesPanelException& operator=(const NCursesPanelException& rhs)
225  {
226    if (this != &rhs) {
227      NCursesException::operator=(rhs);
228      p = rhs.p;
229    }
230    return *this;
231  }
232
233  NCursesPanelException(const NCursesPanelException& rhs)
234    : NCursesException(rhs), p(rhs.p)
235  {
236  }
237
238  virtual const char *classname() const NCURSES_OVERRIDE {
239    return "NCursesPanel";
240  }
241
242  virtual ~NCursesPanelException()
243  {
244  }
245};
246
247class NCURSES_CXX_IMPEXP NCursesMenuException : public NCursesException
248{
249public:
250  const NCursesMenu* m;
251
252  NCursesMenuException (const char *msg, int err) :
253    NCursesException (msg, err),
254    m (0)
255    {};
256
257  NCursesMenuException (const NCursesMenu* menu,
258			const char *msg,
259			int err) :
260    NCursesException (msg, err),
261    m (menu)
262    {};
263
264  explicit NCursesMenuException (int err) :
265    NCursesException ("menu library error", err),
266    m (0)
267    {};
268
269  NCursesMenuException (const NCursesMenu* menu,
270			int err) :
271    NCursesException ("menu library error", err),
272    m (menu)
273    {};
274
275  NCursesMenuException& operator=(const NCursesMenuException& rhs)
276  {
277    if (this != &rhs) {
278      NCursesException::operator=(rhs);
279      m = rhs.m;
280    }
281    return *this;
282  }
283
284  NCursesMenuException(const NCursesMenuException& rhs)
285    : NCursesException(rhs), m(rhs.m)
286  {
287  }
288
289  virtual const char *classname() const NCURSES_OVERRIDE {
290    return "NCursesMenu";
291  }
292
293  virtual ~NCursesMenuException()
294  {
295  }
296};
297
298class NCURSES_CXX_IMPEXP NCursesFormException : public NCursesException
299{
300public:
301  const NCursesForm* f;
302
303  NCursesFormException (const char *msg, int err) :
304    NCursesException (msg, err),
305    f (0)
306    {};
307
308  NCursesFormException (const NCursesForm* form,
309			const char *msg,
310			int err) :
311    NCursesException (msg, err),
312    f (form)
313    {};
314
315  explicit NCursesFormException (int err) :
316    NCursesException ("form library error", err),
317    f (0)
318    {};
319
320  NCursesFormException (const NCursesForm* form,
321			int err) :
322    NCursesException ("form library error", err),
323    f (form)
324    {};
325
326  NCursesFormException& operator=(const NCursesFormException& rhs)
327  {
328    if (this != &rhs) {
329      NCursesException::operator=(rhs);
330      f = rhs.f;
331    }
332    return *this;
333  }
334
335  NCursesFormException(const NCursesFormException& rhs)
336    : NCursesException(rhs), f(rhs.f)
337  {
338  }
339
340  virtual const char *classname() const NCURSES_OVERRIDE {
341    return "NCursesForm";
342  }
343
344  virtual ~NCursesFormException()
345  {
346  }
347};
348
349#if !((defined(__GNUG__) && defined(__EXCEPTIONS) && (__GNUG__ < 7)) || defined(__SUNPRO_CC))
350#  if HAVE_IOSTREAM
351#     include <iostream>
352#     if IOSTREAM_NAMESPACE
353using std::cerr;
354using std::endl;
355#     endif
356#  else
357#     include <iostream.h>
358#  endif
359#endif
360
361inline void THROW(const NCursesException *e) {
362#if defined(__GNUG__) && defined(__EXCEPTIONS)
363#  if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
364      (*lib_error_handler)(e ? e->classname() : "", e ? e->message : "");
365#  elif (__GNUG__ >= 7)
366     // g++ 7.0 warns about deprecation, but lacks the predefined symbols
367      ::endwin();
368      std::cerr << "Found a problem - goodbye" << std::endl;
369      exit(EXIT_FAILURE);
370#  else
371#    define CPP_HAS_TRY_CATCH 1
372#  endif
373#elif defined(__SUNPRO_CC)
374#  if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
375  genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
376#  else
377#    define CPP_HAS_TRY_CATCH 1
378#  endif
379#else
380  if (e)
381    cerr << e->message << endl;
382  exit(0);
383#endif
384
385#ifndef CPP_HAS_TRY_CATCH
386#define CPP_HAS_TRY_CATCH 0
387#define NCURSES_CPP_TRY		/* nothing */
388#define NCURSES_CPP_CATCH(e)	if (false)
389#define THROWS(s)		/* nothing */
390#define THROW2(s,t)		/* nothing */
391#elif CPP_HAS_TRY_CATCH
392  throw *e;
393#define NCURSES_CPP_TRY		try
394#define NCURSES_CPP_CATCH(e)	catch(e)
395#if defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510)
396// C++17 deprecates the usage of throw().
397#define THROWS(s)		/* nothing */
398#define THROW2(s,t)		/* nothing */
399#else
400#define THROWS(s)		throw(s)
401#define THROW2(s,t)		throw(s,t)
402#endif
403#endif
404}
405
406#endif /* NCURSES_ETIP_H_incl */
407