gCAD3D 2.40
ut_memTab.h
Go to the documentation of this file.
1 /* MemTab 2003-05-20 franz.reiter@cadcam.co.at
2 ../ut/ut_memTab.h
3 for Functions see ../ut/ut_memTab.c
4 
5 
6 */
11 #define def_MemTab(vTyp1)\
27  typedef struct {vTyp1 *data; int rMax, rNr, rSiz;\
28  unsigned char typ, incSiz, use, spcTyp;}
29 // size = 20
30 
32 #define typedef_MemTab(vTyp1)\
33  def_MemTab(vTyp1) MemTab_##vTyp1
34 
36 #define MemTab(vTyp1) MemTab_##vTyp1
37 // #define MemTab(vTyp1) (MemTab_##vTyp1) = { ((void *)0), -1, -1}
38 
39 // #define _MEMTAB_NUL {NULL, 0, 0, 0, ' ',' ',' ',' '}
40 #define _MEMTAB_NUL {NULL, 0, 0, 0}
41 
43 def_MemTab(void) MemTab;
44 
45 
46 
47 //================================================================
48 // prototypes:
49 int MemTab_ini (void *memTab, int rSiz, int typ, int incSiz);
50 int MemTab_add (void *memTab, long *spcOff, void* objDat, int recNr, int mode);
51 // inline:
52 void MEMTAB_tmpSpc_get (MemTab *memTab, int rTot);
53 void MEMTAB_tmpSpc_free (MemTab*);
54 int MEMTAB_IND (MemTab*);
55 int MEMTAB_RMAX (MemTab*); // get max. nr of records
56 int MEMTAB_RSIZ (MemTab*);
57 void *MEMTAB__ (MemTab *memTab, int ind);
58 void *MEMTAB_DAT (MemTab*);
59 void *MEMTAB_POS (MemTab*);
60 int MEMTAB_IND_POS (MemTab*, void*);
61 
62 
63 //================================================================
64 // inline functions:
65 
66 
80 #ifdef _MSC_VER
81 #define MEMTAB_tmpSpc_get(mtb1,rTot)\
82  (mtb1)->data=NULL;\
83  (mtb1)->rSiz=sizeof(*(mtb1)->data);\
84  (mtb1)->rNr=(rTot)*(mtb1)->rSiz;\
85  if((mtb1)->rNr < SPC_MAX_STK) (mtb1)->data = _alloca ((mtb1)->rNr + 64);\
86  if(!(mtb1)->data) {\
87  (mtb1)->data = malloc ((mtb1)->rNr);\
88  (mtb1)->spcTyp = 0;\
89  (mtb1)->incSiz = (mtb1)->rNr / 2;\
90  } else {\
91  (mtb1)->spcTyp = 3;\
92  (mtb1)->incSiz = UINT_8_MAX; }\
93  (mtb1)->rMax = rTot;\
94  (mtb1)->rNr = 0;
95 #else
96 #define MEMTAB_tmpSpc_get(mtb1,rTot)\
97  (mtb1)->data=NULL;\
98  (mtb1)->rSiz=sizeof(*(mtb1)->data);\
99  (mtb1)->rNr=(rTot)*(mtb1)->rSiz;\
100  if((mtb1)->rNr < SPC_MAX_STK) (mtb1)->data = alloca ((mtb1)->rNr);\
101  if(!(mtb1)->data) {\
102  (mtb1)->data = malloc ((mtb1)->rNr);\
103  (mtb1)->spcTyp = 0;\
104  (mtb1)->incSiz = (mtb1)->rNr / 2;\
105  } else {\
106  (mtb1)->spcTyp = 3;\
107  (mtb1)->incSiz = UINT_8_MAX; }\
108  (mtb1)->rMax = rTot;\
109  (mtb1)->rNr = 0;
110 #endif
111 
113 #define MEMTAB_tmpSpc_free(mtb1)\
114  if((mtb1)->spcTyp < 2) free ((mtb1)->data);
115 
116 
117 
118 // MEMTAB__ get pointer to data-record from index
119 // MemTab(ObjDB) mtPar = _MEMTAB_NUL; long dli;
120 // dli = (MEMTAB__(&mtPar,ii))->dlInd; // get a part of ObjDB-data index ii
121 #define MEMTAB__(mtb,irec)\
122  (&((mtb)->data[irec]))
123 
124 // MEMTAB_IND get or set index (next free = nr of used) INLINE
125 // Example: see MEMTAB_tmpSpc_get__
126 #define MEMTAB_IND(mtb)\
127  ((mtb)->rNr)
128 
129 // MEMTAB_RESET_IND reset index (nr of used = 0) INLINE
130 #define MEMTAB_RESET_IND(mtb)\
131  ((mtb)->rNr=0)
132 
133 // MEMTAB_RMAX get max. nr of records INLINE
134 #define MEMTAB_RMAX(mtb)\
135  ((mtb)->rMax)
136 
137 // MEMTAB_RSIZ get record size INLINE
138 #define MEMTAB_RSIZ(mtb)\
139  ((mtb)->rSiz)
140 
141 // MEMTAB_RFREE get nr of free records INLINE
142 #define MEMTAB_RFREE(mtb)\
143  ((mtb)->rMax - (mtb)->rSiz)
144 
145 // MEMTAB_DAT get data-record complete INLINE
146 #define MEMTAB_DAT(mtb)\
147  ((mtb)->data)
148 
149 
150 // MEMTAB_POS get position of next data-record INLINE
151 // DOES NOT WORK IF data=NULL: use MemTab_check before.
152 // Example:
153 // // check for space for 4 points
154 // MemTab_check (pmt, &l1, 4);
155 // // get pointer to data
156 // pa = MEMTAB_POS (pmt);
157 // // save point-data
158 // MemTab_sav (pmt, &l1, points, 4);
159 // // pa now is adress of points
160 #define MEMTAB_POS(mtb)\
161  (&((mtb)->data[(mtb)->rNr]))
162 
163 
164 // MEMTAB_IND_POS get record-index from position INLINE
165 #define MEMTAB_IND_POS(mtb,pos)\
166  (((char*)pos - (char*)(mtb)->data) / (mtb)->rSiz)
167 
168 
169 // MEMTAB_IS_EMPTY test if MemTab.data == NULL
170 #define MEMTAB_IS_EMPTY(mtb)\
171  (mtb)->data == NULL
172 
173 
174 // EOF
int typ
Definition: xa_tra.c:151
#define MEMTAB_DAT(mtb)
Definition: ut_memTab.h:146
#define MEMTAB_IND(mtb)
Definition: ut_memTab.h:126
int MemTab_ini(void *mtbv, int rSiz, int typ, int incSiz)
Definition: ut_memTab.c:256
#define MEMTAB_RMAX(mtb)
Definition: ut_memTab.h:134
char mode
Definition: xa_tra.c:152
int MemTab_add(void *mtbv, long *spcOff, void *objDat, int recNr, int mode)
Definition: ut_memTab.c:310
#define MEMTAB_tmpSpc_free(mtb1)
MEMTAB_tmpSpc_free free memSpace from MEMTAB_tmpSpc_get.
Definition: ut_memTab.h:113
#define MEMTAB_RSIZ(mtb)
Definition: ut_memTab.h:138
#define MEMTAB_IND_POS(mtb, pos)
Definition: ut_memTab.h:165
#define MemTab(vTyp1)
template for the typename:
Definition: ut_memTab.h:36
#define MEMTAB_POS(mtb)
Definition: ut_memTab.h:160
#define MEMTAB_tmpSpc_get(mtb1, rTot)
Definition: ut_memTab.h:96
#define def_MemTab(vTyp1)
Definition: ut_memTab.h:26
int ind
Definition: xa_tra.c:151
#define MEMTAB__(mtb, irec)
Definition: ut_memTab.h:121