class.c 1.26 KB
/**
 * \file
 * Helper functions for class.
 *
 * \todo	rename function to fit in the otherwise used scheme.
 * \author	Georg Hopp
 *
 * \copyright
 * Copyright (C) 2012  Georg Hopp
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdarg.h>
#include <stdlib.h>

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

void *
class_getInterface(class_ptr * class, iface_ptr _iface)
{
	void * iface = (void *)IFACE_GET(*class, _iface);

	while(NULL == iface && HAS_PARENT(*class)) {
		*class = (*class)->parent;
		iface = (void *)IFACE_GET(*class, _iface);
	}

	return iface;
}

class_ptr
class_getClass(void * object)
{
	return *(class_ptr *)(object - sizeof(void*));
}

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