os/graphics/m3g/m3gcore11/inc/m3g_object.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: M3G base object class internal interface
    15 *
    16 */
    17 
    18 #ifndef __M3G_OBJECT_H__
    19 #define __M3G_OBJECT_H__
    20 
    21 /*!
    22  * \internal
    23  * \file
    24  * \brief M3G base object class internal interface
    25  *
    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.
    32  *
    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
    37  * classes.
    38  */
    39 
    40 #include "m3g_interface.h"
    41 #include "m3g_array.h"
    42 
    43 /*----------------------------------------------------------------------
    44  * Object class definition
    45  *--------------------------------------------------------------------*/
    46 
    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);
    53 
    54 typedef void    (*m3gDestroyFuncPtr)            (Object *obj);
    55 
    56 /*!
    57  * \internal
    58  * \brief Object class virtual functions
    59  */
    60 typedef struct
    61 {
    62     m3gApplyAnimationFuncPtr    applyAnimation;
    63     m3gIsCompatibleFuncPtr      isCompatible;
    64     m3gUpdatePropertyFuncPtr    updateProperty;
    65     m3gGetReferencesFuncPtr     getReferences;
    66     m3gFindFuncPtr              find;
    67     m3gDuplicateFuncPtr         duplicate;
    68     m3gDestroyFuncPtr           destroy;
    69 } ObjectVFTable;
    70 
    71 /*!
    72  * \internal
    73  * \brief Internal object structure
    74  *
    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
    77  * tracks for anything
    78  */
    79 struct M3GObjectImpl
    80 {
    81     /*! \internal \brief Pointer to the interface that created this object */
    82     Interface *interface;
    83     
    84     /*!
    85      * \internal
    86      * \brief Class ID (as in M3GClass)
    87      *
    88      * This is used to resolve the virtual function table pointer,
    89      * among other things
    90      */
    91     M3Guint classID  :  8;
    92 
    93     /*! \internal \brief Reference count */
    94     M3Guint refCount : 24;
    95     
    96     /*! \internal \brief Table for animation tracks */
    97     PointerArray *animTracks;
    98     
    99     M3Gint userID;
   100 };
   101 
   102 
   103 /* Some compile-time sanity checks... */
   104 
   105 M3G_CT_ASSERT(M3G_CLASS_WORLD <= 255);
   106 //M3G_CT_ASSERT(sizeof(Object) == 16);
   107 
   108 
   109 /* Self-validation */
   110 #if defined(M3G_DEBUG)
   111 /*@notfunction@*/
   112 #   define M3G_VALIDATE_OBJECT(obj)   m3gValidateObject(obj)
   113 static void m3gValidateObject(const void *pObj);
   114 
   115 #else
   116 #   define M3G_VALIDATE_OBJECT(obj)
   117 #endif
   118 
   119 /*!
   120  * \internal
   121  * \brief Returns the interface of any M3GObject-derived object
   122  */
   123 /*@notfunction@*/
   124 #define M3G_INTERFACE(obj) (((const Object *)(obj))->interface)
   125 
   126 /*!
   127  * \internal
   128  * \brief Returns the class ID of any M3GObject-derived object
   129  */
   130 /*@notfunction@*/
   131 #define M3G_CLASS(obj) ((M3GClass)(((const Object *)(obj))->classID))
   132 
   133 /*!
   134  * \internal
   135  * \brief Virtual function call macro
   136  *
   137  * \param className     name of class
   138  * \param pObj          pointer to object instance
   139  * \param funcName      name of function to call
   140  *
   141  */
   142 /*@notfunction@*/
   143 #define M3G_VFUNC(className, pObj, funcName) \
   144     (((className##VFTable*)m3gGetVFTable((Object*)(pObj)))->funcName)
   145 
   146 static M3G_INLINE const ObjectVFTable *m3gGetVFTable(const Object *obj);
   147 
   148 /*--------------------------------------------------------------------
   149  * Constructor
   150  *------------------------------------------------------------------*/
   151 
   152 static void m3gInitObject(Object *object,
   153                           Interface *interface,
   154                           M3GClass classID);
   155 
   156 /*-------------------------------------------------------------------
   157  * Internal functions
   158  *-----------------------------------------------------------------*/
   159 
   160 /*! \internal \brief Nicer form for the \c find virtual function */
   161 static M3G_INLINE Object *m3gFindID(Object *obj, M3Gint userID)
   162 {
   163     return M3G_VFUNC(Object, obj, find)(obj, userID);
   164 }
   165 
   166 /* Reference handling */
   167 static void m3gSetRef(Object **ref, Object *obj);
   168 #define M3G_ASSIGN_REF(ref, value) m3gSetRef((Object**)&(ref), (Object*) value)
   169 
   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);
   178 
   179 #if defined(M3G_LOGLEVEL)
   180 static const char *m3gClassName(M3GClass classID);
   181 #else
   182 /*lint -save -e607 this is intentional */
   183 #   define m3gClassName(id) " ## id ## "
   184 /*lint -restore */
   185 #endif
   186 
   187 #endif /*__M3G_OBJECT_H__*/