diff -r a10ba529ae39 -r 7728d6ec3abf src/lib/object.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/object.h Wed May 27 23:57:48 2009 +0300 @@ -0,0 +1,56 @@ +#ifndef OBJECT_H +#define OBJECT_H + +/** + * @file + * + * The thing feared by every C-programmer - calling C structs "objects". + */ +#include + +/** + * 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 */