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. *
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.48 2021/06/17 21:11:08 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_PARAM_INIT
74 #define CPP_HAS_PARAM_INIT 0
77 #ifndef CPP_HAS_STATIC_CAST
78 #define CPP_HAS_STATIC_CAST 0 // workaround for g++ 2.95.3
81 #ifndef IOSTREAM_NAMESPACE
82 #define IOSTREAM_NAMESPACE 0
86 # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
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
98 # define exception math_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>
109 # include <builtin.h>
113 #elif defined (__SUNPRO_CC)
114 # include <generic.h>
130 #if CPP_HAS_PARAM_INIT
131 #define NCURSES_PARAM_INIT(value) = value
133 #define NCURSES_PARAM_INIT(value) /*nothing*/
136 #if CPP_HAS_STATIC_CAST
137 #define STATIC_CAST(s) static_cast<s>
139 #define STATIC_CAST(s) (s)
142 #ifndef NCURSES_CXX_IMPEXP
143 #define NCURSES_CXX_IMPEXP /* nothing */
146 // Forward Declarations
147 class NCURSES_CXX_IMPEXP NCursesPanel;
148 class NCURSES_CXX_IMPEXP NCursesMenu;
149 class NCURSES_CXX_IMPEXP NCursesForm;
151 class NCURSES_CXX_IMPEXP NCursesException
157 NCursesException (const char* msg, int err)
158 : message(msg), errorno (err)
161 explicit NCursesException (const char* msg)
162 : message(msg), errorno (E_SYSTEM_ERROR)
165 NCursesException& operator=(const NCursesException& rhs)
167 message = rhs.message;
168 errorno = rhs.errorno;
172 NCursesException(const NCursesException& rhs)
173 : message(rhs.message), errorno(rhs.errorno)
177 virtual const char *classname() const {
178 return "NCursesWindow";
181 virtual ~NCursesException()
186 class NCURSES_CXX_IMPEXP NCursesPanelException : public NCursesException
189 const NCursesPanel* p;
191 NCursesPanelException (const char *msg, int err) :
192 NCursesException (msg, err),
196 NCursesPanelException (const NCursesPanel* panel,
199 NCursesException (msg, err),
203 explicit NCursesPanelException (int err) :
204 NCursesException ("panel library error", err),
208 NCursesPanelException (const NCursesPanel* panel,
210 NCursesException ("panel library error", err),
214 NCursesPanelException& operator=(const NCursesPanelException& rhs)
217 NCursesException::operator=(rhs);
223 NCursesPanelException(const NCursesPanelException& rhs)
224 : NCursesException(rhs), p(rhs.p)
228 virtual const char *classname() const {
229 return "NCursesPanel";
232 virtual ~NCursesPanelException()
237 class NCURSES_CXX_IMPEXP NCursesMenuException : public NCursesException
240 const NCursesMenu* m;
242 NCursesMenuException (const char *msg, int err) :
243 NCursesException (msg, err),
247 NCursesMenuException (const NCursesMenu* menu,
250 NCursesException (msg, err),
254 explicit NCursesMenuException (int err) :
255 NCursesException ("menu library error", err),
259 NCursesMenuException (const NCursesMenu* menu,
261 NCursesException ("menu library error", err),
265 NCursesMenuException& operator=(const NCursesMenuException& rhs)
268 NCursesException::operator=(rhs);
274 NCursesMenuException(const NCursesMenuException& rhs)
275 : NCursesException(rhs), m(rhs.m)
279 virtual const char *classname() const {
280 return "NCursesMenu";
283 virtual ~NCursesMenuException()
288 class NCURSES_CXX_IMPEXP NCursesFormException : public NCursesException
291 const NCursesForm* f;
293 NCursesFormException (const char *msg, int err) :
294 NCursesException (msg, err),
298 NCursesFormException (const NCursesForm* form,
301 NCursesException (msg, err),
305 explicit NCursesFormException (int err) :
306 NCursesException ("form library error", err),
310 NCursesFormException (const NCursesForm* form,
312 NCursesException ("form library error", err),
316 NCursesFormException& operator=(const NCursesFormException& rhs)
319 NCursesException::operator=(rhs);
325 NCursesFormException(const NCursesFormException& rhs)
326 : NCursesException(rhs), f(rhs.f)
330 virtual const char *classname() const {
331 return "NCursesForm";
334 virtual ~NCursesFormException()
339 #if !((defined(__GNUG__) && defined(__EXCEPTIONS) && (__GNUG__ < 7)) || defined(__SUNPRO_CC))
342 # if IOSTREAM_NAMESPACE
347 # include <iostream.h>
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
358 std::cerr << "Found a problem - goodbye" << std::endl;
361 # define CPP_HAS_TRY_CATCH 1
363 #elif defined(__SUNPRO_CC)
364 # if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
365 genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
367 # define CPP_HAS_TRY_CATCH 1
371 cerr << e->message << endl;
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
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 */
390 #define THROWS(s) throw(s)
391 #define THROW2(s,t) throw(s,t)
396 #endif /* NCURSES_ETIP_H_incl */