system.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: system.h,v 1.1 1998/07/02 02:58:13 jgg Exp $
  4. /* ######################################################################
  5. System Header - Usefull private definitions
  6. This source is placed in the Public Domain, do with it what you will
  7. It was originally written by Brian C. White.
  8. ##################################################################### */
  9. /*}}}*/
  10. // Private header
  11. // Header section: /
  12. #ifndef SYSTEM_H
  13. #define SYSTEM_H
  14. // MIN_VAL(SINT16) will return -0x8000 and MAX_VAL(SINT16) = 0x7FFF
  15. #define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) )))
  16. #define MAX_VAL(t) (((t)(-1) > 0) ? (t)(-1) : (t)(((1L<<(sizeof(t)*8-1))-1)))
  17. // Min/Max functions
  18. #if defined(__HIGHC__)
  19. #define MIN(x,y) _min(x,y)
  20. #define MAX(x,y) _max(x,y)
  21. #endif
  22. // GNU C++ has a min/max operator <coolio>
  23. #if defined(__GNUG__)
  24. #define MIN(A,B) ((A) <? (B))
  25. #define MAX(A,B) ((A) >? (B))
  26. #endif
  27. /* Templates tend to mess up existing code that uses min/max because of the
  28. strict matching requirements */
  29. #if !defined(MIN)
  30. #define MIN(A,B) ((A) < (B)?(A):(B))
  31. #define MAX(A,B) ((A) > (B)?(A):(B))
  32. #endif
  33. /* Bound functions, bound will return the value b within the limits a-c
  34. bounv will change b so that it is within the limits of a-c. */
  35. #define _bound(a,b,c) MIN(c,MAX(b,a))
  36. #define _boundv(a,b,c) b = _bound(a,b,c)
  37. #define ABS(a) (((a) < (0)) ?-(a) : (a))
  38. /* Usefull count macro, use on an array of things and it will return the
  39. number of items in the array */
  40. #define _count(a) (sizeof(a)/sizeof(a[0]))
  41. // Flag Macros
  42. #define FLAG(f) (1L << (f))
  43. #define SETFLAG(v,f) ((v) |= FLAG(f))
  44. #define CLRFLAG(v,f) ((v) &=~FLAG(f))
  45. #define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false)
  46. #endif