Woolz Image Processing Version 1.4.0
|
00001 #ifndef ALCTEMPLATES_H 00002 #define ALCTEMPLATES_H 00003 #if defined(__GNUC__) 00004 #ident "University of Edinburgh $Id: a83de7cf8d1076a86b4b0b88c40bcee166607a18 $" 00005 #else 00006 static char _AlcTemplates_h[] = "University of Edinburgh $Id: a83de7cf8d1076a86b4b0b88c40bcee166607a18 $"; 00007 #endif 00008 /*! 00009 * \file libAlc/AlcTemplates.h 00010 * \author Bill Hill 00011 * \date March 1999 00012 * \version $Id: a83de7cf8d1076a86b4b0b88c40bcee166607a18 $ 00013 * \par 00014 * Address: 00015 * MRC Human Genetics Unit, 00016 * MRC Institute of Genetics and Molecular Medicine, 00017 * University of Edinburgh, 00018 * Western General Hospital, 00019 * Edinburgh, EH4 2XU, UK. 00020 * \par 00021 * Copyright (C), [2012], 00022 * The University Court of the University of Edinburgh, 00023 * Old College, Edinburgh, UK. 00024 * 00025 * This program is free software; you can redistribute it and/or 00026 * modify it under the terms of the GNU General Public License 00027 * as published by the Free Software Foundation; either version 2 00028 * of the License, or (at your option) any later version. 00029 * 00030 * This program is distributed in the hope that it will be 00031 * useful but WITHOUT ANY WARRANTY; without even the implied 00032 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00033 * PURPOSE. See the GNU General Public License for more 00034 * details. 00035 * 00036 * You should have received a copy of the GNU General Public 00037 * License along with this program; if not, write to the Free 00038 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00039 * Boston, MA 02110-1301, USA. 00040 * \brief Templates used by the 'C' pre-processor to generate the 00041 * body of the Woolz array allocation functions and the 00042 * associated freeing functions. 00043 * \todo - 00044 * \bug None known. 00045 */ 00046 00047 #ifndef WLZ_EXT_BIND 00048 #ifdef __cplusplus 00049 extern "C" { 00050 #endif 00051 #endif /* WLZ_EXT_BIND */ 00052 00053 /*! 00054 * \def ALC_TEMPLATE_C1D(D,T,M,F) 00055 * \ingroup AlcArray 00056 * \brief A template for functions which allocate 1 dimensional 00057 * zero'd arrays of any type. 00058 * - D: Destination pointer, of type T *. 00059 * - T: Type, eg char, short, int, .... 00060 * - M: Number of elements in array. 00061 * - F: String with name of function. 00062 */ 00063 #define ALC_TEMPLATE_C1D(D,T,M,F) \ 00064 AlcErrno alcErrno = ALC_ER_NONE; \ 00065 \ 00066 if((D) == NULL) \ 00067 alcErrno = ALC_ER_NULLPTR; \ 00068 else if((M) < 1) \ 00069 alcErrno = ALC_ER_NUMELEM; \ 00070 else if((*(D) = (T*)AlcCalloc((M), sizeof(T))) == NULL) \ 00071 alcErrno = ALC_ER_ALLOC; \ 00072 if(alcErrno != ALC_ER_NONE) \ 00073 { \ 00074 if(D) \ 00075 *(D) = NULL; \ 00076 } \ 00077 return(alcErrno); 00078 00079 /*! 00080 * \def ALC_TEMPLATE_M1D(D,T,M,F) 00081 * \ingroup AlcArray 00082 * \brief A template for functions which allocate 1 dimensional 00083 * non-zero'd arrays of any type. 00084 * - D: Destination pointer, of type T *. 00085 * - T: Type, eg char, short, int, .... 00086 * - M: Number of elements in array. 00087 * - F: String with name of function. 00088 */ 00089 #define ALC_TEMPLATE_M1D(D,T,M,F) \ 00090 AlcErrno alcErrno = ALC_ER_NONE; \ 00091 \ 00092 if((D) == NULL) \ 00093 alcErrno = ALC_ER_NULLPTR; \ 00094 else if((M) < 1) \ 00095 alcErrno = ALC_ER_NUMELEM; \ 00096 else if((*(D) = (T*)AlcMalloc((M) * sizeof(T))) == NULL) \ 00097 alcErrno = ALC_ER_ALLOC; \ 00098 if(alcErrno != ALC_ER_NONE) \ 00099 { \ 00100 if(D) \ 00101 *(D) = NULL; \ 00102 } \ 00103 return(alcErrno); 00104 00105 /*! 00106 * \def ALC_TEMPLATE_C2D(D,T,M,N,F) 00107 * \ingroup AlcArray 00108 * \brief A template for functions which allocate 2 dimensional 00109 * zero'd arrays of any type. 00110 * - D: Destination pointer, of type T **. 00111 * - T: Type, eg char, short, int, .... 00112 * - M: Number of 1D arrays. 00113 * - N: Number of elements in each 1D 00114 * array. 00115 * - F: String with name of function. 00116 */ 00117 #define ALC_TEMPLATE_C2D(D,T,M,N,F) \ 00118 size_t index; \ 00119 T *dump0 = NULL; \ 00120 T **dump1 = NULL; \ 00121 AlcErrno alcErrno = ALC_ER_NONE; \ 00122 \ 00123 if((D) == NULL) \ 00124 alcErrno = ALC_ER_NULLPTR; \ 00125 else if(((M) < 1) || ((N) < 1)) \ 00126 alcErrno = ALC_ER_NUMELEM; \ 00127 else if(((dump0 = (T*)AlcCalloc((M) * (N), sizeof(T))) == NULL) || \ 00128 ((dump1 = (T**)AlcMalloc((M) * sizeof(T*))) == NULL)) \ 00129 alcErrno = ALC_ER_ALLOC; \ 00130 if(alcErrno == ALC_ER_NONE) \ 00131 { \ 00132 *(D) = dump1; \ 00133 for(index = 0; index < (M); ++index) \ 00134 { \ 00135 (*(D))[index] = dump0; \ 00136 dump0 += (N); \ 00137 } \ 00138 } \ 00139 else \ 00140 { \ 00141 if(D) \ 00142 *(D) = NULL; \ 00143 if(dump0) \ 00144 AlcFree(dump0); \ 00145 if(dump1) \ 00146 AlcFree(dump1); \ 00147 } \ 00148 return(alcErrno); 00149 00150 /*! 00151 * \def ALC_TEMPLATE_M2D(D,T,M,N,F) 00152 * \ingroup AlcArray 00153 * \brief A template for functions which allocate 2 dimensional 00154 * non-zero'd arrays of any type. 00155 * - D: Destination pointer, of type T **. 00156 * - T: Type, eg char, short, int, .... 00157 * - M: Number of 1D arrays. 00158 * - N: Number of elements in each 1D 00159 * array. 00160 * - F: String with name of function. 00161 */ 00162 #define ALC_TEMPLATE_M2D(D,T,M,N,F) \ 00163 size_t index; \ 00164 T *dump0 = NULL; \ 00165 T **dump1 = NULL; \ 00166 AlcErrno alcErrno = ALC_ER_NONE; \ 00167 \ 00168 if((D) == NULL) \ 00169 alcErrno = ALC_ER_NULLPTR; \ 00170 else if(((M) < 1) || ((N) < 1)) \ 00171 alcErrno = ALC_ER_NUMELEM; \ 00172 else if(((dump0 = (T*)AlcMalloc((M) * (N) * sizeof(T))) == NULL) || \ 00173 ((dump1 = (T**)AlcMalloc((M) * sizeof(T*))) == NULL)) \ 00174 alcErrno = ALC_ER_ALLOC; \ 00175 if(alcErrno == ALC_ER_NONE) \ 00176 { \ 00177 *(D) = dump1; \ 00178 for(index = 0; index < (M); ++index) \ 00179 { \ 00180 (*(D))[index] = dump0; \ 00181 dump0 += (N); \ 00182 } \ 00183 } \ 00184 else \ 00185 { \ 00186 if(D) \ 00187 *(D) = NULL; \ 00188 if(dump0) \ 00189 AlcFree(dump0); \ 00190 if(dump1) \ 00191 AlcFree(dump1); \ 00192 } \ 00193 return(alcErrno); 00194 00195 /*! 00196 * \def ALC_TEMPLATE_SYM_C2D(D,T,N,F) 00197 * \ingroup AlcArray 00198 * \brief A template for functions which allocate 2 dimensional 00199 * zero'd symetric arrays of any type. Obviously symetric 00200 * arrays are square, but in this representation only the 00201 * lower trinagle is stored. 00202 * - D: Destination pointer, of type T **. 00203 * - T: Type, eg char, short, int, .... 00204 * - N: Number of rows or columns. 00205 * - F: String with name of function. 00206 */ 00207 #define ALC_TEMPLATE_SYM_C2D(D,T,N,F) \ 00208 size_t totElm, \ 00209 index, \ 00210 offset; \ 00211 T *dump0 = NULL; \ 00212 T **dump1 = NULL; \ 00213 AlcErrno alcErrno = ALC_ER_NONE; \ 00214 \ 00215 if((D) == NULL) \ 00216 { \ 00217 alcErrno = ALC_ER_NULLPTR; \ 00218 } \ 00219 else if((N) < 1) \ 00220 { \ 00221 alcErrno = ALC_ER_NUMELEM; \ 00222 } \ 00223 else \ 00224 { \ 00225 totElm = ((N) * ((N) + 1)) / 2; \ 00226 if(((dump0 = (T*)AlcCalloc(totElm, sizeof(T))) == NULL) || \ 00227 ((dump1 = (T**)AlcMalloc((N) * sizeof(T*))) == NULL)) \ 00228 { \ 00229 alcErrno = ALC_ER_ALLOC; \ 00230 } \ 00231 } \ 00232 if(alcErrno == ALC_ER_NONE) \ 00233 { \ 00234 offset = 0; \ 00235 *(D) = dump1; \ 00236 for(index = 0; index < (N); ++index) \ 00237 { \ 00238 dump1[index] = dump0 + offset; \ 00239 offset += index + 1; \ 00240 } \ 00241 } \ 00242 else \ 00243 { \ 00244 if(D) \ 00245 { \ 00246 *(D) = NULL; \ 00247 } \ 00248 AlcFree(dump0); \ 00249 AlcFree(dump1); \ 00250 } \ 00251 return(alcErrno); 00252 00253 /*! 00254 * \def ALC_TEMPLATE_SYM_M2D(D,T,N,F) 00255 * \ingroup AlcArray 00256 * \brief A template for functions which allocate 2 dimensional 00257 * zero'd symetric arrays of any type. Obviously symetric 00258 * arrays are square, but in this representation only the 00259 * lower trinagle is stored. 00260 * - D: Destination pointer, of type T **. 00261 * - T: Type, eg char, short, int, .... 00262 * - N: Number of rows or columns. 00263 * - F: String with name of function. 00264 */ 00265 #define ALC_TEMPLATE_SYM_M2D(D,T,N,F) \ 00266 size_t totElm, \ 00267 index, \ 00268 offset; \ 00269 T *dump0 = NULL; \ 00270 T **dump1 = NULL; \ 00271 AlcErrno alcErrno = ALC_ER_NONE; \ 00272 \ 00273 if((D) == NULL) \ 00274 { \ 00275 alcErrno = ALC_ER_NULLPTR; \ 00276 } \ 00277 else if((N) < 1) \ 00278 { \ 00279 alcErrno = ALC_ER_NUMELEM; \ 00280 } \ 00281 else \ 00282 { \ 00283 totElm = ((N) * ((N) + 1)) / 2; \ 00284 if(((dump0 = (T*)AlcMalloc(totElm * sizeof(T))) == NULL) || \ 00285 ((dump1 = (T**)AlcMalloc((N) * sizeof(T*))) == NULL)) \ 00286 { \ 00287 alcErrno = ALC_ER_ALLOC; \ 00288 } \ 00289 } \ 00290 if(alcErrno == ALC_ER_NONE) \ 00291 { \ 00292 offset = 0; \ 00293 *(D) = dump1; \ 00294 for(index = 0; index < (N); ++index) \ 00295 { \ 00296 dump1[index] = dump0 + offset; \ 00297 offset += index + 1; \ 00298 } \ 00299 } \ 00300 else \ 00301 { \ 00302 if(D) \ 00303 { \ 00304 *(D) = NULL; \ 00305 } \ 00306 AlcFree(dump0); \ 00307 AlcFree(dump1); \ 00308 } \ 00309 return(alcErrno); 00310 00311 /*! 00312 * \def ALC_TEMPLATE_F2D(D,F) 00313 * \ingroup AlcArray 00314 * \brief A template for functions which free 2 dimensional 00315 * arrays of any type, actualy no type information 00316 * is used in freeing the array. 00317 * - D: Pointer for array to be free'd. 00318 * - F: String with name of function. 00319 */ 00320 #define ALC_TEMPLATE_F2D(D,F) \ 00321 AlcErrno alcErrno = ALC_ER_NONE; \ 00322 \ 00323 if((D == NULL) || (*(D) == NULL)) \ 00324 { \ 00325 alcErrno = ALC_ER_NULLPTR; \ 00326 } \ 00327 else \ 00328 { \ 00329 AlcFree(*(D)); \ 00330 AlcFree(D); \ 00331 } \ 00332 return(alcErrno); 00333 00334 00335 /*! 00336 * \def ALC_TEMPLATE_C3D(D,T,M,N,O,F) 00337 * \ingroup AlcArray 00338 * \brief A template for functions which allocate 3 dimensional 00339 * zero'd arrays of any type. 00340 * - D: Destination pointer, of type T **. 00341 * - T: Type, eg char, short, int, .... 00342 * - M: Number of 2D arrays. 00343 * - N: Number of 1D arrays. 00344 * - O: Number of elements in each 1D 00345 * array. 00346 * - F: String with name of function. 00347 */ 00348 #define ALC_TEMPLATE_C3D(D,T,M,N,O,F) \ 00349 size_t index0, \ 00350 index1; \ 00351 T *dump0 = NULL, \ 00352 **dump1 = NULL, \ 00353 ***dump2 = NULL; \ 00354 AlcErrno alcErrno = ALC_ER_NONE; \ 00355 \ 00356 if((D) == NULL) \ 00357 alcErrno = ALC_ER_NULLPTR; \ 00358 else if(((M) < 1) || ((N) < 1) || ((O) < 1)) \ 00359 alcErrno = ALC_ER_NUMELEM; \ 00360 else if(((dump0 = (T*)AlcCalloc((M) * (N) * (O), sizeof(T))) == NULL) || \ 00361 ((dump1 = (T**)AlcMalloc((M) * (N) * sizeof(T*))) == NULL) || \ 00362 ((dump2 = (T***)AlcMalloc((M) * sizeof(T**))) == NULL)) \ 00363 alcErrno = ALC_ER_ALLOC; \ 00364 if(alcErrno == ALC_ER_NONE) \ 00365 { \ 00366 *(D) = dump2; \ 00367 for(index0 = 0; index0 < (M); ++index0) \ 00368 { \ 00369 for(index1=0; index1 < (N); ++index1) \ 00370 { \ 00371 dump1[index1] = dump0; \ 00372 dump0 += (O); \ 00373 } \ 00374 (*(D))[index0] = dump1; \ 00375 dump1 += (N); \ 00376 } \ 00377 } \ 00378 else \ 00379 { \ 00380 if(D) \ 00381 *(D) = NULL; \ 00382 if(dump2) \ 00383 AlcFree(dump2); \ 00384 if(dump1) \ 00385 AlcFree(dump1); \ 00386 if(dump0) \ 00387 AlcFree(dump0); \ 00388 } \ 00389 return(alcErrno); 00390 00391 /*! 00392 * \def ALC_TEMPLATE_M3D(D,T,M,N,O,F) 00393 * \ingroup AlcArray 00394 * \brief A template for functions which allocate 3 dimensional 00395 * non-zero'd arrays of any type. 00396 * - D: Destination pointer, of type T **. 00397 * - T: Type, eg char, short, int, .... 00398 * - M: Number of 2D arrays. 00399 * - N: Number of 1D arrays. 00400 * - O: Number of elements in each 1D 00401 * array. 00402 * - F: String with name of function. 00403 */ 00404 #define ALC_TEMPLATE_M3D(D,T,M,N,O,F) \ 00405 size_t index0, \ 00406 index1; \ 00407 T *dump0 = NULL, \ 00408 **dump1 = NULL, \ 00409 ***dump2 = NULL; \ 00410 AlcErrno alcErrno = ALC_ER_NONE; \ 00411 \ 00412 if((D) == NULL) \ 00413 alcErrno = ALC_ER_NULLPTR; \ 00414 else if(((M) < 1) || ((N) < 1) || ((O) < 1)) \ 00415 alcErrno = ALC_ER_NUMELEM; \ 00416 else if(((dump0 = (T*)AlcMalloc((M) * (N) * (O) * sizeof(T))) == NULL) || \ 00417 ((dump1 = (T**)AlcMalloc((M) * (N) * sizeof(T*))) == NULL) || \ 00418 ((dump2 = (T***)AlcMalloc((M) * sizeof(T**))) == NULL)) \ 00419 alcErrno = ALC_ER_ALLOC; \ 00420 if(alcErrno == ALC_ER_NONE) \ 00421 { \ 00422 *(D) = dump2; \ 00423 for(index0 = 0; index0 < (M); ++index0) \ 00424 { \ 00425 for(index1=0; index1 < (N); ++index1) \ 00426 { \ 00427 dump1[index1] = dump0; \ 00428 dump0 += (O); \ 00429 } \ 00430 (*(D))[index0] = dump1; \ 00431 dump1 += (N); \ 00432 } \ 00433 } \ 00434 else \ 00435 { \ 00436 if(D) \ 00437 *(D) = NULL; \ 00438 if(dump2) \ 00439 AlcFree(dump2); \ 00440 if(dump1) \ 00441 AlcFree(dump1); \ 00442 if(dump0) \ 00443 AlcFree(dump0); \ 00444 } \ 00445 return(alcErrno); 00446 00447 /*! 00448 * \def ALC_TEMPLATE_F3D(D,F) 00449 * \ingroup AlcArray 00450 * \brief A template for functions which free 3 dimensional 00451 * arrays of any type, actualy no type information 00452 * is used in freeing the array. 00453 * - D: Pointer for array to be free'd. 00454 * - F: String with name of function. 00455 */ 00456 #define ALC_TEMPLATE_F3D(D,F) \ 00457 AlcErrno alcErrno = ALC_ER_NONE; \ 00458 \ 00459 if((D == NULL) || (*(D) == NULL) || (**(D) == NULL)) \ 00460 { \ 00461 alcErrno = ALC_ER_NULLPTR; \ 00462 } \ 00463 else \ 00464 { \ 00465 AlcFree(**(D)); \ 00466 AlcFree(*(D)); \ 00467 AlcFree(D); \ 00468 } \ 00469 return(alcErrno); 00470 00471 #ifndef WLZ_EXT_BIND 00472 #ifdef __cplusplus 00473 } /* Close scope of 'extern "C" */ 00474 #endif 00475 #endif /* WLZ_EXT_BIND */ 00476 00477 #endif /* ALCTEMPLATES_H */