view anagram/agcore/arrays.h @ 5:7661c1604e49

Add additional operator delete calls gcc 10 asked for.
author David A. Holland
date Mon, 30 May 2022 23:32:56 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * 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 */