class.c 896 Bytes
#include <stdarg.h>
#include <stdlib.h>
#include <assert.h>

#include "class.h"
#include "interface/class.h"

const
struct interface i_Class = {
	"class",
	3
};

void *
classNew(class_ptr class, ...)
{
	void * object = calloc(1, class->object_size + sizeof(void*));
	va_list params;

	if (class->init)	class->init();

	* (class_ptr *)object = class;
	object += sizeof(void*);

	va_start(params, class);
	CALL(object, Class, ctor, &params);
	va_end(params);

	return object;
}

void
classDelete(void ** object)
{
	CALL(*object, Class, dtor);

	free(*object - sizeof(void*));
	*object = NULL;
}

void *
classClone(void * _object)
{
	class_ptr class  = class_getClass(_object);
	void *    object = calloc(1, class->object_size + sizeof(void*));

	* (class_ptr *)object = class;
	object += sizeof(void*);

#undef clone
	CALL(object, Class, clone, _object);

	return object;
}

// vim: set ts=4 sw=4: