/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/utils/eh_macros.h

Go to the documentation of this file.
00001 //---
00002 //
00003 // This file is part of sedflux.
00004 //
00005 // sedflux is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // sedflux is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with sedflux; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //
00019 //---
00020 
00021 #ifndef __EH_MACROS_H__
00022 #define __EH_MACROS_H__
00023 
00024 #define E_BADVAL (G_MAXFLOAT)
00025 #define E_NOVAL  (G_MAXFLOAT)
00026 
00027 #define S_LINEMAX     (2048)
00028 #define S_NAMEMAX     (255)
00029 #define S_MAXPATHNAME (1024)
00030 
00031 #define E_MAJOR_VERSION (1)
00032 #define E_MINOR_VERSION (1)
00033 #define E_MICRO_VERSION (0)
00034 
00035 #define E_CHECK_VERSION(major,minor,micro)    \
00036     (E_MAJOR_VERSION > (major) || \
00037      (E_MAJOR_VERSION == (major) && E_MINOR_VERSION > (minor)) || \
00038      (E_MAJOR_VERSION == (major) && E_MINOR_VERSION == (minor) && \
00039       E_MICRO_VERSION >= (micro)))
00040 
00041 #define eh_p_msg( msg_level , str ) \
00042    eh_print_msg( msg_level , __PRETTY_FUNCTION__ , str )
00043 
00044 #define eh_lower_bound( val , low  ) ( val = ((val)<(low) )?(low ):(val) )
00045 #define eh_upper_bound( val , high ) ( val = ((val)>(high))?(high):(val) )
00046 
00047 #define eh_clamp( val , low , high ) \
00048    ( val = ((val)<(low))?(low):(((val)>(high))?(high):(val)) )
00049 
00050 #define EH_SWAP_PTR( a , b ) { void* t=(b); (b)=(a); (a)=t; }
00051 #define swap_int( a , b ) { int temp=b; b=a; a=temp; }
00052 #define swap_dbl( a , b ) { double temp=b; b=a; a=temp; }
00053 #define swap_dbl_vec( x , i , j ) { double temp=x[i]; x[i]=x[j]; x[j]=temp; }
00054 #define eh_memswap( a , b , n ) { void* temp=g_memdup(a,n); g_memmove(a,b,n); g_memmove(b,temp,n); eh_free(temp); }
00055 #define EH_STRUCT_MEMBER( type , st , mem ) ( ((type*)st)->mem )
00056 
00057 #define eh_new_2( type , m , n ) ( (type**)eh_alloc_2( m , n , sizeof(type) ) )
00058 #define eh_free_2( p ) ( eh_free_void_2( ((void**)(p)) ) )
00059 
00060 #define EH_RADS_PER_DEGREE ( 0.01745329251994 )
00061 #define EH_DEGREES_PER_RAD ( 57.29577951308232 )
00062 
00063 #define EH_SQRT_PI ( 1.77245385090552 )
00064 
00065 #define POLYGON_IN_CROSSINGS  ( 1<<0 )
00066 #define POLYGON_OUT_CROSSINGS ( 1<<1 )
00067 
00068 
00069 #define BIT_ON  00000001
00070 #define BIT_OFF 00000000
00071 #define NO  0
00072 #define YES 1
00073 #define PTR_SIZE 8      /* length of a pointer in bytes */
00074 #define ALL -1
00075 
00076 /**********
00077 *
00078 * **** Macro descriptions
00079 *
00080 *  max(a,b)
00081 *    evaluates to the maximum of the numbers a and b.
00082 *
00083 *  min(a,b)
00084 *    evaluates to the minimum of the numbers a and b.
00085 *
00086 *  get_bit(pt,n)
00087 *    returns the value of the nth bit in the data pointed to by pt.  To work
00088 *    properly pt must be converted to char *.
00089 *
00090 *  put_bit(pt,n,bit)
00091 *    Sets the value of the nth bit in the data pointed to by pt to value bit.
00092 *    To work properly pt must be converted to char *. 
00093 *
00094 *  nbb(n)
00095 *    evaluates to the minimum number of bytes able to contain n bits
00096 *
00097 **********/
00098 
00099 #define eh_sign(a)         ( (a>=0)?1:-1 )
00100 #define eh_max(a,b)        ( ( (a) > (b) ) ? (a) : (b) )
00101 #define eh_set_max(a,b)    if ( (b)>(a) ) { (a) = (b); }
00102 #define eh_set_min(a,b)    if ( (b)<(a) ) { (a) = (b); }
00103 #define eh_dbl_set_max(a,b) { double __t=(b); if ( __t>(a) ) { (a)=__t; } }
00104 #define eh_dbl_set_min(a,b) { double __t=(b); if ( __t<(a) ) { (a)=__t; } }
00105 #define eh_min(a,b)        ( ( (a) < (b) ) ? (a) : (b) )
00106 
00107 #define get_bit(pt,n)      ( (pt)[(n)/8]&(0x80>>((n)%8)) )
00108 #define turn_bit_on(pt,n)  (pt)[(n)/8] = (pt)[(n)/8] | (0x80>>((n)%8))
00109 #define turn_bit_off(pt,n) (pt)[(n)/8] = (pt)[(n)/8] &~ (0x80>>((n)%8));
00110 #define nbb(n)             ( ( (n) + 7 ) / 8 )
00111 
00112 #define eh_sqr( x )        ( (x)*(x) )
00113 #define eh_nrsign( a , b )   ( (b>0)?fabs(a):(-fabs(a)) )
00114 
00115 
00116 /**********
00117 *
00118 * **** Macro descriptions
00119 *
00120 *  initarray(pt,len,c)
00121 *    Initializes the array pointed to by pt of length len to value c.
00122 *
00123 *  count_pix(pt,len,val,c)
00124 *    Counts the number of elements of value, val in the data pointed to by pt
00125 *    of length len.  The count is stored in c.
00126 *
00127 *  rotate_array(ar_type,pt,len)
00128 *    Rotates the values in the array pointed to by pt (of length, len and type,
00129 *    ar_type).  The values are rotated such that pt[i]=pt[i+1].  Also, pt[0] is
00130 *    stored in a temporary variable and copied to pt[len-1].
00131 *
00132 *  mmove(dst,src,len)
00133 *    Copies the len characters pointed to by src into the object pointed to by
00134 *    dst.  The characters are not copied to a temporary location before being 
00135 *    copied.  Thus, for the data to be copied correctly, the source and
00136 *    destination objects must not overlap.
00137 *
00138 **********/
00139 
00140 #ifndef initarray
00141 # define initarray(pt,len,c) { unsigned long i; for (i=0;i<len;(pt)[i++]=c); }
00142 #endif
00143 #define count_pix(pt,len,val,c) { unsigned long i; for (i=0;i<len;i++) if ((pt)[i]==val) c++; }
00144 #define rotate_array(ar_type,pt,len) { unsigned long i;                               \
00145                                        ar_type temp;                                          \
00146                                        for (i=0,temp=(pt)[0];i<len-1;(pt)[i]=(pt)[i+1],i++); \
00147                                        (pt)[len-1]=temp;                                      \
00148                                      }
00149 #define mmove(dst,src,len) { unsigned long j;                   \
00150                              for (j=0;j<(len);j++)              \
00151                                       (dst)[j]=(src)[j];        \
00152                            }
00153 
00154 
00155 
00156 #endif /* eh_macros.h is included */

Generated on Fri Jan 4 18:04:16 2008 for sedflux by  doxygen 1.5.2