forked from louipc/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opennurbs_archive.cpp
15617 lines (14234 loc) · 417 KB
/
opennurbs_archive.cpp
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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
FILE* ON_FileStream::Open( const wchar_t* filename, const wchar_t* mode )
{
FILE* fp = 0;
if ( 0 == filename || 0 == filename[0] || 0 == mode || 0 == mode[0] )
return fp;
#if defined(ON_OS_WINDOWS)
errno_t e = _wfopen_s(&fp,filename,mode);
if ( 0 != e && 0 == fp )
fp = 0; // reference e to keep lint quiet.
#else
// I can't find an wfopen() or _wfopen() in
// gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
ON_String fnameUTF8(filename);
ON_String modeUTF8(mode);
fp = fopen(fnameUTF8,modeUTF8);
#endif
return fp;
}
FILE* ON_FileStream::Open( const char* filename, const char* mode )
{
FILE* fp = 0;
if ( 0 == filename || 0 == filename[0] || 0 == mode || 0 == mode[0] )
return fp;
#if defined(ON_OS_WINDOWS)
errno_t e = fopen_s(&fp,filename,mode);
if ( 0 != e && 0 == fp )
fp = 0; // reference e to keep lint quiet.
#else
fp = fopen(filename,mode);
#endif
return fp;
}
int ON_FileStream::Close( FILE* fp )
{
return ( ( 0 != fp ) ? fclose(fp) : -1 );
}
ON__INT64 ON_FileStream::CurrentPosition( FILE* fp )
{
if ( 0 == fp )
return -1;
#if defined(ON_OS_WINDOWS)
return _ftelli64(fp);
#else
return ftell(fp);
#endif
}
bool ON_FileStream::SeekFromCurrentPosition( FILE* fp, ON__INT64 offset )
{
return ON_FileStream::Seek(fp,offset,SEEK_CUR);
}
bool ON_FileStream::SeekFromStart( FILE* fp, ON__INT64 offset )
{
return ON_FileStream::Seek(fp,offset,SEEK_SET);
}
bool ON_FileStream::SeekFromEnd( FILE* fp, ON__INT64 offset )
{
return ON_FileStream::Seek(fp,offset,SEEK_END);
}
bool ON_FileStream::Seek( FILE* fp, ON__INT64 offset, int origin )
{
if ( 0 == fp )
return false;
if ( origin < 0 || origin > 2 )
return false;
if ( 0 == offset )
return true;
#if defined(ON_OS_WINDOWS)
if ( 0 != _fseeki64(fp,offset,origin) )
return false;
#else
const int i = 2147483646;
const ON__INT64 i64 = i;
while ( offset > i64 )
{
if ( 0 != fseek( fp, i, origin ) )
return false;
offset -= i64;
}
while ( offset < -i64 )
{
if ( 0 != fseek( fp, -i, origin ) )
return false;
offset += i64;
}
if ( 0 != offset )
{
int ioffset = (int)offset;
if ( 0 != fseek( fp, ioffset, origin ) )
return false;
}
#endif
return true;
}
ON__UINT64 ON_FileStream::Read( FILE* fp, ON__UINT64 count, void* buffer )
{
ON__UINT64 rc = 0;
if ( 0 == fp || count <= 0 || 0 == buffer )
return rc;
if ( count <= ON_MAX_SIZE_T )
{
rc = (ON__UINT64)fread(buffer,1,(size_t)count,fp);
}
else
{
size_t sz, szread;
while ( count > 0 )
{
sz = ( count > ON_MAX_SIZE_T ) ? ON_MAX_SIZE_T : ((size_t)count);
szread = fread(buffer,1,sz,fp);
rc += szread;
if ( szread != sz )
break;
count -= sz;
buffer = ((unsigned char*)buffer) + sz;
}
}
return rc;
}
ON__UINT64 ON_FileStream::Write( FILE* fp, ON__UINT64 count, const void* buffer )
{
ON__UINT64 rc = 0;
if ( 0 == fp || count <= 0 || 0 == buffer )
return rc;
if ( count <= ON_MAX_SIZE_T )
{
rc = fwrite(buffer,1,(size_t)count,fp);
}
else
{
size_t sz, szwrite;
while ( count > 0 )
{
sz = ( count > ON_MAX_SIZE_T ) ? ON_MAX_SIZE_T : ((size_t)count);
szwrite = fwrite(buffer,1,sz,fp);
rc += szwrite;
if ( szwrite != sz )
break;
count -= sz;
buffer = ((unsigned char*)buffer) + sz;
}
}
return rc;
}
bool ON_FileStream::Flush( FILE* fp )
{
if ( 0 == fp )
return false;
if ( 0 != fflush(fp) )
return false;
return true;
}
bool ON_FileStream::GetFileInformation(
FILE* fp,
ON__UINT64* file_size,
ON__UINT64* file_create_time,
ON__UINT64* file_last_modified_time
)
{
bool rc = false;
if (file_size)
*file_size = 0;
if (file_create_time)
*file_create_time = 0;
if (file_last_modified_time)
*file_last_modified_time = 0;
if ( fp )
{
#if defined(ON_COMPILER_MSC)
// Microsoft compilers
int fd = _fileno(fp);
#if (_MSC_VER >= 1400)
// VC 8 (2005)
// works for file sizes > 4GB
// when size_t is a 64 bit integer
struct _stat64 sb;
memset(&sb,0,sizeof(sb));
int fstat_rc = _fstat64(fd, &sb);
#else
// VC6 compiler
// works on most compilers
struct _stat sb;
memset(&sb,0,sizeof(sb));
int fstat_rc = _fstat(fd, &sb);
#endif
#else
// works on most compilers
int fd = fileno(fp);
struct stat sb;
memset(&sb,0,sizeof(sb));
int fstat_rc = fstat(fd, &sb);
#endif
if (0 == fstat_rc)
{
if (file_size)
*file_size = (ON__UINT64)sb.st_size;
if (file_create_time)
*file_create_time = (ON__UINT64)sb.st_ctime;
if (file_last_modified_time)
*file_last_modified_time = (ON__UINT64)sb.st_mtime;
rc = true;
}
}
return rc;
}
class ON_ReadChunkHelper
{
public:
ON_ReadChunkHelper(ON_BinaryArchive&);
~ON_ReadChunkHelper();
ON_BinaryArchive& m_binary_archive;
bool m_bReadSuccess;
ON__UINT32 m_chunk_tcode;
ON__INT64 m_chunk_value;
private:
bool m_bCallEndRead3dmChunk;
// prohibit use - no implementation
ON_ReadChunkHelper();
ON_ReadChunkHelper(const ON_ReadChunkHelper&);
ON_ReadChunkHelper& operator=(const ON_ReadChunkHelper&);
};
ON_ReadChunkHelper::ON_ReadChunkHelper(ON_BinaryArchive& binary_archive)
: m_binary_archive(binary_archive)
, m_bReadSuccess(0)
, m_chunk_tcode(0)
, m_chunk_value(0)
, m_bCallEndRead3dmChunk(0)
{
m_bReadSuccess = m_binary_archive.BeginRead3dmBigChunk(&m_chunk_tcode,&m_chunk_value);
if ( m_bReadSuccess )
m_bCallEndRead3dmChunk = true;
}
ON_ReadChunkHelper::~ON_ReadChunkHelper()
{
if ( m_bReadSuccess && !m_binary_archive.EndRead3dmChunk() )
m_bReadSuccess = false;
}
bool ON_IsUnsignedChunkTypecode( ON__UINT32 typecode )
{
// returns tru if the chunk value should be treated as an unsigned int.
return ( 0 == (TCODE_SHORT & typecode)
|| TCODE_RGB == typecode
|| TCODE_RGBDISPLAY == typecode
|| TCODE_PROPERTIES_OPENNURBS_VERSION == typecode
|| TCODE_OBJECT_RECORD_TYPE == typecode
);
}
bool ON_IsLongChunkTypecode(ON__UINT32 typecode)
{
// NOTE: RenderXXXX plug-in used zero as a typecode in material userdata, sigh ...
//return (0 != typecode && 0 == (TCODE_SHORT & typecode));
return (0 == (TCODE_SHORT & typecode));
}
bool ON_IsShorChunkTypecode(ON__UINT32 typecode)
{
return (0 != (TCODE_SHORT & typecode));
}
static
bool DownSizeINT( ON__INT64 i64, ON__INT32* i32 )
{
const static ON__INT64 i32max = 2147483647;
if ( i64 <= i32max && i64 >= (-i32max - 1) )
{
*i32 = (ON__INT32)i64;
return true;
}
ON_ERROR("i64 too big to convert to 4 byte signed int");
*i32 = 0;
return false;
}
static
bool DownSizeUINT( ON__UINT64 u64, ON__UINT32* u32 )
{
if ( u64 <= 0xFFFFFFFF )
{
*u32 = (ON__UINT32)u64;
return true;
}
ON_ERROR("u64 too big to convert to 4 byte unsigned int");
*u32 = 0;
return false;
}
static
bool DownSizeChunkValue( ON__UINT32 typecode, ON__INT64 v64, ON__INT32* v32 )
{
if ( 0 == v32 )
return true;
return ( ON_IsLongChunkTypecode(typecode) )
? DownSizeUINT( (ON__UINT64)v64, (ON__UINT32*)v32 )
: DownSizeINT( v64, v32 );
}
struct ON__3dmV1LayerIndex
{
int m_layer_index;
int m_layer_name_length;
char* m_layer_name;
struct ON__3dmV1LayerIndex* m_next;
};
ON_BinaryArchive::ON_BinaryArchive( ON::archive_mode mode )
: m_3dm_version(0),
m_3dm_v1_layer_index(0), m_3dm_v1_material_index(0),
m_error_message_mask(0),
m_3dm_opennurbs_version(0),
m_3dm_start_section_offset(0),
m_active_table(ON_BinaryArchive::no_active_table),
m_bDoChunkCRC(0), m_bad_CRC_count(0),
m_endian(ON::Endian()),
m_mode(mode)
{
// Sparc, MIPS, ... CPUs have big endian byte order
// ON_BinaryArchives use little endian byte order
m_bSaveUserData = true; // true to save user data (increases file size)
m_bSavePreviewImage = false; // true to save 200x200 preview bitmap (increases file size)
m_bEmbedTextureBitmaps = false; // true to embed texture, bump, trace, and wallpaper bitmaps (increases file size)
m_bSaveRenderMeshes = false; // true to save meshes used to render B-rep objects (increases file size)
m_bSaveAnalysisMeshes = false; // true to save meshes used in surface analysis (increases file size)
m_zlib.mode = ON::unknown_archive_mode;
memset( &m_zlib.strm, 0, sizeof(m_zlib.strm) );
m_V1_layer_list = 0;
}
ON_BinaryArchive::~ON_BinaryArchive()
{
if ( 0 != m_V1_layer_list )
{
struct ON__3dmV1LayerIndex* next = m_V1_layer_list;
m_V1_layer_list = 0;
for ( int i = 0; 0 != next && i < 1000; i++ )
{
struct ON__3dmV1LayerIndex* p = next;
next = p->m_next;
onfree(p);
}
}
CompressionEnd();
}
bool ON_BinaryArchive::ToggleByteOrder(
int count, // number of elements
int sizeof_element, // size of element (2,4, or 8)
const void* src, // source buffer
void* dst // destination buffer (can be same as source buffer)
)
{
unsigned char c[32];
const unsigned char* a = (const unsigned char*)src;
unsigned char* b = (unsigned char*)dst;
bool rc = (count==0 || (count>0&&src&&dst));
if ( rc )
{
// loops are unrolled and a switch is used
// to speed things up a bit.
switch(sizeof_element)
{
case 2:
while(count--)
{
c[0] = *a++;
c[1] = *a++;
*b++ = c[1];
*b++ = c[0];
}
break;
case 4:
while(count--)
{
c[0] = *a++;
c[1] = *a++;
c[2] = *a++;
c[3] = *a++;
*b++ = c[3];
*b++ = c[2];
*b++ = c[1];
*b++ = c[0];
}
break;
case 8:
while(count--)
{
c[0] = *a++;
c[1] = *a++;
c[2] = *a++;
c[3] = *a++;
c[4] = *a++;
c[5] = *a++;
c[6] = *a++;
c[7] = *a++;
*b++ = c[7];
*b++ = c[6];
*b++ = c[5];
*b++ = c[4];
*b++ = c[3];
*b++ = c[2];
*b++ = c[1];
*b++ = c[0];
}
break;
default:
if ( sizeof_element > 0 && sizeof_element < 32 )
{
// As of 2 May 2003, this case is never used
// by core opennurbs objects.
//
// This is here so that future code will work
// if and when 128 bit "ints"/"doubles" become common
// enough that they can be stored in 3dm files.
// It may also happen that third party applications
// on specialized CPUs need to toggle byte order
// for 128 bit ints/doubles stored as user data.
int i;
while(count--)
{
for (i = 0; i < sizeof_element; i++)
c[i] = *a++;
while(i--)
*b++ = c[i];
}
}
else
{
rc = false;
}
break;
}
}
return rc;
}
bool ON_BinaryArchive::BigSeekFromStart( ON__UINT64 offset )
{
// SeekFromStart() is a virutal function that
// any developer can implement. Some implementations
// may use signed 4 byte int in critical places.
// BigSeekFromStart() will work correctly in
// this worst case situation.
return ( offset > 2147483632 )
? ( SeekFromStart(2147483632) && BigSeekForward(offset - 2147483632) )
: SeekFromStart((size_t)offset);
}
bool ON_BinaryArchive::BigSeekForward( ON__UINT64 offset )
{
// SeekFromCurrentPosition() is a virutal function that
// uses a signed 4 byte int in critical places.
// BigSeekForward() will work correctly when
// offset is larger than the maximum value of a signed
// 4 byte int.
while ( offset > 2147483632 )
{
if ( !SeekFromCurrentPosition(2147483632) )
return false;
offset -= 2147483632;
}
if ( offset > 0 )
{
int ioffset32 = (int)((ON__INT64)offset);
return SeekFromCurrentPosition(ioffset32);
}
return true;
}
bool ON_BinaryArchive::BigSeekBackward( ON__UINT64 offset )
{
// SeekFromCurrentPosition() is a virutal function that
// uses a signed 4 byte int in critical places.
// BigSeekBackward() will work correctly when
// offset is larger than the maximum value of a signed
// 4 byte int.
while ( offset > 2147483632 )
{
if ( !SeekFromCurrentPosition(-2147483632) )
return false;
offset -= 2147483632;
}
if ( offset > 0 )
{
int ioffset32 = (int)((ON__INT64)offset);
return SeekFromCurrentPosition(-ioffset32);
}
return true;
}
bool ON_BinaryArchive::BigSeekFromCurrentPosition( ON__INT64 offset )
{
// SeekFromCurrentPosition() is a virutal function that
// uses a signed 4 byte int in critical places.
// BigSeekFromCurrentPosition() will work correctly when
// offset is smaller than the minimum value of a signed
// 4 byte int or the maximum value of a signed 4 byte int.
return ( offset >= 0 )
? BigSeekForward((ON__UINT64)offset)
: BigSeekBackward((ON__UINT64)(-offset));
}
bool
ON_BinaryArchive::ReadMode() const
{
return (m_mode & ON::read) ? true : false;
}
bool
ON_BinaryArchive::WriteMode() const
{
return (m_mode & ON::write) ? true : false;
}
bool
ON_BinaryArchive::ReadChar( // Read an array of 8 bit chars
size_t count, // number of chars to read
char* p
)
{
return ReadByte( count, p );
}
bool
ON_BinaryArchive::ReadChar( // Read an array of 8 bit unsigned chars
size_t count, // number of unsigned chars to read
unsigned char* p
)
{
return ReadByte( count, p );
}
bool
ON_BinaryArchive::ReadChar( // Read a single 8 bit char
char* p
)
{
return ReadByte( 1, p );
}
bool
ON_BinaryArchive::ReadChar( // Read a single 8 bit unsigned char
unsigned char* p
)
{
return ReadByte( 1, p );
}
bool
ON_BinaryArchive::ReadInt16( // Read an array of 16 bit integers
size_t count, // number of unsigned integers to read
ON__INT16* p
)
{
bool rc = ReadByte( count<<1, p );
if ( rc && m_endian == ON::big_endian )
{
// reverse byte order
unsigned char* b= (unsigned char*) (p);
unsigned char c;
while(count--) {
c = b[0]; b[0] = b[1]; b[1] = c;
b += 2;
}
}
return rc;
}
bool
ON_BinaryArchive::ReadShort( // Read an array of 16 bit shorts
size_t count, // number of unsigned chars to read
short* p
)
{
#if defined(ON_COMPILER_MSC)
#pragma warning( push )
// Disable the MSC /W4 "conditional expression is constant" warning
// about 2 == sizeof(*p). Since this code has to run on machines
// where sizeof(*p) can be 2, 4, or 8 bytes, the test is necessary.
#pragma warning( disable : 4127 )
#endif
bool rc = true;
if ( 2 == sizeof(*p) )
{
rc = ReadInt16( count, (ON__INT16*)p );
}
else
{
size_t j;
ON__INT16 i16;
for ( j = 0; j < count && rc; j++ )
{
rc = ReadInt16( 1, &i16 );
*p++ = (short)i16;
}
}
return rc;
#if defined(ON_COMPILER_MSC)
#pragma warning( pop )
#endif
}
bool
ON_BinaryArchive::ReadShort( // Read an array of 16 bit unsigned shorts
size_t count, // number of unsigned chars to read
unsigned short* p
)
{
return ReadShort( count, (short*)p );
}
bool
ON_BinaryArchive::ReadShort( // Read a single 16 bit short
short* p
)
{
return ReadShort( 1, p );
}
bool
ON_BinaryArchive::ReadShort( // Read a single 16 bit unsigned short
unsigned short* p
)
{
return ReadShort( 1, p );
}
bool
ON_BinaryArchive::ReadInt32( // Read an array of 32 bit integers
size_t count, // number of 32 bit integers to read
ON__INT32* p
)
{
bool rc = ReadByte( count<<2, p );
if ( rc && m_endian == ON::big_endian )
{
unsigned char* b= (unsigned char*)p;
unsigned char c;
while(count--) {
c = b[0]; b[0] = b[3]; b[3] = c;
c = b[1]; b[1] = b[2]; b[2] = c;
b += 4;
}
}
return rc;
}
bool
ON_BinaryArchive::ReadInt( // Read an array of integers
size_t count, // number of unsigned chars to read
int* p
)
{
#if defined(ON_COMPILER_MSC)
#pragma warning( push )
// Disable the MSC /W4 "conditional expression is constant" warning
// about 4 == sizeof(*p). Since this code has to run on machines
// where sizeof(*p) can be 2, 4, or 8 bytes, the test is necessary.
#pragma warning( disable : 4127 )
#endif
bool rc;
if ( 4 == sizeof(*p) )
{
rc = ReadInt32( count, (ON__INT32*)p );
}
else
{
rc = true;
ON__INT32 i32;
size_t j;
for ( j = 0; j < count && rc; j++ )
{
rc = ReadInt32(1,&i32);
if (rc)
*p++ = (int)i32;
}
}
return rc;
#if defined(ON_COMPILER_MSC)
#pragma warning( pop )
#endif
}
bool
ON_BinaryArchive::ReadInt( // Read an array of 32 bit integers
size_t count, // number of unsigned chars to read
unsigned int* p
)
{
return ReadInt( count, (int*)p );
}
bool
ON_BinaryArchive::ReadInt( // Read a single 32 bit integer
int* p
)
{
return ReadInt( 1, p );
}
bool
ON_BinaryArchive::ReadInt( // Read a single 32 bit unsigned integer
unsigned int* p
)
{
return ReadInt( 1, p );
}
bool ON_BinaryArchive::ReadBigInt( // Read an array of 64 bit integers
size_t count,
ON__INT64* p
)
{
return ReadInt64(1,p);
}
bool ON_BinaryArchive::ReadBigInt( // Read an array of 64 bit integers
size_t count,
ON__UINT64* p
)
{
return ReadInt64(1,(ON__INT64*)p);
}
bool ON_BinaryArchive::ReadBigInt( // Read a single 64 bit integer
ON__INT64* p
)
{
return ReadInt64(1,p);
}
bool ON_BinaryArchive::ReadBigInt( // Read a single 64 bit unsigned integer
ON__UINT64* p
)
{
return ReadInt64(1,(ON__INT64*)p);
}
bool
ON_BinaryArchive::ReadLong( // Read an array of 32 bit integers
size_t count, // number of unsigned chars to read
long* p
)
{
#if defined(ON_COMPILER_MSC)
#pragma warning( push )
// Disable the MSC /W4 "conditional expression is constant" warning
// about 4 == sizeof(*p). Since this code has to run on machines
// where sizeof(*p) can be 2, 4, or 8 bytes, the test is necessary.
#pragma warning( disable : 4127 )
#endif
bool rc;
if ( 4 == sizeof(*p) )
{
rc = ReadInt32( count, (ON__INT32*)p );
}
else
{
rc = true;
ON__INT32 i32;
size_t j;
for ( j = 0; j < count && rc; j++ )
{
rc = ReadInt32(1,&i32);
if (rc)
*p++ = (long)i32;
}
}
return rc;
#if defined(ON_COMPILER_MSC)
#pragma warning( pop )
#endif
}
bool
ON_BinaryArchive::ReadLong( // Read an array of 32 bit integers
size_t count, // number of unsigned chars to read
unsigned long* p
)
{
return ReadLong( count, (long*)p );
}
bool
ON_BinaryArchive::ReadLong( // Read a single 32 bit integer
long* p
)
{
return ReadLong( 1, (long*)p );
}
bool
ON_BinaryArchive::ReadLong( // Read a single 32 bit unsigned integer
unsigned long* p
)
{
return ReadLong( 1, (long*)p );
}
bool
ON_BinaryArchive::ReadFloat( // Read an array of floats
size_t count, // number of unsigned chars to read
float* p
)
{
// 32 bit floats and 32 bit integers have same size and endian issues
return ReadInt32( count, (ON__INT32*)p );
}
bool
ON_BinaryArchive::ReadFloat( // Read a single float
float* p
)
{
return ReadFloat( 1, p );
}
bool
ON_BinaryArchive::ReadDouble( // Read an array of IEEE 64 bit doubles
size_t count, // number of unsigned chars to read
double* p
)
{
bool rc = ReadByte( count<<3, p );
if ( rc && m_endian == ON::big_endian )
{
unsigned char* b=(unsigned char*)p;
unsigned char c;
while(count--) {
c = b[0]; b[0] = b[7]; b[7] = c;
c = b[1]; b[1] = b[6]; b[6] = c;
c = b[2]; b[2] = b[5]; b[5] = c;
c = b[3]; b[3] = b[4]; b[4] = c;
b += 8;
}
}
return rc;
}
bool
ON_BinaryArchive::ReadDouble( // Read a single double
double* p
)
{
return ReadDouble( 1, p );
}
bool
ON_BinaryArchive::ReadColor( ON_Color& color )
{
unsigned int colorref = 0;
bool rc = ReadInt( &colorref );
color = colorref;
return rc;
}
bool
ON_BinaryArchive::ReadPoint (
ON_2dPoint& p
)
{
return ReadDouble( 2, &p.x );
}
bool
ON_BinaryArchive::ReadPoint (
ON_3dPoint& p
)
{
return ReadDouble( 3, &p.x );
}
bool
ON_BinaryArchive::ReadPoint (
ON_4dPoint& p
)
{
return ReadDouble( 4, &p.x );
}
bool
ON_BinaryArchive::ReadVector (
ON_2dVector& v
)
{
return ReadDouble( 2, &v.x );
}
bool
ON_BinaryArchive::ReadVector (
ON_3dVector& v
)
{
return ReadDouble( 3, &v.x );
}
bool ON_BinaryArchive::WriteBoundingBox(const ON_BoundingBox& bbox)
{
bool rc = WritePoint( bbox.m_min );
if (rc) rc = WritePoint( bbox.m_max );
return rc;
}
bool ON_BinaryArchive::ReadBoundingBox(ON_BoundingBox& bbox)
{
bool rc = ReadPoint( bbox.m_min );
if (rc) rc = ReadPoint( bbox.m_max );
return rc;
}
bool
ON_BinaryArchive::WriteXform( const ON_Xform& x )
{