/*** classes.h **************************************************************
 *
 *  Only used by class implementors (in ROM?).  This is the
 *	White Box.
 *
 *  $Header: /home/amiga/V36/src/kickstart/intuition/RCS/classes.h,v 1.4 90/04/06 22:23:58 jimm Exp $
 *
 *  Confidential Information: Commodore-Amiga, Inc.
 *  Copyright (C) 1989, Commodore-Amiga, Inc.
 *  All Rights Reserved
 *
 ****************************************************************************/


#ifndef	INTUITION_CLASSES_H
#define INTUITION_CLASSES_H	1


#ifndef UTILITY_HOOKS_H
#include <utility/hooks.h>
#endif

#ifndef	INTUITION_CLASSUSR_H
#include <intuition/classusr.h>
#endif

/*******************************************/
/*** "White box" access to struct _Class ***/
/*******************************************/

typedef struct _Class {
    struct Hook		cl_Dispatcher;
    ULONG		cl_Reserved;	/* must be 0  */
    struct _Class	*cl_Super;
    ClassID		cl_ID;

    /* where within an object is the instance data for this class? */
    UWORD		cl_InstOffset;
    UWORD		cl_InstSize;

    ULONG		cl_UserData;	/* per-class what have you */
} Class;

/* add offset for instance data to an object handle */
#define INST_DATA( cl, o )	((VOID *) (((UBYTE *)o)+cl->cl_InstOffset))

/* sizeof the instance data for a given class */
#define SIZEOF_INSTANCE( cl )	((cl)->cl_InstOffset + (cl)->cl_InstSize \
			+ sizeof (struct _Object ))

/**************************************************/
/*** "White box" access to struct _Object	***/
/**************************************************/

/*
 * I have this, the instance data of the root class, PRECEDING
 * the "object".  This is so that Gadget objects are Gadget pointers.
 */
struct _Object {
    struct MinNode	o_Node;

    /* "public part" - offset will always same relative to 
     * *end* of this structure
     */
    struct _Class	*o_Class;
};

/* convenient typecast	*/
#define _OBJ( o )	((struct _Object *)(o))

/* get "public" handle on baseclass instance from real beginning of obj data */
#define BASEOBJECT( _obj )	( (Object *) (_OBJ(_obj)+1) )

/* get back to object data struct from public handle */
#define _OBJECT( o )		(_OBJ(o) - 1)

/* get class pointer from an object handle	*/
#define OCLASS( o )	( (_OBJECT(o))->o_Class )

#endif
