ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/vector.h
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/vector.h (file contents):
Revision 1.1 by ats, Sun Apr 4 21:17:58 2004 UTC vs.
Revision 1.6 by ats, Mon Apr 5 15:40:15 2004 UTC

# Line 7 | Line 7 | typedef struct {
7          size_t item_size;
8          int used_count;
9          int alloc_count;
10 +        int error;
11          int block_size;
12          vector_init_function init_fn;
13          vector_destroy_function destroy_fn;
14   } vector_header;
15  
16 < int statgrab_vector_resize(void **vector, vector_header *h, int count);
16 <
17 < /* Declare a vector. Specify the init/destroy functions as NULL if you don't
18 < * need them. The block size is how many items to allocate at once. */
19 < #define VECTOR_DECLARE(name, item_type, block_size, init_fn, destroy_fn) \
20 <        item_type * name = NULL; \
16 > #define VECTOR_HEADER(name, item_type, block_size, init_fn, destroy_fn) \
17          vector_header name##_header = { \
18                  sizeof(item_type), \
19                  0, \
20                  0, \
21 +                0, \
22                  block_size, \
23                  (vector_init_function) init_fn, \
24                  (vector_destroy_function) destroy_fn \
25          }
26  
27 + /* Internal function to resize the vector. */
28 + void *sg_vector_resize(void *vector, vector_header *h, int count);
29 +
30 + /* Declare a vector. Specify the init/destroy functions as NULL if you don't
31 + * need them. The block size is how many items to allocate at once. */
32 + #define VECTOR_DECLARE(name, item_type, block_size, init_fn, destroy_fn) \
33 +        item_type *name = NULL; \
34 +        VECTOR_HEADER(name, item_type, block_size, init_fn, destroy_fn)
35 +
36 + /* As VECTOR_DECLARE, but for a static vector. */
37 + #define VECTOR_DECLARE_STATIC(name, item_type, block_size, init_fn, destroy_fn) \
38 +        static item_type *name = NULL; \
39 +        static VECTOR_HEADER(name, item_type, block_size, init_fn, destroy_fn)
40 +
41   /* Return the current size of a vector. */
42   #define VECTOR_SIZE(name) \
43          name##_header.used_count
# Line 35 | Line 46 | int statgrab_vector_resize(void **vector, vector_heade
46   * out-of-memory, the old contents of the vector will be destroyed and the old
47   * vector will be freed. */
48   #define VECTOR_RESIZE(name, num_items) \
49 <        statgrab_vector_resize((void **) &name, &name##_header, num_items)
49 >        (name = sg_vector_resize((char *) name, &name##_header, num_items), \
50 >         name##_header.error)
51  
52   /* Free a vector, destroying its contents. */
53   #define VECTOR_FREE(name) \
54          VECTOR_RESIZE(name, 0)
43
55  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines