Update contrib.
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: M3G base object class internal interface
18 #ifndef __M3G_OBJECT_H__
19 #define __M3G_OBJECT_H__
24 * \brief M3G base object class internal interface
26 * The fundamental feature of the object model is that each object
27 * instance structure includes the base class structure as its first
28 * member. Consequently, pointers to derived classes can be resolved
29 * to pointers to base classes by simple casts, and things such as
30 * virtual function pointers can be found at a fixed offset regardless
31 * of the actual class of the object being dealt with.
33 * The per-class virtual function tables are laid out similarly to the
34 * class structures, with the base class table preceding the derived
35 * class table in memory. Currently, virtual function tables are
36 * constructed by hand, but they are only needed for non-abstract
40 #include "m3g_interface.h"
41 #include "m3g_array.h"
43 /*----------------------------------------------------------------------
44 * Object class definition
45 *--------------------------------------------------------------------*/
47 typedef M3Gint (*m3gApplyAnimationFuncPtr) (Object *self, M3Gint time);
48 typedef M3Gbool (*m3gIsCompatibleFuncPtr) (M3Gint property);
49 typedef void (*m3gUpdatePropertyFuncPtr) (Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value);
50 typedef M3Gint (*m3gGetReferencesFuncPtr) (Object *self, Object **references);
51 typedef Object* (*m3gFindFuncPtr) (Object *self, M3Gint userID);
52 typedef M3Gbool (*m3gDuplicateFuncPtr) (const Object *original, Object **clone, Object **pairs, M3Gint *numPairs);
54 typedef void (*m3gDestroyFuncPtr) (Object *obj);
58 * \brief Object class virtual functions
62 m3gApplyAnimationFuncPtr applyAnimation;
63 m3gIsCompatibleFuncPtr isCompatible;
64 m3gUpdatePropertyFuncPtr updateProperty;
65 m3gGetReferencesFuncPtr getReferences;
67 m3gDuplicateFuncPtr duplicate;
68 m3gDestroyFuncPtr destroy;
73 * \brief Internal object structure
75 * \note Part of this is JSR-184 Object3D related and doesn't apply to
76 * all native objects; namely, RenderContext does not use animation
81 /*! \internal \brief Pointer to the interface that created this object */
86 * \brief Class ID (as in M3GClass)
88 * This is used to resolve the virtual function table pointer,
93 /*! \internal \brief Reference count */
94 M3Guint refCount : 24;
96 /*! \internal \brief Table for animation tracks */
97 PointerArray *animTracks;
103 /* Some compile-time sanity checks... */
105 M3G_CT_ASSERT(M3G_CLASS_WORLD <= 255);
106 //M3G_CT_ASSERT(sizeof(Object) == 16);
109 /* Self-validation */
110 #if defined(M3G_DEBUG)
112 # define M3G_VALIDATE_OBJECT(obj) m3gValidateObject(obj)
113 static void m3gValidateObject(const void *pObj);
116 # define M3G_VALIDATE_OBJECT(obj)
121 * \brief Returns the interface of any M3GObject-derived object
124 #define M3G_INTERFACE(obj) (((const Object *)(obj))->interface)
128 * \brief Returns the class ID of any M3GObject-derived object
131 #define M3G_CLASS(obj) ((M3GClass)(((const Object *)(obj))->classID))
135 * \brief Virtual function call macro
137 * \param className name of class
138 * \param pObj pointer to object instance
139 * \param funcName name of function to call
143 #define M3G_VFUNC(className, pObj, funcName) \
144 (((className##VFTable*)m3gGetVFTable((Object*)(pObj)))->funcName)
146 static M3G_INLINE const ObjectVFTable *m3gGetVFTable(const Object *obj);
148 /*--------------------------------------------------------------------
150 *------------------------------------------------------------------*/
152 static void m3gInitObject(Object *object,
153 Interface *interface,
156 /*-------------------------------------------------------------------
158 *-----------------------------------------------------------------*/
160 /*! \internal \brief Nicer form for the \c find virtual function */
161 static M3G_INLINE Object *m3gFindID(Object *obj, M3Gint userID)
163 return M3G_VFUNC(Object, obj, find)(obj, userID);
166 /* Reference handling */
167 static void m3gSetRef(Object **ref, Object *obj);
168 #define M3G_ASSIGN_REF(ref, value) m3gSetRef((Object**)&(ref), (Object*) value)
170 /* Virtual functions */
171 static M3Gint m3gObjectApplyAnimation (Object *self, M3Gint time);
172 static M3Gbool m3gObjectIsCompatible (M3Gint property);
173 static void m3gObjectUpdateProperty (Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value);
174 static M3Gint m3gObjectDoGetReferences(Object *self, Object **references);
175 static Object* m3gObjectFindID (Object *self, M3Gint userID);
176 static M3Gbool m3gObjectDuplicate (const Object *original, Object **clone, Object **pairs, M3Gint *numPairs);
177 static void m3gDestroyObject (Object *object);
179 #if defined(M3G_LOGLEVEL)
180 static const char *m3gClassName(M3GClass classID);
182 /*lint -save -e607 this is intentional */
183 # define m3gClassName(id) " ## id ## "
187 #endif /*__M3G_OBJECT_H__*/