Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

lib/gas.h

Go to the documentation of this file.
00001 #ifndef _VCL_GAS_H_
00002 #define _VCL_GAS_H_
00003 
00013 #include <stdlib.h>
00014 
00015 struct vcl_growing_array
00016 {
00017   void *array;
00018   int used;
00019   int size;
00020   int item_size;
00021 };
00022 
00023 
00024 #define VCL_GA_REF(GA, INDEX, TYPE) (((TYPE *) ((GA) -> array)) [INDEX])
00025 #define VCL_GA_REF_LAST(GA, TYPE) (((TYPE *) ((GA) -> array)) [(GA) -> used - 1])
00026 
00027 
00028 extern void
00029 vcl_ga_init (struct vcl_growing_array *ga, int init_items, int item_size);
00030 
00031 
00032 extern void
00033 vcl_ga_ensure (struct vcl_growing_array *ga, int pos);
00034 
00035 
00036 static inline struct vcl_growing_array *
00037 vcl_ga_new (int init_items, int item_size)
00038 {
00039   struct vcl_growing_array *ga = xmalloc (sizeof (struct vcl_growing_array));
00040   vcl_ga_init (ga, init_items, item_size);
00041   return (ga);
00042 }
00043 
00044 static inline void
00045 vcl_ga_flush (struct vcl_growing_array *ga)
00046 {
00047   ga -> used = 0;
00048 }
00049 
00050 static inline void
00051 vcl_ga_finish (struct vcl_growing_array *ga)
00052 {
00053   xfree (ga -> array);
00054 }
00055 
00056 static inline void
00057 vcl_ga_destroy (struct vcl_growing_array *ga)
00058 {
00059   vcl_ga_finish (ga);
00060   xfree (ga);
00061 }
00062 
00063 static inline int
00064 vcl_ga_new_item (struct vcl_growing_array *ga)
00065 {
00066   int i = ga -> used ++;
00067   vcl_ga_ensure (ga, i);
00068   return (i);
00069 }
00070 
00071 static inline void *
00072 vcl_ga_allocate (struct vcl_growing_array *ga, int items)
00073 {
00074   int i = ga -> used;
00075   ga -> used += items;
00076   vcl_ga_ensure (ga, ga -> used - 1);
00077   return ((void *) (((char *) ga -> array) + (i * ga -> item_size)));
00078 }
00079 
00080 static inline void *
00081 vcl_ga_unallocate (struct vcl_growing_array *ga, int items)
00082 {
00083   ga -> used -= items;
00084   ASSERT (ga -> used >= 0);
00085   return ((void *) (((char *) ga -> array) + (ga -> used * ga -> item_size)));
00086 }
00087 
00088 
00089 #endif

Generated on Tue Dec 9 16:30:08 2008 for Vrr by doxygen 1.3.5