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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
//
// 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) 2018 NVIDIA Corporation. All rights reserved.




#include <stdio.h>
#include <string.h>
#include <stdarg.h>

#include "MiPlatformConfig.h"
#include "MiFileInterface.h"

#pragma warning(disable:4267)

/*
 * Copyright 2009-2011 NVIDIA Corporation.  All rights reserved.
 *
 * NOTICE TO USER:
 *
 * This source code is subject to NVIDIA ownership rights under U.S. and
 * international Copyright laws.  Users and possessors of this source code
 * are hereby granted a nonexclusive, royalty-free license to use this code
 * in individual and commercial software.
 *
 * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
 * CODE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
 * IMPLIED WARRANTY OF ANY KIND.  NVIDIA DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
 * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 * OF USE, DATA OR PROFITS,  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION,  ARISING OUT OF OR IN CONNECTION WITH THE USE
 * OR PERFORMANCE OF THIS SOURCE CODE.
 *
 * U.S. Government End Users.   This source code is a "commercial item" as
 * that term is defined at  48 C.F.R. 2.101 (OCT 1995), consisting  of
 * "commercial computer  software"  and "commercial computer software
 * documentation" as such terms are  used in 48 C.F.R. 12.212 (SEPT 1995)
 * and is provided to the U.S. Government only as a commercial end item.
 * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
 * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
 * source code with only those rights set forth herein.
 *
 * Any use of this source code in individual and commercial software must
 * include, in the user documentation and internal comments to the code,
 * the above Disclaimer and U.S. Government End Users Notice.
 */


//********************************************************************************************
//***
//*** A wrapper interface for standard FILE IO services that provides support to read and
//** write 'files' to and from a buffer in memory.
//***
//********************************************************************************************



#pragma warning(disable:4996) // Disabling stupid .NET deprecated warning.

#define DEFAULT_BUFFER_SIZE 8192
#define BUFFER_GROW_SIZE    1000000 // grow in 1 MB chunks

namespace mimp
{

class MemoryBlock : public MeshImportAllocated
{
public:
  MemoryBlock(size_t size)
  {
    mNextBlock = 0;
    mMemory    = (char *)MI_ALLOC(size);
    mSize      = size;
    mLen       = 0;
  }

  ~MemoryBlock(void)
  {
    MI_FREE(mMemory);
  }

  const char * write(const char *mem,size_t len,size_t &remaining)
  {
    const char *ret = 0;

    if ( (len+mLen) <= mSize )
    {
      char *dest = &mMemory[mLen];
      memcpy(dest,mem,len);
      mLen+=len;
	  remaining = 0;
    }
    else
    {
      MiU32 slen = mSize-mLen;
      if ( slen )
      {
        char *dest = &mMemory[mLen];
        memcpy(dest,mem,slen);
        mLen+=slen;
      }
      ret = mem+slen;
      remaining = len-slen;
      MI_ASSERT( remaining != 0 );
    }
    return ret;
  }

  char * getData(char *dest)
  {
    memcpy(dest,mMemory,mLen);
    dest+=mLen;
    return dest;
  }

  MemoryBlock    *mNextBlock;
  char           *mMemory;
  MiU32    mLen;
  MiU32    mSize;

};

class _FILE_INTERFACE : public MeshImportAllocated
{
public:
	_FILE_INTERFACE(const char *fname,const char *spec,void *mem,size_t len)
	{
    mHeadBlock = 0;
    mTailBlock = 0;
		mMyAlloc   = false;
		mRead      = true; // default is read access.
		mFph       = 0;
		mData      = (char *) mem;
		mLen       = len;
		mLoc       = 0;

		if ( spec && MESH_IMPORT_STRING::stricmp(spec,"wmem") == 0 )
		{
			mRead = false;
			if ( mem == 0 || len == 0 )
			{
				mHeadBlock = MI_NEW(MemoryBlock)(DEFAULT_BUFFER_SIZE);
				mTailBlock = mHeadBlock;
				mData = 0;
				mLen  = 0;
				mMyAlloc = true;
			}
		}

		if ( mData == 0 && mHeadBlock == 0 )
		{
			mFph = fopen(fname,spec);
		}

  	strncpy(mName,fname,512);
	}

  ~_FILE_INTERFACE(void)
  {
  	if ( mMyAlloc )
  	{
  		MI_FREE(mData);

      MemoryBlock *mb = mHeadBlock;
      while ( mb )
      {
        MemoryBlock *next = mb->mNextBlock;
        delete mb;
        mb = next;
      }

  	}
  	if ( mFph )
  	{
  		fclose(mFph);
  	}
  }

  size_t read(char *data,size_t size)
  {
  	size_t ret = 0;
  	if ( (mLoc+size) <= mLen )
  	{
  		memcpy(data, &mData[mLoc], size );
  		mLoc+=size;
  		ret = 1;
  	}
    return ret;
  }

  void validateLen(void)
  {
    if ( mHeadBlock )
    {
      MiU32 slen = 0;

      MemoryBlock *mb = mHeadBlock;
      while ( mb )
      {
        slen+=mb->mLen;
        mb = mb->mNextBlock;
      }
      MI_ASSERT( slen == mLoc );
    }
  }

  size_t write(const char *data,size_t size)
  {
  	size_t ret = 0;

    if ( mMyAlloc )
    {
#ifdef _DEBUG
      validateLen();
#endif
      size_t remaining;
      data = mTailBlock->write(data,size,remaining);
      while ( data )
      {
        size_t _size = remaining;
        MemoryBlock *block = MI_NEW(MemoryBlock)(BUFFER_GROW_SIZE);
        mTailBlock->mNextBlock = block;
        mTailBlock = block;
        data = mTailBlock->write(data,_size,remaining);
      }
      mLoc+=size;
#ifdef _DEBUG
      validateLen();
#endif
      ret = 1;
    }
    else
    {
    	if ( (mLoc+size) <= mLen )
    	{
    		memcpy(&mData[mLoc],data,size);
    		mLoc+=size;
    		ret = 1;
    	}
    }
  	return ret;
  }

	size_t read(void *buffer,size_t size,size_t count)
	{
		size_t ret = 0;
		if ( mFph )
		{
			ret = fread(buffer,size,count,mFph);
		}
		else
		{
			char *data = (char *)buffer;
			for (size_t i=0; i<count; i++)
			{
				if ( (mLoc+size) <= mLen )
				{
					read(data,size);
					data+=size;
					ret++;
				}
				else
				{
					break;
				}
			}
		}
		return ret;
	}

  size_t write(const void *buffer,size_t size,size_t count)
  {
  	size_t ret = 0;

  	if ( mFph )
  	{
  		ret = fwrite(buffer,size,count,mFph);
  	}
  	else
  	{
  		const char *data = (const char *)buffer;
  		for (size_t i=0; i<count; i++)
  		{
    		if ( write(data,size) )
				{
    			data+=size;
    			ret++;
    		}
    		else
    		{
    			break;
    		}
  		}
  	}
  	return ret;
  }

  size_t writeString(const char *str)
  {
  	size_t ret = 0;
  	if ( str )
  	{
  		size_t len = strlen(str);
  		ret = write(str,len, 1 );
  	}
  	return ret;
  }


  size_t  flush(void)
  {
  	size_t ret = 0;
  	if ( mFph )
  	{
  		ret = (size_t)fflush(mFph);
  	}
  	return ret;
  }


  size_t seek(size_t loc,size_t mode)
  {
  	size_t ret = 0;
  	if ( mFph )
  	{
  		ret = (size_t)fseek(mFph,(long)loc,(int)mode);
  	}
  	else
  	{
  		if ( mode == SEEK_SET )
  		{
  			if ( loc <= mLen )
  			{
  				mLoc = loc;
  				ret = 1;
  			}
  		}
  		else if ( mode == SEEK_END )
  		{
  			mLoc = mLen;
  		}
  		else
  		{
  			MI_ALWAYS_ASSERT();
  		}
  	}
  	return ret;
  }

  size_t tell(void)
  {
  	size_t ret = 0;
  	if ( mFph )
  	{
  		ret = (size_t)ftell(mFph);
  	}
  	else
  	{
  		ret = mLoc;
  	}
  	return ret;
  }

  size_t myputc(char c)
  {
  	size_t ret = 0;
  	if ( mFph )
  	{
  		ret = (size_t)fputc(c,mFph);
  	}
  	else
  	{
  		ret = write(&c,1);
  	}
  	return ret;
  }

  size_t eof(void)
  {
  	size_t ret = 0;
  	if ( mFph )
  	{
  		ret = (size_t)feof(mFph);
  	}
  	else
  	{
  		if ( mLoc >= mLen )
  			ret = 1;
  	}
  	return ret;
  }

  size_t  error(void)
  {
  	size_t ret = 0;
  	if ( mFph )
  	{
  		ret = (size_t)ferror(mFph);
  	}
  	return ret;
  }

  void * getMemBuffer(size_t &outputLength)
  {
    outputLength = mLoc;

    if ( mHeadBlock && mLoc > 0 )
    {
      MI_ASSERT(mData==0);
      mData = (char *)MI_ALLOC(mLoc);
      char *dest = mData;
      MemoryBlock *mb = mHeadBlock;
      while ( mb )
      {
        dest = mb->getData(dest);
        MemoryBlock *next = mb->mNextBlock;
        delete mb;
        mb = next;
      }

      mHeadBlock = 0;
      mTailBlock = 0;
    }
    return mData;
  }

  void  myclearerr(void)
  {
    if ( mFph )
    {
      clearerr(mFph);
    }
  }

  FILE 	            *mFph;
  char              *mData;
  size_t             mLen;
  size_t             mLoc;
  bool               mRead;
	char               mName[512];
	bool               mMyAlloc;
  MemoryBlock       *mHeadBlock;
  MemoryBlock       *mTailBlock;

};

FILE_INTERFACE * fi_fopen(const char *fname,const char *spec,void *mem,size_t len)
{
	_FILE_INTERFACE *ret = 0;

	ret = MI_NEW(_FILE_INTERFACE)(fname,spec,mem,len);

	if ( mem == 0 && ret->mData == 0 && ret->mHeadBlock == 0 )
  {
  	if ( ret->mFph == 0 )
  	{
      delete ret;
  		ret = 0;
  	}
  }

	return (FILE_INTERFACE *)ret;
}

size_t  fi_fclose(FILE_INTERFACE *_file)
{
  size_t ret = 0;

  if ( _file )
  {
    _FILE_INTERFACE *file = (_FILE_INTERFACE *)_file;
    delete file;
  }
  return ret;
}

void  fi_clearerr(FILE_INTERFACE *_fph)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
  if ( fph )
  {
    fph->myclearerr();
  }
}

size_t        fi_fread(void *buffer,size_t size,size_t count,FILE_INTERFACE *_fph)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;
	if ( fph )
	{
		ret = fph->read(buffer,size,count);
	}
	return ret;
}

size_t        fi_fwrite(const void *buffer,size_t size,size_t count,FILE_INTERFACE *_fph)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;
	if ( fph )
	{
		ret = fph->write(buffer,size,count);
	}
	return ret;
}

size_t        fi_fprintf(FILE_INTERFACE *_fph,const char *fmt,...)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;

	char buffer[2048];
	buffer[2047] = 0;
	va_list arg;
	va_start( arg, fmt );
	MESH_IMPORT_STRING::vsnprintf(buffer,2047, fmt, arg);
	va_end(arg);

	if ( fph )
	{
		ret = fph->writeString(buffer);
	}

	return ret;
}


size_t        fi_fflush(FILE_INTERFACE *_fph)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;
	if ( fph )
	{
		ret = fph->flush();
	}
	return ret;
}


size_t        fi_fseek(FILE_INTERFACE *_fph,size_t loc,size_t mode)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;
	if ( fph )
	{
		ret = fph->seek(loc,mode);
	}
	return ret;
}

size_t        fi_ftell(FILE_INTERFACE *_fph)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;
	if ( fph )
	{
		ret = fph->tell();
	}
	return ret;
}

size_t        fi_fputc(char c,FILE_INTERFACE *_fph)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;
	if ( fph )
	{
		ret = fph->myputc(c);
	}
	return ret;
}

size_t        fi_fputs(const char *str,FILE_INTERFACE *_fph)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;
	if ( fph )
	{
		ret = fph->writeString(str);
	}
	return ret;
}

size_t        fi_feof(FILE_INTERFACE *_fph)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;
	if ( fph )
	{
		ret = fph->eof();
	}
	return ret;
}

size_t        fi_ferror(FILE_INTERFACE *_fph)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	size_t ret = 0;
	if ( fph )
	{
		ret = fph->error();
	}
	return ret;
}

void *     fi_getMemBuffer(FILE_INTERFACE *_fph,size_t *outputLength)
{
  _FILE_INTERFACE *fph = (_FILE_INTERFACE *)_fph;
	*outputLength = 0;
	void * ret = 0;
	if ( fph && outputLength )
	{
    ret = fph->getMemBuffer(*outputLength);
	}
	return ret;
}

};

Commits for Divide-Dependencies/physx/APEX_1.4/shared/general/meshimport/src/utils/MiFileInterface.cpp

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

Forgot to actually add physx