NVIDIA(R) PhysX(R) SDK 3.4 API Reference: PxSerializer.h Source File

NVIDIA PhysX SDK 3.4 API

PxSerializer.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
00029 
00030 
00031 #ifndef PX_SERIALIZER_H
00032 #define PX_SERIALIZER_H
00033 
00037 #include "PxSerialFramework.h"
00038 #include "PxCollection.h"
00039 #include "foundation/PxAssert.h"
00040 
00041 #if !PX_DOXYGEN
00042 namespace physx
00043 {
00044 #endif
00045 
00061 class PxSerializer
00062 {
00063 public:
00064 
00065     /**********************************************************************************************************************/
00066 
00070     
00076     virtual  const  char*           getConcreteTypeName() const                                                         = 0;   
00077 
00085     virtual         void            requires(PxBase&, PxProcessPxBaseCallback&) const                                   = 0;
00086     
00096     virtual         bool            isSubordinate() const                                                               = 0;
00097 
00099     /**********************************************************************************************************************/
00100 
00101     /**********************************************************************************************************************/
00102 
00106 
00110     virtual         void            exportExtraData(PxBase&, PxSerializationContext&) const                             = 0;
00111 
00115     virtual         void            exportData(PxBase&, PxSerializationContext&) const                                  = 0;
00116 
00120     virtual         void            registerReferences(PxBase& obj, PxSerializationContext& s) const                    = 0;
00121 
00127     virtual         size_t          getClassSize() const                                                                = 0;
00128 
00136     virtual         PxBase*         createObject(PxU8*& address, PxDeserializationContext& context) const   = 0; 
00137 
00139     /**********************************************************************************************************************/
00140     virtual ~PxSerializer() {}
00141 };
00142 
00143 
00147 template<class T>
00148 class PxSerializerDefaultAdapter : public PxSerializer
00149 {
00150 public:
00151 
00152     /************************************************************************************************/
00153 
00157 
00158     PxSerializerDefaultAdapter(const char* name) : mTypeName(name){}
00159 
00160     virtual const char* getConcreteTypeName() const
00161     { 
00162         return mTypeName; 
00163     }
00164 
00165     virtual void requires(PxBase& obj, PxProcessPxBaseCallback& c) const
00166     {
00167         T& t = static_cast<T&>(obj);
00168         t.requires(c);
00169     }
00170 
00171     virtual bool isSubordinate() const
00172     {
00173         return false;
00174     }
00175         
00177     /************************************************************************************************/
00178 
00182 
00183     // object methods
00184 
00185     virtual void exportExtraData(PxBase& obj, PxSerializationContext& s) const
00186     { 
00187         T& t = static_cast<T&>(obj);
00188         t.exportExtraData(s);
00189     }
00190 
00191     virtual void exportData(PxBase& obj, PxSerializationContext& s) const
00192     { 
00193         s.writeData(&obj, sizeof(T));
00194     }
00195 
00196     virtual void registerReferences(PxBase& obj, PxSerializationContext& s) const
00197     {
00198         T& t = static_cast<T&>(obj);
00199 
00200         s.registerReference(obj, PX_SERIAL_REF_KIND_PXBASE, size_t(&obj));
00201 
00202         struct RequiresCallback : public PxProcessPxBaseCallback
00203         {
00204             RequiresCallback(PxSerializationContext& c) : context(c) {}
00205             RequiresCallback& operator=(RequiresCallback&) { PX_ASSERT(0); return *this; }
00206             void process(physx::PxBase& base)
00207             {               
00208                 context.registerReference(base, PX_SERIAL_REF_KIND_PXBASE, size_t(&base));
00209             }
00210             PxSerializationContext& context;
00211         };
00212 
00213         RequiresCallback callback(s);
00214         t.requires(callback);   
00215     }
00216 
00217     // class methods
00218 
00219     virtual size_t getClassSize() const
00220     {
00221         return sizeof(T);
00222     }
00223 
00224     virtual PxBase* createObject(PxU8*& address, PxDeserializationContext& context) const
00225     {
00226         return T::createObject(address, context);
00227     }
00228 
00229 
00231     /************************************************************************************************/
00232 
00233 private:
00234     const char*    mTypeName;   
00235 };
00236 
00242 #define PX_NEW_SERIALIZER_ADAPTER(x) \
00243     *new( PxGetFoundation().getAllocatorCallback().allocate(sizeof(PxSerializerDefaultAdapter<x>), \
00244     "PxSerializerDefaultAdapter",  __FILE__, __LINE__ )) PxSerializerDefaultAdapter<x>(#x)
00245 
00249 #define PX_DELETE_SERIALIZER_ADAPTER(x) \
00250     { PxSerializer* s = x; if (s) { s->~PxSerializer(); PxGetFoundation().getAllocatorCallback().deallocate(s); } }
00251 
00252 #if !PX_DOXYGEN
00253 } // namespace physx
00254 #endif
00255 
00257 #endif


Copyright © 2008-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com