#ifndef ITS1_ALLOCATOR_H_INCLUDED
#define ITS1_ALLOCATOR_H_INCLUDED

struct its1_allocator {
	void	*(*allocate)(struct its1_allocator *allocator, size_t n);
	void	 (*deallocate)(struct its1_allocator *allocator, void *ptr);
};

extern struct its1_allocator its1_default_allocator;

/* allocator interface */
void	*its1_malloc(struct its1_allocator *allocator, size_t n);
void	 its1_free(struct its1_allocator *allocator, void *ptr);

/* helper functions */
char	*its1_strdup(struct its1_allocator *allocator, const char *str);
void	*its1_malloc_zero(struct its1_allocator *allocator, size_t n);

#define ALLOCATE(n) \
	its1_malloc(&its1_default_allocator, (n))

#define ALLOCATE_ZERO(n) \
	its1_malloc_zero(&its1_default_allocator, (n))

#define FREE(ptr) \
	(its1_free(&its1_default_allocator, (ptr)), (ptr) = NULL)

#define  NEW(ptr) ((ptr) = ALLOCATE(sizeof *(ptr)))
#define NEW0(ptr) ((ptr) = ALLOCATE_ZERO(sizeof *(ptr)))

#endif
