ref: 1890aeca379976e46deabb0ce844aefc8be1a2c5
dir: /nate_construct.h/
#include "nate.h"
void nc_push(Nelem*);
void nc_pop(void);
Nelem* nc_get(void);
// #define N_TYPE in your implementation
#define COND(N) (N->type == N_TYPE)
#define GUARD(N) assert(COND(N))
// create with benefits
Nelem *makenelem(long size, char *type, Nelemfunctions *funcs, char *name, int nchildren);
#define MakeNelem(Type, Char, F, N, NUM) ((Type*)makenelem(sizeof(Type), Char, F, N, NUM));
void nc_addchild(Nelem*, Nelem*);
// internal stuff
void nc_init(void);
// trace hits
extern int nctracehitlevel;
void nctracehit(Nelem *el, int passthrough);
// default functionality
Nelem* nd_checkhit(Nelem* nelem, Image* screen, Mouse m);
void nd_free(Nelem *nelem);
// syntactic sugar: default slot
#define DEF_SLOTFUNC(Type, Func) \
static Type* \
Func(Nelem *el) \
{ \
if (el == nc_get()) \
nc_pop(); \
Type *b = (Type*)nc_get(); \
GUARD(b); \
nc_addchild(b, el); \
return b; \
}
// syntactic sugar: default accessors
#define DEF_ACCESSOR_OneParam(Type, Func, T1, N1) \
static Type* \
Func(T1 N1) \
{ \
Type *b = (Type*)nc_get(); \
GUARD(b); \
b->N1 = N1; \
return b; \
}
#define DEF_ACCESSOR_TwoParams(Type, Func, T1, N1, T2, N2) \
static Type* \
Func(T1 N1, T2 N2) \
{ \
Type *b = (Type*)nc_get(); \
GUARD(b); \
b->N1 = N1; \
b->N2 = N2; \
return b; \
}
#define DEF_ACCESSOR_ThreeParams(Type, Func, T1, N1, T2, N2, T3, N3) \
static Type* \
Func(T1 N1, T2 N2, T3 N3) \
{ \
Type *b = (Type*)nc_get(); \
GUARD(b); \
b->N1 = N1; \
b->N2 = N2; \
b->N3 = N3; \
return b; \
}