~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina5/tina-libs/tina/sys/sysMem_dynamic_n_ts.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/sys/sysMem_dynamic_n_ts.c,v $
 37  * Date    :  $Date: 2003/09/22 16:09:02 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: sysMem_dynamic_n_ts.c,v 1.3 2003/09/22 16:09:02 tony Exp $
 40  *
 41  * Notes :
 42  *
 43  *  Vector (1 dimension array) handling for Tstructs
 44  *  Allocate and free displaced vectors & arrays.
 45  *  Elements (of general size) are initialised to zero.
 46  *
 47  *********
 48 */
 49 
 50 #include "sysMem_dynamic_n_ts.h"
 51 
 52 #if HAVE_CONFIG_H
 53   #include <config.h>
 54 #endif
 55 
 56 #include <math.h>
 57 #include <stdio.h>
 58 #include <tina/sys/sys_GenDef.h>
 59 #include <tina/sys/sysMem_dynamic_n.h>
 60 #include <tina/sys/sysGen_error.h>
 61 #include <tina/sys/sysMem_ralloc.h>
 62 
 63 
 64 /* Allocate and tag multiple Tina structures */
 65 void *ts_nralloc_fn(int n, size_t size, Ts_id ts_id)
 66 {
 67         char *structure = (char *) ralloc(n * size);
 68 
 69         while (n--)
 70         {
 71                 *(Ts_id *) (structure + n * size) = ts_id;
 72         }
 73 
 74         return (void *) structure;
 75 }
 76 
 77 /* Generic tagged structure create function */
 78 void *ts_ralloc_fn(size_t size, Ts_id ts_id)
 79 {
 80         void *structure = (void *) ralloc(size);
 81 
 82         *(Ts_id *) structure = ts_id;
 83         return structure;
 84 }
 85 
 86 /* Displaced array of Tstruct's whose type is coded by ts_id.
 87  * vector[i]: n1 <= i < n2 */
 88 void *ts_nvector_alloc_fn(int n1, int n2, size_t size, Ts_id ts_id)
 89 {
 90         char *nvector;
 91         if (n1 >= n2)
 92                 return (NULL);
 93 
 94         nvector = ts_nralloc_fn((n2 - n1), size, ts_id);
 95 /* store offset vector for checking later NAT 1999 see also dynamic.c */
 96         nvector_test((void *) nvector, n1, size, true);
 97         nvector -= n1 * size;
 98         return ((void *) nvector);
 99 }
100 
101 /* Displaced array of Tstruct's whose type is coded by ts_id.
102  * array[i][j]: m1 <= i < m2, n1 <= j < n2 */
103 void **ts_narray_alloc_fn(int m1, int n1, int m2, int n2, size_t size,
104                                                                                                         Ts_id ts_id)
105 {
106         int i;
107         void **array = NULL;
108 
109         if (m1 < m2 && n1 < n2)
110         {
111                 array = (void **) nvector_alloc(m1, m2, sizeof(void *));
112                 for (i = m1; i < m2; ++i)
113                 {
114                         array[i] = ts_nvector_alloc_fn(n1, n2, size, ts_id);
115                 }
116         }
117         return array;
118 }
119 
120 /* Displaced lower triangle of Tstruct's whose type is coded by ts_id.
121  * Element size s a[i][j]: n1 <=i < n2, i <= j < n2. */
122 void **ts_nlower_alloc_fn(int n1, int n2, size_t size, Ts_id ts_id)
123 {
124         char **a;
125         int n = n2 - n1;
126         int i;
127 
128         if (n < 1)
129                 return (NULL);
130         a = (char **) nvector_alloc(n1, n2, sizeof(char *));
131         for (i = n1; i < n2; ++i)
132                 a[i] = (char *) ts_nvector_alloc_fn(n1, i + 1, size, ts_id);
133         return ((void **) a);
134 }
135 
136 /* Displaced upper triangle of Tstruct's whose type is coded by ts_id.
137  * Element size s a[i][j]: n1 <=i < n2, i <= j < n2. */
138 void **ts_nupper_alloc_fn(int n1, int n2, size_t size, Ts_id ts_id)
139 {
140         char **a;
141         int n = n2 - n1;
142         int i;
143 
144         if (n < 1)
145                 return (NULL);
146         a = (char **) nvector_alloc(n1, n2, sizeof(char *));
147         for (i = n1; i < n2; ++i)
148                 a[i] = (char *) ts_nvector_alloc_fn(i, n2, size, ts_id);
149         return ((void **) a);
150 }
151 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.