00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef NX_SERIALIZER_H
00029 #define NX_SERIALIZER_H
00030
00037 #include "foundation/PxAssert.h"
00038 #include <PxFileBuf.h>
00039
00040 #include "NxApexUsingNamespace.h"
00041
00042 namespace NxParameterized
00043 {
00044
00045 PX_PUSH_PACK_DEFAULT
00046
00052 struct SerializePlatform
00053 {
00058 typedef enum
00059 {
00060 ARCH_GEN = 0,
00061 ARCH_X86 = 1,
00062 ARCH_X86_64 = 2,
00063 ARCH_PPC = 3,
00064 ARCH_CELL = 4,
00065 ARCH_ARM = 5,
00066 ARCH_LAST
00067 } ArchType;
00068
00072 ArchType archType;
00073
00078 typedef enum
00079 {
00080 COMP_GEN = 0,
00081 COMP_GCC = 1,
00082 COMP_VC = 2,
00083 COMP_MW = 3,
00084 COMP_LAST
00085 } CompilerType;
00086
00090 CompilerType compilerType;
00091
00095 physx::PxU32 compilerVer;
00096
00101 typedef enum
00102 {
00103 OS_WINDOWS = 0,
00104 OS_LINUX = 1,
00105 OS_LV2 = 2,
00106 OS_MACOSX = 3,
00107 OS_XBOX = 4,
00108 OS_GEN = 5,
00109 OS_ANDROID = 6,
00110 OS_XBOXONE = 7,
00111 OS_PS4 = 8,
00112 OS_LAST
00113 } OsType;
00114
00118 OsType osType;
00119
00123 physx::PxU32 osVer;
00124
00128 static const physx::PxU32 ANY_VERSION = (physx::PxU32)-1;
00129
00130 PX_INLINE SerializePlatform();
00131
00135 PX_INLINE SerializePlatform(ArchType archType, CompilerType compType, physx::PxU32 compVer, OsType osType, physx::PxU32 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
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
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
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
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 ::NxParameterized::Interface **objs,
00274 physx::PxU32 nobjs,
00275 bool doSerializeMetadata = false) = 0;
00276
00284 virtual ErrorType peekNumObjects(physx::general_PxIOStream2::PxFileBuf &stream, physx::PxU32 &numObjects) = 0;
00285
00294 virtual ErrorType peekClassNames(physx::general_PxIOStream2::PxFileBuf &stream, char **classNames, physx::PxU32 &numClassNames) = 0;
00295
00302 virtual ErrorType peekNumObjectsInplace(const void *data, physx::PxU32 dataLen, physx::PxU32 &numObjects) = 0;
00303
00305 template < typename T, int bufSize = 8 > class DeserializedResults
00306 {
00307 T buf[bufSize];
00308
00309 T *objs;
00310
00311 physx::PxU32 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_, physx::PxU32 nobjs_);
00337
00341 PX_INLINE void init(Traits *traits_, T *objs_, physx::PxU32 nobjs_);
00342
00346 PX_INLINE physx::PxU32 size() const;
00347
00351 PX_INLINE T &operator[](physx::PxU32 i);
00352
00356 PX_INLINE const T &operator[](physx::PxU32 i) const;
00357
00362 PX_INLINE void getObjects(T *outObjs);
00363
00367 PX_INLINE void releaseAll();
00368 };
00369
00375 typedef DeserializedResults< ::NxParameterized::Interface *> DeserializedData;
00376
00378 struct MetadataEntry
00379 {
00381 const char *className;
00382
00384 physx::PxU32 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, physx::PxU32 dataLen, DeserializedData &desData);
00430
00441 virtual ErrorType deserializeInplace(void *data, physx::PxU32 dataLen, DeserializedData &desData, bool &isUpdated) = 0;
00442
00449 virtual ErrorType peekInplaceAlignment(physx::general_PxIOStream2::PxFileBuf& stream, physx::PxU32& align) = 0;
00450
00454 virtual void release() = 0;
00455 };
00456
00457 PX_POP_PACK
00458
00459 }
00460
00461 #include "NxSerializer.inl"
00462
00463 #endif // NX_SERIALIZER_H