home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / TLX.H < prev    next >
C/C++ Source or Header  |  1996-07-02  |  15KB  |  450 lines

  1. /****************************************************************************
  2.     $Id: tlx.h 501.0 1995/03/07 12:28:50 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++
  7.     Author:     Ron van der Wal
  8.  
  9.     Typedefs, manifest constants, and more that are generally platform
  10.     dependent.
  11.  
  12.     $Log: tlx.h $
  13.     Revision 501.0  1995/03/07 12:28:50  RON
  14.     Updated for TLX 5.01
  15.     Revision 1.17  1995/02/28 15:08:30  RON
  16.     Update for release 012
  17.     Added partial support for SunPro C++ compiler
  18.  
  19.     Revision 1.16  1995/01/18  18:56:27  ron
  20.     No changes
  21.  
  22.     Revision 1.15  1995/01/12  13:31:31  ron
  23.     Updated revision number
  24.  
  25.     Revision 1.14  1995/01/06  16:01:51  ron
  26.     Changed revision number to 008
  27.  
  28.     Revision 1.13  1995/01/05  15:34:46  ron
  29.     Simplified compilation flags
  30.  
  31.     Revision 1.12  1994/11/16  15:23:41  ron
  32.     Many small changes
  33.  
  34.     Revision 1.11  1994/10/10  17:05:50  ron
  35.     Added TLX::Maturity() indicator
  36.  
  37.     Revision 1.10  1994/10/07  17:08:50  ron
  38.     Changed word and dword mapping macros
  39.  
  40.     Revision 1.9  1994/10/05  18:25:36  ron
  41.     Renamed TLx...() functions to tl...()
  42.     Removed comments regarding link time checks
  43.     Changed some macros because of SC++ 7.0 bugs
  44.  
  45.     Revision 1.8  1994/09/28  14:29:24  ron
  46.     Updated release number to 004
  47.  
  48.     Revision 1.7  1994/09/27  20:25:51  ron
  49.     Changed path separator from / to \
  50.  
  51.     Revision 1.6  1994/09/26  15:24:31  ron
  52.     Changed version number construction
  53.     Changed compilation/link checks
  54.  
  55.     Revision 1.5  1994/09/12  14:52:05  ron
  56.     Small formatting changes
  57.  
  58.     Revision 1.4  1994/09/08  15:54:49  ron
  59.     Removed O/S-specific macros to individual compiler files
  60.     Added link time checks for DLL vs. static version
  61.  
  62.     Revision 1.3  1994/09/07  15:33:41  ron
  63.     Added special TLX class to catch compilation/linking mismatches
  64.     Moved several TlxXxx() information functions to class TLX
  65.  
  66.     Revision 1.2  1994/09/06  13:56:16  ron
  67.     Added support for 16- and 32-bit DOS extenders
  68.     Added support for new C++ type 'bool'
  69.     Changed style of constants to 'kConstantName'
  70.  
  71.     Revision 1.1  1994/08/16  18:06:54  ron
  72.     Initial revision
  73.  
  74. ****************************************************************************/
  75.  
  76. #ifndef _TLX_TLX_H
  77. #define _TLX_TLX_H
  78.  
  79. #ifndef __cplusplus
  80. #error TLX is a C++ library; C compilations are not supported.
  81. #endif
  82.  
  83. //-----    Macro utilities
  84.  
  85. #define __CC2(a,b)        a ## b
  86. #define _CC2(a,b)        __CC2(a,b)
  87. #define __CC3(a,b,c)        a ## b ## c
  88. #define _CC3(a,b,c)        __CC3(a,b,c)
  89. #define __CC4(a,b,c,d)        a ## b ## c ## d
  90. #define _CC4(a,b,c,d)        __CC4(a,b,c,d)
  91. #define __CC5(a,b,c,d,e)    a ## b ## c ## d ## e
  92. #define _CC5(a,b,c,d,e)        __CC5(a,b,c,d,e)
  93.  
  94. //-----    Version information
  95.  
  96. #define _TLXMAJ        5        // Major version number
  97. #define _TLXMIN         01        // Minor version number
  98. #define _TLXREV         000        // Revision number
  99.  
  100. #define _TLXVER         _CC3(0x,_TLXMAJ,_TLXMIN)    // Hexadecimal
  101. #define _TLXDEC         _CC2(_TLXMAJ,_TLXMIN)        // Decimal
  102. #define _TLXVNAME    _CC5(V,_TLXMAJ,_TLXMIN,r,_TLXREV) // Vddd.rrr
  103.  
  104. #ifdef _TLXDLL
  105.   #define _TLXDS    DLL
  106. #else
  107.   #define _TLXDS    Static
  108. #endif
  109.  
  110. #ifdef _TLXDBG
  111.   #define _TLXDR    Debug
  112. #else
  113.   #define _TLXDR    Retail
  114. #endif
  115.  
  116. //-----    Instructions to LINT
  117.  
  118. //lint -esym(553,OS_BSD,OS_DOS,OS_DOS286,OS_DOS386,OS_DOSXXX,OS_MAC,OS_OS2)
  119. //lint -esym(553,OS_WIN16,OS_WIN32,OS_WIN32S,OS_WINXXX)
  120. //lint -e1725            Don't complain about reference data members
  121.  
  122. /*---------------------------------------------------------------------------
  123.     Find out on what target platform we are supposed to run:
  124.  
  125.     OS_BSD      - defined on BSD Unix platforms
  126.     OS_DOS      - defined on 16-bit real mode DOS platforms
  127.     OS_DOS286   - defined on 16-bit protected mode DOS platforms
  128.     OS_DOS386   - defined on 32-bit protected mode DOS platforms
  129.     OS_DOSXXX    - defined on all DOS platforms
  130.     OS_MAC      - defined on Macintosh 6.x and above platforms
  131.     OS_OS2      - defined on OS/2 2.x platforms
  132.     OS_SCO      - defined on SCO Unix platforms
  133.     OS_SV4      - defined on Unix SVR4.2 platforms
  134.     OS_UNIX     - defined on all Unix platforms
  135.     OS_WIN16    - defined on 16-bit Windows platforms
  136.     OS_WIN32    - defined on 32-bit Windows platforms
  137.     OS_WIN32S   - defined on 32-bit subset Windows platforms
  138.     OS_WINXXX    - defined on all Windows platforms
  139.  
  140.     The one-to-one relation between platform and processor is blurring
  141.     (it wasn't that clear for Unix systems anyway), so we take this into
  142.     account as well:
  143.  
  144.     _CPU_ALPHA  - Alpha
  145.     _CPU_I86    - Intel 80x86, i486, Pentium, or compatible
  146.     _CPU_M68    - Motorola 680xx or compatible
  147.     _CPU_MIPS   - MIPS
  148.     _CPU_PPC    - Motorola/IBM PowerPC
  149.     _CPU_SPARC  - Sparc
  150.  
  151.     This determination takes place based on compiler-specific headers.
  152.     These headers also contain compiler-specific versions of keywords.
  153. ---------------------------------------------------------------------------*/
  154.  
  155. #if defined(__TURBOC__)
  156.     #include <tlx\501\borland.h>
  157. #elif defined(_MSC_VER)
  158.     #include <tlx\501\microsof.h>
  159. #elif defined(__IBMC__) || defined(__IBMCPP__)
  160.     #include <tlx\501\ibm.h>
  161. #elif defined (THINK_CPLUS)
  162.     #include <tlx\501\think.h>
  163. #elif defined (__SC__)
  164.     #include <tlx\501\symantec.h>
  165. #elif defined(__WATCOMC__)
  166.     #include <tlx\501\watcom.h>
  167. #elif defined(__ZTC__>
  168.     #include <tlx\501\zortech.h>
  169. #elif defined(__SUNPRO_CC>
  170.     #include <tlx\501\sunpro.h>
  171. #else
  172.     #error Unsupported compiler type; contact Tarma Software Research
  173.     #include <tlx\501\compiler.h>
  174. #endif
  175.  
  176. // Check required macros
  177.  
  178. #if !OS_DOSXXX && !OS_MAC && !OS_OS2 && !OS_WINXXX && !OS_UNIX
  179. #error Must specify a target platform
  180. #endif
  181.  
  182. #if !_MEM_FLAT && !_MEM_SEG
  183. #error Must specify a memory architecture
  184. #elif _MEM_FLAT && _MEM_SEG
  185. #error Must specify exactly 1 memory architecture
  186. #endif
  187.  
  188. #if !_CPU_I86 && !_CPU_M68 && !_CPU_SPARC
  189. #error Must specify a processor architecture
  190. #elif _CPU_I86 && _CPU_M68
  191. #error Must specify exactly 1 processor architecture
  192. #endif
  193.  
  194. #if !_BENDIAN && !_LENDIAN
  195. #error Must specify an endianity
  196. #elif _BENDIAN && _LENDIAN
  197. #error Must specify exactly 1 endianity
  198. #endif
  199.  
  200. // Provide defaults for non-required macros
  201.  
  202. #ifndef _CCNAME
  203. #define _CCNAME        Unknown compiler
  204. #endif
  205. #ifndef _CCVER
  206. #define _CCVER        0
  207. #endif
  208. #ifndef _MODEL
  209. #define _MODEL          Unknown
  210. #endif
  211. #ifndef _RTLCLASS
  212. #define _RTLCLASS       // Empty
  213. #endif
  214.  
  215. /*---------------------------------------------------------------------------
  216.     ANSI/ISO C++ extensions that are not always available yet. Some specific
  217.     extensions are covered in other files:
  218.  
  219.     except.h    - exceptions and 'throw'
  220.     rtti.h    - RTTI and new-style casts
  221. ---------------------------------------------------------------------------*/
  222.  
  223. #include <limits.h>         // Pull in the ANSI-C limits for convenience
  224. #include <stddef.h>         // ANSI-C declarations of size_t and others
  225.  
  226. class _RTLCLASS ostream;        // To avoid #including <iostream.h>
  227.  
  228. #ifndef _NORTTI
  229. #include <typeinfo.h>        // Required by some compilers, useful on most
  230. #endif
  231.  
  232. #ifdef _NOMUTABLE
  233. #define mutable            // Operation allowed on const object
  234. #endif
  235.  
  236. #ifdef _NOBOOL
  237. typedef int    bool;         // ANSI C++ name
  238. const bool     false = 0;    // ANSI C++
  239. const bool     true  = 1;    // ANSI C++
  240. #endif
  241.  
  242. /*----------------------------------------------------------------------------
  243.     Modifiers for class, function, and data declarations
  244. ---------------------------------------------------------------------------*/
  245.  
  246. #ifdef _TLXDLL          // Building or using DLL version of TLX
  247.     #ifdef _TLXBUILD
  248.         #define _TLXCLASS       _ExportClass
  249.         #define _TLXFUNC        _ExportFunc
  250.         #define _TLXDATA        _ExportData
  251.     #else
  252.         #define _TLXCLASS       _ImportClass
  253.         #define _TLXFUNC        _ImportFunc
  254.         #define _TLXDATA        _ImportData
  255.     #endif
  256.     #if defined(_MEM_SEG) && !defined(_DATA_FAR)
  257.         #error DLLs are only supported with FAR data models
  258.     #endif
  259. #else                   // Building or using static version of TLX
  260.     #define _TLXCLASS
  261.     #define _TLXFUNC
  262.     #define _TLXDATA
  263. #endif
  264.  
  265. /*----------------------------------------------------------------------------
  266.     Typedefs and type characteristics that are platform dependent.
  267. ---------------------------------------------------------------------------*/
  268.  
  269. #if OS_DOSXXX || OS_MAC || OS_OS2 || OS_WINXXX
  270.   #ifdef __BORLANDC__
  271.     #include <systypes.h>
  272.   #else
  273.     typedef signed char         int8;
  274.     typedef signed short        int16;
  275.     typedef signed long         int32;
  276.     typedef unsigned char       uint8;
  277.     typedef unsigned short      uint16;
  278.     typedef unsigned long       uint32;
  279.   #endif
  280. #elif defined(__SUNPRO_CC)
  281.     typedef signed char         int8;
  282.     typedef signed short        int16;
  283.     typedef signed long         int32;
  284.     typedef signed long long    int64;
  285.     typedef unsigned char       uint8;
  286.     typedef unsigned short      uint16;
  287.     typedef unsigned long       uint32;
  288.     typedef unsigned long long  uint64;
  289. #else
  290.     #error Unknown target platform; contact Tarma Software Research
  291. #endif
  292.  
  293. typedef int             index_t;         // Used for indexing
  294. typedef int             result_t;        // Function result; 0 = no error
  295.  
  296. typedef uint8              byte_t;          // BYTE  = 8-bit unsigned
  297. typedef uint16             word_t;          // WORD  = 16 bit unsigned
  298. typedef uint32             dword_t;         // DWORD = 32-bit unsigned
  299.  
  300. // For backward compatibility, define the following:
  301.  
  302. typedef int8        tInt8;
  303. typedef int16        tInt16;
  304. typedef int32        tInt32;
  305. typedef uint8        tUint8;
  306. typedef uint16        tUint16;
  307. typedef uint32        tUint32;
  308. typedef size_t        tSize;
  309. typedef bool        tBool;
  310. typedef byte_t        tByte;
  311. typedef word_t        tWord;
  312. typedef dword_t        tDword;
  313. typedef index_t        tIndex;
  314. typedef result_t    tResult;
  315.  
  316. // The following union combines several commonly used iterator types
  317.  
  318. union iter_t {
  319.     void *      ptr;
  320.     index_t      ix;
  321. };
  322.  
  323. // Structs and unions to access bytes in multiple-byte quantities;
  324. // platform-independent.
  325.  
  326. struct TL2Bytes {
  327.   #ifdef _LENDIAN
  328.     byte_t       b0;                     // Least significant
  329.     byte_t       b1;                     // Most significant
  330.   #else
  331.     byte_t       b1;                     // Most significant
  332.     byte_t       b0;                     // Least significant
  333.   #endif
  334. };
  335.  
  336. struct TL4Bytes {
  337.   #ifdef _LENDIAN
  338.     byte_t       b0;                     // Least significant
  339.     byte_t       b1;
  340.     byte_t       b2;
  341.     byte_t       b3;                     // Most significant
  342.   #else
  343.     byte_t       b3;                     // Most significant
  344.     byte_t       b2;
  345.     byte_t       b1;
  346.     byte_t       b0;                     // Least significant
  347.   #endif
  348. };
  349.  
  350. struct TL2Words {
  351.   #ifdef _LENDIAN
  352.     word_t       w0;                     // Least significant
  353.     word_t       w1;                     // Most significant
  354.   #else
  355.     word_t       w1;                     // Most significant
  356.     word_t       w0;                     // Least significant
  357.   #endif
  358. };
  359.  
  360. union TLWordMap {
  361.     word_t       w;
  362.     TL2Bytes     b;
  363. };
  364.  
  365. union TLDwordMap {
  366.     TL2Words     w;
  367.     TL4Bytes     b;
  368. };
  369.  
  370. // Macros to map integers, allowing access to individual bytes
  371.  
  372. #define _MAP_WORD(w)    (*(TLWordMap *)&w)
  373. #define _MAP_DWORD(d)   (*(TLDwordMap *)&d)
  374.  
  375. #define WORD_LSB(w)     (_MAP_WORD(w).b.b0)
  376. #define WORD_MSB(w)     (_MAP_WORD(w).b.b1)
  377.  
  378. #define DWORD_LSB(d)    (_MAP_DWORD(d).b.b0)
  379. #define DWORD_MSB(d)    (_MAP_DWORD(d).b.b3)
  380. #define DWORD_B0(d)     (_MAP_DWORD(d).b.b0)
  381. #define DWORD_B1(d)     (_MAP_DWORD(d).b.b1)
  382. #define DWORD_B2(d)     (_MAP_DWORD(d).b.b2)
  383. #define DWORD_B3(d)     (_MAP_DWORD(d).b.b3)
  384.  
  385. #define DWORD_LSW(d)    (_MAP_DWORD(d).w.w0)
  386. #define DWORD_MSW(d)    (_MAP_DWORD(d).w.w1)
  387.  
  388. /*----------------------------------------------------------------------------
  389.     Manifest constants
  390. ----------------------------------------------------------------------------*/
  391.  
  392. #ifndef NULL
  393. #define NULL    0
  394. #endif
  395.  
  396. const size_t kMaxSize  = (size_t)(-1);
  397. const size_t kMaxAlloc = kMaxSize - 16u;
  398.  
  399. /*----------------------------------------------------------------------------
  400.     TLX -
  401.  
  402.     Class that contains information about the library. This information
  403.     is available through static member functions.
  404.  
  405.     The class also contains a special constructor, that serves to detect
  406.     compilation/linking mismatches. In conjunction with a global object
  407.     that will be included in every module that #includes this file, it will
  408.     cause the linker to complain if you link with a different version of
  409.     TLX than your compiler saw. This whole detection process is automatic.
  410. ----------------------------------------------------------------------------*/
  411.  
  412. class _TLXCLASS TLX
  413. {
  414.     static const char *    sTimeStamp;
  415.  
  416. public:
  417.     // The following functions are statics, and are therefore available
  418.     // without constructing an object of this class. They return information
  419.     // about the library for use at runtime.
  420.  
  421.     static word_t    Version();    // Returns version number
  422.     static const char *    Platform();    // Platform description
  423.     static const char *    Model();    // Memory model description
  424.     static const char *    Compiler();    // Compiler description
  425.     static const char *    Description();    // Complete description
  426.     static const char *    TimeStamp();    // Timestamp of library build
  427.     static const char *    Maturity();    // Maturity level of library release
  428.     static bool     IsDebug();    // Nonzero if debug version
  429.  
  430.     // Link check functions
  431.  
  432.     static int        _TLXVNAME();    // Checks version + release
  433.     static int        _TLXDS();    // Checks DLL vs. static
  434.     static int        _TLXDR();    // Checks debug vs. retail
  435. };
  436.  
  437. // The following definition of a global variable will cause a copy of that
  438. // variable to be added to each module that #includes this file.
  439. //
  440. // Note: if space is at a premium and you are absolutely certain that you
  441. // link to the correct version of the library, define _NO_LINK_CHECK at
  442. // the compiler command line, and no data space will be wasted.
  443.  
  444. #if !defined(_NO_LINK_CHECK) && !defined(_MSC_VER)  // MSVC 4.x bug
  445. static int _gLinkCheck = TLX::_TLXVNAME() + TLX::_TLXDS() + TLX::_TLXDR();
  446. //lint -esym(528,_gLinkCheck)    Do not complain about not being referenced
  447. #endif
  448.  
  449. #endif  // _TLX_TLX_H
  450.