NvSerializer.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-2013 NVIDIA Corporation. All rights reserved. 00027 00028 #ifndef NV_SERIALIZER_H 00029 #define NV_SERIALIZER_H 00030 00037 #include <filebuf/PxFileBuf.h> 00038 00039 00040 namespace NvParameterized 00041 { 00042 00043 PX_PUSH_PACK_DEFAULT 00044 00050 struct SerializePlatform 00051 { 00056 typedef enum 00057 { 00058 ARCH_GEN = 0, 00059 ARCH_X86 = 1, 00060 ARCH_X86_64 = 2, 00061 ARCH_PPC = 3, 00062 ARCH_CELL = 4, 00063 ARCH_ARM = 5, 00064 ARCH_ARM_64 = 6, 00065 ARCH_LAST 00066 } ArchType; 00067 00071 ArchType archType; 00072 00077 typedef enum 00078 { 00079 COMP_GEN = 0, 00080 COMP_GCC = 1, 00081 COMP_VC = 2, 00082 COMP_MW = 3, 00083 COMP_LAST 00084 } CompilerType; 00085 00089 CompilerType compilerType; 00090 00094 uint32_t compilerVer; 00095 00100 typedef enum 00101 { 00102 OS_WINDOWS = 0, 00103 OS_LINUX = 1, 00104 OS_LV2 = 2, // PS3 00105 OS_MACOSX = 3, 00106 OS_XBOX = 4, 00107 OS_GEN = 5, 00108 OS_ANDROID = 6, 00109 OS_XBOXONE = 7, 00110 OS_PS4 = 8, 00111 OS_HOS = 9, 00112 OS_LAST 00113 } OsType; 00114 00118 OsType osType; 00119 00123 uint32_t osVer; 00124 00128 static const uint32_t ANY_VERSION = (uint32_t)-1; 00129 00130 PX_INLINE SerializePlatform(); 00131 00135 PX_INLINE SerializePlatform(ArchType archType, CompilerType compType, uint32_t compVer, OsType osType, uint32_t osVer); 00136 00140 PX_INLINE bool operator ==(const SerializePlatform &p) const; 00141 00145 PX_INLINE bool operator !=(const SerializePlatform &p) const; 00146 }; 00147 00148 class Interface; 00149 class Definition; 00150 class Traits; 00151 struct SerializePlatform; 00152 00159 class Serializer 00160 { 00161 public: 00162 00166 enum ErrorType 00167 { 00168 ERROR_NONE = 0, 00169 00170 ERROR_UNKNOWN, 00171 ERROR_NOT_IMPLEMENTED, 00172 00173 // File format related errors 00174 ERROR_INVALID_PLATFORM, 00175 ERROR_INVALID_PLATFORM_NAME, 00176 ERROR_INVALID_FILE_VERSION, 00177 ERROR_INVALID_FILE_FORMAT, 00178 ERROR_INVALID_MAGIC, 00179 ERROR_INVALID_CHAR, 00180 00181 // External errors 00182 ERROR_STREAM_ERROR, 00183 ERROR_MEMORY_ALLOCATION_FAILURE, 00184 ERROR_UNALIGNED_MEMORY, 00185 ERROR_PRESERIALIZE_FAILED, 00186 ERROR_INTERNAL_BUFFER_OVERFLOW, 00187 ERROR_OBJECT_CREATION_FAILED, 00188 ERROR_CONVERSION_FAILED, 00189 00190 // Xml-specific errors 00191 ERROR_VAL2STRING_FAILED, 00192 ERROR_STRING2VAL_FAILED, 00193 ERROR_INVALID_TYPE_ATTRIBUTE, 00194 ERROR_UNKNOWN_XML_TAG, 00195 ERROR_MISSING_DOCTYPE, 00196 ERROR_MISSING_ROOT_ELEMENT, 00197 ERROR_INVALID_NESTING, 00198 ERROR_INVALID_ATTR, 00199 00200 // Other stuff 00201 ERROR_INVALID_ARRAY, 00202 ERROR_ARRAY_INDEX_OUT_OF_RANGE, 00203 ERROR_INVALID_VALUE, 00204 ERROR_INVALID_INTERNAL_PTR, 00205 ERROR_INVALID_PARAM_HANDLE, 00206 ERROR_INVALID_RELOC_TYPE, 00207 ERROR_INVALID_DATA_TYPE, 00208 ERROR_INVALID_REFERENCE 00209 }; 00210 00214 enum SerializeType 00215 { 00217 NST_XML = 0, 00218 00220 NST_BINARY, 00221 00222 NST_LAST 00223 }; 00224 00229 static SerializeType peekSerializeType(physx::general_PxIOStream2::PxFileBuf &stream); 00230 00236 static ErrorType peekPlatform(physx::general_PxIOStream2::PxFileBuf &stream, SerializePlatform &platform); 00237 00238 virtual ~Serializer() {} 00239 00250 virtual ErrorType setTargetPlatform(const SerializePlatform &platform) = 0; 00251 00260 virtual void setAutoUpdate(bool doUpdate) = 0; 00261 00271 virtual ErrorType serialize( 00272 physx::general_PxIOStream2::PxFileBuf &stream, 00273 const ::NvParameterized::Interface **objs, 00274 uint32_t nobjs, 00275 bool doSerializeMetadata = false) = 0; 00276 00284 virtual ErrorType peekNumObjects(physx::general_PxIOStream2::PxFileBuf &stream, uint32_t &numObjects) = 0; 00285 00294 virtual ErrorType peekClassNames(physx::general_PxIOStream2::PxFileBuf &stream, char **classNames, uint32_t &numClassNames) = 0; 00295 00302 virtual ErrorType peekNumObjectsInplace(const void *data, uint32_t dataLen, uint32_t &numObjects) = 0; 00303 00305 template < typename T, int bufSize = 8 > class DeserializedResults 00306 { 00307 T buf[bufSize]; //For small number of objects 00308 00309 T *objs; 00310 00311 uint32_t nobjs; 00312 00313 Traits *traits; 00314 00315 void clear(); 00316 00317 public: 00318 00319 PX_INLINE DeserializedResults(); 00320 00321 PX_INLINE ~DeserializedResults(); 00322 00326 PX_INLINE DeserializedResults(const DeserializedResults &data); 00327 00331 PX_INLINE DeserializedResults &operator =(const DeserializedResults &rhs); 00332 00336 PX_INLINE void init(Traits *traits_, uint32_t nobjs_); 00337 00341 PX_INLINE void init(Traits *traits_, T *objs_, uint32_t nobjs_); 00342 00346 PX_INLINE uint32_t size() const; 00347 00351 PX_INLINE T &operator[](uint32_t i); 00352 00356 PX_INLINE const T &operator[](uint32_t i) const; 00357 00362 PX_INLINE void getObjects(T *outObjs); 00363 00367 PX_INLINE void releaseAll(); 00368 }; 00369 00375 typedef DeserializedResults< ::NvParameterized::Interface *> DeserializedData; 00376 00378 struct MetadataEntry 00379 { 00381 const char *className; 00382 00384 uint32_t version; 00385 00387 Definition *def; 00388 }; 00389 00395 typedef DeserializedResults<MetadataEntry> DeserializedMetadata; 00396 00403 virtual ErrorType deserializeMetadata(physx::general_PxIOStream2::PxFileBuf &stream, DeserializedMetadata &desData); 00404 00410 virtual ErrorType deserialize(physx::general_PxIOStream2::PxFileBuf &stream, DeserializedData &desData); 00411 00418 virtual ErrorType deserialize(physx::general_PxIOStream2::PxFileBuf &stream, DeserializedData &desData, bool &isUpdated) = 0; 00419 00429 virtual ErrorType deserializeInplace(void *data, uint32_t dataLen, DeserializedData &desData); 00430 00441 virtual ErrorType deserializeInplace(void *data, uint32_t dataLen, DeserializedData &desData, bool &isUpdated) = 0; 00442 00449 virtual ErrorType peekInplaceAlignment(physx::general_PxIOStream2::PxFileBuf& stream, uint32_t& align) = 0; 00450 00454 virtual void release() = 0; 00455 }; 00456 00457 PX_POP_PACK 00458 00459 } // namespace NvParameterized 00460 00461 #include "NvSerializer.inl" 00462 00463 #endif // NV_SERIALIZER_H
Generated on Fri Dec 15 2017 13:58:35 Copyright © 2012-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.