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