Home | History | Annotate | Download | only in include
      1 // * This makes emacs happy -*-Mode: C++;-*-
      2 /****************************************************************************
      3  * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
      4  *                                                                          *
      5  * Permission is hereby granted, free of charge, to any person obtaining a  *
      6  * copy of this software and associated documentation files (the            *
      7  * "Software"), to deal in the Software without restriction, including      *
      8  * without limitation the rights to use, copy, modify, merge, publish,      *
      9  * distribute, distribute with modifications, sublicense, and/or sell       *
     10  * copies of the Software, and to permit persons to whom the Software is    *
     11  * furnished to do so, subject to the following conditions:                 *
     12  *                                                                          *
     13  * The above copyright notice and this permission notice shall be included  *
     14  * in all copies or substantial portions of the Software.                   *
     15  *                                                                          *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
     17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
     19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
     20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
     21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
     22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
     23  *                                                                          *
     24  * Except as contained in this notice, the name(s) of the above copyright   *
     25  * holders shall not be used in advertising or otherwise to promote the     *
     26  * sale, use or other dealings in this Software without prior written       *
     27  * authorization.                                                           *
     28  ****************************************************************************/
     29 
     30 /****************************************************************************
     31  *   Author: Juergen Pfeifer, 1997                                          *
     32  ****************************************************************************/
     33 
     34 // $Id: etip.h.in,v 1.37 2008/08/30 19:27:32 tom Exp $
     35 
     36 #ifndef NCURSES_ETIP_H_incl
     37 #define NCURSES_ETIP_H_incl 1
     38 
     39 // These are substituted at configure/build time
     40 #ifndef HAVE_BUILTIN_H
     41 #define HAVE_BUILTIN_H 0
     42 #endif
     43 
     44 #ifndef HAVE_GXX_BUILTIN_H
     45 #define HAVE_GXX_BUILTIN_H 0
     46 #endif
     47 
     48 #ifndef HAVE_GPP_BUILTIN_H
     49 #define HAVE_GPP_BUILTIN_H 0
     50 #endif
     51 
     52 #ifndef HAVE_IOSTREAM
     53 #define HAVE_IOSTREAM 1
     54 #endif
     55 
     56 #ifndef HAVE_TYPEINFO
     57 #define HAVE_TYPEINFO 1
     58 #endif
     59 
     60 #ifndef HAVE_VALUES_H
     61 #define HAVE_VALUES_H 0
     62 #endif
     63 
     64 #ifndef ETIP_NEEDS_MATH_H
     65 #define ETIP_NEEDS_MATH_H 0
     66 #endif
     67 
     68 #ifndef ETIP_NEEDS_MATH_EXCEPTION
     69 #define ETIP_NEEDS_MATH_EXCEPTION 0
     70 #endif
     71 
     72 #ifndef CPP_HAS_PARAM_INIT
     73 #define CPP_HAS_PARAM_INIT 0
     74 #endif
     75 
     76 #ifndef CPP_HAS_STATIC_CAST
     77 #define CPP_HAS_STATIC_CAST 1
     78 #endif
     79 
     80 #ifndef IOSTREAM_NAMESPACE
     81 #define IOSTREAM_NAMESPACE 1
     82 #endif
     83 
     84 #ifdef __GNUG__
     85 #  if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
     86 #    if HAVE_TYPEINFO
     87 #      include <typeinfo>
     88 #    endif
     89 #  endif
     90 #endif
     91 
     92 #if defined(__GNUG__)
     93 #  if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H
     94 #    if ETIP_NEEDS_MATH_H
     95 #      if ETIP_NEEDS_MATH_EXCEPTION
     96 #        undef exception
     97 #        define exception math_exception
     98 #      endif
     99 #      include <math.h>
    100 #    endif
    101 #    undef exception
    102 #    define exception builtin_exception
    103 #    if HAVE_GPP_BUILTIN_H
    104 #     include <gpp/builtin.h>
    105 #    elif HAVE_GXX_BUILTIN_H
    106 #     include <g++/builtin.h>
    107 #    else
    108 #     include <builtin.h>
    109 #    endif
    110 #    undef exception
    111 #  endif
    112 #elif defined (__SUNPRO_CC)
    113 #  include <generic.h>
    114 #endif
    115 
    116 #include <ncurses_dll.h>
    117 
    118 extern "C" {
    119 #if HAVE_VALUES_H
    120 #  include <values.h>
    121 #endif
    122 
    123 #include <assert.h>
    124 #include <eti.h>
    125 #include <errno.h>
    126 }
    127 
    128 // Language features
    129 #if CPP_HAS_PARAM_INIT
    130 #define NCURSES_PARAM_INIT(value) = value
    131 #else
    132 #define NCURSES_PARAM_INIT(value) /*nothing*/
    133 #endif
    134 
    135 #if CPP_HAS_STATIC_CAST
    136 #define STATIC_CAST(s) static_cast<s>
    137 #else
    138 #define STATIC_CAST(s) (s)
    139 #endif
    140 
    141 // Forward Declarations
    142 class NCURSES_IMPEXP NCursesPanel;
    143 class NCURSES_IMPEXP NCursesMenu;
    144 class NCURSES_IMPEXP NCursesForm;
    145 
    146 class NCURSES_IMPEXP NCursesException
    147 {
    148 public:
    149   const char *message;
    150   int errorno;
    151 
    152   NCursesException (const char* msg, int err)
    153     : message(msg), errorno (err)
    154     {};
    155 
    156   NCursesException (const char* msg)
    157     : message(msg), errorno (E_SYSTEM_ERROR)
    158     {};
    159 
    160   NCursesException& operator=(const NCursesException& rhs)
    161   {
    162     errorno = rhs.errorno;
    163     return *this;
    164   }
    165 
    166   NCursesException(const NCursesException& rhs)
    167     : message(rhs.message), errorno(rhs.errorno)
    168   {
    169   }
    170 
    171   virtual const char *classname() const {
    172     return "NCursesWindow";
    173   }
    174 
    175   virtual ~NCursesException()
    176   {
    177   }
    178 };
    179 
    180 class NCURSES_IMPEXP NCursesPanelException : public NCursesException
    181 {
    182 public:
    183   const NCursesPanel* p;
    184 
    185   NCursesPanelException (const char *msg, int err) :
    186     NCursesException (msg, err),
    187     p (NULL)
    188     {};
    189 
    190   NCursesPanelException (const NCursesPanel* panel,
    191 			 const char *msg,
    192 			 int err) :
    193     NCursesException (msg, err),
    194     p (panel)
    195     {};
    196 
    197   NCursesPanelException (int err) :
    198     NCursesException ("panel library error", err),
    199     p (NULL)
    200     {};
    201 
    202   NCursesPanelException (const NCursesPanel* panel,
    203 			 int err) :
    204     NCursesException ("panel library error", err),
    205     p (panel)
    206     {};
    207 
    208   NCursesPanelException& operator=(const NCursesPanelException& rhs)
    209   {
    210     if (this != &rhs) {
    211       NCursesException::operator=(rhs);
    212       p = rhs.p;
    213     }
    214     return *this;
    215   }
    216 
    217   NCursesPanelException(const NCursesPanelException& rhs)
    218     : NCursesException(rhs), p(rhs.p)
    219   {
    220   }
    221 
    222   virtual const char *classname() const {
    223     return "NCursesPanel";
    224   }
    225 
    226   virtual ~NCursesPanelException()
    227   {
    228   }
    229 };
    230 
    231 class NCURSES_IMPEXP NCursesMenuException : public NCursesException
    232 {
    233 public:
    234   const NCursesMenu* m;
    235 
    236   NCursesMenuException (const char *msg, int err) :
    237     NCursesException (msg, err),
    238     m (NULL)
    239     {};
    240 
    241   NCursesMenuException (const NCursesMenu* menu,
    242 			const char *msg,
    243 			int err) :
    244     NCursesException (msg, err),
    245     m (menu)
    246     {};
    247 
    248   NCursesMenuException (int err) :
    249     NCursesException ("menu library error", err),
    250     m (NULL)
    251     {};
    252 
    253   NCursesMenuException (const NCursesMenu* menu,
    254 			int err) :
    255     NCursesException ("menu library error", err),
    256     m (menu)
    257     {};
    258 
    259   NCursesMenuException& operator=(const NCursesMenuException& rhs)
    260   {
    261     if (this != &rhs) {
    262       NCursesException::operator=(rhs);
    263       m = rhs.m;
    264     }
    265     return *this;
    266   }
    267 
    268   NCursesMenuException(const NCursesMenuException& rhs)
    269     : NCursesException(rhs), m(rhs.m)
    270   {
    271   }
    272 
    273   virtual const char *classname() const {
    274     return "NCursesMenu";
    275   }
    276 
    277   virtual ~NCursesMenuException()
    278   {
    279   }
    280 };
    281 
    282 class NCURSES_IMPEXP NCursesFormException : public NCursesException
    283 {
    284 public:
    285   const NCursesForm* f;
    286 
    287   NCursesFormException (const char *msg, int err) :
    288     NCursesException (msg, err),
    289     f (NULL)
    290     {};
    291 
    292   NCursesFormException (const NCursesForm* form,
    293 			const char *msg,
    294 			int err) :
    295     NCursesException (msg, err),
    296     f (form)
    297     {};
    298 
    299   NCursesFormException (int err) :
    300     NCursesException ("form library error", err),
    301     f (NULL)
    302     {};
    303 
    304   NCursesFormException (const NCursesForm* form,
    305 			int err) :
    306     NCursesException ("form library error", err),
    307     f (form)
    308     {};
    309 
    310   NCursesFormException& operator=(const NCursesFormException& rhs)
    311   {
    312     if (this != &rhs) {
    313       NCursesException::operator=(rhs);
    314       f = rhs.f;
    315     }
    316     return *this;
    317   }
    318 
    319   NCursesFormException(const NCursesFormException& rhs)
    320     : NCursesException(rhs), f(rhs.f)
    321   {
    322   }
    323 
    324   virtual const char *classname() const {
    325     return "NCursesForm";
    326   }
    327 
    328   virtual ~NCursesFormException()
    329   {
    330   }
    331 };
    332 
    333 #if !((defined(__GNUG__) && defined(__EXCEPTIONS)) || defined(__SUNPRO_CC))
    334 #  if HAVE_IOSTREAM
    335 #     include <iostream>
    336 #     if IOSTREAM_NAMESPACE
    337 using std::cerr;
    338 using std::endl;
    339 #     endif
    340 #  else
    341 #     include <iostream.h>
    342 #  endif
    343    extern "C" void exit(int);
    344 #endif
    345 
    346 inline void THROW(const NCursesException *e) {
    347 #if defined(__GNUG__) && defined(__EXCEPTIONS)
    348 #  if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
    349       (*lib_error_handler)(e ? e->classname() : "", e ? e->message : "");
    350 #else
    351 #define CPP_HAS_TRY_CATCH 1
    352 #endif
    353 #elif defined(__SUNPRO_CC)
    354 #  if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
    355   genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
    356 #else
    357 #define CPP_HAS_TRY_CATCH 1
    358 #endif
    359 #else
    360   if (e)
    361     cerr << e->message << endl;
    362   exit(0);
    363 #endif
    364 
    365 #ifndef CPP_HAS_TRY_CATCH
    366 #define CPP_HAS_TRY_CATCH 0
    367 #define NCURSES_CPP_TRY		/* nothing */
    368 #define NCURSES_CPP_CATCH(e)	if (false)
    369 #define THROWS(s)		/* nothing */
    370 #elif CPP_HAS_TRY_CATCH
    371   throw *e;
    372 #define NCURSES_CPP_TRY		try
    373 #define NCURSES_CPP_CATCH(e)	catch(e)
    374 #define THROWS(s)		throw(s)
    375 #endif
    376 }
    377 
    378 #endif /* NCURSES_ETIP_H_incl */
    379