#ifndef ARRAYLIST_H #define ARRAYLIST_H typedef entity ArrayList; .int al_buf; .int al_len; #define AL_NEW(this, n, default, T) \ MACRO_BEGIN \ { \ ArrayList _al = this = new(ArrayList); \ make_pure(_al); \ _al.al_buf = buf_create(); \ for (int i = 0, _n = _al.al_len = n; i < _n; ++i) \ { \ const _AL_type__##T() it = default; \ AL_set##T(this, i, it); \ } \ } MACRO_END #define AL_DELETE(this) \ MACRO_BEGIN \ { \ buf_del(this.al_buf); \ remove(this); \ this = NULL; \ } MACRO_END #define _AL_type__s() string #define AL_gets(this, idx) bufstr_get(this.al_buf, idx) #define AL_sets(this, idx, val) bufstr_set(this.al_buf, idx, val) #define _AL_type__f() float #define AL_getf(this, idx) stof(AL_gets(this, idx)) #define AL_setf(this, idx, val) AL_sets(this, idx, ftos(val)) #define _AL_type__e() entity #define AL_gete(this, idx) ftoe(AL_getf(this, idx)) #define AL_sete(this, idx, val) AL_setf(this, idx, etof(val)) #define AL_EACH(this, T, cond, body) \ MACRO_BEGIN \ { \ const noref ArrayList _al = this; \ for (int i = 0, n = _al.al_len; i < n; ++i) \ { \ const noref _AL_type__##T() it = AL_get##T(_al, i); \ if (cond) { body } \ } \ } MACRO_END #endif