#ifndef ARRAYLIST_H
#define ARRAYLIST_H
-typedef int ArrayList;
+typedef entity ArrayList;
+.int al_buf;
+.int al_len;
-#define AL_declare(this) ArrayList this; int this##_len = (0)
-#define AL_init(this, n, default, T) \
+#define AL_NEW(this, n, default, T) \
do \
{ \
- this = buf_create(); \
- this##_len = n; \
- for (int i = 0; i < this##_len; ++i) \
+ 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); \
} \
} \
while (0)
-#define AL_delete(this) buf_del(this)
+
+#define AL_DELETE(this) \
+ do \
+ { \
+ buf_del(this.al_buf); \
+ remove(this); \
+ this = NULL; \
+ } \
+ while (0)
#define _AL_type__s() string
-#define AL_gets(this, idx) bufstr_get(this, idx)
-#define AL_sets(this, idx, val) bufstr_set(this, idx, val)
+#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))
do \
{ \
const noref ArrayList _al = this; \
- for (int i = 0, n = this##_len; i < n; ++i) \
+ 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 } \