Mercurial > ~dholland > hg > ag > index.cgi
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/anagram/agcore/arrays.h Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,73 @@ +/* + * AnaGram, A System for Syntax Directed Programming + * Copyright 1993-2002 Parsifal Software. All Rights Reserved. + * See the file COPYING for license and usage terms. + * + * arrays.h - old arrays + */ + +#ifndef ARRAYS_H +#define ARRAYS_H + +#include "assert.h" + +struct tsd; + + +void *init_array(void); + +#define MAP(name,size) \ + map_##name = (name##_map *)init_array(size,sizeof(name##_map)) + +void *check_array_size(void *ptr, unsigned n1, unsigned n); + +#define check_size(a,n1,n2) (*(void **)(&a) = check_array_size((a),(n1),(n2))) + +int ok_index(void *, unsigned); + +//int array_ok(void *ptr); +void *delete_array(void *a); +void *init_array(unsigned n, unsigned size); +void *reset_array(void *a); +void *set_array_size(void *ptr, unsigned n); + +int store_list_data(unsigned *list); +int store_tuple_data(tsd *t, unsigned *list); +void *check_list_size(unsigned *list, unsigned n); +//void *init_list(int n); + + +#define lstptr(map, name) (name##_list + (map).name##_index) + +#define store_list(list) \ + store_list_data((list) = (unsigned *) \ + check_list_size(list,tis())) + +#define store_tuples(t,list) \ + store_tuple_data((t), (list) = (unsigned *) \ + check_list_size((list),t->nt*t->tw)) + +unsigned *reset_list(unsigned *, unsigned); +void *reset_array_size(void *, unsigned, unsigned); +//void *slide_array(void *); + +void *check_local_array(void *); +#define local_array(n,type) (type *)check_local_array(alloca((n)*sizeof(type))) + +template <class T> +class LocalArray { +private: + T *data; + unsigned length; + LocalArray(const LocalArray<T> &) : data(0) {} + +public: + LocalArray(int n) : data(new T[n]), length(n) {} + ~LocalArray() {delete [] data;} + operator T* () {return data;} + T &operator [](int x) { assert((unsigned) x < length); return data[x]; } + T &operator [](unsigned x) { assert(x < length); return data[x]; } +}; + + +#endif /* ARRAYS_H */