sl@0: /* sl@0: * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: M3G base object class internal interface sl@0: * sl@0: */ sl@0: sl@0: #ifndef __M3G_OBJECT_H__ sl@0: #define __M3G_OBJECT_H__ sl@0: sl@0: /*! sl@0: * \internal sl@0: * \file sl@0: * \brief M3G base object class internal interface sl@0: * sl@0: * The fundamental feature of the object model is that each object sl@0: * instance structure includes the base class structure as its first sl@0: * member. Consequently, pointers to derived classes can be resolved sl@0: * to pointers to base classes by simple casts, and things such as sl@0: * virtual function pointers can be found at a fixed offset regardless sl@0: * of the actual class of the object being dealt with. sl@0: * sl@0: * The per-class virtual function tables are laid out similarly to the sl@0: * class structures, with the base class table preceding the derived sl@0: * class table in memory. Currently, virtual function tables are sl@0: * constructed by hand, but they are only needed for non-abstract sl@0: * classes. sl@0: */ sl@0: sl@0: #include "m3g_interface.h" sl@0: #include "m3g_array.h" sl@0: sl@0: /*---------------------------------------------------------------------- sl@0: * Object class definition sl@0: *--------------------------------------------------------------------*/ sl@0: sl@0: typedef M3Gint (*m3gApplyAnimationFuncPtr) (Object *self, M3Gint time); sl@0: typedef M3Gbool (*m3gIsCompatibleFuncPtr) (M3Gint property); sl@0: typedef void (*m3gUpdatePropertyFuncPtr) (Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value); sl@0: typedef M3Gint (*m3gGetReferencesFuncPtr) (Object *self, Object **references); sl@0: typedef Object* (*m3gFindFuncPtr) (Object *self, M3Gint userID); sl@0: typedef M3Gbool (*m3gDuplicateFuncPtr) (const Object *original, Object **clone, Object **pairs, M3Gint *numPairs); sl@0: sl@0: typedef void (*m3gDestroyFuncPtr) (Object *obj); sl@0: sl@0: /*! sl@0: * \internal sl@0: * \brief Object class virtual functions sl@0: */ sl@0: typedef struct sl@0: { sl@0: m3gApplyAnimationFuncPtr applyAnimation; sl@0: m3gIsCompatibleFuncPtr isCompatible; sl@0: m3gUpdatePropertyFuncPtr updateProperty; sl@0: m3gGetReferencesFuncPtr getReferences; sl@0: m3gFindFuncPtr find; sl@0: m3gDuplicateFuncPtr duplicate; sl@0: m3gDestroyFuncPtr destroy; sl@0: } ObjectVFTable; sl@0: sl@0: /*! sl@0: * \internal sl@0: * \brief Internal object structure sl@0: * sl@0: * \note Part of this is JSR-184 Object3D related and doesn't apply to sl@0: * all native objects; namely, RenderContext does not use animation sl@0: * tracks for anything sl@0: */ sl@0: struct M3GObjectImpl sl@0: { sl@0: /*! \internal \brief Pointer to the interface that created this object */ sl@0: Interface *interface; sl@0: sl@0: /*! sl@0: * \internal sl@0: * \brief Class ID (as in M3GClass) sl@0: * sl@0: * This is used to resolve the virtual function table pointer, sl@0: * among other things sl@0: */ sl@0: M3Guint classID : 8; sl@0: sl@0: /*! \internal \brief Reference count */ sl@0: M3Guint refCount : 24; sl@0: sl@0: /*! \internal \brief Table for animation tracks */ sl@0: PointerArray *animTracks; sl@0: sl@0: M3Gint userID; sl@0: }; sl@0: sl@0: sl@0: /* Some compile-time sanity checks... */ sl@0: sl@0: M3G_CT_ASSERT(M3G_CLASS_WORLD <= 255); sl@0: //M3G_CT_ASSERT(sizeof(Object) == 16); sl@0: sl@0: sl@0: /* Self-validation */ sl@0: #if defined(M3G_DEBUG) sl@0: /*@notfunction@*/ sl@0: # define M3G_VALIDATE_OBJECT(obj) m3gValidateObject(obj) sl@0: static void m3gValidateObject(const void *pObj); sl@0: sl@0: #else sl@0: # define M3G_VALIDATE_OBJECT(obj) sl@0: #endif sl@0: sl@0: /*! sl@0: * \internal sl@0: * \brief Returns the interface of any M3GObject-derived object sl@0: */ sl@0: /*@notfunction@*/ sl@0: #define M3G_INTERFACE(obj) (((const Object *)(obj))->interface) sl@0: sl@0: /*! sl@0: * \internal sl@0: * \brief Returns the class ID of any M3GObject-derived object sl@0: */ sl@0: /*@notfunction@*/ sl@0: #define M3G_CLASS(obj) ((M3GClass)(((const Object *)(obj))->classID)) sl@0: sl@0: /*! sl@0: * \internal sl@0: * \brief Virtual function call macro sl@0: * sl@0: * \param className name of class sl@0: * \param pObj pointer to object instance sl@0: * \param funcName name of function to call sl@0: * sl@0: */ sl@0: /*@notfunction@*/ sl@0: #define M3G_VFUNC(className, pObj, funcName) \ sl@0: (((className##VFTable*)m3gGetVFTable((Object*)(pObj)))->funcName) sl@0: sl@0: static M3G_INLINE const ObjectVFTable *m3gGetVFTable(const Object *obj); sl@0: sl@0: /*-------------------------------------------------------------------- sl@0: * Constructor sl@0: *------------------------------------------------------------------*/ sl@0: sl@0: static void m3gInitObject(Object *object, sl@0: Interface *interface, sl@0: M3GClass classID); sl@0: sl@0: /*------------------------------------------------------------------- sl@0: * Internal functions sl@0: *-----------------------------------------------------------------*/ sl@0: sl@0: /*! \internal \brief Nicer form for the \c find virtual function */ sl@0: static M3G_INLINE Object *m3gFindID(Object *obj, M3Gint userID) sl@0: { sl@0: return M3G_VFUNC(Object, obj, find)(obj, userID); sl@0: } sl@0: sl@0: /* Reference handling */ sl@0: static void m3gSetRef(Object **ref, Object *obj); sl@0: #define M3G_ASSIGN_REF(ref, value) m3gSetRef((Object**)&(ref), (Object*) value) sl@0: sl@0: /* Virtual functions */ sl@0: static M3Gint m3gObjectApplyAnimation (Object *self, M3Gint time); sl@0: static M3Gbool m3gObjectIsCompatible (M3Gint property); sl@0: static void m3gObjectUpdateProperty (Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value); sl@0: static M3Gint m3gObjectDoGetReferences(Object *self, Object **references); sl@0: static Object* m3gObjectFindID (Object *self, M3Gint userID); sl@0: static M3Gbool m3gObjectDuplicate (const Object *original, Object **clone, Object **pairs, M3Gint *numPairs); sl@0: static void m3gDestroyObject (Object *object); sl@0: sl@0: #if defined(M3G_LOGLEVEL) sl@0: static const char *m3gClassName(M3GClass classID); sl@0: #else sl@0: /*lint -save -e607 this is intentional */ sl@0: # define m3gClassName(id) " ## id ## " sl@0: /*lint -restore */ sl@0: #endif sl@0: sl@0: #endif /*__M3G_OBJECT_H__*/