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 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,
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
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 ::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];
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 }
00460
00461 #include "NvSerializer.inl"
00462
00463 #endif // NV_SERIALIZER_H