1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/m3g/m3gcore11/inc/m3g_object.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,187 @@
1.4 +/*
1.5 +* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: M3G base object class internal interface
1.18 +*
1.19 +*/
1.20 +
1.21 +#ifndef __M3G_OBJECT_H__
1.22 +#define __M3G_OBJECT_H__
1.23 +
1.24 +/*!
1.25 + * \internal
1.26 + * \file
1.27 + * \brief M3G base object class internal interface
1.28 + *
1.29 + * The fundamental feature of the object model is that each object
1.30 + * instance structure includes the base class structure as its first
1.31 + * member. Consequently, pointers to derived classes can be resolved
1.32 + * to pointers to base classes by simple casts, and things such as
1.33 + * virtual function pointers can be found at a fixed offset regardless
1.34 + * of the actual class of the object being dealt with.
1.35 + *
1.36 + * The per-class virtual function tables are laid out similarly to the
1.37 + * class structures, with the base class table preceding the derived
1.38 + * class table in memory. Currently, virtual function tables are
1.39 + * constructed by hand, but they are only needed for non-abstract
1.40 + * classes.
1.41 + */
1.42 +
1.43 +#include "m3g_interface.h"
1.44 +#include "m3g_array.h"
1.45 +
1.46 +/*----------------------------------------------------------------------
1.47 + * Object class definition
1.48 + *--------------------------------------------------------------------*/
1.49 +
1.50 +typedef M3Gint (*m3gApplyAnimationFuncPtr) (Object *self, M3Gint time);
1.51 +typedef M3Gbool (*m3gIsCompatibleFuncPtr) (M3Gint property);
1.52 +typedef void (*m3gUpdatePropertyFuncPtr) (Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value);
1.53 +typedef M3Gint (*m3gGetReferencesFuncPtr) (Object *self, Object **references);
1.54 +typedef Object* (*m3gFindFuncPtr) (Object *self, M3Gint userID);
1.55 +typedef M3Gbool (*m3gDuplicateFuncPtr) (const Object *original, Object **clone, Object **pairs, M3Gint *numPairs);
1.56 +
1.57 +typedef void (*m3gDestroyFuncPtr) (Object *obj);
1.58 +
1.59 +/*!
1.60 + * \internal
1.61 + * \brief Object class virtual functions
1.62 + */
1.63 +typedef struct
1.64 +{
1.65 + m3gApplyAnimationFuncPtr applyAnimation;
1.66 + m3gIsCompatibleFuncPtr isCompatible;
1.67 + m3gUpdatePropertyFuncPtr updateProperty;
1.68 + m3gGetReferencesFuncPtr getReferences;
1.69 + m3gFindFuncPtr find;
1.70 + m3gDuplicateFuncPtr duplicate;
1.71 + m3gDestroyFuncPtr destroy;
1.72 +} ObjectVFTable;
1.73 +
1.74 +/*!
1.75 + * \internal
1.76 + * \brief Internal object structure
1.77 + *
1.78 + * \note Part of this is JSR-184 Object3D related and doesn't apply to
1.79 + * all native objects; namely, RenderContext does not use animation
1.80 + * tracks for anything
1.81 + */
1.82 +struct M3GObjectImpl
1.83 +{
1.84 + /*! \internal \brief Pointer to the interface that created this object */
1.85 + Interface *interface;
1.86 +
1.87 + /*!
1.88 + * \internal
1.89 + * \brief Class ID (as in M3GClass)
1.90 + *
1.91 + * This is used to resolve the virtual function table pointer,
1.92 + * among other things
1.93 + */
1.94 + M3Guint classID : 8;
1.95 +
1.96 + /*! \internal \brief Reference count */
1.97 + M3Guint refCount : 24;
1.98 +
1.99 + /*! \internal \brief Table for animation tracks */
1.100 + PointerArray *animTracks;
1.101 +
1.102 + M3Gint userID;
1.103 +};
1.104 +
1.105 +
1.106 +/* Some compile-time sanity checks... */
1.107 +
1.108 +M3G_CT_ASSERT(M3G_CLASS_WORLD <= 255);
1.109 +//M3G_CT_ASSERT(sizeof(Object) == 16);
1.110 +
1.111 +
1.112 +/* Self-validation */
1.113 +#if defined(M3G_DEBUG)
1.114 +/*@notfunction@*/
1.115 +# define M3G_VALIDATE_OBJECT(obj) m3gValidateObject(obj)
1.116 +static void m3gValidateObject(const void *pObj);
1.117 +
1.118 +#else
1.119 +# define M3G_VALIDATE_OBJECT(obj)
1.120 +#endif
1.121 +
1.122 +/*!
1.123 + * \internal
1.124 + * \brief Returns the interface of any M3GObject-derived object
1.125 + */
1.126 +/*@notfunction@*/
1.127 +#define M3G_INTERFACE(obj) (((const Object *)(obj))->interface)
1.128 +
1.129 +/*!
1.130 + * \internal
1.131 + * \brief Returns the class ID of any M3GObject-derived object
1.132 + */
1.133 +/*@notfunction@*/
1.134 +#define M3G_CLASS(obj) ((M3GClass)(((const Object *)(obj))->classID))
1.135 +
1.136 +/*!
1.137 + * \internal
1.138 + * \brief Virtual function call macro
1.139 + *
1.140 + * \param className name of class
1.141 + * \param pObj pointer to object instance
1.142 + * \param funcName name of function to call
1.143 + *
1.144 + */
1.145 +/*@notfunction@*/
1.146 +#define M3G_VFUNC(className, pObj, funcName) \
1.147 + (((className##VFTable*)m3gGetVFTable((Object*)(pObj)))->funcName)
1.148 +
1.149 +static M3G_INLINE const ObjectVFTable *m3gGetVFTable(const Object *obj);
1.150 +
1.151 +/*--------------------------------------------------------------------
1.152 + * Constructor
1.153 + *------------------------------------------------------------------*/
1.154 +
1.155 +static void m3gInitObject(Object *object,
1.156 + Interface *interface,
1.157 + M3GClass classID);
1.158 +
1.159 +/*-------------------------------------------------------------------
1.160 + * Internal functions
1.161 + *-----------------------------------------------------------------*/
1.162 +
1.163 +/*! \internal \brief Nicer form for the \c find virtual function */
1.164 +static M3G_INLINE Object *m3gFindID(Object *obj, M3Gint userID)
1.165 +{
1.166 + return M3G_VFUNC(Object, obj, find)(obj, userID);
1.167 +}
1.168 +
1.169 +/* Reference handling */
1.170 +static void m3gSetRef(Object **ref, Object *obj);
1.171 +#define M3G_ASSIGN_REF(ref, value) m3gSetRef((Object**)&(ref), (Object*) value)
1.172 +
1.173 +/* Virtual functions */
1.174 +static M3Gint m3gObjectApplyAnimation (Object *self, M3Gint time);
1.175 +static M3Gbool m3gObjectIsCompatible (M3Gint property);
1.176 +static void m3gObjectUpdateProperty (Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value);
1.177 +static M3Gint m3gObjectDoGetReferences(Object *self, Object **references);
1.178 +static Object* m3gObjectFindID (Object *self, M3Gint userID);
1.179 +static M3Gbool m3gObjectDuplicate (const Object *original, Object **clone, Object **pairs, M3Gint *numPairs);
1.180 +static void m3gDestroyObject (Object *object);
1.181 +
1.182 +#if defined(M3G_LOGLEVEL)
1.183 +static const char *m3gClassName(M3GClass classID);
1.184 +#else
1.185 +/*lint -save -e607 this is intentional */
1.186 +# define m3gClassName(id) " ## id ## "
1.187 +/*lint -restore */
1.188 +#endif
1.189 +
1.190 +#endif /*__M3G_OBJECT_H__*/