etip.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. // * This makes emacs happy -*-Mode: C++;-*-
  2. /****************************************************************************
  3. * Copyright (c) 1998-2011,2012 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. * Author: Juergen Pfeifer, 1997 *
  31. ****************************************************************************/
  32. // $Id: etip.h.in,v 1.39 2012/12/29 21:50:44 tom Exp $
  33. #ifndef NCURSES_ETIP_H_incl
  34. #define NCURSES_ETIP_H_incl 1
  35. // These are substituted at configure/build time
  36. #ifndef HAVE_BUILTIN_H
  37. #define HAVE_BUILTIN_H 0
  38. #endif
  39. #ifndef HAVE_GXX_BUILTIN_H
  40. #define HAVE_GXX_BUILTIN_H 0
  41. #endif
  42. #ifndef HAVE_GPP_BUILTIN_H
  43. #define HAVE_GPP_BUILTIN_H 0
  44. #endif
  45. #ifndef HAVE_IOSTREAM
  46. #define HAVE_IOSTREAM 1
  47. #endif
  48. #ifndef HAVE_TYPEINFO
  49. #define HAVE_TYPEINFO 1
  50. #endif
  51. #ifndef HAVE_VALUES_H
  52. #define HAVE_VALUES_H 0
  53. #endif
  54. #ifndef ETIP_NEEDS_MATH_H
  55. #define ETIP_NEEDS_MATH_H 0
  56. #endif
  57. #ifndef ETIP_NEEDS_MATH_EXCEPTION
  58. #define ETIP_NEEDS_MATH_EXCEPTION 0
  59. #endif
  60. #ifndef CPP_HAS_PARAM_INIT
  61. #define CPP_HAS_PARAM_INIT 0
  62. #endif
  63. #ifndef CPP_HAS_STATIC_CAST
  64. #define CPP_HAS_STATIC_CAST 1
  65. #endif
  66. #ifndef IOSTREAM_NAMESPACE
  67. #define IOSTREAM_NAMESPACE 1
  68. #endif
  69. #ifdef __GNUG__
  70. # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
  71. # if HAVE_TYPEINFO
  72. # include <typeinfo>
  73. # endif
  74. # endif
  75. #endif
  76. #if defined(__GNUG__)
  77. # if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H
  78. # if ETIP_NEEDS_MATH_H
  79. # if ETIP_NEEDS_MATH_EXCEPTION
  80. # undef exception
  81. # define exception math_exception
  82. # endif
  83. # include <math.h>
  84. # endif
  85. # undef exception
  86. # define exception builtin_exception
  87. # if HAVE_GPP_BUILTIN_H
  88. # include <gpp/builtin.h>
  89. # elif HAVE_GXX_BUILTIN_H
  90. # include <g++/builtin.h>
  91. # else
  92. # include <builtin.h>
  93. # endif
  94. # undef exception
  95. # endif
  96. #elif defined (__SUNPRO_CC)
  97. # include <generic.h>
  98. #endif
  99. #include <ncurses_dll.h>
  100. extern "C" {
  101. #if HAVE_VALUES_H
  102. # include <values.h>
  103. #endif
  104. #include <assert.h>
  105. #include <eti.h>
  106. #include <errno.h>
  107. }
  108. // Language features
  109. #if CPP_HAS_PARAM_INIT
  110. #define NCURSES_PARAM_INIT(value) = value
  111. #else
  112. #define NCURSES_PARAM_INIT(value) /*nothing*/
  113. #endif
  114. #if CPP_HAS_STATIC_CAST
  115. #define STATIC_CAST(s) static_cast<s>
  116. #else
  117. #define STATIC_CAST(s) (s)
  118. #endif
  119. // Forward Declarations
  120. class NCURSES_IMPEXP NCursesPanel;
  121. class NCURSES_IMPEXP NCursesMenu;
  122. class NCURSES_IMPEXP NCursesForm;
  123. class NCURSES_IMPEXP NCursesException
  124. {
  125. public:
  126. const char *message;
  127. int errorno;
  128. NCursesException (const char* msg, int err)
  129. : message(msg), errorno (err)
  130. {};
  131. NCursesException (const char* msg)
  132. : message(msg), errorno (E_SYSTEM_ERROR)
  133. {};
  134. NCursesException& operator=(const NCursesException& rhs)
  135. {
  136. errorno = rhs.errorno;
  137. return *this;
  138. }
  139. NCursesException(const NCursesException& rhs)
  140. : message(rhs.message), errorno(rhs.errorno)
  141. {
  142. }
  143. virtual const char *classname() const {
  144. return "NCursesWindow";
  145. }
  146. virtual ~NCursesException()
  147. {
  148. }
  149. };
  150. class NCURSES_IMPEXP NCursesPanelException : public NCursesException
  151. {
  152. public:
  153. const NCursesPanel* p;
  154. NCursesPanelException (const char *msg, int err) :
  155. NCursesException (msg, err),
  156. p (0)
  157. {};
  158. NCursesPanelException (const NCursesPanel* panel,
  159. const char *msg,
  160. int err) :
  161. NCursesException (msg, err),
  162. p (panel)
  163. {};
  164. NCursesPanelException (int err) :
  165. NCursesException ("panel library error", err),
  166. p (0)
  167. {};
  168. NCursesPanelException (const NCursesPanel* panel,
  169. int err) :
  170. NCursesException ("panel library error", err),
  171. p (panel)
  172. {};
  173. NCursesPanelException& operator=(const NCursesPanelException& rhs)
  174. {
  175. if (this != &rhs) {
  176. NCursesException::operator=(rhs);
  177. p = rhs.p;
  178. }
  179. return *this;
  180. }
  181. NCursesPanelException(const NCursesPanelException& rhs)
  182. : NCursesException(rhs), p(rhs.p)
  183. {
  184. }
  185. virtual const char *classname() const {
  186. return "NCursesPanel";
  187. }
  188. virtual ~NCursesPanelException()
  189. {
  190. }
  191. };
  192. class NCURSES_IMPEXP NCursesMenuException : public NCursesException
  193. {
  194. public:
  195. const NCursesMenu* m;
  196. NCursesMenuException (const char *msg, int err) :
  197. NCursesException (msg, err),
  198. m (0)
  199. {};
  200. NCursesMenuException (const NCursesMenu* menu,
  201. const char *msg,
  202. int err) :
  203. NCursesException (msg, err),
  204. m (menu)
  205. {};
  206. NCursesMenuException (int err) :
  207. NCursesException ("menu library error", err),
  208. m (0)
  209. {};
  210. NCursesMenuException (const NCursesMenu* menu,
  211. int err) :
  212. NCursesException ("menu library error", err),
  213. m (menu)
  214. {};
  215. NCursesMenuException& operator=(const NCursesMenuException& rhs)
  216. {
  217. if (this != &rhs) {
  218. NCursesException::operator=(rhs);
  219. m = rhs.m;
  220. }
  221. return *this;
  222. }
  223. NCursesMenuException(const NCursesMenuException& rhs)
  224. : NCursesException(rhs), m(rhs.m)
  225. {
  226. }
  227. virtual const char *classname() const {
  228. return "NCursesMenu";
  229. }
  230. virtual ~NCursesMenuException()
  231. {
  232. }
  233. };
  234. class NCURSES_IMPEXP NCursesFormException : public NCursesException
  235. {
  236. public:
  237. const NCursesForm* f;
  238. NCursesFormException (const char *msg, int err) :
  239. NCursesException (msg, err),
  240. f (0)
  241. {};
  242. NCursesFormException (const NCursesForm* form,
  243. const char *msg,
  244. int err) :
  245. NCursesException (msg, err),
  246. f (form)
  247. {};
  248. NCursesFormException (int err) :
  249. NCursesException ("form library error", err),
  250. f (0)
  251. {};
  252. NCursesFormException (const NCursesForm* form,
  253. int err) :
  254. NCursesException ("form library error", err),
  255. f (form)
  256. {};
  257. NCursesFormException& operator=(const NCursesFormException& rhs)
  258. {
  259. if (this != &rhs) {
  260. NCursesException::operator=(rhs);
  261. f = rhs.f;
  262. }
  263. return *this;
  264. }
  265. NCursesFormException(const NCursesFormException& rhs)
  266. : NCursesException(rhs), f(rhs.f)
  267. {
  268. }
  269. virtual const char *classname() const {
  270. return "NCursesForm";
  271. }
  272. virtual ~NCursesFormException()
  273. {
  274. }
  275. };
  276. #if !((defined(__GNUG__) && defined(__EXCEPTIONS)) || defined(__SUNPRO_CC))
  277. # if HAVE_IOSTREAM
  278. # include <iostream>
  279. # if IOSTREAM_NAMESPACE
  280. using std::cerr;
  281. using std::endl;
  282. # endif
  283. # else
  284. # include <iostream.h>
  285. # endif
  286. extern "C" void exit(int);
  287. #endif
  288. inline void THROW(const NCursesException *e) {
  289. #if defined(__GNUG__) && defined(__EXCEPTIONS)
  290. # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
  291. (*lib_error_handler)(e ? e->classname() : "", e ? e->message : "");
  292. #else
  293. #define CPP_HAS_TRY_CATCH 1
  294. #endif
  295. #elif defined(__SUNPRO_CC)
  296. # if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
  297. genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
  298. #else
  299. #define CPP_HAS_TRY_CATCH 1
  300. #endif
  301. #else
  302. if (e)
  303. cerr << e->message << endl;
  304. exit(0);
  305. #endif
  306. #ifndef CPP_HAS_TRY_CATCH
  307. #define CPP_HAS_TRY_CATCH 0
  308. #define NCURSES_CPP_TRY /* nothing */
  309. #define NCURSES_CPP_CATCH(e) if (false)
  310. #define THROWS(s) /* nothing */
  311. #define THROW2(s,t) /* nothing */
  312. #elif CPP_HAS_TRY_CATCH
  313. throw *e;
  314. #define NCURSES_CPP_TRY try
  315. #define NCURSES_CPP_CATCH(e) catch(e)
  316. #define THROWS(s) throw(s)
  317. #define THROW2(s,t) throw(s,t)
  318. #endif
  319. }
  320. #endif /* NCURSES_ETIP_H_incl */