Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1057 lines
28 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. /*
  9. *
  10. * Copyright (c) 1998-9
  11. * Dr John Maddock
  12. *
  13. * Permission to use, copy, modify, distribute and sell this software
  14. * and its documentation for any purpose is hereby granted without fee,
  15. * provided that the above copyright notice appear in all copies and
  16. * that both that copyright notice and this permission notice appear
  17. * in supporting documentation. Dr John Maddock makes no representations
  18. * about the suitability of this software for any purpose.
  19. * It is provided "as is" without express or implied warranty.
  20. *
  21. */
  22. /*
  23. * FILE jm_cfg.h
  24. * VERSION 2.12
  25. */
  26. #ifndef JM_CFG_H
  27. #define JM_CFG_H
  28. /************************************************************************
  29. The purpose of this header is to provide compiler and STL configuration
  30. options. Options fall into three categaries (namespaces, compiler and STL),
  31. throughout, the defaults assume that the compiler and STL are fully C++ standard
  32. compliant, features that are not supported on your system may be selectively
  33. turned off by defining the appropriate macros. Borland C++, Borland C++ Builder,
  34. and Microsoft Visual C++ should be auto-recognised and configured. The HP aCC and
  35. SunPro C++ compiler should also be supported - but run configure for best results.
  36. The SGI, HP, Microsoft and Rogue Wave STL's should be auto-recognised and configured.
  37. Do not change this file unless you really really have to, add options to
  38. <jm_opt.h> instead. See <jm_opt.h> for a full list of macros and their usage.
  39. ************************************************************************/
  40. #include <jm/jm_opt.h>
  41. #include <stdlib.h>
  42. #include <stddef.h>
  43. /* this will increase in future versions: */
  44. #define JM_VERSION 212
  45. #ifndef JM_AUTO_CONFIGURE
  46. #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
  47. #define JM_PLATFORM_W32
  48. #endif
  49. #ifdef __BORLANDC__
  50. #if __BORLANDC__ < 0x500
  51. #define JM_NO_NAMESPACES
  52. #define JM_NO_BOOL
  53. #define JM_NO_MUTABLE
  54. #endif
  55. #if __BORLANDC__ < 0x520
  56. #define JM_NO_WCSTRING
  57. #define JM_NO_INT64
  58. // Early versions of Borlands namespace code can't cope with iterators
  59. // that are in different namespaces from STL code.
  60. #define __JM std
  61. #define JM_NO_NOT_EQUAL
  62. #endif
  63. #if __BORLANDC__ < 0x530
  64. #define JM_NO_WCTYPE_H
  65. #define JM_NO_WCHAR_H
  66. #define JM_OLD_IOSTREAM
  67. #define __JM_STDC
  68. #define JM_NO_TRICKY_DEFAULT_PARAM
  69. #define JM_NO_EXCEPTION_H
  70. #ifndef __WIN32__
  71. #define JM_NO_WCSTRING
  72. #endif
  73. #define JM_NO_LOCALE_H
  74. #define JM_NO_TEMPLATE_RETURNS
  75. #define JM_TEMPLATE_SPECIALISE
  76. #endif
  77. #if __BORLANDC__ < 0x540
  78. #define JM_NO_MEMBER_TEMPLATES
  79. // inline contructors exhibit strange behaviour
  80. // under Builder 3 and C++ 5.x when throwing exceptions
  81. #define INLINE_EXCEPTION_BUG
  82. #define JM_NESTED_TEMPLATE_DECL
  83. #define JM_NO_PARTIAL_FUNC_SPEC
  84. #define JM_NO_STRING_DEF_ARGS
  85. #define JM_NO_TYPEINFO // bad_cast etc not in namespace std.
  86. #endif
  87. //
  88. // Builder 4 seems to have broken template friend support:
  89. #define JM_NO_TEMPLATE_FRIEND
  90. #ifndef _CPPUNWIND
  91. #define JM_NO_EXCEPTIONS
  92. #endif
  93. #ifdef _Windows
  94. #define JM_PLATFORM_WINDOWS
  95. #else
  96. #define JM_PLATFORM_DOS
  97. #endif
  98. #ifndef __WIN32__
  99. #define RE_CALL
  100. #define RE_CCALL
  101. #else
  102. #define RE_CALL __fastcall
  103. #define RE_CCALL __stdcall
  104. #endif
  105. #define JM_INT64t __int64
  106. #define JM_IMM64(val) val##i64
  107. #define JM_NO_CAT
  108. #ifdef __MT__
  109. #define JM_THREADS
  110. #endif
  111. //
  112. // import export options:
  113. #ifdef _RTLDLL
  114. #ifdef RE_BUILD_DLL
  115. #define JM_IX_DECL __declspec( dllexport )
  116. #else
  117. #define JM_IX_DECL __declspec( dllimport )
  118. #endif
  119. #endif
  120. #include <jm/re_lib.h>
  121. #endif
  122. #ifdef _MSC_VER
  123. #define RE_CALL __fastcall
  124. #define RE_CCALL __stdcall
  125. #if _MSC_VER < 1100
  126. #define JM_NO_NAMESPACES
  127. #define JM_NO_DEFAULT_PARAM
  128. #define JM_NO_BOOL
  129. #define JM_NO_MUTABLE
  130. #define JM_NO_WCSTRING
  131. #define JM_NO_LOCALE_H
  132. #define JM_NO_TEMPLATE_RETURNS
  133. #define JM_NO_INT64
  134. #endif
  135. #if _MSC_VER < 1200
  136. #define JM_TEMPLATE_SPECIALISE
  137. #define JM_NESTED_TEMPLATE_DECL
  138. #endif
  139. #ifndef _CPPUNWIND
  140. #define JM_NO_EXCEPTIONS
  141. #endif
  142. #define __JM_STDC
  143. #define JM_PLATFORM_WINDOWS
  144. //
  145. // no support for nested template classes yet....
  146. // although this part of VC6 is badly documented
  147. #define JM_NO_MEMBER_TEMPLATES
  148. #define JM_INT64t __int64
  149. #define JM_IMM64(val) val##i64
  150. #define JM_NO_CAT
  151. #define JM_NO_PARTIAL_FUNC_SPEC
  152. #define JM_NO_TEMPLATE_FRIEND
  153. #ifdef _MT
  154. #define JM_THREADS
  155. #endif
  156. #pragma warning(disable: 4786)
  157. #pragma warning(disable: 4800)
  158. #pragma warning(disable: 4200)
  159. //
  160. // import export options:
  161. #ifdef _DLL
  162. #ifdef RE_BUILD_DLL
  163. #define JM_IX_DECL __declspec( dllexport )
  164. #else
  165. #define JM_IX_DECL __declspec( dllimport )
  166. #endif
  167. #endif
  168. #include <jm/re_lib.h>
  169. #endif
  170. #ifdef __GNUC__
  171. #if (__GNUC__ < 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ < 91))
  172. #define JM_NO_NAMESPACES
  173. #define JM_NO_MUTABLE
  174. #define JM_NO_MEMBER_TEMPLATES
  175. #define JM_NO_PARTIAL_FUNC_SPEC
  176. #define JM_NO_TEMPLATE_FRIEND
  177. #endif
  178. #ifndef __STL_USE_NAMESPACES
  179. #define JM_NO_EXCEPTION_H
  180. #endif
  181. #define JM_INT64t long long
  182. #define JM_IMM64(val) val##LL
  183. #ifdef _WIN32
  184. #define JM_PLATFORM_WINDOWS
  185. #define JM_NO_WCTYPE_H
  186. //#define JM_NO_TEMPLATE_SWITCH_MERGE
  187. #endif
  188. #define JM_NO_CAT
  189. #define OLD_IOSTREAM
  190. #define JM_NESTED_TEMPLATE_DECL
  191. #define JM_NO_TEMPLATE_TYPENAME
  192. #endif
  193. #ifdef __SUNPRO_CC
  194. #if (__SUNPRO_CC < 0x500)
  195. #define JM_NO_NAMESPACES
  196. #define JM_NO_MUTABLE
  197. #define JM_NO_MEMBER_TEMPLATES
  198. #define OLD_IOSTREAM
  199. #endif
  200. #ifndef __STL_USE_NAMESPACES
  201. #define JM_NO_EXCEPTION_H
  202. #endif
  203. #define JM_INT64t long long
  204. #define JM_IMM64(val) val##LL
  205. #define JM_NESTED_TEMPLATE_DECL
  206. #define JM_NO_TEMPLATE_TYPENAME
  207. #define JM_NO_SWPRINTF
  208. #define JM_NO_TEMPLATE_FRIEND
  209. #endif
  210. #ifdef __HP_aCC
  211. // putative HP aCC support, run configure for
  212. // support tailored to your system....
  213. #define JM_NO_NAMESPACES
  214. #define JM_NO_MUTABLE
  215. #define JM_NO_MEMBER_TEMPLATES
  216. #define OLD_IOSTREAM
  217. #ifndef __STL_USE_NAMESPACES
  218. #define JM_NO_EXCEPTION_H
  219. #endif
  220. #define JM_INT64t long long
  221. #define JM_IMM64(val) val##LL
  222. #define JM_NESTED_TEMPLATE_DECL
  223. #define JM_NO_TEMPLATE_TYPENAME
  224. #define JM_NO_TEMPLATE_FRIEND
  225. #endif
  226. #endif // JM_AUTO_CONFIGURE
  227. #ifndef JM_NO_WCSTRING
  228. #ifndef JM_NO_WCTYPE_H
  229. #include <wctype.h>
  230. #endif
  231. #ifndef JM_NO_WCHAR_H
  232. #include <wchar.h>
  233. #endif
  234. #endif
  235. #ifdef JM_NO_NAMESPACES
  236. #define JM_MAYBE_ACCESS_SPEC ::
  237. #else
  238. #define JM_MAYBE_ACCESS_SPEC __JM::
  239. #endif
  240. #if !defined(JM_INT64t) || !defined(JM_IMM64)
  241. #define JM_NO_INT64
  242. #endif
  243. #ifndef JM_INT32
  244. typedef unsigned int jm_uintfast32_t;
  245. #else
  246. typedef JM_INT32 jm_uintfast32_t;
  247. #endif
  248. #ifndef JM_TEMPLATE_SPECIALISE
  249. #define JM_TEMPLATE_SPECIALISE template <>
  250. #endif
  251. #ifndef JM_NESTED_TEMPLATE_DECL
  252. #define JM_NESTED_TEMPLATE_DECL template
  253. #endif
  254. #ifndef JM_IX_DECL
  255. #define JM_IX_DECL
  256. #endif
  257. #ifndef MB_CUR_MAX
  258. // yuk!
  259. // better make a conservative guess!
  260. #define MB_CUR_MAX 10
  261. #endif
  262. /* everything else is C++: */
  263. #ifdef __cplusplus
  264. /* define macro's to make default parameter declaration easier: */
  265. #ifdef JM_NO_DEFAULT_PARAM
  266. #define JM_DEFAULT_PARAM(x)
  267. #define JM_TRICKY_DEFAULT_PARAM(x)
  268. #elif defined(JM_NO_TRICKY_DEFAULT_PARAM)
  269. #define JM_DEFAULT_PARAM(x) = x
  270. #define JM_TRICKY_DEFAULT_PARAM(x)
  271. #else
  272. #define JM_DEFAULT_PARAM(x) = x
  273. #define JM_TRICKY_DEFAULT_PARAM(x) = x
  274. #endif
  275. /* STL configuration goes here: */
  276. #ifndef JM_AUTO_CONFIGURE
  277. #ifdef JM_NO_STL
  278. #define JM_NO_EXCEPTION_H
  279. #define JM_NO_ITERATOR_H
  280. #define JM_NO_MEMORY_H
  281. #define JM_NO_LOCALE_H
  282. #define JM_NO_STRING_H
  283. #endif
  284. #ifndef JM_NO_EXCEPTION_H
  285. #include <exception>
  286. #endif
  287. #ifndef JM_NO_ITERATOR_H
  288. #include <iterator>
  289. #if defined(__SGI_STL_INTERNAL_ITERATOR_H) || defined(__SGI_STL_ITERATOR_H)
  290. #define JM_NO_LOCALE_H
  291. #define OLD_IOSTREAM
  292. /* we are using SGI's STL
  293. some of these (__JM_STDC)
  294. may be guesswork: */
  295. #if !defined(__STL_MEMBER_TEMPLATE_CLASSES) || !defined(__STL_MEMBER_TEMPLATES)
  296. #define JM_NO_MEMBER_TEMPLATES
  297. #endif
  298. #if !defined( __JM_STD)
  299. #if defined (__STL_USE_NAMESPACES)
  300. #define __JM_STD __STD
  301. #else
  302. #define __JM_STD
  303. #endif
  304. #endif
  305. #ifndef __JM_STDC
  306. #define __JM_STDC
  307. #endif
  308. #ifdef __STL_NO_BOOL
  309. #define JM_NO_BOOL
  310. #endif
  311. #ifdef __STL_LIMITED_DEFAULT_TEMPLATES
  312. #define JM_NO_TRICKY_DEFAULT_PARAM
  313. #define JM_NO_STRING_DEF_ARGS
  314. #endif
  315. #ifndef __STL_USE_EXCEPTIONS
  316. #define JM_NO_EXCEPTIONS
  317. #endif
  318. #include <algo.h>
  319. #include <alloc.h>
  320. #define JM_ALGO_INCLUDED
  321. #define JM_DISTANCE(i, j, n) __JM_STD::distance(i, j, n)
  322. #define JM_OUTPUT_ITERATOR(T, D) __JM_STD::output_iterator
  323. #define JM_INPUT_ITERATOR(T, D) __JM_STD::input_iterator<T, D>
  324. #define JM_FWD_ITERATOR(T, D) __JM_STD::forward_iterator<T, D>
  325. #define JM_BIDI_ITERATOR(T, D) __JM_STD::bidirectional_iterator<T, D>
  326. #define JM_RA_ITERATOR(T, D) __JM_STD::random_access_iterator<T, D>
  327. #ifdef __STL_USE_STD_ALLOCATORS
  328. /* new style allocator's with nested template classes */
  329. #define REBIND_INSTANCE(x, y, inst) y::JM_NESTED_TEMPLATE_DECL rebind<x>::other(inst)
  330. #define REBIND_TYPE(x, y) y::JM_NESTED_TEMPLATE_DECL rebind<x>::other
  331. #define JM_DEF_ALLOC_PARAM(x) JM_TRICKY_DEFAULT_PARAM( __JM_STD::allocator<x> )
  332. #define JM_DEF_ALLOC(x) __JM_STD::allocator<x>
  333. #else /* __STL_USE_STD_ALLOCATORS */
  334. /* old style byte allocator's, no nested templates */
  335. #define JM_OLD_ALLOCATORS
  336. #define REBIND_INSTANCE(x, y, inst) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>(inst)
  337. #define REBIND_TYPE(x, y) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>
  338. #define JM_DEF_ALLOC_PARAM(x) JM_DEFAULT_PARAM( __JM_STD::alloc )
  339. #define JM_DEF_ALLOC(x) __JM_STD::alloc
  340. #define JM_NEED_BINDER
  341. #endif /* __STL_USE_STD_ALLOCATORS */
  342. #define JM_STL_DONE
  343. #define JM_NO_NOT_EQUAL
  344. #elif defined(__STD_ITERATOR__)
  345. /* Rogue Wave STL */
  346. #if defined(RWSTD_NO_MEMBER_TEMPLATES) || defined(RWSTD_NO_MEM_CLASS_TEMPLATES)
  347. #define JM_NO_MEMBER_TEMPLATES
  348. #endif
  349. #ifdef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  350. #define JM_NO_TEMPLATE_RETURNS
  351. #endif
  352. #ifdef _RWSTD_NO_NAMESPACE
  353. #define __JM_STD
  354. #define __JM_STDC
  355. #else
  356. #define __JM_STD std
  357. #endif
  358. #ifdef RWSTD_NO_EXCEPTIONS
  359. #define JM_NO_EXCEPTIONS
  360. #endif
  361. #ifdef RWSTD_NO_MUTABLE
  362. #define JM_NO_MUTABLE
  363. #endif
  364. #ifdef RWSTD_NO_DEFAULT_TEMPLATES
  365. #define JM_NO_DEFAULT_PARAM
  366. #define JM_NO_TRICKY_DEFAULT_PARAM
  367. #define JM_NO_STRING_DEF_ARGS
  368. #endif
  369. #ifdef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  370. #define JM_NO_TRICKY_DEFAULT_PARAM
  371. #define JM_NO_STRING_DEF_ARGS
  372. #endif
  373. #ifdef RWSTD_NO_BOOL
  374. #define JM_NO_BOOL
  375. #endif
  376. #if _RWSTD_VER > 0x020000
  377. #ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC
  378. #define JM_DISTANCE(i, j, n) __JM_STD::distance(i, j, n)
  379. #else
  380. #define JM_DISTANCE(i, j, n) (n = __JM_STD::distance(i, j))
  381. #endif
  382. #define JM_OUTPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::output_iterator_tag, T, D, T*, T&>
  383. #define JM_INPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::input_iterator_tag, T, D, T*, T&>
  384. #define JM_FWD_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::forward_iterator_tag, T, D, T*, T&>
  385. #define JM_BIDI_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::bidirectional_iterator_tag, T, D, T*, T&>
  386. #define JM_RA_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::random_access_iterator_tag, T, D, T*, T&>
  387. #else
  388. #define JM_DISTANCE(i, j, n) __JM_STD::distance(i, j, n)
  389. #define JM_OUTPUT_ITERATOR(T, D) __JM_STD::output_iterator
  390. #if _RWSTD_VER >= 0x0200
  391. #define JM_INPUT_ITERATOR(T, D) __JM_STD::input_iterator<T>
  392. #else
  393. #define JM_INPUT_ITERATOR(T, D) __JM_STD::input_iterator<T, D>
  394. #endif
  395. #define JM_FWD_ITERATOR(T, D) __JM_STD::forward_iterator<T, D>
  396. #define JM_BIDI_ITERATOR(T, D) __JM_STD::bidirectional_iterator<T, D>
  397. #define JM_RA_ITERATOR(T, D) __JM_STD::random_access_iterator<T, D>
  398. #endif
  399. #include <memory>
  400. #ifdef _RWSTD_ALLOCATOR
  401. /* new style allocator */
  402. #define REBIND_INSTANCE(x, y, inst) y::JM_NESTED_TEMPLATE_DECL rebind<x>::other(inst)
  403. #define REBIND_TYPE(x, y) y::JM_NESTED_TEMPLATE_DECL rebind<x>::other
  404. #define JM_DEF_ALLOC_PARAM(x) JM_TRICKY_DEFAULT_PARAM( __JM_STD::allocator<x> )
  405. #define JM_DEF_ALLOC(x) __JM_STD::allocator<x>
  406. #else
  407. /*
  408. // old style allocator
  409. // this varies a great deal between versions, and there is no way
  410. // that I can tell of differentiating between them, so use our
  411. // own default allocator...
  412. */
  413. #define JM_OLD_ALLOCATORS
  414. #define REBIND_INSTANCE(x, y, inst) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>(inst)
  415. #define REBIND_TYPE(x, y) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>
  416. #define JM_DEF_ALLOC_PARAM(x) JM_DEFAULT_PARAM( jm_def_alloc )
  417. #define JM_DEF_ALLOC(x) jm_def_alloc
  418. #define JM_NEED_BINDER
  419. #define JM_NEED_ALLOC
  420. #endif
  421. #define JM_STL_DONE
  422. #define JM_NO_OI_ASSIGN
  423. #elif defined (ITERATOR_H)
  424. /* HP STL */
  425. #define __JM_STD
  426. #define __JM_STDC
  427. #define JM_NO_LOCALE_H
  428. #include <algo.h>
  429. #define JM_ALGO_INCLUDED
  430. #define JM_DISTANCE(i, j, n) __JM_STD::distance(i, j, n)
  431. #define JM_OUTPUT_ITERATOR(T, D) __JM_STD::output_iterator
  432. #define JM_INPUT_ITERATOR(T, D) __JM_STD::input_iterator<T, D>
  433. #define JM_FWD_ITERATOR(T, D) __JM_STD::forward_iterator<T, D>
  434. #define JM_BIDI_ITERATOR(T, D) __JM_STD::bidirectional_iterator<T, D>
  435. #define JM_RA_ITERATOR(T, D) __JM_STD::random_access_iterator<T, D>
  436. /* old style allocator */
  437. #define JM_OLD_ALLOCATORS
  438. #define REBIND_INSTANCE(x, y, inst) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>(inst)
  439. #define REBIND_TYPE(x, y) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>
  440. #define JM_DEF_ALLOC_PARAM(x) JM_DEFAULT_PARAM( jm_def_alloc )
  441. #define JM_DEF_ALLOC(x) jm_def_alloc
  442. #define JM_NEED_BINDER
  443. #define JM_NEED_ALLOC
  444. #define JM_NO_NOT_EQUAL
  445. #define JM_STL_DONE
  446. #elif defined (_MSC_VER)
  447. /* assume we're using MS's own STL (VC++ 5/6) */
  448. #define __JM_STD std
  449. #define __JM_STDC
  450. #define JM_NO_OI_ASSIGN
  451. #define JM_DISTANCE(i, j, n) n = __JM_STD::distance(i, j)
  452. #define JM_OUTPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::output_iterator_tag, T, D>
  453. #define JM_INPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::input_iterator_tag, T, D>
  454. #define JM_FWD_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::forward_iterator_tag, T, D>
  455. #define JM_BIDI_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::bidirectional_iterator_tag, T, D>
  456. #define JM_RA_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::random_access_iterator_tag, T, D>
  457. /* MS's allocators are rather ambiguous about their properties
  458. at least as far as MSDN is concerned, so play safe: */
  459. #define JM_OLD_ALLOCATORS
  460. #define REBIND_INSTANCE(x, y, inst) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>(inst)
  461. #define REBIND_TYPE(x, y) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>
  462. #define JM_DEF_ALLOC_PARAM(x) JM_DEFAULT_PARAM( jm_def_alloc )
  463. #define JM_DEF_ALLOC(x) jm_def_alloc
  464. #define JM_NEED_BINDER
  465. #define JM_NEED_ALLOC
  466. #define JM_STL_DONE
  467. #define JM_USE_FACET(l, type) __JM_STD::use_facet(l, (type*)0, true)
  468. #define JM_HAS_FACET(l, type) __JM_STD::has_facet(l, (type*)0)
  469. #else
  470. /* unknown STL version
  471. try the defaults: */
  472. #define JM_DISTANCE(i, j, n) __JM_STD::distance(i, j, n)
  473. /* these may be suspect for older libraries */
  474. #define JM_OUTPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::output_iterator_tag, T, D, T*, T&>
  475. #define JM_INPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::input_iterator_tag, T, D, T*, T&>
  476. #define JM_FWD_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::forward_iterator_tag, T, D, T*, T&>
  477. #define JM_BIDI_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::bidirectional_iterator_tag, T, D, T*, T&>
  478. #define JM_RA_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::random_access_iterator_tag, T, D, T*, T&>
  479. #endif /* <iterator> config */
  480. #else /* no <iterator> at all */
  481. #define JM_DISTANCE(i, j, n) (n = j - i)
  482. #define JM_OUTPUT_ITERATOR(T, D) dummy_iterator_base<T>
  483. #define JM_INPUT_ITERATOR(T, D) dummy_iterator_base<T>
  484. #define JM_FWD_ITERATOR(T, D) dummy_iterator_base<T>
  485. #define JM_BIDI_ITERATOR(T, D) dummy_iterator_base<T>
  486. #define JM_RA_ITERATOR(T, D) dummy_iterator_base<T>
  487. #endif
  488. /* now do allocator if not already done */
  489. #ifndef JM_STL_DONE
  490. #ifdef JM_NO_MEMORY_H
  491. /* old style allocator */
  492. #define JM_OLD_ALLOCATORS
  493. #define REBIND_INSTANCE(x, y, inst) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>(inst)
  494. #define REBIND_TYPE(x, y) JM_MAYBE_ACCESS_SPEC re_alloc_binder<x, y>
  495. #define JM_DEF_ALLOC_PARAM(x) JM_DEFAULT_PARAM( jm_def_alloc )
  496. #define JM_DEF_ALLOC(x) jm_def_alloc
  497. #define JM_NEED_BINDER
  498. #define JM_NEED_ALLOC
  499. #else
  500. /* new style allocator's with nested template classes */
  501. #define REBIND_INSTANCE(x, y, inst) y::JM_NESTED_TEMPLATE_DECL rebind<x>::other(inst)
  502. #define REBIND_TYPE(x, y) y::JM_NESTED_TEMPLATE_DECL rebind<x>::other
  503. #define JM_DEF_ALLOC_PARAM(x) JM_TRICKY_DEFAULT_PARAM( __JM_STD::allocator<x> )
  504. #define JM_DEF_ALLOC(x) __JM_STD::allocator<x>
  505. #endif
  506. #endif
  507. #endif // JM_AUTO_CONFIGURE
  508. /* namespace configuration goes here: */
  509. #ifdef JM_NO_NAMESPACES
  510. #ifdef __JM_STD
  511. #undef __JM_STD
  512. #endif
  513. #ifdef __JM_STDC
  514. #undef __JM_STDC
  515. #endif
  516. #ifdef __JM
  517. #undef __JM
  518. #endif
  519. #define __JM
  520. #define __JM_STD
  521. #define __JM_STDC
  522. #define JM_NAMESPACE(x)
  523. #define JM_END_NAMESPACE
  524. #define JM_USING(x)
  525. #else
  526. #ifndef __JM_STD
  527. #define __JM_STD std
  528. #endif
  529. #ifndef __JM_STDC
  530. #define __JM_STDC std
  531. #endif
  532. #ifndef __JM
  533. #define __JM jm
  534. #endif
  535. #define JM_NAMESPACE(x) namespace x{
  536. #define JM_END_NAMESPACE };
  537. #define JM_USING(x) using namespace x;
  538. #endif
  539. /* locale configuration goes here */
  540. #if !defined(JM_NO_LOCALE_H) && defined(RE_LOCALE_CPP)
  541. #include <locale>
  542. #define LOCALE_INSTANCE(i) __JM_STD::locale i;
  543. #define MAYBE_PASS_LOCALE(i) , i
  544. #ifndef JM_NO_TEMPLATE_RETURNS
  545. #ifndef JM_USE_FACET
  546. #define JM_USE_FACET(l, type) __JM_STD::use_facet< type >(l)
  547. #endif
  548. #ifndef JM_HAS_FACET
  549. #define JM_HAS_FACET(l, type) __JM_STD::has_facet< type >(l)
  550. #endif
  551. #else
  552. #ifndef JM_USE_FACET
  553. #define JM_USE_FACET(l, type) __JM_STD::use_facet(l, (type*)0)
  554. #endif
  555. #ifndef JM_HAS_FACET
  556. #define JM_HAS_FACET(l, type) __JM_STD::has_facet(l, (type*)0)
  557. #endif
  558. #endif
  559. #else
  560. #define LOCALE_INSTANCE(i)
  561. #define MAYBE_PASS_LOCALE(i)
  562. #endif
  563. /* compiler configuration goes here: */
  564. #ifdef JM_NO_MUTABLE
  565. #define JM_MUTABLE
  566. #else
  567. #define JM_MUTABLE mutable
  568. #endif
  569. #if defined( JM_NO_BOOL) && !defined(bool)
  570. #define bool int
  571. #define true 1
  572. #define false 0
  573. #endif
  574. #ifndef RE_CALL
  575. #define RE_CALL
  576. #endif
  577. #ifndef RE_CCALL
  578. #define RE_CCALL
  579. #endif
  580. #ifndef RE_DECL
  581. #define RE_DECL
  582. #endif
  583. #if defined(JM_NO_DEFAULT_PARAM) || defined(JM_NO_TRICKY_DEFAULT_PARAM)
  584. #define JM_NO_STRING_DEF_ARGS
  585. #endif
  586. /* add our class def's if they are needed: */
  587. JM_NAMESPACE(__JM)
  588. // add our destroy functions:
  589. template <class T>
  590. inline void RE_CALL jm_destroy(T* t)
  591. {
  592. t->~T();
  593. }
  594. inline void RE_CALL jm_destroy(char* t){}
  595. inline void RE_CALL jm_destroy(short* t){}
  596. inline void RE_CALL jm_destroy(unsigned short* t){}
  597. inline void RE_CALL jm_destroy(int* t){}
  598. inline void RE_CALL jm_destroy(unsigned int* t){}
  599. inline void RE_CALL jm_destroy(long* t){}
  600. inline void RE_CALL jm_destroy(unsigned long* t){}
  601. template <class T>
  602. inline void RE_CALL jm_construct(void* p, const T& t)
  603. {
  604. new (p) T(t);
  605. }
  606. template<class T, class Allocator>
  607. class re_alloc_binder : public Allocator
  608. {
  609. public:
  610. typedef T value_type;
  611. typedef T* pointer;
  612. typedef const T* const_pointer;
  613. typedef T& reference;
  614. typedef const T& const_reference;
  615. typedef size_t size_type;
  616. typedef __JM_STDC::ptrdiff_t difference_type;
  617. re_alloc_binder(const Allocator& i);
  618. re_alloc_binder(const re_alloc_binder& o) : Allocator(o) {}
  619. T* RE_CALL allocate(size_t n, size_t /* hint */ = 0)
  620. { return 0 == n ? 0 : (T*) this->Allocator::allocate(n * sizeof(T)); }
  621. void RE_CALL deallocate(T *p, size_t n)
  622. { if (0 != n) this->Allocator::deallocate((char*)p, n * sizeof (T)); }
  623. pointer RE_CALL address(reference x) const { return &x; }
  624. const_pointer RE_CALL address(const_reference x) const { return &x; }
  625. static size_type RE_CALL max_size() { return -1; }
  626. static void RE_CALL construct(pointer p, const T& val) { jm_construct(p, val); }
  627. void RE_CALL destroy(pointer p) { jm_destroy(p); }
  628. const Allocator& RE_CALL instance()const { return *this; }
  629. #ifndef JM_NO_MEMBER_TEMPLATES
  630. template <class U>
  631. struct rebind
  632. {
  633. typedef re_alloc_binder<U, Allocator> other;
  634. };
  635. template <class U>
  636. RE_CALL re_alloc_binder(const re_alloc_binder<U, Allocator>& o) throw()
  637. : Allocator(o.instance())
  638. {
  639. }
  640. #endif
  641. };
  642. template<class T, class Allocator>
  643. inline re_alloc_binder<T, Allocator>::re_alloc_binder(const Allocator &i)
  644. : Allocator(i)
  645. {}
  646. //
  647. // class jm_def_alloc
  648. // basically a standard allocator that only allocates bytes...
  649. // think of it as allocator<char>, with a non-standard
  650. // rebind::other typedef.
  651. //
  652. class jm_def_alloc
  653. {
  654. public:
  655. typedef char value_type;
  656. typedef char* pointer;
  657. typedef const char* const_pointer;
  658. typedef char& reference;
  659. typedef const char& const_reference;
  660. typedef size_t size_type;
  661. typedef __JM_STDC::ptrdiff_t difference_type;
  662. pointer RE_CALL address(reference x) const { return &x; }
  663. const_pointer RE_CALL address(const_reference x) const { return &x; }
  664. static size_type RE_CALL max_size() { return (size_type)-1; }
  665. static void RE_CALL construct(pointer , const char& ) { }
  666. void RE_CALL destroy(pointer ) { }
  667. static void * RE_CALL allocate(size_t n, size_t /* hint */ = 0)
  668. {
  669. return ::operator new(n);
  670. }
  671. static void RE_CALL deallocate(void *p, size_t /*n*/ )
  672. {
  673. ::operator delete(p);
  674. }
  675. #ifndef JM_NO_MEMBER_TEMPLATES
  676. template <class U>
  677. struct rebind
  678. {
  679. typedef re_alloc_binder<U, jm_def_alloc> other;
  680. };
  681. template <class U>
  682. RE_CALL jm_def_alloc(const re_alloc_binder<U, jm_def_alloc>& ) throw() { }
  683. #endif
  684. jm_def_alloc(const jm_def_alloc&) {}
  685. jm_def_alloc() {}
  686. };
  687. template <class T>
  688. struct dummy_iterator_base
  689. {
  690. typedef T value_type;
  691. typedef __JM_STDC::ptrdiff_t difference_type;
  692. typedef T* pointer;
  693. typedef T& reference;
  694. //typedef Category iterator_category;
  695. };
  696. // we need to absolutely sure that int values are correctly
  697. // translated to bool (true or false) values...
  698. // note that the original HP STL redefines the bool type regardless
  699. // of whether the compiler supports it.... yuk
  700. #if defined(JM_NO_BOOL) || defined(ITERATOR_H) || defined(bool)
  701. #define JM_MAKE_BOOL(x) boolify(x)
  702. template <class I>
  703. inline bool RE_CALL boolify(I val)
  704. {
  705. return val ? true : false;
  706. }
  707. #else
  708. #define JM_MAKE_BOOL(x) x
  709. #endif
  710. // class auto_array:
  711. //
  712. // encapsulates objects allocated with ::operator new[]()
  713. // interface the same as auto_ptr, but no stream operators
  714. // since we don't know how big the array is.
  715. //
  716. // Usage: auto_array<char> buf = new char[256];
  717. //
  718. template<class X>
  719. class auto_array
  720. {
  721. public: // construct/copy/destroy:
  722. auto_array(X* p =0)
  723. { ptr = p; }
  724. auto_array(const auto_array& ap)
  725. { ptr = const_cast<auto_array&>(ap).release(); }
  726. void RE_CALL operator=(const auto_array&);
  727. ~auto_array();
  728. // members:
  729. X& RE_CALL operator*() const;
  730. X* RE_CALL operator->() const;
  731. X* RE_CALL get() const;
  732. X& RE_CALL operator[](int i);
  733. X* RE_CALL release();
  734. // operator not part of the spec:
  735. RE_CALL operator X*()const
  736. { return ptr; }
  737. private: // data:
  738. X* ptr;
  739. };
  740. template <class X>
  741. inline void RE_CALL auto_array<X>::operator=(const auto_array<X>& ap)
  742. {
  743. delete[] ptr;
  744. ptr = const_cast<auto_array<X>&>(ap).release();
  745. }
  746. template <class X>
  747. inline auto_array<X>::~auto_array()
  748. {
  749. delete[] ptr;
  750. }
  751. template <class X>
  752. inline X& RE_CALL auto_array<X>::operator*() const
  753. {
  754. return *ptr;
  755. }
  756. template <class X>
  757. inline X* RE_CALL auto_array<X>::operator->() const
  758. {
  759. return ptr;
  760. }
  761. template <class X>
  762. inline X* RE_CALL auto_array<X>::get() const
  763. {
  764. return ptr;
  765. }
  766. template <class X>
  767. inline X& RE_CALL auto_array<X>::operator[](int i)
  768. {
  769. return ptr[i];
  770. }
  771. template <class X>
  772. inline X* RE_CALL auto_array<X>::release()
  773. {
  774. X* tmp = ptr;
  775. ptr = NULL;
  776. return tmp;
  777. }
  778. JM_END_NAMESPACE
  779. #if !defined(INLINE_EXCEPTION_BUG) || defined(JM_NO_TEMPLATE_MERGE)
  780. #define CONSTRUCTOR_INLINE inline
  781. #else
  782. #define CONSTRUCTOR_INLINE
  783. #endif
  784. #if defined(JM_PLATFORM_W32) && !defined(RE_LOCALE_W32) && !defined(RE_LOCALE_C) && !defined(RE_LOCALE_CPP) && !defined(JM_NO_W32)
  785. #define RE_LOCALE_W32
  786. #endif
  787. #if !defined(RE_LOCALE_W32) && !defined(RE_LOCALE_C) && !defined(RE_LOCALE_CPP)
  788. #define RE_LOCALE_C
  789. #endif
  790. #if defined(JM_OLD_ALLOCATORS) && defined(JM_NO_TEMPLATE_TYPENAME)
  791. #define JM_MAYBE_TYPENAME
  792. #else
  793. #define JM_MAYBE_TYPENAME typename
  794. #endif
  795. #ifdef RE_LOCALE_W32
  796. #include <windows.h>
  797. #endif
  798. /* now do debugging stuff: */
  799. #ifdef JM_DEBUG
  800. #ifdef OLD_IOSTREAM
  801. #include <iostream.h>
  802. #else
  803. #include <iostream>
  804. using std::cout;
  805. using std::cin;
  806. using std::cerr;
  807. #endif
  808. #ifndef jm_assert
  809. #define jm_assert(x) if((x) == 0){ cerr << "Assertion failed: " << #x << " in file " << __FILE__ << "and line " << __LINE__ << endl; exit(-1); }
  810. #endif
  811. #ifndef jm_trace
  812. #define jm_trace(x) cerr << x;
  813. #endif
  814. #ifdef __BORLANDC__
  815. #pragma message "macro __jm_std: " __JM_STD
  816. #pragma message "macro __jm_stdc: " __JM_STDC
  817. #pragma message "macro namespace: " JM_NAMESPACE(__JM_STD)
  818. #pragma message "macro allocator: " JM_DEF_ALLOC_PARAM(wchar_t)
  819. #pragma message "macro jm_input_iterator: " JM_INPUT_ITERATOR(char, __JM_STDC::ptrdiff_t)
  820. #pragma message "macro jm_output_iterator: " JM_OUTPUT_ITERATOR(char, __JM_STDC::ptrdiff_t)
  821. #pragma message "macro jm_fwd_iterator: " JM_FWD_ITERATOR(char, __JM_STDC::ptrdiff_t)
  822. #pragma message "macro jm_bidi_iterator: " JM_BIDI_ITERATOR(char, __JM_STDC::ptrdiff_t)
  823. #pragma message "macro jm_ra_iterator: " JM_RA_ITERATOR(char, __JM_STDC::ptrdiff_t)
  824. #ifdef RE_LOCALE_CPP
  825. #pragma message "locale support enabled"
  826. #endif
  827. #endif
  828. #else
  829. #define jm_assert(x)
  830. #define jm_trace(x)
  831. #endif
  832. #endif /* __cplusplus */
  833. #endif