jpayne@69: // * This makes emacs happy -*-Mode: C++;-*- jpayne@69: /**************************************************************************** jpayne@69: * Copyright 2018-2021,2022 Thomas E. Dickey * jpayne@69: * Copyright 1998-2012,2017 Free Software Foundation, Inc. * jpayne@69: * * jpayne@69: * Permission is hereby granted, free of charge, to any person obtaining a * jpayne@69: * copy of this software and associated documentation files (the * jpayne@69: * "Software"), to deal in the Software without restriction, including * jpayne@69: * without limitation the rights to use, copy, modify, merge, publish, * jpayne@69: * distribute, distribute with modifications, sublicense, and/or sell * jpayne@69: * copies of the Software, and to permit persons to whom the Software is * jpayne@69: * furnished to do so, subject to the following conditions: * jpayne@69: * * jpayne@69: * The above copyright notice and this permission notice shall be included * jpayne@69: * in all copies or substantial portions of the Software. * jpayne@69: * * jpayne@69: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * jpayne@69: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * jpayne@69: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * jpayne@69: * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * jpayne@69: * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * jpayne@69: * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * jpayne@69: * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * jpayne@69: * * jpayne@69: * Except as contained in this notice, the name(s) of the above copyright * jpayne@69: * holders shall not be used in advertising or otherwise to promote the * jpayne@69: * sale, use or other dealings in this Software without prior written * jpayne@69: * authorization. * jpayne@69: ****************************************************************************/ jpayne@69: jpayne@69: /**************************************************************************** jpayne@69: * Author: Juergen Pfeifer, 1997 * jpayne@69: ****************************************************************************/ jpayne@69: jpayne@69: // $Id: etip.h.in,v 1.50 2022/08/20 20:50:00 tom Exp $ jpayne@69: jpayne@69: #ifndef NCURSES_ETIP_H_incl jpayne@69: #define NCURSES_ETIP_H_incl 1 jpayne@69: jpayne@69: // These are substituted at configure/build time jpayne@69: #ifndef HAVE_BUILTIN_H jpayne@69: #define HAVE_BUILTIN_H 0 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef HAVE_GXX_BUILTIN_H jpayne@69: #define HAVE_GXX_BUILTIN_H 0 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef HAVE_GPP_BUILTIN_H jpayne@69: #define HAVE_GPP_BUILTIN_H 0 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef HAVE_IOSTREAM jpayne@69: #define HAVE_IOSTREAM 1 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef HAVE_TYPEINFO jpayne@69: #define HAVE_TYPEINFO 1 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef HAVE_VALUES_H jpayne@69: #define HAVE_VALUES_H 0 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef ETIP_NEEDS_MATH_H jpayne@69: #define ETIP_NEEDS_MATH_H 0 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef ETIP_NEEDS_MATH_EXCEPTION jpayne@69: #define ETIP_NEEDS_MATH_EXCEPTION 0 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef CPP_HAS_OVERRIDE jpayne@69: #define CPP_HAS_OVERRIDE 0 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef CPP_HAS_PARAM_INIT jpayne@69: #define CPP_HAS_PARAM_INIT 0 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef CPP_HAS_STATIC_CAST jpayne@69: #define CPP_HAS_STATIC_CAST 1 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef IOSTREAM_NAMESPACE jpayne@69: #define IOSTREAM_NAMESPACE 1 jpayne@69: #endif jpayne@69: jpayne@69: #ifdef __GNUG__ jpayne@69: # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8)) jpayne@69: # if HAVE_TYPEINFO jpayne@69: # include jpayne@69: # endif jpayne@69: # endif jpayne@69: #endif jpayne@69: jpayne@69: #if defined(__GNUG__) jpayne@69: # if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H jpayne@69: # if ETIP_NEEDS_MATH_H jpayne@69: # if ETIP_NEEDS_MATH_EXCEPTION jpayne@69: # undef exception jpayne@69: # define exception math_exception jpayne@69: # endif jpayne@69: # include jpayne@69: # endif jpayne@69: # undef exception jpayne@69: # define exception builtin_exception jpayne@69: # if HAVE_GPP_BUILTIN_H jpayne@69: # include jpayne@69: # elif HAVE_GXX_BUILTIN_H jpayne@69: # include jpayne@69: # else jpayne@69: # include jpayne@69: # endif jpayne@69: # undef exception jpayne@69: # endif jpayne@69: #elif defined (__SUNPRO_CC) jpayne@69: # include jpayne@69: #endif jpayne@69: jpayne@69: #include jpayne@69: jpayne@69: extern "C" { jpayne@69: #if HAVE_VALUES_H jpayne@69: # include jpayne@69: #endif jpayne@69: jpayne@69: #include jpayne@69: #include jpayne@69: #include jpayne@69: } jpayne@69: jpayne@69: // Language features jpayne@69: #if CPP_HAS_OVERRIDE jpayne@69: #define NCURSES_OVERRIDE override jpayne@69: #else jpayne@69: #define NCURSES_OVERRIDE /*nothing*/ jpayne@69: #endif jpayne@69: jpayne@69: #if CPP_HAS_PARAM_INIT jpayne@69: #define NCURSES_PARAM_INIT(value) = value jpayne@69: #else jpayne@69: #define NCURSES_PARAM_INIT(value) /*nothing*/ jpayne@69: #endif jpayne@69: jpayne@69: #if CPP_HAS_STATIC_CAST jpayne@69: #define STATIC_CAST(s) static_cast jpayne@69: #else jpayne@69: #define STATIC_CAST(s) (s) jpayne@69: #endif jpayne@69: jpayne@69: #ifndef NCURSES_CXX_IMPEXP jpayne@69: #define NCURSES_CXX_IMPEXP /* nothing */ jpayne@69: #endif jpayne@69: jpayne@69: // Forward Declarations jpayne@69: class NCURSES_CXX_IMPEXP NCursesPanel; jpayne@69: class NCURSES_CXX_IMPEXP NCursesMenu; jpayne@69: class NCURSES_CXX_IMPEXP NCursesForm; jpayne@69: jpayne@69: class NCURSES_CXX_IMPEXP NCursesException jpayne@69: { jpayne@69: public: jpayne@69: const char *message; jpayne@69: int errorno; jpayne@69: jpayne@69: NCursesException (const char* msg, int err) jpayne@69: : message(msg), errorno (err) jpayne@69: {}; jpayne@69: jpayne@69: explicit NCursesException (const char* msg) jpayne@69: : message(msg), errorno (E_SYSTEM_ERROR) jpayne@69: {}; jpayne@69: jpayne@69: NCursesException& operator=(const NCursesException& rhs) jpayne@69: { jpayne@69: message = rhs.message; jpayne@69: errorno = rhs.errorno; jpayne@69: return *this; jpayne@69: } jpayne@69: jpayne@69: NCursesException(const NCursesException& rhs) jpayne@69: : message(rhs.message), errorno(rhs.errorno) jpayne@69: { jpayne@69: } jpayne@69: jpayne@69: virtual const char *classname() const { jpayne@69: return "NCursesWindow"; jpayne@69: } jpayne@69: jpayne@69: virtual ~NCursesException() jpayne@69: { jpayne@69: } jpayne@69: }; jpayne@69: jpayne@69: class NCURSES_CXX_IMPEXP NCursesPanelException : public NCursesException jpayne@69: { jpayne@69: public: jpayne@69: const NCursesPanel* p; jpayne@69: jpayne@69: NCursesPanelException (const char *msg, int err) : jpayne@69: NCursesException (msg, err), jpayne@69: p (0) jpayne@69: {}; jpayne@69: jpayne@69: NCursesPanelException (const NCursesPanel* panel, jpayne@69: const char *msg, jpayne@69: int err) : jpayne@69: NCursesException (msg, err), jpayne@69: p (panel) jpayne@69: {}; jpayne@69: jpayne@69: explicit NCursesPanelException (int err) : jpayne@69: NCursesException ("panel library error", err), jpayne@69: p (0) jpayne@69: {}; jpayne@69: jpayne@69: NCursesPanelException (const NCursesPanel* panel, jpayne@69: int err) : jpayne@69: NCursesException ("panel library error", err), jpayne@69: p (panel) jpayne@69: {}; jpayne@69: jpayne@69: NCursesPanelException& operator=(const NCursesPanelException& rhs) jpayne@69: { jpayne@69: if (this != &rhs) { jpayne@69: NCursesException::operator=(rhs); jpayne@69: p = rhs.p; jpayne@69: } jpayne@69: return *this; jpayne@69: } jpayne@69: jpayne@69: NCursesPanelException(const NCursesPanelException& rhs) jpayne@69: : NCursesException(rhs), p(rhs.p) jpayne@69: { jpayne@69: } jpayne@69: jpayne@69: virtual const char *classname() const NCURSES_OVERRIDE { jpayne@69: return "NCursesPanel"; jpayne@69: } jpayne@69: jpayne@69: virtual ~NCursesPanelException() jpayne@69: { jpayne@69: } jpayne@69: }; jpayne@69: jpayne@69: class NCURSES_CXX_IMPEXP NCursesMenuException : public NCursesException jpayne@69: { jpayne@69: public: jpayne@69: const NCursesMenu* m; jpayne@69: jpayne@69: NCursesMenuException (const char *msg, int err) : jpayne@69: NCursesException (msg, err), jpayne@69: m (0) jpayne@69: {}; jpayne@69: jpayne@69: NCursesMenuException (const NCursesMenu* menu, jpayne@69: const char *msg, jpayne@69: int err) : jpayne@69: NCursesException (msg, err), jpayne@69: m (menu) jpayne@69: {}; jpayne@69: jpayne@69: explicit NCursesMenuException (int err) : jpayne@69: NCursesException ("menu library error", err), jpayne@69: m (0) jpayne@69: {}; jpayne@69: jpayne@69: NCursesMenuException (const NCursesMenu* menu, jpayne@69: int err) : jpayne@69: NCursesException ("menu library error", err), jpayne@69: m (menu) jpayne@69: {}; jpayne@69: jpayne@69: NCursesMenuException& operator=(const NCursesMenuException& rhs) jpayne@69: { jpayne@69: if (this != &rhs) { jpayne@69: NCursesException::operator=(rhs); jpayne@69: m = rhs.m; jpayne@69: } jpayne@69: return *this; jpayne@69: } jpayne@69: jpayne@69: NCursesMenuException(const NCursesMenuException& rhs) jpayne@69: : NCursesException(rhs), m(rhs.m) jpayne@69: { jpayne@69: } jpayne@69: jpayne@69: virtual const char *classname() const NCURSES_OVERRIDE { jpayne@69: return "NCursesMenu"; jpayne@69: } jpayne@69: jpayne@69: virtual ~NCursesMenuException() jpayne@69: { jpayne@69: } jpayne@69: }; jpayne@69: jpayne@69: class NCURSES_CXX_IMPEXP NCursesFormException : public NCursesException jpayne@69: { jpayne@69: public: jpayne@69: const NCursesForm* f; jpayne@69: jpayne@69: NCursesFormException (const char *msg, int err) : jpayne@69: NCursesException (msg, err), jpayne@69: f (0) jpayne@69: {}; jpayne@69: jpayne@69: NCursesFormException (const NCursesForm* form, jpayne@69: const char *msg, jpayne@69: int err) : jpayne@69: NCursesException (msg, err), jpayne@69: f (form) jpayne@69: {}; jpayne@69: jpayne@69: explicit NCursesFormException (int err) : jpayne@69: NCursesException ("form library error", err), jpayne@69: f (0) jpayne@69: {}; jpayne@69: jpayne@69: NCursesFormException (const NCursesForm* form, jpayne@69: int err) : jpayne@69: NCursesException ("form library error", err), jpayne@69: f (form) jpayne@69: {}; jpayne@69: jpayne@69: NCursesFormException& operator=(const NCursesFormException& rhs) jpayne@69: { jpayne@69: if (this != &rhs) { jpayne@69: NCursesException::operator=(rhs); jpayne@69: f = rhs.f; jpayne@69: } jpayne@69: return *this; jpayne@69: } jpayne@69: jpayne@69: NCursesFormException(const NCursesFormException& rhs) jpayne@69: : NCursesException(rhs), f(rhs.f) jpayne@69: { jpayne@69: } jpayne@69: jpayne@69: virtual const char *classname() const NCURSES_OVERRIDE { jpayne@69: return "NCursesForm"; jpayne@69: } jpayne@69: jpayne@69: virtual ~NCursesFormException() jpayne@69: { jpayne@69: } jpayne@69: }; jpayne@69: jpayne@69: #if !((defined(__GNUG__) && defined(__EXCEPTIONS) && (__GNUG__ < 7)) || defined(__SUNPRO_CC)) jpayne@69: # if HAVE_IOSTREAM jpayne@69: # include jpayne@69: # if IOSTREAM_NAMESPACE jpayne@69: using std::cerr; jpayne@69: using std::endl; jpayne@69: # endif jpayne@69: # else jpayne@69: # include jpayne@69: # endif jpayne@69: #endif jpayne@69: jpayne@69: inline void THROW(const NCursesException *e) { jpayne@69: #if defined(__GNUG__) && defined(__EXCEPTIONS) jpayne@69: # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8)) jpayne@69: (*lib_error_handler)(e ? e->classname() : "", e ? e->message : ""); jpayne@69: # elif (__GNUG__ >= 7) jpayne@69: // g++ 7.0 warns about deprecation, but lacks the predefined symbols jpayne@69: ::endwin(); jpayne@69: std::cerr << "Found a problem - goodbye" << std::endl; jpayne@69: exit(EXIT_FAILURE); jpayne@69: # else jpayne@69: # define CPP_HAS_TRY_CATCH 1 jpayne@69: # endif jpayne@69: #elif defined(__SUNPRO_CC) jpayne@69: # if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5) jpayne@69: genericerror(1, ((e != 0) ? (char *)(e->message) : "")); jpayne@69: # else jpayne@69: # define CPP_HAS_TRY_CATCH 1 jpayne@69: # endif jpayne@69: #else jpayne@69: if (e) jpayne@69: cerr << e->message << endl; jpayne@69: exit(0); jpayne@69: #endif jpayne@69: jpayne@69: #ifndef CPP_HAS_TRY_CATCH jpayne@69: #define CPP_HAS_TRY_CATCH 0 jpayne@69: #define NCURSES_CPP_TRY /* nothing */ jpayne@69: #define NCURSES_CPP_CATCH(e) if (false) jpayne@69: #define THROWS(s) /* nothing */ jpayne@69: #define THROW2(s,t) /* nothing */ jpayne@69: #elif CPP_HAS_TRY_CATCH jpayne@69: throw *e; jpayne@69: #define NCURSES_CPP_TRY try jpayne@69: #define NCURSES_CPP_CATCH(e) catch(e) jpayne@69: #if defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510) jpayne@69: // C++17 deprecates the usage of throw(). jpayne@69: #define THROWS(s) /* nothing */ jpayne@69: #define THROW2(s,t) /* nothing */ jpayne@69: #else jpayne@69: #define THROWS(s) throw(s) jpayne@69: #define THROW2(s,t) throw(s,t) jpayne@69: #endif jpayne@69: #endif jpayne@69: } jpayne@69: jpayne@69: #endif /* NCURSES_ETIP_H_incl */