home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / UTIL.H < prev    next >
C/C++ Source or Header  |  1996-01-05  |  4KB  |  140 lines

  1. /****************************************************************************
  2.     $Id: util.h 501.0 1995/03/07 12:26:48 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:    Ron van der Wal
  8.  
  9.     Declarations of global utility functions.
  10.  
  11.     $Log: util.h $
  12.     Revision 501.0  1995/03/07 12:26:48  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.9  1995/01/31 16:29:28  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.8  1995/01/17  16:59:26  ron
  18.     Added tlRange() function template
  19.  
  20.     Revision 1.7  1994/10/05  18:27:07  ron
  21.     Renamed TLx...() functions to tl...()
  22.  
  23.     Revision 1.6  1994/09/28  14:29:47  ron
  24.     Removed Macintosh-style #include references
  25.  
  26.     Revision 1.5  1994/09/27  20:25:55  ron
  27.     Changed path separator from / to \
  28.  
  29.     Revision 1.4  1994/09/26  15:25:11  ron
  30.     Renamed MAKESTR() macro to STR()
  31.  
  32.     Revision 1.3  1994/09/07  15:34:30  ron
  33.     Removed TlxXxxx() information functions to tlx.h
  34.     Small formatting changes
  35.  
  36.     Revision 1.2  1994/09/06  13:59:36  ron
  37.     Adapted to new (beta) release of Symantec C++ compiler
  38.  
  39.     Revision 1.1  1994/08/16  18:06:56  ron
  40.     Initial revision
  41.  
  42. ****************************************************************************/
  43.  
  44. #ifndef _TLX_UTIL_H
  45. #define _TLX_UTIL_H
  46.  
  47. #ifndef _TLX_TLX_H
  48. #include <tlx\501\tlx.h>
  49. #endif
  50.  
  51. /*---------------------------------------------------------------------------
  52.     Various macros
  53. ---------------------------------------------------------------------------*/
  54.  
  55. // The VERSION macro creates a string with version information; its arguments
  56. // are typically a version number (e.g. 2.3) followed by a revision number.
  57. // The version string conforms to the Novell format, and will be recognized
  58. // by utilities such as VERSION from Novell and NOVER from Tarma Software
  59. // Research.
  60.  
  61. #define VERSION(ver,rel) \
  62.     "VeRsIoN=" #ver "r" #rel " (" __DATE__ " " __TIME__ ")"
  63.  
  64. // STR() expands its argument to a quoted string. The _STR() helper macro
  65. // is necessary to help expand STR() arguments that are themselves
  66. // macros; ANSI-C (and C++) require an extra level of indirection for them.
  67.  
  68. #define    _STR(s)        #s
  69. #define STR(a)        _STR(a)
  70.  
  71. // TABLE_SIZE() returns the number of elements in a C-style vector table
  72.  
  73. #define    TABLE_SIZE(tbl)    (sizeof(tbl) / sizeof(tbl[0]))
  74.  
  75. /*---------------------------------------------------------------------------
  76.     Utility functions
  77. ---------------------------------------------------------------------------*/
  78.  
  79. int16         _TLXFUNC tlSwap16(int16);    // Swap bytes in 16-bit int
  80. int32         _TLXFUNC tlSwap32(int32);    // Swap bytes in 32-bit int
  81.  
  82. index_t        _TLXFUNC tlStrHash(const char *);
  83. index_t        _TLXFUNC tlPtrHash(const void *);
  84.  
  85. char *         _TLXFUNC tlStrDup(const char *, size_t = 0);
  86.  
  87. // Overload 'tlSwapBytes()' for all relevant integer sizes.
  88.  
  89. inline int16    tlSwapBytes(int16 aInt)  { return tlSwap16(aInt); }
  90. inline int32    tlSwapBytes(int32 aInt)  { return tlSwap32(aInt); }
  91. inline uint16    tlSwapBytes(uint16 aInt) { return tlSwap16(aInt); }
  92. inline uint32    tlSwapBytes(uint32 aInt) { return tlSwap32(aInt); }
  93.  
  94. template<class T> void tlSwap(T &a, T &b)
  95. {
  96.     T tmp = a;
  97.     a = b;
  98.     b = tmp;
  99. }
  100.  
  101. template<class T> T tlMax(T a, T b) { return a >= b ? a : b; }
  102. template<class T> T tlMin(T a, T b) { return a <= b ? a : b; }
  103. template<class T> T tlRange(T lo, T val, T hi)
  104.     { return val <= lo ? lo : val >= hi ? hi : val; }
  105.  
  106. // Inline versions for data types that generate little code, or an amount
  107. // of code comparable to the code required to call a non-inline function.
  108.  
  109. #define _INL_MAX(T)    inline T tlMax(T a, T b) { return a >= b ? a : b; }
  110. #define _INL_MIN(T)    inline T tlMin(T a, T b) { return a <= b ? a : b; }
  111.  
  112. _INL_MAX(short)
  113. _INL_MAX(int)
  114. _INL_MAX(long)
  115. _INL_MAX(unsigned short)
  116. _INL_MAX(unsigned int)
  117. _INL_MAX(unsigned long)
  118. _INL_MAX(float)
  119. _INL_MAX(double)
  120. #ifndef __SC__        // Symantec C++ has no 'long double'
  121. _INL_MAX(long double)
  122. #endif
  123.  
  124. _INL_MIN(short)
  125. _INL_MIN(int)
  126. _INL_MIN(long)
  127. _INL_MIN(unsigned short)
  128. _INL_MIN(unsigned int)
  129. _INL_MIN(unsigned long)
  130. _INL_MIN(float)
  131. _INL_MIN(double)
  132. #ifndef __SC__        // Symantec C++ has no 'long double'
  133. _INL_MIN(long double)
  134. #endif
  135.  
  136. #undef _INL_MAX
  137. #undef _INL_MIN
  138.  
  139. #endif    // _TLX_UTIL_H
  140.