VIA - Volumetric Image Analysis
mu.h
1 /*
2  * $Id: mu.h 726 2004-03-08 13:12:45Z lohmann $
3  *
4  * Miscellaneous utility macros provided by Vista.
5  */
6 
7 #ifndef V_mu_h
8 #define V_mu_h 1
9 
10 /*
11  * Copyright 1993, 1994 University of British Columbia
12  *
13  * Permission to use, copy, modify, distribute, and sell this software and its
14  * documentation for any purpose is hereby granted without fee, provided that
15  * the above copyright notice appears in all copies and that both that
16  * copyright notice and this permission notice appear in supporting
17  * documentation. UBC makes no representations about the suitability of this
18  * software for any purpose. It is provided "as is" without express or
19  * implied warranty.
20  *
21  * Author: Arthur Pope, UBC Laboratory for Computational Intelligence
22  */
23 
24 /* From the Vista library: */
25 #include "viaio/Vlib.h"
26 
27 /* From the standard C library: */
28 #include <string.h>
29 
30 /* Under SunOS 4.x, definition of memxxx() aren't in <string.h>. */
31 #ifdef sun
32 #if NeedFunctionPrototypes
33 extern void *memcpy (void *, const void *, size_t);
34 extern void *memset (void *, int, size_t);
35 #else
36 extern void *memcpy ();
37 extern void *memset ();
38 #endif
39 #endif
40 
41 
42 /*
43  * Convenience macros.
44  */
45 
46 /* The minimum and maximum of two values: */
47 /* #if __GNUC__ && ! __STRICT_ANSI__ */
48 /* #define VMin(a,b) \ */
49 /* ( { typedef _ta = (a), _tb = (b); \ */
50 /* _ta _a = (a); _tb _b = (b); \ */
51 /* _a < _b ? _a : _b; } ) */
52 /* #define VMax(a,b) \ */
53 /* ( { typedef _ta = (a), _tb = (b); \ */
54 /* _ta _a = (a); _tb _b = (b); \ */
55 /* _a > _b ? _a : _b; } ) */
56 /* #else */
57 #define VMax(a,b) ((a) > (b) ? (a) : (b))
58 #define VMin(a,b) ((a) < (b) ? (a) : (b))
59 /* #endif */
60 
61 /* The offset of a field within a particular structure type: */
62 #define VOffset(type, field) \
63  ((size_t) (((char *) & ((type) 0)->field) - (char *) 0))
64 
65 #define VOffsetOf(type, field) VOffset(type *, field)
66 
67 /* The length of a statically-allocated one-dimensional array: */
68 #define VNumber(array) ((size_t) (sizeof (array) / sizeof ((array)[0])))
69 
70 /* Zero out a one-dimensional array: */
71 #define VZero(array, nels) \
72  ((void) memset ((void *) array, 0, (size_t) (nels) * sizeof ((array)[0])))
73 
74 /* Copy one vector to another: */
75 #define VCopy(from, to, nels) \
76  ((void) memcpy ((void *) (to), (void *) (from), \
77  (size_t) (nels) * sizeof ((from)[0])))
78 
79 /* Allocate storage for a particular type of object: */
80 #define VNew(type) ((type *) VMalloc (sizeof (type)))
81 
82 /* Copy a string into a new block of storage: */
83 #define VNewString(str) \
84  ((VString) ((str) ? strcpy ((char *) VMalloc (strlen (str) + 1), str) : 0))
85 
86 #endif /* V_mu_h */