1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <FSD_BinaryFile.ixx>
22 const Standard_CString MAGICNUMBER = "BINFILE";
24 //=======================================================================
25 //function : FSD_BinaryFile
27 //=======================================================================
29 FSD_BinaryFile::FSD_BinaryFile() :
32 myHeader.testindian = -1;
35 myHeader.bcomment = -1;
36 myHeader.ecomment = -1;
47 //=======================================================================
48 //function : IsGoodFileType
49 //purpose : INFO SECTION
51 //=======================================================================
53 Storage_Error FSD_BinaryFile::IsGoodFileType(const TCollection_AsciiString& aName)
58 s = f.Open(aName,Storage_VSRead);
60 if (s == Storage_VSOk) {
61 TCollection_AsciiString l;
62 Standard_Size len = strlen(FSD_BinaryFile::MagicNumber());
68 if (strncmp(FSD_BinaryFile::MagicNumber(),l.ToCString(),len) != 0) {
69 s = Storage_VSFormatError;
76 //=======================================================================
79 //=======================================================================
81 Storage_Error FSD_BinaryFile::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
83 Storage_Error result = Storage_VSOk;
87 if (OpenMode() == Storage_VSNone) {
88 if (aMode == Storage_VSRead) {
89 myStream = fopen(aName.ToCString(),"rb");
91 else if (aMode == Storage_VSWrite) {
92 myStream = fopen(aName.ToCString(),"wb");
94 else if (aMode == Storage_VSReadWrite) {
95 myStream = fopen(aName.ToCString(),"w+b");
99 result = Storage_VSOpenError;
106 result = Storage_VSAlreadyOpen;
112 //=======================================================================
115 //=======================================================================
117 Standard_Boolean FSD_BinaryFile::IsEnd()
119 return (feof(myStream) != 0);
122 //=======================================================================
125 //=======================================================================
127 Storage_Error FSD_BinaryFile::Close()
129 Storage_Error result = Storage_VSOk;
131 if (OpenMode() != Storage_VSNone) {
133 SetOpenMode(Storage_VSNone);
136 result = Storage_VSNotOpen;
142 //=======================================================================
143 //function : MagicNumber
144 //purpose : ------------------ PROTECTED
145 //=======================================================================
147 const Standard_CString FSD_BinaryFile::MagicNumber()
152 //=======================================================================
153 //function : ReadChar
154 //purpose : read <rsize> character from the current position.
155 //=======================================================================
157 void FSD_BinaryFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsize)
160 Standard_Size ccount = 0;
164 while (!IsEnd() && (ccount < rsize)) {
165 fread(&c, sizeof(char),1, myStream);
171 //=======================================================================
172 //function : SkipObject
174 //=======================================================================
176 void FSD_BinaryFile::SkipObject()
181 //=======================================================================
182 //function : PutReference
183 //purpose : ---------------------- PUBLIC : PUT
184 //=======================================================================
186 Storage_BaseDriver& FSD_BinaryFile::PutReference(const Standard_Integer aValue)
189 Standard_Integer t = InverseInt (aValue);
191 if (!fwrite(&t,sizeof(Standard_Integer),1,myStream)) Storage_StreamWriteError::Raise();
193 if (!fwrite(&aValue,sizeof(Standard_Integer),1,myStream)) Storage_StreamWriteError::Raise();
198 //=======================================================================
199 //function : PutCharacter
201 //=======================================================================
203 Storage_BaseDriver& FSD_BinaryFile::PutCharacter(const Standard_Character aValue)
205 if (!fwrite(&aValue,sizeof(Standard_Character),1,myStream)) Storage_StreamWriteError::Raise();
209 //=======================================================================
210 //function : PutExtCharacter
212 //=======================================================================
214 Storage_BaseDriver& FSD_BinaryFile::PutExtCharacter(const Standard_ExtCharacter aValue)
217 Standard_ExtCharacter t = InverseExtChar (aValue);
219 if (!fwrite(&t,sizeof(Standard_ExtCharacter),1,myStream)) Storage_StreamWriteError::Raise();
221 if (!fwrite(&aValue,sizeof(Standard_ExtCharacter),1,myStream)) Storage_StreamWriteError::Raise();
226 //=======================================================================
227 //function : PutInteger
229 //=======================================================================
231 Storage_BaseDriver& FSD_BinaryFile::PutInteger(const Standard_Integer aValue)
234 Standard_Integer t = InverseInt (aValue);
236 if (!fwrite(&t,sizeof(Standard_Integer),1,myStream)) Storage_StreamWriteError::Raise();
238 if (!fwrite(&aValue,sizeof(Standard_Integer),1,myStream)) Storage_StreamWriteError::Raise();
244 //=======================================================================
245 //function : PutBoolean
247 //=======================================================================
249 Storage_BaseDriver& FSD_BinaryFile::PutBoolean(const Standard_Boolean aValue)
252 Standard_Integer t = InverseInt ((Standard_Integer) aValue);
254 if (!fwrite(&t,sizeof(Standard_Integer),1,myStream)) Storage_StreamWriteError::Raise();
256 if (!fwrite(&aValue,sizeof(Standard_Boolean),1,myStream)) Storage_StreamWriteError::Raise();
261 //=======================================================================
264 //=======================================================================
266 Storage_BaseDriver& FSD_BinaryFile::PutReal(const Standard_Real aValue)
269 Standard_Real t = InverseReal (aValue);
271 if (!fwrite(&t,sizeof(Standard_Real),1,myStream)) Storage_StreamWriteError::Raise();
273 if (!fwrite(&aValue,sizeof(Standard_Real),1,myStream)) Storage_StreamWriteError::Raise();
278 //=======================================================================
279 //function : PutShortReal
281 //=======================================================================
283 Storage_BaseDriver& FSD_BinaryFile::PutShortReal(const Standard_ShortReal aValue)
286 Standard_ShortReal t = InverseShortReal (aValue);
288 if (!fwrite(&t,sizeof(Standard_ShortReal),1,myStream)) Storage_StreamWriteError::Raise();
290 if (!fwrite(&aValue,sizeof(Standard_ShortReal),1,myStream)) Storage_StreamWriteError::Raise();
295 //=======================================================================
296 //function : GetReference
297 //purpose : ----------------- PUBLIC : GET
298 //=======================================================================
300 Storage_BaseDriver& FSD_BinaryFile::GetReference(Standard_Integer& aValue)
302 if (!fread(&aValue,sizeof(Standard_Integer),1,myStream))
303 Storage_StreamTypeMismatchError::Raise();
305 aValue = InverseInt (aValue);
310 //=======================================================================
311 //function : GetCharacter
313 //=======================================================================
315 Storage_BaseDriver& FSD_BinaryFile::GetCharacter(Standard_Character& aValue)
317 if (!fread(&aValue,sizeof(Standard_Character),1,myStream))
318 Storage_StreamTypeMismatchError::Raise();
322 //=======================================================================
323 //function : GetExtCharacter
325 //=======================================================================
327 Storage_BaseDriver& FSD_BinaryFile::GetExtCharacter(Standard_ExtCharacter& aValue)
329 if (!fread(&aValue,sizeof(Standard_ExtCharacter),1,myStream))
330 Storage_StreamTypeMismatchError::Raise();
332 aValue = InverseExtChar (aValue);
337 //=======================================================================
338 //function : GetInteger
340 //=======================================================================
342 Storage_BaseDriver& FSD_BinaryFile::GetInteger(Standard_Integer& aValue)
344 if (!fread(&aValue,sizeof(Standard_Integer),1,myStream))
345 Storage_StreamTypeMismatchError::Raise();
347 aValue = InverseInt (aValue);
352 //=======================================================================
353 //function : GetBoolean
355 //=======================================================================
357 Storage_BaseDriver& FSD_BinaryFile::GetBoolean(Standard_Boolean& aValue)
359 if (!fread(&aValue,sizeof(Standard_Boolean),1,myStream))
360 Storage_StreamTypeMismatchError::Raise();
362 aValue = InverseInt ((Standard_Integer) aValue);
367 //=======================================================================
370 //=======================================================================
372 Storage_BaseDriver& FSD_BinaryFile::GetReal(Standard_Real& aValue)
374 if (!fread(&aValue,sizeof(Standard_Real),1,myStream))
375 Storage_StreamTypeMismatchError::Raise();
377 aValue = InverseReal (aValue);
382 //=======================================================================
383 //function : GetShortReal
385 //=======================================================================
387 Storage_BaseDriver& FSD_BinaryFile::GetShortReal(Standard_ShortReal& aValue)
389 if (!fread(&aValue,sizeof(Standard_ShortReal),1,myStream))
390 Storage_StreamTypeMismatchError::Raise();
392 aValue = InverseShortReal (aValue);
397 //=======================================================================
400 //=======================================================================
402 void FSD_BinaryFile::Destroy()
404 if (OpenMode() != Storage_VSNone) {
409 //=======================================================================
410 //function : BeginWriteInfoSection
411 //purpose : -------------------------- INFO : WRITE
412 //=======================================================================
414 Storage_Error FSD_BinaryFile::BeginWriteInfoSection()
421 myHeader.testindian = *((int*)ti);
422 if (!fwrite(FSD_BinaryFile::MagicNumber(),
423 strlen(FSD_BinaryFile::MagicNumber()),
426 Storage_StreamWriteError::Raise();
428 myHeader.binfo = ftell(myStream);
434 //=======================================================================
435 //function : WriteInfo
437 //=======================================================================
439 void FSD_BinaryFile::WriteInfo(const Standard_Integer nbObj,
440 const TCollection_AsciiString& dbVersion,
441 const TCollection_AsciiString& date,
442 const TCollection_AsciiString& schemaName,
443 const TCollection_AsciiString& schemaVersion,
444 const TCollection_ExtendedString& appName,
445 const TCollection_AsciiString& appVersion,
446 const TCollection_ExtendedString& dataType,
447 const TColStd_SequenceOfAsciiString& userInfo)
452 WriteString(dbVersion);
454 WriteString(schemaName);
455 WriteString(schemaVersion);
456 WriteExtendedString(appName);
457 WriteString(appVersion);
458 WriteExtendedString(dataType);
459 i = userInfo.Length();
462 for (i = 1; i <= userInfo.Length(); i++) {
463 WriteString(userInfo.Value(i));
467 //=======================================================================
468 //function : EndWriteInfoSection
470 //=======================================================================
472 Storage_Error FSD_BinaryFile::EndWriteInfoSection()
474 myHeader.einfo = ftell(myStream);
479 //=======================================================================
480 //function : BeginReadInfoSection
482 //=======================================================================
484 Storage_Error FSD_BinaryFile::BeginReadInfoSection()
486 Storage_Error s = Storage_VSOk;
487 TCollection_AsciiString l;
488 Standard_Size len = strlen(FSD_BinaryFile::MagicNumber());
492 if (strncmp(FSD_BinaryFile::MagicNumber(),l.ToCString(),len) != 0) {
493 s = Storage_VSFormatError;
502 //=======================================================================
503 //function : ReadInfo
504 //purpose : ------------------- INFO : READ
505 //=======================================================================
507 void FSD_BinaryFile::ReadInfo(Standard_Integer& nbObj,
508 TCollection_AsciiString& dbVersion,
509 TCollection_AsciiString& date,
510 TCollection_AsciiString& schemaName,
511 TCollection_AsciiString& schemaVersion,
512 TCollection_ExtendedString& appName,
513 TCollection_AsciiString& appVersion,
514 TCollection_ExtendedString& dataType,
515 TColStd_SequenceOfAsciiString& userInfo)
518 ReadString(dbVersion);
520 ReadString(schemaName);
521 ReadString(schemaVersion);
522 ReadExtendedString(appName);
523 ReadString(appVersion);
524 ReadExtendedString(dataType);
526 Standard_Integer i,len = 0;
529 TCollection_AsciiString line;
531 for (i = 1; i <= len && !IsEnd(); i++) {
533 userInfo.Append(line);
537 //=======================================================================
538 //function : EndReadInfoSection
539 //purpose : COMMENTS SECTION
541 //=======================================================================
543 Storage_Error FSD_BinaryFile::EndReadInfoSection()
545 if (!fseek(myStream,myHeader.einfo,SEEK_SET)) return Storage_VSOk;
546 else return Storage_VSSectionNotFound;
549 //=======================================================================
550 //function : BeginWriteCommentSection
551 //purpose : ---------------- COMMENTS : WRITE
552 //=======================================================================
554 Storage_Error FSD_BinaryFile::BeginWriteCommentSection()
556 myHeader.bcomment = ftell(myStream);
560 //=======================================================================
561 //function : WriteComment
563 //=======================================================================
565 void FSD_BinaryFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
567 Standard_Integer i,aSize;
569 aSize = aCom.Length();
571 for (i = 1; i <= aSize; i++) {
572 WriteExtendedString(aCom.Value(i));
576 //=======================================================================
577 //function : EndWriteCommentSection
579 //=======================================================================
581 Storage_Error FSD_BinaryFile::EndWriteCommentSection()
583 myHeader.ecomment = ftell(myStream);
588 //=======================================================================
589 //function : BeginReadCommentSection
590 //purpose : ---------------- COMMENTS : READ
591 //=======================================================================
593 Storage_Error FSD_BinaryFile::BeginReadCommentSection()
595 if (!fseek(myStream,myHeader.bcomment,SEEK_SET)) return Storage_VSOk;
596 else return Storage_VSSectionNotFound;
599 //=======================================================================
600 //function : ReadComment
602 //=======================================================================
604 void FSD_BinaryFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
606 TCollection_ExtendedString line;
607 Standard_Integer len,i;
610 for (i = 1; i <= len && !IsEnd(); i++) {
611 ReadExtendedString(line);
616 //=======================================================================
617 //function : EndReadCommentSection
619 //=======================================================================
621 Storage_Error FSD_BinaryFile::EndReadCommentSection()
623 if (!fseek(myStream,myHeader.ecomment,SEEK_SET)) return Storage_VSOk;
624 else return Storage_VSSectionNotFound;
627 //=======================================================================
628 //function : BeginWriteTypeSection
629 //purpose : --------------- TYPE : WRITE
630 //=======================================================================
632 Storage_Error FSD_BinaryFile::BeginWriteTypeSection()
634 myHeader.btype = ftell(myStream);
639 //=======================================================================
640 //function : SetTypeSectionSize
642 //=======================================================================
644 void FSD_BinaryFile::SetTypeSectionSize(const Standard_Integer aSize)
649 //=======================================================================
650 //function : WriteTypeInformations
652 //=======================================================================
654 void FSD_BinaryFile::WriteTypeInformations(const Standard_Integer typeNum,
655 const TCollection_AsciiString& typeName)
658 WriteString(typeName);
661 //=======================================================================
662 //function : EndWriteTypeSection
664 //=======================================================================
666 Storage_Error FSD_BinaryFile::EndWriteTypeSection()
668 myHeader.etype = ftell(myStream);
673 //=======================================================================
674 //function : BeginReadTypeSection
675 //purpose : ------------------- TYPE : READ
676 //=======================================================================
678 Storage_Error FSD_BinaryFile::BeginReadTypeSection()
680 if (!fseek(myStream,myHeader.btype,SEEK_SET)) return Storage_VSOk;
681 else return Storage_VSSectionNotFound;
684 //=======================================================================
685 //function : TypeSectionSize
687 //=======================================================================
689 Standard_Integer FSD_BinaryFile::TypeSectionSize()
697 //=======================================================================
698 //function : ReadTypeInformations
700 //=======================================================================
702 void FSD_BinaryFile::ReadTypeInformations(Standard_Integer& typeNum,TCollection_AsciiString& typeName)
705 ReadString(typeName);
708 //=======================================================================
709 //function : EndReadTypeSection
710 //purpose : ROOT SECTION
712 //=======================================================================
714 Storage_Error FSD_BinaryFile::EndReadTypeSection()
716 if (!fseek(myStream,myHeader.etype,SEEK_SET)) return Storage_VSOk;
717 else return Storage_VSSectionNotFound;
720 //=======================================================================
721 //function : BeginWriteRootSection
722 //purpose : -------------------- ROOT : WRITE
723 //=======================================================================
725 Storage_Error FSD_BinaryFile::BeginWriteRootSection()
727 myHeader.broot = ftell(myStream);
732 //=======================================================================
733 //function : SetRootSectionSize
735 //=======================================================================
737 void FSD_BinaryFile::SetRootSectionSize(const Standard_Integer aSize)
742 //=======================================================================
743 //function : WriteRoot
745 //=======================================================================
747 void FSD_BinaryFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
750 WriteString(rootName);
751 WriteString(rootType);
754 //=======================================================================
755 //function : EndWriteRootSection
757 //=======================================================================
759 Storage_Error FSD_BinaryFile::EndWriteRootSection()
761 myHeader.eroot = ftell(myStream);
766 //=======================================================================
767 //function : BeginReadRootSection
768 //purpose : ----------------------- ROOT : READ
769 //=======================================================================
771 Storage_Error FSD_BinaryFile::BeginReadRootSection()
773 if (!fseek(myStream,myHeader.broot,SEEK_SET)) return Storage_VSOk;
774 else return Storage_VSSectionNotFound;
777 //=======================================================================
778 //function : RootSectionSize
780 //=======================================================================
782 Standard_Integer FSD_BinaryFile::RootSectionSize()
790 //=======================================================================
791 //function : ReadRoot
793 //=======================================================================
795 void FSD_BinaryFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
798 ReadString(rootName);
799 ReadString(rootType);
802 //=======================================================================
803 //function : EndReadRootSection
804 //purpose : REF SECTION
806 //=======================================================================
808 Storage_Error FSD_BinaryFile::EndReadRootSection()
810 if (!fseek(myStream,myHeader.eroot,SEEK_SET)) return Storage_VSOk;
811 else return Storage_VSSectionNotFound;
814 //=======================================================================
815 //function : BeginWriteRefSection
816 //purpose : -------------------------- REF : WRITE
817 //=======================================================================
819 Storage_Error FSD_BinaryFile::BeginWriteRefSection()
821 myHeader.bref = ftell(myStream);
826 //=======================================================================
827 //function : SetRefSectionSize
829 //=======================================================================
831 void FSD_BinaryFile::SetRefSectionSize(const Standard_Integer aSize)
836 //=======================================================================
837 //function : WriteReferenceType
839 //=======================================================================
841 void FSD_BinaryFile::WriteReferenceType(const Standard_Integer reference,const Standard_Integer typeNum)
843 PutReference(reference);
847 //=======================================================================
848 //function : EndWriteRefSection
850 //=======================================================================
852 Storage_Error FSD_BinaryFile::EndWriteRefSection()
854 myHeader.eref = ftell(myStream);
859 //=======================================================================
860 //function : BeginReadRefSection
861 //purpose : ----------------------- REF : READ
862 //=======================================================================
864 Storage_Error FSD_BinaryFile::BeginReadRefSection()
866 if (!fseek(myStream,myHeader.bref,SEEK_SET)) return Storage_VSOk;
867 else return Storage_VSSectionNotFound;
870 //=======================================================================
871 //function : RefSectionSize
873 //=======================================================================
875 Standard_Integer FSD_BinaryFile::RefSectionSize()
883 //=======================================================================
884 //function : ReadReferenceType
886 //=======================================================================
888 void FSD_BinaryFile::ReadReferenceType(Standard_Integer& reference,
889 Standard_Integer& typeNum)
891 GetReference(reference);
895 //=======================================================================
896 //function : EndReadRefSection
897 //purpose : DATA SECTION
899 //=======================================================================
901 Storage_Error FSD_BinaryFile::EndReadRefSection()
903 if (!fseek(myStream,myHeader.eref,SEEK_SET)) return Storage_VSOk;
904 else return Storage_VSSectionNotFound;
907 //=======================================================================
908 //function : BeginWriteDataSection
909 //purpose : -------------------- DATA : WRITE
910 //=======================================================================
912 Storage_Error FSD_BinaryFile::BeginWriteDataSection()
914 myHeader.bdata = ftell(myStream);
919 //=======================================================================
920 //function : WritePersistentObjectHeader
922 //=======================================================================
924 void FSD_BinaryFile::WritePersistentObjectHeader(const Standard_Integer aRef,
925 const Standard_Integer aType)
931 //=======================================================================
932 //function : BeginWritePersistentObjectData
934 //=======================================================================
936 void FSD_BinaryFile::BeginWritePersistentObjectData()
940 //=======================================================================
941 //function : BeginWriteObjectData
943 //=======================================================================
945 void FSD_BinaryFile::BeginWriteObjectData()
949 //=======================================================================
950 //function : EndWriteObjectData
952 //=======================================================================
954 void FSD_BinaryFile::EndWriteObjectData()
958 //=======================================================================
959 //function : EndWritePersistentObjectData
961 //=======================================================================
963 void FSD_BinaryFile::EndWritePersistentObjectData()
967 //=======================================================================
968 //function : EndWriteDataSection
970 //=======================================================================
972 Storage_Error FSD_BinaryFile::EndWriteDataSection()
974 myHeader.edata = ftell(myStream);
976 fseek(myStream,myHeader.binfo,SEEK_SET);
981 //=======================================================================
982 //function : BeginReadDataSection
983 //purpose : ---------------------- DATA : READ
984 //=======================================================================
986 Storage_Error FSD_BinaryFile::BeginReadDataSection()
988 if (!fseek(myStream,myHeader.bdata,SEEK_SET)) return Storage_VSOk;
989 else return Storage_VSSectionNotFound;
992 //=======================================================================
993 //function : ReadPersistentObjectHeader
995 //=======================================================================
997 void FSD_BinaryFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
998 Standard_Integer& aType)
1004 //=======================================================================
1005 //function : BeginReadPersistentObjectData
1007 //=======================================================================
1009 void FSD_BinaryFile::BeginReadPersistentObjectData()
1013 //=======================================================================
1014 //function : BeginReadObjectData
1016 //=======================================================================
1018 void FSD_BinaryFile::BeginReadObjectData()
1022 //=======================================================================
1023 //function : EndReadObjectData
1025 //=======================================================================
1027 void FSD_BinaryFile::EndReadObjectData()
1031 //=======================================================================
1032 //function : EndReadPersistentObjectData
1034 //=======================================================================
1036 void FSD_BinaryFile::EndReadPersistentObjectData()
1040 //=======================================================================
1041 //function : EndReadDataSection
1043 //=======================================================================
1045 Storage_Error FSD_BinaryFile::EndReadDataSection()
1047 if (!fseek(myStream,myHeader.edata,SEEK_SET)) return Storage_VSOk;
1048 else return Storage_VSSectionNotFound;
1051 //=======================================================================
1052 //function : WriteString
1053 //purpose : write string at the current position.
1054 //=======================================================================
1056 void FSD_BinaryFile::WriteString(const TCollection_AsciiString& aString)
1058 Standard_Integer size;
1060 size = aString.Length();
1065 if (!fwrite(aString.ToCString(),aString.Length(),1,myStream)) Storage_StreamWriteError::Raise();
1069 //=======================================================================
1070 //function : ReadString
1071 //purpose : read string from the current position.
1072 //=======================================================================
1074 void FSD_BinaryFile::ReadString(TCollection_AsciiString& aString)
1076 Standard_Integer size = 0;
1080 Standard_Character *c = (Standard_Character *)Standard::Allocate((size+1) * sizeof(Standard_Character));
1081 if (!fread(c,size,1,myStream)) Storage_StreamWriteError::Raise();
1084 Standard::Free((Standard_Address&)c);
1091 //=======================================================================
1092 //function : WriteExtendedString
1093 //purpose : write string at the current position.
1094 //=======================================================================
1096 void FSD_BinaryFile::WriteExtendedString(const TCollection_ExtendedString& aString)
1098 Standard_Integer size;
1100 size = aString.Length();
1105 Standard_ExtString anExtStr;
1107 TCollection_ExtendedString aCopy = aString;
1108 anExtStr = aCopy.ToExtString();
1110 Standard_PExtCharacter pChar;
1112 pChar=(Standard_PExtCharacter)anExtStr;
1114 for (Standard_Integer i=0; i < size; i++)
1115 pChar[i] = InverseExtChar (pChar[i]);
1117 anExtStr = aString.ToExtString();
1119 if (!fwrite(anExtStr,sizeof(Standard_ExtCharacter)*aString.Length(),1,myStream))
1120 Storage_StreamWriteError::Raise();
1124 //=======================================================================
1125 //function : ReadExtendedString
1126 //purpose : read string from the current position.
1127 //=======================================================================
1129 void FSD_BinaryFile::ReadExtendedString(TCollection_ExtendedString& aString)
1131 Standard_Integer size = 0;
1135 Standard_ExtCharacter *c = (Standard_ExtCharacter *)
1136 Standard::Allocate((size+1) * sizeof(Standard_ExtCharacter));
1137 if (!fread(c,size*sizeof(Standard_ExtCharacter),1,myStream))
1138 Storage_StreamWriteError::Raise();
1141 for (Standard_Integer i=0; i < size; i++)
1142 c[i] = InverseExtChar (c[i]);
1145 Standard::Free((Standard_Address&)c);
1152 //=======================================================================
1153 //function : WriteHeader
1155 //=======================================================================
1157 void FSD_BinaryFile::WriteHeader()
1159 PutInteger(myHeader.testindian);
1160 PutInteger(myHeader.binfo);
1161 PutInteger(myHeader.einfo);
1162 PutInteger(myHeader.bcomment);
1163 PutInteger(myHeader.ecomment);
1164 PutInteger(myHeader.btype);
1165 PutInteger(myHeader.etype);
1166 PutInteger(myHeader.broot);
1167 PutInteger(myHeader.eroot);
1168 PutInteger(myHeader.bref);
1169 PutInteger(myHeader.eref);
1170 PutInteger(myHeader.bdata);
1171 PutInteger(myHeader.edata);
1174 //=======================================================================
1175 //function : ReadHeader
1177 //=======================================================================
1179 void FSD_BinaryFile::ReadHeader()
1181 GetInteger(myHeader.testindian);
1182 GetInteger(myHeader.binfo);
1183 GetInteger(myHeader.einfo);
1184 GetInteger(myHeader.bcomment);
1185 GetInteger(myHeader.ecomment);
1186 GetInteger(myHeader.btype);
1187 GetInteger(myHeader.etype);
1188 GetInteger(myHeader.broot);
1189 GetInteger(myHeader.eroot);
1190 GetInteger(myHeader.bref);
1191 GetInteger(myHeader.eref);
1192 GetInteger(myHeader.bdata);
1193 GetInteger(myHeader.edata);
1197 //=======================================================================
1199 //purpose : return position in the file. Return -1 upon error.
1200 //=======================================================================
1202 Storage_Position FSD_BinaryFile::Tell()
1204 return (Storage_Position) ftell(myStream);