• Main Page
  • Data Structures
  • Files
  • File List
  • Globals

mu.h

00001 /*
00002  *  $Id: mu.h 726 2004-03-08 13:12:45Z lohmann $
00003  *
00004  *  Miscellaneous utility macros provided by Vista.
00005  */
00006 
00007 #ifndef V_mu_h
00008 #define V_mu_h 1
00009 
00010 /*
00011  *  Copyright 1993, 1994 University of British Columbia
00012  *
00013  *  Permission to use, copy, modify, distribute, and sell this software and its
00014  *  documentation for any purpose is hereby granted without fee, provided that
00015  *  the above copyright notice appears in all copies and that both that
00016  *  copyright notice and this permission notice appear in supporting
00017  *  documentation. UBC makes no representations about the suitability of this
00018  *  software for any purpose. It is provided "as is" without express or
00019  *  implied warranty.
00020  *
00021  *  Author: Arthur Pope, UBC Laboratory for Computational Intelligence
00022  */
00023 
00024 /* From the Vista library: */
00025 #include "viaio/Vlib.h"
00026 
00027 /* From the standard C library: */
00028 #include <string.h>
00029 
00030 /* Under SunOS 4.x, definition of memxxx() aren't in <string.h>. */
00031 #ifdef sun
00032 #if NeedFunctionPrototypes
00033 extern void *memcpy (void *, const void *, size_t);
00034 extern void *memset (void *, int, size_t);
00035 #else
00036 extern void *memcpy ();
00037 extern void *memset ();
00038 #endif
00039 #endif
00040 
00041 
00042 /*
00043  *  Convenience macros.
00044  */
00045 
00046 /* The minimum and maximum of two values: */
00047 /* #if __GNUC__ && ! __STRICT_ANSI__ */
00048 /* #define VMin(a,b)                    \ */
00049 /*     ( { typedef _ta = (a), _tb = (b);        \ */
00050 /*      _ta _a = (a); _tb _b = (b);     \ */
00051 /*      _a < _b ? _a : _b; } ) */
00052 /* #define VMax(a,b)                    \ */
00053 /*     ( { typedef _ta = (a), _tb = (b);        \ */
00054 /*      _ta _a = (a); _tb _b = (b);     \ */
00055 /*      _a > _b ? _a : _b; } ) */
00056 /* #else */
00057 #define VMax(a,b)       ((a) > (b) ? (a) : (b))
00058 #define VMin(a,b)       ((a) < (b) ? (a) : (b))
00059 /* #endif */
00060 
00061 /* The offset of a field within a particular structure type: */
00062 #define VOffset(type, field) \
00063     ((size_t) (((char *) & ((type) 0)->field) - (char *) 0))
00064 
00065 #define VOffsetOf(type, field)  VOffset(type *, field)
00066 
00067 /* The length of a statically-allocated one-dimensional array: */
00068 #define VNumber(array)  ((size_t) (sizeof (array) / sizeof ((array)[0])))
00069 
00070 /* Zero out a one-dimensional array: */
00071 #define VZero(array, nels) \
00072     ((void) memset ((void *) array, 0, (size_t) (nels) * sizeof ((array)[0])))
00073 
00074 /* Copy one vector to another: */
00075 #define VCopy(from, to, nels) \
00076     ((void) memcpy ((void *) (to), (void *) (from), \
00077                     (size_t) (nels) * sizeof ((from)[0])))
00078 
00079 /* Allocate storage for a particular type of object: */
00080 #define VNew(type)      ((type *) VMalloc (sizeof (type)))
00081 
00082 /* Copy a string into a new block of storage: */
00083 #define VNewString(str) \
00084     ((VString) ((str) ? strcpy ((char *) VMalloc (strlen (str) + 1), str) : 0))
00085 
00086 #endif /* V_mu_h */

Generated on Thu Feb 16 2012 22:03:37 for VIA - Volumetric Image Analysis by  doxygen 1.7.1