/** * object.h: Object management. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2007 William Pitcock * Rights to this code are as documented in doc/pod/license.pod. * * $Id: object.h,v 1.6 2007/09/22 14:27:26 pippijn Exp $ */ #ifndef OBJECT_H #define OBJECT_H #include /* object base class */ class object { mutable int refcnt; protected: object () : refcnt (1) { } object (const object &other) : refcnt (1) { } virtual ~object () { } virtual void _destroy () = 0; public: int refcnt_inc () { return ++refcnt; } int refcnt_dec () { if (!--refcnt) { this->_destroy (); return 0; } else return refcnt; } }; typedef void (*destructor_t) (void *); struct object_t : zero_initialised { char *name; int refcount; destructor_t destructor; }; E void object_init (object_t *, const char *name, destructor_t destructor); E void *object_ref (void *); E void object_unref (void *); #define asobject(x) ((object_t *) x) #endif