Subversion Repository Public Repository

Divide-Dependencies

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.

#ifndef NV_SERIALIZER_H
#define NV_SERIALIZER_H

/*!
\file
\brief NvParameterized serializer class
*/


#include <filebuf/PxFileBuf.h>


namespace NvParameterized
{

PX_PUSH_PACK_DEFAULT

/**
\brief Platform descriptor

This class describes target serialization platform which consists of processor architecture, compiler and OS.
*/
struct SerializePlatform
{
	/** 
	\brief Processor architectures enumeration
	\warning Do not change values of enums!
	*/
	typedef enum
	{
		ARCH_GEN = 0,
		ARCH_X86 = 1,
		ARCH_X86_64 = 2,
		ARCH_PPC = 3,
		ARCH_CELL = 4,
		ARCH_ARM = 5,
		ARCH_ARM_64 = 6,
		ARCH_LAST
	} ArchType;

	/**
	\brief Platform processor architecture
	*/
	ArchType archType;

	/** 
	\brief Compilers enumeration
	\warning Do not change values of enums!
	*/
	typedef enum
	{
		COMP_GEN = 0,
		COMP_GCC = 1,
		COMP_VC = 2,
		COMP_MW = 3,
		COMP_LAST
	} CompilerType;

	/**
	\brief Platform compiler
	*/
	CompilerType compilerType;

	/**
	\brief Platform compiler version
	*/
	uint32_t compilerVer;

	/** 
	\brief OSes enumeration
	\warning Do not change values of enums!
	*/
	typedef enum
	{
		OS_WINDOWS = 0,
		OS_LINUX = 1,
		OS_LV2 = 2, // PS3
		OS_MACOSX = 3,
		OS_XBOX = 4,
		OS_GEN = 5,
		OS_ANDROID = 6,
		OS_XBOXONE = 7,
		OS_PS4 = 8,
		OS_HOS = 9,
		OS_LAST
	} OsType;

	/**
	\brief Platform OS
	*/
	OsType osType;

	/**
	\brief Platform OS version
	*/
	uint32_t osVer;

	/**
	\brief This value identfies that version is unknown
	*/
	static const uint32_t ANY_VERSION = (uint32_t)-1;

	PX_INLINE SerializePlatform();
	
	/**
	\brief Constructor of SerializePlatform
	*/
	PX_INLINE SerializePlatform(ArchType archType, CompilerType compType, uint32_t compVer, OsType osType, uint32_t osVer);

	/**
	\brief Checks if platforms are binary-compatible
	*/
	PX_INLINE bool operator ==(const SerializePlatform &p) const;

	/**
	\brief Checks if platforms are binary-incompatible
	*/
	PX_INLINE bool operator !=(const SerializePlatform &p) const;
};

class Interface;
class Definition;
class Traits;
struct SerializePlatform;

/**
\brief Interface class for serializer-deserializer of NvParameterized objects

Serializer serializes and deserializes one or more NvParameterized objects to file using various output formats
(see SerializeType).
*/
class Serializer
{
public:

	/**
	\brief Status enums that the Serializer methods may return
	*/
	enum ErrorType
	{
		ERROR_NONE = 0,

		ERROR_UNKNOWN,
		ERROR_NOT_IMPLEMENTED,

		// File format related errors
		ERROR_INVALID_PLATFORM,
		ERROR_INVALID_PLATFORM_NAME,
		ERROR_INVALID_FILE_VERSION,
		ERROR_INVALID_FILE_FORMAT,
		ERROR_INVALID_MAGIC,
		ERROR_INVALID_CHAR,

		// External errors
		ERROR_STREAM_ERROR,
		ERROR_MEMORY_ALLOCATION_FAILURE,
		ERROR_UNALIGNED_MEMORY,
		ERROR_PRESERIALIZE_FAILED,
		ERROR_INTERNAL_BUFFER_OVERFLOW,
		ERROR_OBJECT_CREATION_FAILED,
		ERROR_CONVERSION_FAILED,

		// Xml-specific errors
		ERROR_VAL2STRING_FAILED,
		ERROR_STRING2VAL_FAILED,
		ERROR_INVALID_TYPE_ATTRIBUTE,
		ERROR_UNKNOWN_XML_TAG,
		ERROR_MISSING_DOCTYPE,
		ERROR_MISSING_ROOT_ELEMENT,
		ERROR_INVALID_NESTING,
		ERROR_INVALID_ATTR,

		// Other stuff
		ERROR_INVALID_ARRAY,
		ERROR_ARRAY_INDEX_OUT_OF_RANGE,
		ERROR_INVALID_VALUE,
		ERROR_INVALID_INTERNAL_PTR,
		ERROR_INVALID_PARAM_HANDLE,
		ERROR_INVALID_RELOC_TYPE,
		ERROR_INVALID_DATA_TYPE,
		ERROR_INVALID_REFERENCE
	};

	/**
	\brief The supported serialization formats
	*/
	enum SerializeType
	{
		/// serialize in XML format.
		NST_XML = 0,

		/// serialize in a binary format
		NST_BINARY,

		NST_LAST
	};

	/**
	\brief Get type of stream (binary or xml)
	\param [in] stream stream to be analyzed
	*/
	static SerializeType peekSerializeType(physx::general_PxIOStream2::PxFileBuf &stream);

	/**
	\brief Get stream native platform
	\param [in] stream stream to be analyzed
	\param [out] platform stream native platform
	*/
	static ErrorType peekPlatform(physx::general_PxIOStream2::PxFileBuf &stream, SerializePlatform &platform);

	virtual ~Serializer() {}

	/**
	\brief Set platform to use in platform-dependent serialization
	\param [in] platform target platform

	\warning Currently this is used only in binary serializer

	Application running on target platforms may potentially make use of extremely fast
	inplace deserialization (using method deserializeInplace) on files which were serialized
	for this platform.
	*/
	virtual ErrorType setTargetPlatform(const SerializePlatform &platform) = 0;

	/**
	\brief Sets whether serializer will automatically update
		objects after deserialization
	\param [in] doUpdate should automatic update be done?

	\warning Normally you will not need this
	\warning This is true by default
	*/
	virtual void setAutoUpdate(bool doUpdate) = 0;

	/**
	\brief Serialize array of NvParameterized-objects to a stream
	\param [in] stream the stream to which the object will be serialized
	\param [in] objs NvParameterized-objects which will be serialized
	\param [in] nobjs number of objects
	\param [in] doSerializeMetadata set this to store object metadata in file

	\warning Serialized file may depend on selected target platform
	*/
	virtual ErrorType serialize(
		physx::general_PxIOStream2::PxFileBuf &stream,
		const ::NvParameterized::Interface **objs,
		uint32_t nobjs,
		bool doSerializeMetadata = false) = 0;

	/**
	\brief Peek number of NvParameterized-objects in stream with serialized data
	\param [in] stream the stream from which the object will be deserialized
	\param [out] numObjects number of objects

	\warning Not all streams support peeking
	*/
	virtual ErrorType peekNumObjects(physx::general_PxIOStream2::PxFileBuf &stream, uint32_t &numObjects) = 0;

	/**
	\brief Peek number of NvParameterized-objects in stream with serialized data
	\param [in] stream the stream from which objects will be deserialized
	\param [in] classNames pointer to buffer for resulting names
	\param [in,out] numClassNames limit on number of returned classNames; number of returned names

	\warning User is responsible for releasing every element of classNames via Traits::strfree()
	*/
	virtual ErrorType peekClassNames(physx::general_PxIOStream2::PxFileBuf &stream, char **classNames, uint32_t &numClassNames) = 0;

	/**
	\brief Peek number of NvParameterized-objects in memory buffer with serialized data
	\param [in] data pointer to memory buffer
	\param [in] dataLen length of memory buffer
	\param [out] numObjects number of objects
	*/
	virtual ErrorType peekNumObjectsInplace(const void *data, uint32_t dataLen, uint32_t &numObjects) = 0;

	/// TODO
	template < typename T, int bufSize = 8 > class DeserializedResults
	{
		T buf[bufSize]; //For small number of objects

		T *objs;

		uint32_t nobjs;

		Traits *traits;

		void clear();

	public:

		PX_INLINE DeserializedResults();

		PX_INLINE ~DeserializedResults();

		/**
		\brief Copy constructor
		*/
		PX_INLINE DeserializedResults(const DeserializedResults &data);

		/**
		\brief Assignment operator
		*/
		PX_INLINE DeserializedResults &operator =(const DeserializedResults &rhs);

		/**
		\brief Allocate memory for values
		*/
		PX_INLINE void init(Traits *traits_, uint32_t nobjs_);

		/**
		\brief Allocate memory and set values
		*/
		PX_INLINE void init(Traits *traits_, T *objs_, uint32_t nobjs_);

		/**
		\brief Number of objects in a container
		*/
		PX_INLINE uint32_t size() const;

		/**
		\brief Access individual object in container
		*/
		PX_INLINE T &operator[](uint32_t i);

		/**
		\brief Const-access individual object in container
		*/
		PX_INLINE const T &operator[](uint32_t i) const;

		/**
		\brief Read all NvParameterized objects in container to buffer outObjs
		\warning outObjs must be large enough to hold all contained objects
		*/
		PX_INLINE void getObjects(T *outObjs);

		/**
		\brief Release all objects
		*/
		PX_INLINE void releaseAll();
	};

	/**
	\brief Container for results of deserialization

	DeserializedData holds array of NvParameterized objects obtained during deserialization.
	*/
	typedef DeserializedResults< ::NvParameterized::Interface *> DeserializedData;

	/// This class keeps metadata of a single NvParameterized class
	struct MetadataEntry
	{
		/// Class name
		const char *className;

		/// Class version
		uint32_t version;

		/// Class metadata
		Definition *def;
	};

	/**
	\brief Container for results of metadata deserialization

	DeserializedMetadata holds array of MetadataEntry obtained during metadata deserialization.
	*/
	typedef DeserializedResults<MetadataEntry> DeserializedMetadata;

	/**
	\brief Deserialize metadata from a stream into one or more definitions
	\param [in] stream the stream from which metadata will be deserialized
	\param [out] desData storage for deserialized metadata
	\warning This is a draft implementation!
	*/
	virtual ErrorType deserializeMetadata(physx::general_PxIOStream2::PxFileBuf &stream, DeserializedMetadata &desData);

	/**
	\brief Deserialize a stream into one or more NvParameterized objects
	\param [in] stream the stream from which objects will be deserialized
	\param [out] desData storage for deserialized data
	*/
	virtual ErrorType deserialize(physx::general_PxIOStream2::PxFileBuf &stream, DeserializedData &desData);

	/**
	\brief Deserialize a stream into one or more NvParameterized objects
	\param [in] stream the stream from which objects will be deserialized
	\param [out] desData storage for deserialized data
	\param [out] isUpdated true if any legacy object was updated, false otherwise
	*/
	virtual ErrorType deserialize(physx::general_PxIOStream2::PxFileBuf &stream, DeserializedData &desData, bool &isUpdated) = 0;

	/**
	\brief Deserialize memory buffer into one or more NvParameterized objects
	\param [in] data pointer to serialized data. It should be allocated via Traits.
	\param [in] dataLen length of serialized data
	\param [out] desData storage for deserialized data

	\warning Currently only binary serializer supports inplace deserialization
	\warning Memory must be aligned to 8 byte boundary
	*/
	virtual ErrorType deserializeInplace(void *data, uint32_t dataLen, DeserializedData &desData);

	/**
	\brief Deserialize memory buffer into one or more NvParameterized objects
	\param [in] data pointer to serialized data
	\param [in] dataLen length of serialized data
	\param [out] desData storage for deserialized data
	\param [out] isUpdated true if any legacy object was updated, false otherwise

	\warning Currently only binary serializer supports inplace deserialization
	\warning Memory must be aligned to the boundary required by the data (see getInplaceAlignment)
	*/
	virtual ErrorType deserializeInplace(void *data, uint32_t dataLen, DeserializedData &desData, bool &isUpdated) = 0;

	/**
	\brief Get minimum alignment required for inplace deserialization of data in stream
	\param [in] stream stream which will be inplace deserialized
	\param [out] align alignment required for inplace deserialization of stream
	\note For most of the objects this will return default alignment of 8 bytes
	*/
	virtual ErrorType peekInplaceAlignment(physx::general_PxIOStream2::PxFileBuf& stream, uint32_t& align) = 0;

	/**
	\brief Release deserializer and any memory allocations associated with it
	*/
	virtual void release() = 0;
};

PX_POP_PACK

} // namespace NvParameterized

#include "NvSerializer.inl"

#endif // NV_SERIALIZER_H

Commits for Divide-Dependencies/physx/APEX_1.4/include/nvparameterized/NvSerializer.h

Diff revisions: vs.
Revision Author Commited Message
105 IonutCava picture IonutCava Tue 16 Apr, 2019 19:55:41 +0000

Forgot to actually add physx