Woolz Image Processing
Version 1.8.3
AlcTemplates.h
Go to the documentation of this file.
1
#ifndef ALCTEMPLATES_H
2
#define ALCTEMPLATES_H
3
#if defined(__GNUC__)
4
#ident "University of Edinburgh $Id: 88ba88d568e7192e82d786dadfe9e88d45412e26 $"
5
#else
6
static
char
_AlcTemplates_h[] =
"University of Edinburgh $Id: 88ba88d568e7192e82d786dadfe9e88d45412e26 $"
;
7
#endif
8
/*!
9
* \file libAlc/AlcTemplates.h
10
* \author Bill Hill
11
* \date March 1999
12
* \version $Id: 88ba88d568e7192e82d786dadfe9e88d45412e26 $
13
* \par
14
* Address:
15
* MRC Human Genetics Unit,
16
* MRC Institute of Genetics and Molecular Medicine,
17
* University of Edinburgh,
18
* Western General Hospital,
19
* Edinburgh, EH4 2XU, UK.
20
* \par
21
* Copyright (C), [2012],
22
* The University Court of the University of Edinburgh,
23
* Old College, Edinburgh, UK.
24
*
25
* This program is free software; you can redistribute it and/or
26
* modify it under the terms of the GNU General Public License
27
* as published by the Free Software Foundation; either version 2
28
* of the License, or (at your option) any later version.
29
*
30
* This program is distributed in the hope that it will be
31
* useful but WITHOUT ANY WARRANTY; without even the implied
32
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
33
* PURPOSE. See the GNU General Public License for more
34
* details.
35
*
36
* You should have received a copy of the GNU General Public
37
* License along with this program; if not, write to the Free
38
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39
* Boston, MA 02110-1301, USA.
40
* \brief Templates used by the 'C' pre-processor to generate the
41
* body of the Woolz array allocation functions and the
42
* associated freeing functions.
43
* \todo -
44
* \bug None known.
45
*/
46
47
#ifndef WLZ_EXT_BIND
48
#ifdef __cplusplus
49
extern
"C"
{
50
#endif
51
#endif
/* WLZ_EXT_BIND */
52
53
/*!
54
* \def ALC_TEMPLATE_C1D(D,T,M,F)
55
* \ingroup AlcArray
56
* \brief A template for functions which allocate 1 dimensional
57
* zero'd arrays of any type.
58
* \param D Destination pointer, of type T *.
59
* \param T Type, eg char, short, int, ....
60
* \param M Number of elements in array.
61
* \param F String with name of function.
62
*/
63
#define ALC_TEMPLATE_C1D(D,T,M,F) \
64
AlcErrno alcErrno = ALC_ER_NONE; \
65
\
66
if((D) == NULL) \
67
alcErrno = ALC_ER_NULLPTR; \
68
else if((M) < 1) \
69
alcErrno = ALC_ER_NUMELEM; \
70
else if((*(D) = (T*)AlcCalloc((M), sizeof(T))) == NULL) \
71
alcErrno = ALC_ER_ALLOC; \
72
if(alcErrno != ALC_ER_NONE) \
73
{ \
74
if(D) \
75
*(D) = NULL; \
76
} \
77
return(alcErrno);
78
79
/*!
80
* \def ALC_TEMPLATE_M1D(D,T,M,F)
81
* \ingroup AlcArray
82
* \brief A template for functions which allocate 1 dimensional
83
* non-zero'd arrays of any type.
84
* \param D Destination pointer, of type T *.
85
* \param T Type, eg char, short, int, ....
86
* \param M Number of elements in array.
87
* \param F String with name of function.
88
*/
89
#define ALC_TEMPLATE_M1D(D,T,M,F) \
90
AlcErrno alcErrno = ALC_ER_NONE; \
91
\
92
if((D) == NULL) \
93
alcErrno = ALC_ER_NULLPTR; \
94
else if((M) < 1) \
95
alcErrno = ALC_ER_NUMELEM; \
96
else if((*(D) = (T*)AlcMalloc((M) * sizeof(T))) == NULL) \
97
alcErrno = ALC_ER_ALLOC; \
98
if(alcErrno != ALC_ER_NONE) \
99
{ \
100
if(D) \
101
*(D) = NULL; \
102
} \
103
return(alcErrno);
104
105
/*!
106
* \def ALC_TEMPLATE_C2D(D,T,M,N,F)
107
* \ingroup AlcArray
108
* \brief A template for functions which allocate 2 dimensional
109
* zero'd arrays of any type.
110
* \param D Destination pointer, of type T **.
111
* \param T Type, eg char, short, int, ....
112
* \param M Number of 1D arrays.
113
* \param N Number of elements in each 1D array.
114
* \param F String with name of function.
115
*/
116
#define ALC_TEMPLATE_C2D(D,T,M,N,F) \
117
size_t index; \
118
T *dump0 = NULL; \
119
T **dump1 = NULL; \
120
AlcErrno alcErrno = ALC_ER_NONE; \
121
\
122
if((D) == NULL) \
123
alcErrno = ALC_ER_NULLPTR; \
124
else if(((M) < 1) || ((N) < 1)) \
125
alcErrno = ALC_ER_NUMELEM; \
126
else if(((dump0 = (T*)AlcCalloc((M) * (N), sizeof(T))) == NULL) || \
127
((dump1 = (T**)AlcMalloc((M) * sizeof(T*))) == NULL)) \
128
alcErrno = ALC_ER_ALLOC; \
129
if(alcErrno == ALC_ER_NONE) \
130
{ \
131
*(D) = dump1; \
132
for(index = 0; index < (M); ++index) \
133
{ \
134
(*(D))[index] = dump0; \
135
dump0 += (N); \
136
} \
137
} \
138
else \
139
{ \
140
if(D) \
141
*(D) = NULL; \
142
if(dump0) \
143
AlcFree(dump0); \
144
if(dump1) \
145
AlcFree(dump1); \
146
} \
147
return(alcErrno);
148
149
/*!
150
* \def ALC_TEMPLATE_M2D(D,T,M,N,F)
151
* \ingroup AlcArray
152
* \brief A template for functions which allocate 2 dimensional
153
* non-zero'd arrays of any type.
154
* \param D Destination pointer, of type T **.
155
* \param T Type, eg char, short, int, ....
156
* \param M Number of 1D arrays.
157
* \param N Number of elements in each 1D array.
158
* \param F String with name of function.
159
*/
160
#define ALC_TEMPLATE_M2D(D,T,M,N,F) \
161
size_t index; \
162
T *dump0 = NULL; \
163
T **dump1 = NULL; \
164
AlcErrno alcErrno = ALC_ER_NONE; \
165
\
166
if((D) == NULL) \
167
alcErrno = ALC_ER_NULLPTR; \
168
else if(((M) < 1) || ((N) < 1)) \
169
alcErrno = ALC_ER_NUMELEM; \
170
else if(((dump0 = (T*)AlcMalloc((M) * (N) * sizeof(T))) == NULL) || \
171
((dump1 = (T**)AlcMalloc((M) * sizeof(T*))) == NULL)) \
172
alcErrno = ALC_ER_ALLOC; \
173
if(alcErrno == ALC_ER_NONE) \
174
{ \
175
*(D) = dump1; \
176
for(index = 0; index < (M); ++index) \
177
{ \
178
(*(D))[index] = dump0; \
179
dump0 += (N); \
180
} \
181
} \
182
else \
183
{ \
184
if(D) \
185
*(D) = NULL; \
186
if(dump0) \
187
AlcFree(dump0); \
188
if(dump1) \
189
AlcFree(dump1); \
190
} \
191
return(alcErrno);
192
193
/*!
194
* \def ALC_TEMPLATE_SYM_C2D(D,T,N,F)
195
* \ingroup AlcArray
196
* \brief A template for functions which allocate 2 dimensional
197
* zero'd symetric arrays of any type. Obviously symetric
198
* arrays are square, but in this representation only the
199
* lower trinagle is stored.
200
* \param D Destination pointer, of type T **.
201
* \param T Type, eg char, short, int, ....
202
* \param N Number of rows or columns.
203
* \param F String with name of function.
204
*/
205
#define ALC_TEMPLATE_SYM_C2D(D,T,N,F) \
206
size_t totElm, \
207
index, \
208
offset; \
209
T *dump0 = NULL; \
210
T **dump1 = NULL; \
211
AlcErrno alcErrno = ALC_ER_NONE; \
212
\
213
if((D) == NULL) \
214
{ \
215
alcErrno = ALC_ER_NULLPTR; \
216
} \
217
else if((N) < 1) \
218
{ \
219
alcErrno = ALC_ER_NUMELEM; \
220
} \
221
else \
222
{ \
223
totElm = ((N) * ((N) + 1)) / 2; \
224
if(((dump0 = (T*)AlcCalloc(totElm, sizeof(T))) == NULL) || \
225
((dump1 = (T**)AlcMalloc((N) * sizeof(T*))) == NULL)) \
226
{ \
227
alcErrno = ALC_ER_ALLOC; \
228
} \
229
} \
230
if(alcErrno == ALC_ER_NONE) \
231
{ \
232
offset = 0; \
233
*(D) = dump1; \
234
for(index = 0; index < (N); ++index) \
235
{ \
236
dump1[index] = dump0 + offset; \
237
offset += index + 1; \
238
} \
239
} \
240
else \
241
{ \
242
if(D) \
243
{ \
244
*(D) = NULL; \
245
} \
246
AlcFree(dump0); \
247
AlcFree(dump1); \
248
} \
249
return(alcErrno);
250
251
/*!
252
* \def ALC_TEMPLATE_SYM_M2D(D,T,N,F)
253
* \ingroup AlcArray
254
* \brief A template for functions which allocate 2 dimensional
255
* zero'd symetric arrays of any type. Obviously symetric
256
* arrays are square, but in this representation only the
257
* lower trinagle is stored.
258
* \param D Destination pointer, of type T **.
259
* \param T Type, eg char, short, int, ....
260
* \param N Number of rows or columns.
261
* \param F String with name of function.
262
*/
263
#define ALC_TEMPLATE_SYM_M2D(D,T,N,F) \
264
size_t totElm, \
265
index, \
266
offset; \
267
T *dump0 = NULL; \
268
T **dump1 = NULL; \
269
AlcErrno alcErrno = ALC_ER_NONE; \
270
\
271
if((D) == NULL) \
272
{ \
273
alcErrno = ALC_ER_NULLPTR; \
274
} \
275
else if((N) < 1) \
276
{ \
277
alcErrno = ALC_ER_NUMELEM; \
278
} \
279
else \
280
{ \
281
totElm = ((N) * ((N) + 1)) / 2; \
282
if(((dump0 = (T*)AlcMalloc(totElm * sizeof(T))) == NULL) || \
283
((dump1 = (T**)AlcMalloc((N) * sizeof(T*))) == NULL)) \
284
{ \
285
alcErrno = ALC_ER_ALLOC; \
286
} \
287
} \
288
if(alcErrno == ALC_ER_NONE) \
289
{ \
290
offset = 0; \
291
*(D) = dump1; \
292
for(index = 0; index < (N); ++index) \
293
{ \
294
dump1[index] = dump0 + offset; \
295
offset += index + 1; \
296
} \
297
} \
298
else \
299
{ \
300
if(D) \
301
{ \
302
*(D) = NULL; \
303
} \
304
AlcFree(dump0); \
305
AlcFree(dump1); \
306
} \
307
return(alcErrno);
308
309
/*!
310
* \def ALC_TEMPLATE_F2D(D,F)
311
* \ingroup AlcArray
312
* \brief A template for functions which free 2 dimensional
313
* arrays of any type, actualy no type information
314
* is used in freeing the array.
315
* \param D Pointer for array to be free'd.
316
* \param F String with name of function.
317
*/
318
#define ALC_TEMPLATE_F2D(D,F) \
319
AlcErrno alcErrno = ALC_ER_NONE; \
320
\
321
if((D == NULL) || (*(D) == NULL)) \
322
{ \
323
alcErrno = ALC_ER_NULLPTR; \
324
} \
325
else \
326
{ \
327
AlcFree(*(D)); \
328
AlcFree(D); \
329
} \
330
return(alcErrno);
331
332
333
/*!
334
* \def ALC_TEMPLATE_C3D(D,T,M,N,O,F)
335
* \ingroup AlcArray
336
* \brief A template for functions which allocate 3 dimensional
337
* zero'd arrays of any type.
338
* \param D Destination pointer, of type T **.
339
* \param T Type, eg char, short, int, ....
340
* \param M Number of 2D arrays.
341
* \param N Number of 1D arrays.
342
* \param O Number of elements in each 1D array.
343
* \param F String with name of function.
344
*/
345
#define ALC_TEMPLATE_C3D(D,T,M,N,O,F) \
346
size_t index0, \
347
index1; \
348
T *dump0 = NULL, \
349
**dump1 = NULL, \
350
***dump2 = NULL; \
351
AlcErrno alcErrno = ALC_ER_NONE; \
352
\
353
if((D) == NULL) \
354
alcErrno = ALC_ER_NULLPTR; \
355
else if(((M) < 1) || ((N) < 1) || ((O) < 1)) \
356
alcErrno = ALC_ER_NUMELEM; \
357
else if(((dump0 = (T*)AlcCalloc((M) * (N) * (O), sizeof(T))) == NULL) || \
358
((dump1 = (T**)AlcMalloc((M) * (N) * sizeof(T*))) == NULL) || \
359
((dump2 = (T***)AlcMalloc((M) * sizeof(T**))) == NULL)) \
360
alcErrno = ALC_ER_ALLOC; \
361
if(alcErrno == ALC_ER_NONE) \
362
{ \
363
*(D) = dump2; \
364
for(index0 = 0; index0 < (M); ++index0) \
365
{ \
366
for(index1=0; index1 < (N); ++index1) \
367
{ \
368
dump1[index1] = dump0; \
369
dump0 += (O); \
370
} \
371
(*(D))[index0] = dump1; \
372
dump1 += (N); \
373
} \
374
} \
375
else \
376
{ \
377
if(D) \
378
*(D) = NULL; \
379
if(dump2) \
380
AlcFree(dump2); \
381
if(dump1) \
382
AlcFree(dump1); \
383
if(dump0) \
384
AlcFree(dump0); \
385
} \
386
return(alcErrno);
387
388
/*!
389
* \def ALC_TEMPLATE_M3D(D,T,M,N,O,F)
390
* \ingroup AlcArray
391
* \brief A template for functions which allocate 3 dimensional
392
* non-zero'd arrays of any type.
393
* \param D Destination pointer, of type T **.
394
* \param T Type, eg char, short, int, ....
395
* \param M Number of 2D arrays.
396
* \param N Number of 1D arrays.
397
* \param O Number of elements in each 1D array.
398
* \param F String with name of function.
399
*/
400
#define ALC_TEMPLATE_M3D(D,T,M,N,O,F) \
401
size_t index0, \
402
index1; \
403
T *dump0 = NULL, \
404
**dump1 = NULL, \
405
***dump2 = NULL; \
406
AlcErrno alcErrno = ALC_ER_NONE; \
407
\
408
if((D) == NULL) \
409
alcErrno = ALC_ER_NULLPTR; \
410
else if(((M) < 1) || ((N) < 1) || ((O) < 1)) \
411
alcErrno = ALC_ER_NUMELEM; \
412
else if(((dump0 = (T*)AlcMalloc((M) * (N) * (O) * sizeof(T))) == NULL) || \
413
((dump1 = (T**)AlcMalloc((M) * (N) * sizeof(T*))) == NULL) || \
414
((dump2 = (T***)AlcMalloc((M) * sizeof(T**))) == NULL)) \
415
alcErrno = ALC_ER_ALLOC; \
416
if(alcErrno == ALC_ER_NONE) \
417
{ \
418
*(D) = dump2; \
419
for(index0 = 0; index0 < (M); ++index0) \
420
{ \
421
for(index1=0; index1 < (N); ++index1) \
422
{ \
423
dump1[index1] = dump0; \
424
dump0 += (O); \
425
} \
426
(*(D))[index0] = dump1; \
427
dump1 += (N); \
428
} \
429
} \
430
else \
431
{ \
432
if(D) \
433
*(D) = NULL; \
434
if(dump2) \
435
AlcFree(dump2); \
436
if(dump1) \
437
AlcFree(dump1); \
438
if(dump0) \
439
AlcFree(dump0); \
440
} \
441
return(alcErrno);
442
443
/*!
444
* \def ALC_TEMPLATE_F3D(D,F)
445
* \ingroup AlcArray
446
* \brief A template for functions which free 3 dimensional
447
* arrays of any type, actualy no type information
448
* is used in freeing the array.
449
* \param D Pointer for array to be free'd.
450
* \param F String with name of function.
451
*/
452
#define ALC_TEMPLATE_F3D(D,F) \
453
AlcErrno alcErrno = ALC_ER_NONE; \
454
\
455
if((D == NULL) || (*(D) == NULL) || (**(D) == NULL)) \
456
{ \
457
alcErrno = ALC_ER_NULLPTR; \
458
} \
459
else \
460
{ \
461
AlcFree(**(D)); \
462
AlcFree(*(D)); \
463
AlcFree(D); \
464
} \
465
return(alcErrno);
466
467
#ifndef WLZ_EXT_BIND
468
#ifdef __cplusplus
469
}
/* Close scope of 'extern "C" */
470
#endif
471
#endif
/* WLZ_EXT_BIND */
472
473
#endif
/* ALCTEMPLATES_H */
export
data0
bill
MouseAtlas
Build
src
Woolz
libAlc
AlcTemplates.h
Generated by
1.8.14