Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/agcore/arrays.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * arrays.h - old arrays | |
7 */ | |
8 | |
9 #ifndef ARRAYS_H | |
10 #define ARRAYS_H | |
11 | |
12 #include "assert.h" | |
13 | |
14 struct tsd; | |
15 | |
16 | |
17 void *init_array(void); | |
18 | |
19 #define MAP(name,size) \ | |
20 map_##name = (name##_map *)init_array(size,sizeof(name##_map)) | |
21 | |
22 void *check_array_size(void *ptr, unsigned n1, unsigned n); | |
23 | |
24 #define check_size(a,n1,n2) (*(void **)(&a) = check_array_size((a),(n1),(n2))) | |
25 | |
26 int ok_index(void *, unsigned); | |
27 | |
28 //int array_ok(void *ptr); | |
29 void *delete_array(void *a); | |
30 void *init_array(unsigned n, unsigned size); | |
31 void *reset_array(void *a); | |
32 void *set_array_size(void *ptr, unsigned n); | |
33 | |
34 int store_list_data(unsigned *list); | |
35 int store_tuple_data(tsd *t, unsigned *list); | |
36 void *check_list_size(unsigned *list, unsigned n); | |
37 //void *init_list(int n); | |
38 | |
39 | |
40 #define lstptr(map, name) (name##_list + (map).name##_index) | |
41 | |
42 #define store_list(list) \ | |
43 store_list_data((list) = (unsigned *) \ | |
44 check_list_size(list,tis())) | |
45 | |
46 #define store_tuples(t,list) \ | |
47 store_tuple_data((t), (list) = (unsigned *) \ | |
48 check_list_size((list),t->nt*t->tw)) | |
49 | |
50 unsigned *reset_list(unsigned *, unsigned); | |
51 void *reset_array_size(void *, unsigned, unsigned); | |
52 //void *slide_array(void *); | |
53 | |
54 void *check_local_array(void *); | |
55 #define local_array(n,type) (type *)check_local_array(alloca((n)*sizeof(type))) | |
56 | |
57 template <class T> | |
58 class LocalArray { | |
59 private: | |
60 T *data; | |
61 unsigned length; | |
62 LocalArray(const LocalArray<T> &) : data(0) {} | |
63 | |
64 public: | |
65 LocalArray(int n) : data(new T[n]), length(n) {} | |
66 ~LocalArray() {delete [] data;} | |
67 operator T* () {return data;} | |
68 T &operator [](int x) { assert((unsigned) x < length); return data[x]; } | |
69 T &operator [](unsigned x) { assert(x < length); return data[x]; } | |
70 }; | |
71 | |
72 | |
73 #endif /* ARRAYS_H */ |