Lines Matching defs:obj
33 int DynAppend(obj, els, num)
34 DynObjectP obj;
38 return DynInsert(obj, DynSize(obj), els, num);
58 DynObjectP obj;
60 obj = (DynObjectP) malloc(sizeof(DynObjectRecP));
61 if (obj == NULL)
64 obj->array = (DynPtr) malloc(1);
65 if (obj->array == NULL) {
66 free(obj);
69 obj->array[0] = '\0';
71 obj->el_size = el_size;
72 obj->num_el = obj->size = 0;
73 obj->debug = obj->paranoid = 0;
74 obj->inc = (inc) ? inc : default_increment;
75 obj->initzero = 0;
77 return obj;
80 DynObjectP DynCopy(obj)
81 DynObjectP obj;
89 obj1->el_size = obj->el_size;
90 obj1->num_el = obj->num_el;
91 obj1->size = obj->size;
92 obj1->inc = obj->inc;
93 obj1->debug = obj->debug;
94 obj1->paranoid = obj->paranoid;
95 obj1->initzero = obj->initzero;
101 memcpy(obj1->array, obj->array,
107 int DynDestroy(obj)
108 /*@only@*/DynObjectP obj;
110 if (obj->paranoid) {
111 if (obj->debug)
113 obj->el_size * obj->size, obj->array);
114 memset(obj->array, 0, (size_t) (obj->el_size * obj->size));
116 free(obj->array);
117 free(obj);
121 int DynRelease(obj)
122 DynObjectP obj;
124 if (obj->debug)
126 free(obj);
137 int DynDebug(obj, state)
138 DynObjectP obj;
141 obj->debug = state;
158 int DynDelete(obj, idx)
159 DynObjectP obj;
163 if (obj->debug)
168 if (idx >= obj->num_el) {
169 if (obj->debug)
171 obj->num_el);
175 if (idx == obj->num_el-1) {
176 if (obj->paranoid) {
177 if (obj->debug)
179 memset(obj->array + idx*obj->el_size, 0, (size_t) obj->el_size);
182 if (obj->debug)
187 if (obj->debug)
190 obj->el_size*(obj->num_el - idx), obj->array,
191 (idx+1)*obj->el_size, idx*obj->el_size);
193 memmove(obj->array + idx*obj->el_size,
194 obj->array + (idx+1)*obj->el_size,
195 (size_t) obj->el_size*(obj->num_el - idx));
196 if (obj->paranoid) {
197 if (obj->debug)
200 obj->el_size, obj->array,
201 obj->el_size*(obj->num_el - 1));
202 memset(obj->array + obj->el_size*(obj->num_el - 1), 0,
203 (size_t) obj->el_size);
207 --obj->num_el;
209 if (obj->debug)
222 int DynInitzero(obj, state)
223 DynObjectP obj;
226 obj->initzero = state;
228 if (obj->debug)
240 int DynInsert(obj, idx, els_in, num)
241 DynObjectP obj;
248 if (idx < 0 || idx > obj->num_el) {
249 if (obj->debug)
251 idx, obj->num_el);
256 if (obj->debug)
262 if (obj->debug)
264 (obj->num_el-idx)*obj->el_size, obj->array,
265 obj->el_size*idx, obj->el_size*(idx+num));
267 if ((ret = _DynResize(obj, obj->num_el + num)) != DYN_OK)
269 memmove(obj->array + obj->el_size*(idx + num),
270 obj->array + obj->el_size*idx,
271 (size_t) ((obj->num_el-idx)*obj->el_size));
273 if (obj->debug)
275 obj->el_size*num, els, obj->array, obj->el_size*idx);
277 memmove(obj->array + obj->el_size*idx, els, (size_t) (obj->el_size*num));
278 obj->num_el += num;
280 if (obj->debug)
293 int DynParanoid(obj, state)
294 DynObjectP obj;
297 obj->paranoid = state;
299 if (obj->debug)
311 DynPtr DynArray(obj)
312 DynObjectP obj;
314 if (obj->debug)
316 obj->array);
318 return obj->array;
321 DynPtr DynGet(obj, num)
322 DynObjectP obj;
326 if (obj->debug)
331 if (num >= obj->num_el) {
332 if (obj->debug)
334 obj->num_el);
338 if (obj->debug)
340 obj->array, obj->el_size*num);
342 return (DynPtr) obj->array + obj->el_size*num;
345 int DynAdd(obj, el)
346 DynObjectP obj;
351 ret = DynPut(obj, el, obj->num_el);
355 ++obj->num_el;
364 * obj->num_el) will not be updated properly and many other functions
367 int DynPut(obj, el_in, idx)
368 DynObjectP obj;
375 if (obj->debug)
377 obj->el_size, el, obj->array, idx*obj->el_size);
379 if ((ret = _DynResize(obj, idx)) != DYN_OK)
382 memmove(obj->array + idx*obj->el_size, el, (size_t) obj->el_size);
384 if (obj->debug)
400 int _DynResize(obj, req)
401 DynObjectP obj;
406 if (obj->size > req)
408 else if (obj->inc > 0)
409 return _DynRealloc(obj, (req - obj->size) / obj->inc + 1);
411 if (obj->size == 0)
412 size = -obj->inc;
414 size = obj->size;
421 return _DynRealloc(obj, size);
426 * Resize the array by num_incs units. If obj->inc is positive, this
427 * means make it obj->inc*num_incs elements larger. If obj->inc is
433 int _DynRealloc(obj, num_incs)
434 DynObjectP obj;
440 if (obj->inc > 0)
441 new_size_in_bytes = obj->el_size*(obj->size + obj->inc*num_incs);
443 new_size_in_bytes = obj->el_size*num_incs;
445 if (obj->debug)
448 new_size_in_bytes - obj->el_size*obj->size,
451 temp = (DynPtr) realloc(obj->array, (size_t) new_size_in_bytes);
453 if (obj->debug)
458 obj->array = temp;
459 if (obj->inc > 0)
460 obj->size += obj->inc*num_incs;
462 obj->size = num_incs;
465 if (obj->debug)
478 int DynSize(obj)
479 DynObjectP obj;
481 if (obj->debug)
482 fprintf(stderr, "dyn: size: returning size %d.\n", obj->num_el);
484 return obj->num_el;
487 int DynCapacity(obj)
488 DynObjectP obj;
490 if (obj->debug)
491 fprintf(stderr, "dyn: capacity: returning cap of %d.\n", obj->size);
493 return obj->size;