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_File.ixx>
22 const Standard_CString MAGICNUMBER = "FSDFILE";
23 const Standard_CString ENDOFNORMALEXTENDEDSECTION = "BEGIN_REF_SECTION";
24 const Standard_Integer SIZEOFNORMALEXTENDEDSECTION = 16;
26 //#define USEOSDREAL 1
28 //=======================================================================
31 //=======================================================================
38 //=======================================================================
39 //function : IsGoodFileType
40 //purpose : INFO SECTION
42 //=======================================================================
44 Storage_Error FSD_File::IsGoodFileType(const TCollection_AsciiString& aName)
49 s = f.Open(aName,Storage_VSRead);
51 if (s == Storage_VSOk) {
52 TCollection_AsciiString l;
53 Standard_Size len = strlen(FSD_File::MagicNumber());
59 if (strncmp(FSD_File::MagicNumber(),l.ToCString(),len) != 0) {
60 s = Storage_VSFormatError;
67 //=======================================================================
70 //=======================================================================
72 Storage_Error FSD_File::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
74 Storage_Error result = Storage_VSOk;
78 if (OpenMode() == Storage_VSNone) {
79 if (aMode == Storage_VSRead) {
80 myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
82 else if (aMode == Storage_VSWrite) {
83 myStream.open(aName.ToCString(),ios::out);
85 else if (aMode == Storage_VSReadWrite) {
86 myStream.open(aName.ToCString(),ios::in|ios::out);
89 if (myStream.fail()) {
90 result = Storage_VSOpenError;
93 myStream.precision(17);
94 myStream.imbue (std::locale::classic()); // use always C locale
99 result = Storage_VSAlreadyOpen;
105 //=======================================================================
108 //=======================================================================
110 Standard_Boolean FSD_File::IsEnd()
112 return myStream.eof();
115 //=======================================================================
118 //=======================================================================
120 Storage_Error FSD_File::Close()
122 Storage_Error result = Storage_VSOk;
124 if (OpenMode() != Storage_VSNone) {
126 SetOpenMode(Storage_VSNone);
129 result = Storage_VSNotOpen;
135 //=======================================================================
136 //function : MagicNumber
137 //purpose : ------------------ PROTECTED
138 //=======================================================================
140 const Standard_CString FSD_File::MagicNumber()
145 //=======================================================================
146 //function : FlushEndOfLine
148 //=======================================================================
150 void FSD_File::FlushEndOfLine()
152 TCollection_AsciiString aDummy;
153 ReadLine (aDummy); // flush is nothing more than to read till the line-break
154 /* static char Buffer[8192];
156 Standard_Boolean IsEnd = Standard_False;
158 while (!IsEnd && !FSD_File::IsEnd()) {
160 myStream.get(Buffer,8192,'\n');
162 if (myStream.get(c) && c != '\n') {
165 IsEnd = Standard_True;
170 //=======================================================================
171 //function : ReadLine
172 //purpose : read from the current position to the end of line.
173 //=======================================================================
175 void FSD_File::ReadLine(TCollection_AsciiString& buffer)
178 Standard_Boolean IsEnd = Standard_False;
182 while (!IsEnd && !FSD_File::IsEnd()) {
184 myStream.getline(Buffer,8192,'\n');
187 // if (myStream.get(c) && c != '\n') {
193 IsEnd = Standard_True;
198 //=======================================================================
199 //function : WriteExtendedLine
200 //purpose : write from the current position to the end of line.
201 //=======================================================================
203 void FSD_File::WriteExtendedLine(const TCollection_ExtendedString& buffer)
205 Standard_ExtString extBuffer;
206 Standard_Integer i,c,d;
208 extBuffer = buffer.ToExtString();
210 for (i = 0; i < buffer.Length(); i++) {
211 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
212 d = extBuffer[i] & 0x000000FF;
214 myStream << (char)c << (char)d;
217 myStream << (char)0 << "\n";
220 //=======================================================================
221 //function : ReadExtendedLine
223 //=======================================================================
225 void FSD_File::ReadExtendedLine(TCollection_ExtendedString& buffer)
228 Standard_ExtCharacter i = 0,j,count = 0;
229 Standard_Boolean fin = Standard_False;
230 Standard_CString tg = ENDOFNORMALEXTENDEDSECTION;
234 while (!fin && !IsEnd()) {
237 if (c == tg[count]) count++;
239 if (count < SIZEOFNORMALEXTENDEDSECTION) {
241 i += (Standard_ExtCharacter)c;
242 if (c == '\0') fin = Standard_True;
246 if (c == tg[count]) count++;
248 if (count < SIZEOFNORMALEXTENDEDSECTION) {
249 j += (Standard_ExtCharacter)c;
251 fin = Standard_False;
253 buffer += (Standard_ExtCharacter)i;
257 Storage_StreamExtCharParityError::Raise();
261 Storage_StreamExtCharParityError::Raise();
266 //=======================================================================
267 //function : ReadChar
268 //purpose : read <rsize> character from the current position.
269 //=======================================================================
271 void FSD_File::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsize)
274 Standard_Size ccount = 0;
278 while (!IsEnd() && (ccount < rsize)) {
285 //=======================================================================
286 //function : ReadString
287 //purpose : read from the first none space character position to the end of line.
288 //=======================================================================
290 void FSD_File::ReadString(TCollection_AsciiString& buffer)
294 Standard_Boolean IsEnd = Standard_False,isFirstTime = Standard_True;
298 while (!IsEnd && !FSD_File::IsEnd()) {
300 myStream.getline(Buffer,8192,'\n');
306 isFirstTime = Standard_False;
307 while (*bpos == '\n' || *bpos == ' ') bpos++;
310 // if (myStream.get(c) && c != '\n') {
316 IsEnd = Standard_True;
322 //=======================================================================
323 //function : ReadWord
324 //purpose : read from the current position to the next white space or end of line.
325 //=======================================================================
327 void FSD_File::ReadWord(TCollection_AsciiString& buffer)
331 Standard_Boolean IsEnd = Standard_False;
338 while (!IsEnd && !FSD_File::IsEnd()) {
340 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
343 IsEnd = Standard_False;
346 while (!IsEnd && !FSD_File::IsEnd()) {
356 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
362 //=======================================================================
365 //=======================================================================
367 Storage_Error FSD_File::FindTag(const Standard_CString aTag)
369 TCollection_AsciiString l;
373 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
378 return Storage_VSSectionNotFound;
385 //=======================================================================
386 //function : SkipObject
388 //=======================================================================
390 void FSD_File::SkipObject()
395 //=======================================================================
396 //function : PutReference
397 //purpose : ---------------------- PUBLIC : PUT
398 //=======================================================================
400 Storage_BaseDriver& FSD_File::PutReference(const Standard_Integer aValue)
402 myStream << aValue << " ";
403 if (myStream.bad()) Storage_StreamWriteError::Raise();
407 //=======================================================================
408 //function : PutCharacter
410 //=======================================================================
412 Storage_BaseDriver& FSD_File::PutCharacter(const Standard_Character aValue)
417 myStream << i << " ";
418 if (myStream.bad()) Storage_StreamWriteError::Raise();
422 //=======================================================================
423 //function : PutExtCharacter
425 //=======================================================================
427 Storage_BaseDriver& FSD_File::PutExtCharacter(const Standard_ExtCharacter aValue)
429 myStream << aValue << " ";
430 if (myStream.bad()) Storage_StreamWriteError::Raise();
434 //=======================================================================
435 //function : PutInteger
437 //=======================================================================
439 Storage_BaseDriver& FSD_File::PutInteger(const Standard_Integer aValue)
441 myStream << aValue << " ";
442 if (myStream.bad()) Storage_StreamWriteError::Raise();
446 //=======================================================================
447 //function : PutBoolean
449 //=======================================================================
451 Storage_BaseDriver& FSD_File::PutBoolean(const Standard_Boolean aValue)
453 myStream << ((Standard_Integer)aValue) << " ";
454 if (myStream.bad()) Storage_StreamWriteError::Raise();
458 //=======================================================================
461 //=======================================================================
463 Storage_BaseDriver& FSD_File::PutReal(const Standard_Real aValue)
465 myStream << ((Standard_Real)aValue) << " ";
466 if (myStream.bad()) Storage_StreamWriteError::Raise();
470 //=======================================================================
471 //function : PutShortReal
473 //=======================================================================
475 Storage_BaseDriver& FSD_File::PutShortReal(const Standard_ShortReal aValue)
477 myStream << aValue << " ";
478 if (myStream.bad()) Storage_StreamWriteError::Raise();
482 //=======================================================================
483 //function : GetReference
484 //purpose : ----------------- PUBLIC : GET
485 //=======================================================================
487 Storage_BaseDriver& FSD_File::GetReference(Standard_Integer& aValue)
489 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
494 //=======================================================================
495 //function : GetCharacter
497 //=======================================================================
499 Storage_BaseDriver& FSD_File::GetCharacter(Standard_Character& aValue)
501 unsigned short i = 0;
502 if (!(myStream >> i)) {
503 // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
504 // signes (-80 fait ios::badbit, mais la variable i est initialisee)
506 if (i == 0) Storage_StreamTypeMismatchError::Raise();
507 myStream.clear(ios::goodbit); // .clear(0) is not portable
514 //=======================================================================
515 //function : GetExtCharacter
517 //=======================================================================
519 Storage_BaseDriver& FSD_File::GetExtCharacter(Standard_ExtCharacter& aValue)
521 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
526 //=======================================================================
527 //function : GetInteger
529 //=======================================================================
531 Storage_BaseDriver& FSD_File::GetInteger(Standard_Integer& aValue)
533 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
538 //=======================================================================
539 //function : GetBoolean
541 //=======================================================================
543 Storage_BaseDriver& FSD_File::GetBoolean(Standard_Boolean& aValue)
545 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
550 //=======================================================================
553 //=======================================================================
555 Storage_BaseDriver& FSD_File::GetReal(Standard_Real& aValue)
558 char realbuffer[100];
560 realbuffer[0] = '\0';
561 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
562 if (!OSD::CStringToReal(realbuffer,aValue)) Storage_StreamTypeMismatchError::Raise();
566 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
572 //=======================================================================
573 //function : GetShortReal
575 //=======================================================================
577 Storage_BaseDriver& FSD_File::GetShortReal(Standard_ShortReal& aValue)
580 char realbuffer[100];
581 Standard_Real r = 0.0;
583 realbuffer[0] = '\0';
584 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
585 if (!OSD::CStringToReal(realbuffer,r)) Storage_StreamTypeMismatchError::Raise();
591 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
596 //=======================================================================
599 //=======================================================================
601 void FSD_File::Destroy()
603 if (OpenMode() != Storage_VSNone) {
608 //=======================================================================
609 //function : BeginWriteInfoSection
610 //purpose : -------------------------- INFO : WRITE
611 //=======================================================================
613 Storage_Error FSD_File::BeginWriteInfoSection()
615 myStream << FSD_File::MagicNumber() << '\n';
616 myStream << "BEGIN_INFO_SECTION\n";
617 if (myStream.bad()) Storage_StreamWriteError::Raise();
622 //=======================================================================
623 //function : WriteInfo
625 //=======================================================================
627 void FSD_File::WriteInfo(const Standard_Integer nbObj,
628 const TCollection_AsciiString& dbVersion,
629 const TCollection_AsciiString& date,
630 const TCollection_AsciiString& schemaName,
631 const TCollection_AsciiString& schemaVersion,
632 const TCollection_ExtendedString& appName,
633 const TCollection_AsciiString& appVersion,
634 const TCollection_ExtendedString& dataType,
635 const TColStd_SequenceOfAsciiString& userInfo)
641 myStream << dbVersion.ToCString() << "\n";
642 myStream << date.ToCString() << "\n";
643 myStream << schemaName.ToCString() << "\n";
644 myStream << schemaVersion.ToCString() << "\n";
645 WriteExtendedLine(appName);
646 myStream << appVersion.ToCString() << "\n";
647 WriteExtendedLine(dataType);
648 myStream << userInfo.Length() << "\n";
650 if (myStream.bad()) Storage_StreamWriteError::Raise();
652 for (i = 1; i <= userInfo.Length(); i++) {
653 myStream << userInfo.Value(i).ToCString() << "\n";
654 if (myStream.bad()) Storage_StreamWriteError::Raise();
658 //=======================================================================
659 //function : EndWriteInfoSection
661 //=======================================================================
663 Storage_Error FSD_File::EndWriteInfoSection()
665 myStream << "END_INFO_SECTION\n";
666 if (myStream.bad()) Storage_StreamWriteError::Raise();
670 //=======================================================================
671 //function : BeginReadInfoSection
673 //=======================================================================
675 Storage_Error FSD_File::BeginReadInfoSection()
678 TCollection_AsciiString l;
679 Standard_Size len = strlen(FSD_File::MagicNumber());
683 if (strncmp(FSD_File::MagicNumber(),l.ToCString(),len) != 0) {
684 s = Storage_VSFormatError;
687 s = FindTag("BEGIN_INFO_SECTION");
693 //=======================================================================
694 //function : ReadInfo
695 //purpose : ------------------- INFO : READ
696 //=======================================================================
698 void FSD_File::ReadInfo(Standard_Integer& nbObj,
699 TCollection_AsciiString& dbVersion,
700 TCollection_AsciiString& date,
701 TCollection_AsciiString& schemaName,
702 TCollection_AsciiString& schemaVersion,
703 TCollection_ExtendedString& appName,
704 TCollection_AsciiString& appVersion,
705 TCollection_ExtendedString& dataType,
706 TColStd_SequenceOfAsciiString& userInfo)
708 if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
714 ReadLine(schemaName);
715 ReadLine(schemaVersion);
716 ReadExtendedLine(appName);
717 ReadLine(appVersion);
718 ReadExtendedLine(dataType);
720 Standard_Integer i,len = 0;
722 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
726 TCollection_AsciiString line;
728 for (i = 1; i <= len && !IsEnd(); i++) {
730 userInfo.Append(line);
735 //=======================================================================
736 //function : EndReadInfoSection
737 //purpose : COMMENTS SECTION
739 //=======================================================================
741 Storage_Error FSD_File::EndReadInfoSection()
743 return FindTag("END_INFO_SECTION");
746 //=======================================================================
747 //function : BeginWriteCommentSection
748 //purpose : ---------------- COMMENTS : WRITE
749 //=======================================================================
751 Storage_Error FSD_File::BeginWriteCommentSection()
753 myStream << "BEGIN_COMMENT_SECTION\n";
754 if (myStream.bad()) Storage_StreamWriteError::Raise();
758 //=======================================================================
759 //function : WriteComment
761 //=======================================================================
763 void FSD_File::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
765 Standard_Integer i,aSize;
767 aSize = aCom.Length();
768 myStream << aSize << "\n";
769 if (myStream.bad()) Storage_StreamWriteError::Raise();
771 for (i = 1; i <= aSize; i++) {
772 WriteExtendedLine(aCom.Value(i));
773 if (myStream.bad()) Storage_StreamWriteError::Raise();
777 //=======================================================================
778 //function : EndWriteCommentSection
780 //=======================================================================
782 Storage_Error FSD_File::EndWriteCommentSection()
784 myStream << "END_COMMENT_SECTION\n";
785 if (myStream.bad()) Storage_StreamWriteError::Raise();
789 //=======================================================================
790 //function : BeginReadCommentSection
791 //purpose : ---------------- COMMENTS : READ
792 //=======================================================================
794 Storage_Error FSD_File::BeginReadCommentSection()
796 return FindTag("BEGIN_COMMENT_SECTION");
799 //=======================================================================
800 //function : ReadComment
802 //=======================================================================
804 void FSD_File::ReadComment(TColStd_SequenceOfExtendedString& aCom)
806 TCollection_ExtendedString line;
807 Standard_Integer len,i;
809 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
813 for (i = 1; i <= len && !IsEnd(); i++) {
814 ReadExtendedLine(line);
820 //=======================================================================
821 //function : EndReadCommentSection
823 //=======================================================================
825 Storage_Error FSD_File::EndReadCommentSection()
827 return FindTag("END_COMMENT_SECTION");
830 //=======================================================================
831 //function : BeginWriteTypeSection
832 //purpose : --------------- TYPE : WRITE
833 //=======================================================================
835 Storage_Error FSD_File::BeginWriteTypeSection()
837 myStream << "BEGIN_TYPE_SECTION\n";
838 if (myStream.bad()) Storage_StreamWriteError::Raise();
842 //=======================================================================
843 //function : SetTypeSectionSize
845 //=======================================================================
847 void FSD_File::SetTypeSectionSize(const Standard_Integer aSize)
849 myStream << aSize << "\n";
850 if (myStream.bad()) Storage_StreamWriteError::Raise();
853 //=======================================================================
854 //function : WriteTypeInformations
856 //=======================================================================
858 void FSD_File::WriteTypeInformations(const Standard_Integer typeNum,
859 const TCollection_AsciiString& typeName)
861 myStream << typeNum << " " << typeName.ToCString() << "\n";
862 if (myStream.bad()) Storage_StreamWriteError::Raise();
865 //=======================================================================
866 //function : EndWriteTypeSection
868 //=======================================================================
870 Storage_Error FSD_File::EndWriteTypeSection()
872 myStream << "END_TYPE_SECTION\n";
873 if (myStream.bad()) Storage_StreamWriteError::Raise();
877 //=======================================================================
878 //function : BeginReadTypeSection
879 //purpose : ------------------- TYPE : READ
880 //=======================================================================
882 Storage_Error FSD_File::BeginReadTypeSection()
884 return FindTag("BEGIN_TYPE_SECTION");
887 //=======================================================================
888 //function : TypeSectionSize
890 //=======================================================================
892 Standard_Integer FSD_File::TypeSectionSize()
896 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
903 //=======================================================================
904 //function : ReadTypeInformations
906 //=======================================================================
908 void FSD_File::ReadTypeInformations(Standard_Integer& typeNum,
909 TCollection_AsciiString& typeName)
911 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
912 if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
916 //=======================================================================
917 //function : EndReadTypeSection
918 //purpose : ROOT SECTION
920 //=======================================================================
922 Storage_Error FSD_File::EndReadTypeSection()
924 return FindTag("END_TYPE_SECTION");
927 //=======================================================================
928 //function : BeginWriteRootSection
929 //purpose : -------------------- ROOT : WRITE
930 //=======================================================================
932 Storage_Error FSD_File::BeginWriteRootSection()
934 myStream << "BEGIN_ROOT_SECTION\n";
935 if (myStream.bad()) Storage_StreamWriteError::Raise();
939 //=======================================================================
940 //function : SetRootSectionSize
942 //=======================================================================
944 void FSD_File::SetRootSectionSize(const Standard_Integer aSize)
946 myStream << aSize << "\n";
947 if (myStream.bad()) Storage_StreamWriteError::Raise();
950 //=======================================================================
951 //function : WriteRoot
953 //=======================================================================
955 void FSD_File::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
957 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
958 if (myStream.bad()) Storage_StreamWriteError::Raise();
961 //=======================================================================
962 //function : EndWriteRootSection
964 //=======================================================================
966 Storage_Error FSD_File::EndWriteRootSection()
968 myStream << "END_ROOT_SECTION\n";
969 if (myStream.bad()) Storage_StreamWriteError::Raise();
973 //=======================================================================
974 //function : BeginReadRootSection
975 //purpose : ----------------------- ROOT : READ
976 //=======================================================================
978 Storage_Error FSD_File::BeginReadRootSection()
980 return FindTag("BEGIN_ROOT_SECTION");
983 //=======================================================================
984 //function : RootSectionSize
986 //=======================================================================
988 Standard_Integer FSD_File::RootSectionSize()
992 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
999 //=======================================================================
1000 //function : ReadRoot
1002 //=======================================================================
1004 void FSD_File::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1006 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1011 //=======================================================================
1012 //function : EndReadRootSection
1013 //purpose : REF SECTION
1015 //=======================================================================
1017 Storage_Error FSD_File::EndReadRootSection()
1019 return FindTag("END_ROOT_SECTION");
1022 //=======================================================================
1023 //function : BeginWriteRefSection
1024 //purpose : -------------------------- REF : WRITE
1025 //=======================================================================
1027 Storage_Error FSD_File::BeginWriteRefSection()
1029 myStream << "BEGIN_REF_SECTION\n";
1030 if (myStream.bad()) Storage_StreamWriteError::Raise();
1031 return Storage_VSOk;
1034 //=======================================================================
1035 //function : SetRefSectionSize
1037 //=======================================================================
1039 void FSD_File::SetRefSectionSize(const Standard_Integer aSize)
1041 myStream << aSize << "\n";
1042 if (myStream.bad()) Storage_StreamWriteError::Raise();
1045 //=======================================================================
1046 //function : WriteReferenceType
1048 //=======================================================================
1050 void FSD_File::WriteReferenceType(const Standard_Integer reference,
1051 const Standard_Integer typeNum)
1053 myStream << reference << " " << typeNum << "\n";
1054 if (myStream.bad()) Storage_StreamWriteError::Raise();
1057 //=======================================================================
1058 //function : EndWriteRefSection
1060 //=======================================================================
1062 Storage_Error FSD_File::EndWriteRefSection()
1064 myStream << "END_REF_SECTION\n";
1065 if (myStream.bad()) Storage_StreamWriteError::Raise();
1066 return Storage_VSOk;
1069 //=======================================================================
1070 //function : BeginReadRefSection
1071 //purpose : ----------------------- REF : READ
1072 //=======================================================================
1074 Storage_Error FSD_File::BeginReadRefSection()
1076 return FindTag("BEGIN_REF_SECTION");
1079 //=======================================================================
1080 //function : RefSectionSize
1082 //=======================================================================
1084 Standard_Integer FSD_File::RefSectionSize()
1088 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1094 //=======================================================================
1095 //function : ReadReferenceType
1097 //=======================================================================
1099 void FSD_File::ReadReferenceType(Standard_Integer& reference,
1100 Standard_Integer& typeNum)
1102 if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
1103 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1107 //=======================================================================
1108 //function : EndReadRefSection
1109 //purpose : DATA SECTION
1111 //=======================================================================
1113 Storage_Error FSD_File::EndReadRefSection()
1115 return FindTag("END_REF_SECTION");
1118 //=======================================================================
1119 //function : BeginWriteDataSection
1120 //purpose : -------------------- DATA : WRITE
1121 //=======================================================================
1123 Storage_Error FSD_File::BeginWriteDataSection()
1125 myStream << "BEGIN_DATA_SECTION";
1126 if (myStream.bad()) Storage_StreamWriteError::Raise();
1127 return Storage_VSOk;
1130 //=======================================================================
1131 //function : WritePersistentObjectHeader
1133 //=======================================================================
1135 void FSD_File::WritePersistentObjectHeader(const Standard_Integer aRef,
1136 const Standard_Integer aType)
1138 myStream << "\n#" << aRef << "=%" << aType;
1139 if (myStream.bad()) Storage_StreamWriteError::Raise();
1142 //=======================================================================
1143 //function : BeginWritePersistentObjectData
1145 //=======================================================================
1147 void FSD_File::BeginWritePersistentObjectData()
1150 if (myStream.bad()) Storage_StreamWriteError::Raise();
1153 //=======================================================================
1154 //function : BeginWriteObjectData
1156 //=======================================================================
1158 void FSD_File::BeginWriteObjectData()
1161 if (myStream.bad()) Storage_StreamWriteError::Raise();
1164 //=======================================================================
1165 //function : EndWriteObjectData
1167 //=======================================================================
1169 void FSD_File::EndWriteObjectData()
1172 if (myStream.bad()) Storage_StreamWriteError::Raise();
1175 //=======================================================================
1176 //function : EndWritePersistentObjectData
1178 //=======================================================================
1180 void FSD_File::EndWritePersistentObjectData()
1183 if (myStream.bad()) Storage_StreamWriteError::Raise();
1186 //=======================================================================
1187 //function : EndWriteDataSection
1189 //=======================================================================
1191 Storage_Error FSD_File::EndWriteDataSection()
1193 myStream << "\nEND_DATA_SECTION\n";
1194 if (myStream.bad()) Storage_StreamWriteError::Raise();
1195 return Storage_VSOk;
1198 //=======================================================================
1199 //function : BeginReadDataSection
1200 //purpose : ---------------------- DATA : READ
1201 //=======================================================================
1203 Storage_Error FSD_File::BeginReadDataSection()
1205 return FindTag("BEGIN_DATA_SECTION");
1208 //=======================================================================
1209 //function : ReadPersistentObjectHeader
1211 //=======================================================================
1213 void FSD_File::ReadPersistentObjectHeader(Standard_Integer& aRef,
1214 Standard_Integer& aType)
1221 if (IsEnd() || (c != ' ') || (c == '\n')) {
1222 Storage_StreamFormatError::Raise();
1227 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1233 if (IsEnd() || (c != ' ') || (c == '\n')) {
1234 Storage_StreamFormatError::Raise();
1242 if (IsEnd() || (c != ' ') || (c == '\n')) {
1243 Storage_StreamFormatError::Raise();
1248 if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
1249 // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
1252 //=======================================================================
1253 //function : BeginReadPersistentObjectData
1255 //=======================================================================
1257 void FSD_File::BeginReadPersistentObjectData()
1262 if (IsEnd() || (c != ' ') || (c == '\n')) {
1263 Storage_StreamFormatError::Raise();
1268 //cout << "BeginReadPersistentObjectData" << endl;
1271 //=======================================================================
1272 //function : BeginReadObjectData
1274 //=======================================================================
1276 void FSD_File::BeginReadObjectData()
1282 if (IsEnd() || (c != ' ') || (c == '\n')) {
1283 Storage_StreamFormatError::Raise();
1288 // cout << "BeginReadObjectData" << endl;
1291 //=======================================================================
1292 //function : EndReadObjectData
1294 //=======================================================================
1296 void FSD_File::EndReadObjectData()
1302 if (IsEnd() || (c != ' ') || (c == '\n')) {
1303 Storage_StreamFormatError::Raise();
1308 // cout << "EndReadObjectData" << endl;
1311 //=======================================================================
1312 //function : EndReadPersistentObjectData
1314 //=======================================================================
1316 void FSD_File::EndReadPersistentObjectData()
1323 if (IsEnd() || (c != ' ') || (c == '\n')) {
1324 Storage_StreamFormatError::Raise();
1331 if (IsEnd() || (c != ' ')) {
1332 Storage_StreamFormatError::Raise();
1336 // cout << "EndReadPersistentObjectData" << endl;
1339 //=======================================================================
1340 //function : EndReadDataSection
1342 //=======================================================================
1344 Storage_Error FSD_File::EndReadDataSection()
1346 return FindTag("END_DATA_SECTION");
1349 //=======================================================================
1351 //purpose : return position in the file. Return -1 upon error.
1352 //=======================================================================
1354 Storage_Position FSD_File::Tell()
1356 switch (OpenMode()) {
1357 case Storage_VSRead:
1358 return (Storage_Position) myStream.tellp();
1359 case Storage_VSWrite:
1360 return (Storage_Position) myStream.tellg();
1361 case Storage_VSReadWrite: {
1362 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1363 Storage_Position aPosW = (Storage_Position) myStream.tellg();