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. *
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: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
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. *
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 *
29 ****************************************************************************/
31 /****************************************************************************
32 * Author: Juergen Pfeifer, 1997 *
33 ****************************************************************************/
35 // $Id: etip.h.in,v 1.50 2022/08/20 20:50:00 tom Exp $
37 #ifndef NCURSES_ETIP_H_incl
38 #define NCURSES_ETIP_H_incl 1
40 // These are substituted at configure/build time
41 #ifndef HAVE_BUILTIN_H
42 #define HAVE_BUILTIN_H 0
45 #ifndef HAVE_GXX_BUILTIN_H
46 #define HAVE_GXX_BUILTIN_H 0
49 #ifndef HAVE_GPP_BUILTIN_H
50 #define HAVE_GPP_BUILTIN_H 0
54 #define HAVE_IOSTREAM 0
58 #define HAVE_TYPEINFO 0
62 #define HAVE_VALUES_H 0
65 #ifndef ETIP_NEEDS_MATH_H
66 #define ETIP_NEEDS_MATH_H 0
69 #ifndef ETIP_NEEDS_MATH_EXCEPTION
70 #define ETIP_NEEDS_MATH_EXCEPTION 0
73 #ifndef CPP_HAS_OVERRIDE
74 #define CPP_HAS_OVERRIDE 0
77 #ifndef CPP_HAS_PARAM_INIT
78 #define CPP_HAS_PARAM_INIT 0
81 #ifndef CPP_HAS_STATIC_CAST
82 #define CPP_HAS_STATIC_CAST 0 // workaround for g++ 2.95.3
85 #ifndef IOSTREAM_NAMESPACE
86 #define IOSTREAM_NAMESPACE 0
90 # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
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
102 # define exception math_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>
113 # include <builtin.h>
117 #elif defined (__SUNPRO_CC)
118 # include <generic.h>
135 #define NCURSES_OVERRIDE override
137 #define NCURSES_OVERRIDE /*nothing*/
140 #if CPP_HAS_PARAM_INIT
141 #define NCURSES_PARAM_INIT(value) = value
143 #define NCURSES_PARAM_INIT(value) /*nothing*/
146 #if CPP_HAS_STATIC_CAST
147 #define STATIC_CAST(s) static_cast<s>
149 #define STATIC_CAST(s) (s)
152 #ifndef NCURSES_CXX_IMPEXP
153 #define NCURSES_CXX_IMPEXP /* nothing */
156 // Forward Declarations
157 class NCURSES_CXX_IMPEXP NCursesPanel;
158 class NCURSES_CXX_IMPEXP NCursesMenu;
159 class NCURSES_CXX_IMPEXP NCursesForm;
161 class NCURSES_CXX_IMPEXP NCursesException
167 NCursesException (const char* msg, int err)
168 : message(msg), errorno (err)
171 explicit NCursesException (const char* msg)
172 : message(msg), errorno (E_SYSTEM_ERROR)
175 NCursesException& operator=(const NCursesException& rhs)
177 message = rhs.message;
178 errorno = rhs.errorno;
182 NCursesException(const NCursesException& rhs)
183 : message(rhs.message), errorno(rhs.errorno)
187 virtual const char *classname() const {
188 return "NCursesWindow";
191 virtual ~NCursesException()
196 class NCURSES_CXX_IMPEXP NCursesPanelException : public NCursesException
199 const NCursesPanel* p;
201 NCursesPanelException (const char *msg, int err) :
202 NCursesException (msg, err),
206 NCursesPanelException (const NCursesPanel* panel,
209 NCursesException (msg, err),
213 explicit NCursesPanelException (int err) :
214 NCursesException ("panel library error", err),
218 NCursesPanelException (const NCursesPanel* panel,
220 NCursesException ("panel library error", err),
224 NCursesPanelException& operator=(const NCursesPanelException& rhs)
227 NCursesException::operator=(rhs);
233 NCursesPanelException(const NCursesPanelException& rhs)
234 : NCursesException(rhs), p(rhs.p)
238 virtual const char *classname() const NCURSES_OVERRIDE {
239 return "NCursesPanel";
242 virtual ~NCursesPanelException()
247 class NCURSES_CXX_IMPEXP NCursesMenuException : public NCursesException
250 const NCursesMenu* m;
252 NCursesMenuException (const char *msg, int err) :
253 NCursesException (msg, err),
257 NCursesMenuException (const NCursesMenu* menu,
260 NCursesException (msg, err),
264 explicit NCursesMenuException (int err) :
265 NCursesException ("menu library error", err),
269 NCursesMenuException (const NCursesMenu* menu,
271 NCursesException ("menu library error", err),
275 NCursesMenuException& operator=(const NCursesMenuException& rhs)
278 NCursesException::operator=(rhs);
284 NCursesMenuException(const NCursesMenuException& rhs)
285 : NCursesException(rhs), m(rhs.m)
289 virtual const char *classname() const NCURSES_OVERRIDE {
290 return "NCursesMenu";
293 virtual ~NCursesMenuException()
298 class NCURSES_CXX_IMPEXP NCursesFormException : public NCursesException
301 const NCursesForm* f;
303 NCursesFormException (const char *msg, int err) :
304 NCursesException (msg, err),
308 NCursesFormException (const NCursesForm* form,
311 NCursesException (msg, err),
315 explicit NCursesFormException (int err) :
316 NCursesException ("form library error", err),
320 NCursesFormException (const NCursesForm* form,
322 NCursesException ("form library error", err),
326 NCursesFormException& operator=(const NCursesFormException& rhs)
329 NCursesException::operator=(rhs);
335 NCursesFormException(const NCursesFormException& rhs)
336 : NCursesException(rhs), f(rhs.f)
340 virtual const char *classname() const NCURSES_OVERRIDE {
341 return "NCursesForm";
344 virtual ~NCursesFormException()
349 #if !((defined(__GNUG__) && defined(__EXCEPTIONS) && (__GNUG__ < 7)) || defined(__SUNPRO_CC))
352 # if IOSTREAM_NAMESPACE
357 # include <iostream.h>
361 inline 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
368 std::cerr << "Found a problem - goodbye" << std::endl;
371 # define CPP_HAS_TRY_CATCH 1
373 #elif defined(__SUNPRO_CC)
374 # if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
375 genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
377 # define CPP_HAS_TRY_CATCH 1
381 cerr << e->message << endl;
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
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 */
400 #define THROWS(s) throw(s)
401 #define THROW2(s,t) throw(s,t)
406 #endif /* NCURSES_ETIP_H_incl */