src/object.h
author Tero Marttila <terom@fixme.fi>
Thu, 21 May 2009 16:57:56 +0300
changeset 213 f0e52e026197
parent 174 c56680e9e021
permissions -rw-r--r--
implement lua_console_on_interrupt to abort any executing thread
#ifndef OBJECT_H
#define OBJECT_H

/**
 * @file
 *
 * The thing feared by every C-programmer - calling C structs "objects".
 */
#include <stdbool.h>

/**
 * Basic object type info
 */
struct object_type {
    /** Parent type for nested structs, NULL if the parent is object_type */
    const struct object_type *parent;
};

/**
 * Basic object state
 */
struct object {
    /** Object's type */
    const struct object_type *type;
};

/**
 * Initialize an object to the given type.
 */
void object_init (struct object *obj, const struct object_type *type);

/**
 * Check that the given object type is compatible with the given type.
 */
bool object_type_check (const struct object_type *obj_type, const struct object_type *type);

/**
 * Check that the given object "implements" the given type.
 */
bool object_check (struct object *obj, const struct object_type *type);

/**
 * Return the given object as a pointer suitable for casting to the struct for the given type.
 *
 * It is a bug to call this with an object that's not compatible with the given type.
 */
void* object_cast (struct object *obj, const struct object_type *type);

/**
 * Return a pointer to the object's type that is compatible with the given type.
 *
 * It is a bug to call this with a object that's not compatible with the given type.
 */
const void* object_type (struct object *obj, const struct object_type *type);

#endif /* OBJECT_H */