1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <FSD_File.hxx>
18 #include <OSD_OpenFile.hxx>
19 #include <Storage_BaseDriver.hxx>
20 #include <Storage_StreamExtCharParityError.hxx>
21 #include <Storage_StreamFormatError.hxx>
22 #include <Storage_StreamTypeMismatchError.hxx>
23 #include <Storage_StreamWriteError.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TCollection_ExtendedString.hxx>
27 const Standard_CString MAGICNUMBER = "FSDFILE";
28 const Standard_CString ENDOFNORMALEXTENDEDSECTION = "BEGIN_REF_SECTION";
29 const Standard_Integer SIZEOFNORMALEXTENDEDSECTION = 16;
33 IMPLEMENT_STANDARD_RTTIEXT(FSD_File, Storage_BaseDriver)
35 //=======================================================================
38 //=======================================================================
45 //=======================================================================
46 //function : IsGoodFileType
47 //purpose : INFO SECTION
49 //=======================================================================
51 Storage_Error FSD_File::IsGoodFileType(const TCollection_AsciiString& aName)
56 s = f.Open(aName,Storage_VSRead);
58 if (s == Storage_VSOk) {
59 TCollection_AsciiString l;
60 Standard_Size len = strlen(FSD_File::MagicNumber());
66 if (strncmp(FSD_File::MagicNumber(),l.ToCString(),len) != 0) {
67 s = Storage_VSFormatError;
74 //=======================================================================
77 //=======================================================================
79 Storage_Error FSD_File::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
81 Storage_Error result = Storage_VSOk;
85 if (OpenMode() == Storage_VSNone)
87 std::ios_base::openmode anOpenMode = std::ios_base::openmode(0);
96 // std::ios::nocreate is not portable
97 anOpenMode = std::ios::in;
100 case Storage_VSWrite:
102 anOpenMode = std::ios::out;
105 case Storage_VSReadWrite:
107 anOpenMode = std::ios::in | std::ios::out;
113 OSD_OpenStream (myStream, aName.ToCString(), anOpenMode);
115 if (myStream.fail()) {
116 result = Storage_VSOpenError;
119 myStream.precision(17);
120 myStream.imbue (std::locale::classic()); // use always C locale
125 result = Storage_VSAlreadyOpen;
131 //=======================================================================
134 //=======================================================================
136 Standard_Boolean FSD_File::IsEnd()
138 return myStream.eof();
141 //=======================================================================
144 //=======================================================================
146 Storage_Error FSD_File::Close()
148 Storage_Error result = Storage_VSOk;
150 if (OpenMode() != Storage_VSNone) {
152 SetOpenMode(Storage_VSNone);
155 result = Storage_VSNotOpen;
161 //=======================================================================
162 //function : MagicNumber
163 //purpose : ------------------ PROTECTED
164 //=======================================================================
166 Standard_CString FSD_File::MagicNumber()
171 //=======================================================================
172 //function : FlushEndOfLine
174 //=======================================================================
176 void FSD_File::FlushEndOfLine()
178 TCollection_AsciiString aDummy;
179 ReadLine (aDummy); // flush is nothing more than to read till the line-break
182 //=======================================================================
183 //function : ReadLine
184 //purpose : read from the current position to the end of line.
185 //=======================================================================
187 void FSD_File::ReadLine(TCollection_AsciiString& buffer)
190 Standard_Boolean IsEnd = Standard_False;
194 while (!IsEnd && !FSD_File::IsEnd()) {
196 myStream.getline(Buffer,8192,'\n');
199 // if (myStream.get(c) && c != '\n') {
205 IsEnd = Standard_True;
210 //=======================================================================
211 //function : WriteExtendedLine
212 //purpose : write from the current position to the end of line.
213 //=======================================================================
215 void FSD_File::WriteExtendedLine(const TCollection_ExtendedString& buffer)
217 Standard_ExtString extBuffer;
218 Standard_Integer i,c,d;
220 extBuffer = buffer.ToExtString();
222 for (i = 0; i < buffer.Length(); i++) {
223 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
224 d = extBuffer[i] & 0x000000FF;
226 myStream << (char)c << (char)d;
229 myStream << (char)0 << "\n";
232 //=======================================================================
233 //function : ReadExtendedLine
235 //=======================================================================
237 void FSD_File::ReadExtendedLine(TCollection_ExtendedString& buffer)
240 Standard_ExtCharacter i = 0,j,count = 0;
241 Standard_Boolean fin = Standard_False;
242 Standard_CString tg = ENDOFNORMALEXTENDEDSECTION;
246 while (!fin && !IsEnd()) {
249 if (c == tg[count]) count++;
251 if (count < SIZEOFNORMALEXTENDEDSECTION) {
253 i = (Standard_ExtCharacter)c;
254 if (c == '\0') fin = Standard_True;
258 if (c == tg[count]) count++;
260 if (count < SIZEOFNORMALEXTENDEDSECTION) {
261 j = (Standard_ExtCharacter)c;
263 fin = Standard_False;
265 buffer += (Standard_ExtCharacter)i;
269 throw Storage_StreamExtCharParityError();
273 throw Storage_StreamExtCharParityError();
278 //=======================================================================
279 //function : ReadChar
280 //purpose : read <rsize> character from the current position.
281 //=======================================================================
283 void FSD_File::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsize)
286 Standard_Size ccount = 0;
290 while (!IsEnd() && (ccount < rsize)) {
297 //=======================================================================
298 //function : ReadString
299 //purpose : read from the first none space character position to the end of line.
300 //=======================================================================
302 void FSD_File::ReadString(TCollection_AsciiString& buffer)
306 Standard_Boolean IsEnd = Standard_False,isFirstTime = Standard_True;
310 while (!IsEnd && !FSD_File::IsEnd()) {
312 myStream.getline(Buffer,8192,'\n');
318 isFirstTime = Standard_False;
319 while (*bpos == '\n' || *bpos == ' ') bpos++;
322 // if (myStream.get(c) && c != '\n') {
328 IsEnd = Standard_True;
334 //=======================================================================
335 //function : ReadWord
336 //purpose : read from the current position to the next white space or end of line.
337 //=======================================================================
339 void FSD_File::ReadWord(TCollection_AsciiString& buffer)
343 Standard_Boolean IsEnd = Standard_False;
350 while (!IsEnd && !FSD_File::IsEnd()) {
352 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
355 IsEnd = Standard_False;
358 while (!IsEnd && !FSD_File::IsEnd()) {
368 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
374 //=======================================================================
377 //=======================================================================
379 Storage_Error FSD_File::FindTag(const Standard_CString aTag)
381 TCollection_AsciiString l;
385 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
390 return Storage_VSSectionNotFound;
397 //=======================================================================
398 //function : SkipObject
400 //=======================================================================
402 void FSD_File::SkipObject()
407 //=======================================================================
408 //function : PutReference
409 //purpose : ---------------------- PUBLIC : PUT
410 //=======================================================================
412 Storage_BaseDriver& FSD_File::PutReference(const Standard_Integer aValue)
414 myStream << aValue << " ";
415 if (myStream.bad()) throw Storage_StreamWriteError();
419 //=======================================================================
420 //function : PutCharacter
422 //=======================================================================
424 Storage_BaseDriver& FSD_File::PutCharacter(const Standard_Character aValue)
429 myStream << i << " ";
430 if (myStream.bad()) throw Storage_StreamWriteError();
434 //=======================================================================
435 //function : PutExtCharacter
437 //=======================================================================
439 Storage_BaseDriver& FSD_File::PutExtCharacter(const Standard_ExtCharacter aValue)
441 myStream << (short )aValue << " ";
442 if (myStream.bad()) throw Storage_StreamWriteError();
446 //=======================================================================
447 //function : PutInteger
449 //=======================================================================
451 Storage_BaseDriver& FSD_File::PutInteger(const Standard_Integer aValue)
453 myStream << aValue << " ";
454 if (myStream.bad()) throw Storage_StreamWriteError();
458 //=======================================================================
459 //function : PutBoolean
461 //=======================================================================
463 Storage_BaseDriver& FSD_File::PutBoolean(const Standard_Boolean aValue)
465 myStream << ((Standard_Integer)aValue) << " ";
466 if (myStream.bad()) throw Storage_StreamWriteError();
470 //=======================================================================
473 //=======================================================================
475 Storage_BaseDriver& FSD_File::PutReal(const Standard_Real aValue)
477 myStream << ((Standard_Real)aValue) << " ";
478 if (myStream.bad()) throw Storage_StreamWriteError();
482 //=======================================================================
483 //function : PutShortReal
485 //=======================================================================
487 Storage_BaseDriver& FSD_File::PutShortReal(const Standard_ShortReal aValue)
489 myStream << aValue << " ";
490 if (myStream.bad()) throw Storage_StreamWriteError();
494 //=======================================================================
495 //function : GetReference
496 //purpose : ----------------- PUBLIC : GET
497 //=======================================================================
499 Storage_BaseDriver& FSD_File::GetReference(Standard_Integer& aValue)
501 if (!(myStream >> aValue)) throw Storage_StreamTypeMismatchError();
506 //=======================================================================
507 //function : GetCharacter
509 //=======================================================================
511 Storage_BaseDriver& FSD_File::GetCharacter(Standard_Character& aValue)
513 unsigned short i = 0;
514 if (!(myStream >> i)) {
515 // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
516 // signes (-80 fait std::ios::badbit, mais la variable i est initialisee)
518 if (i == 0) throw Storage_StreamTypeMismatchError();
519 myStream.clear(std::ios::goodbit); // .clear(0) is not portable
526 //=======================================================================
527 //function : GetExtCharacter
529 //=======================================================================
531 Storage_BaseDriver& FSD_File::GetExtCharacter(Standard_ExtCharacter& aValue)
534 if (!(myStream >> aChar)) throw Storage_StreamTypeMismatchError();
539 //=======================================================================
540 //function : GetInteger
542 //=======================================================================
544 Storage_BaseDriver& FSD_File::GetInteger(Standard_Integer& aValue)
546 if (!(myStream >> aValue)) throw Storage_StreamTypeMismatchError();
551 //=======================================================================
552 //function : GetBoolean
554 //=======================================================================
556 Storage_BaseDriver& FSD_File::GetBoolean(Standard_Boolean& aValue)
558 if (!(myStream >> aValue)) throw Storage_StreamTypeMismatchError();
563 //=======================================================================
566 //=======================================================================
568 Storage_BaseDriver& FSD_File::GetReal(Standard_Real& aValue)
571 char realbuffer[100];
573 realbuffer[0] = '\0';
574 if (!(myStream >> realbuffer)) throw Storage_StreamTypeMismatchError();
575 if (!OSD::CStringToReal(realbuffer,aValue)) throw Storage_StreamTypeMismatchError();
579 if (!(myStream >> aValue)) throw Storage_StreamTypeMismatchError();
585 //=======================================================================
586 //function : GetShortReal
588 //=======================================================================
590 Storage_BaseDriver& FSD_File::GetShortReal(Standard_ShortReal& aValue)
593 char realbuffer[100];
594 Standard_Real r = 0.0;
596 realbuffer[0] = '\0';
597 if (!(myStream >> realbuffer)) throw Storage_StreamTypeMismatchError();
598 if (!OSD::CStringToReal(realbuffer,r)) throw Storage_StreamTypeMismatchError();
600 aValue = (Standard_ShortReal)r;
604 if (!(myStream >> aValue)) throw Storage_StreamTypeMismatchError();
609 //=======================================================================
612 //=======================================================================
614 void FSD_File::Destroy()
616 if (OpenMode() != Storage_VSNone) {
621 //=======================================================================
622 //function : BeginWriteInfoSection
623 //purpose : -------------------------- INFO : WRITE
624 //=======================================================================
626 Storage_Error FSD_File::BeginWriteInfoSection()
628 myStream << FSD_File::MagicNumber() << '\n';
629 myStream << "BEGIN_INFO_SECTION\n";
630 if (myStream.bad()) throw Storage_StreamWriteError();
635 //=======================================================================
636 //function : WriteInfo
638 //=======================================================================
640 void FSD_File::WriteInfo(const Standard_Integer nbObj,
641 const TCollection_AsciiString& dbVersion,
642 const TCollection_AsciiString& date,
643 const TCollection_AsciiString& schemaName,
644 const TCollection_AsciiString& schemaVersion,
645 const TCollection_ExtendedString& appName,
646 const TCollection_AsciiString& appVersion,
647 const TCollection_ExtendedString& dataType,
648 const TColStd_SequenceOfAsciiString& userInfo)
654 myStream << dbVersion.ToCString() << "\n";
655 myStream << date.ToCString() << "\n";
656 myStream << schemaName.ToCString() << "\n";
657 myStream << schemaVersion.ToCString() << "\n";
658 WriteExtendedLine(appName);
659 myStream << appVersion.ToCString() << "\n";
660 WriteExtendedLine(dataType);
661 myStream << userInfo.Length() << "\n";
663 if (myStream.bad()) throw Storage_StreamWriteError();
665 for (i = 1; i <= userInfo.Length(); i++) {
666 myStream << userInfo.Value(i).ToCString() << "\n";
667 if (myStream.bad()) throw Storage_StreamWriteError();
671 //=======================================================================
672 //function : EndWriteInfoSection
674 //=======================================================================
676 Storage_Error FSD_File::EndWriteInfoSection()
678 myStream << "END_INFO_SECTION\n";
679 if (myStream.bad()) throw Storage_StreamWriteError();
683 //=======================================================================
684 //function : BeginReadInfoSection
686 //=======================================================================
688 Storage_Error FSD_File::BeginReadInfoSection()
691 TCollection_AsciiString l;
692 Standard_Size len = strlen(FSD_File::MagicNumber());
696 if (strncmp(FSD_File::MagicNumber(),l.ToCString(),len) != 0) {
697 s = Storage_VSFormatError;
700 s = FindTag("BEGIN_INFO_SECTION");
706 //=======================================================================
707 //function : ReadInfo
708 //purpose : ------------------- INFO : READ
709 //=======================================================================
711 void FSD_File::ReadInfo(Standard_Integer& nbObj,
712 TCollection_AsciiString& dbVersion,
713 TCollection_AsciiString& date,
714 TCollection_AsciiString& schemaName,
715 TCollection_AsciiString& schemaVersion,
716 TCollection_ExtendedString& appName,
717 TCollection_AsciiString& appVersion,
718 TCollection_ExtendedString& dataType,
719 TColStd_SequenceOfAsciiString& userInfo)
721 if (!(myStream >> nbObj)) throw Storage_StreamTypeMismatchError();
727 ReadLine(schemaName);
728 ReadLine(schemaVersion);
729 ReadExtendedLine(appName);
730 ReadLine(appVersion);
731 ReadExtendedLine(dataType);
733 Standard_Integer i,len = 0;
735 if (!(myStream >> len)) throw Storage_StreamTypeMismatchError();
739 TCollection_AsciiString line;
741 for (i = 1; i <= len && !IsEnd(); i++) {
743 userInfo.Append(line);
748 //=======================================================================
749 //function : ReadCompleteInfo
752 //=======================================================================
753 void FSD_File::ReadCompleteInfo( Standard_IStream& /*theIStream*/, Handle(Storage_Data)& /*theData*/)
758 //=======================================================================
759 //function : EndReadInfoSection
760 //purpose : COMMENTS SECTION
762 //=======================================================================
764 Storage_Error FSD_File::EndReadInfoSection()
766 return FindTag("END_INFO_SECTION");
769 //=======================================================================
770 //function : BeginWriteCommentSection
771 //purpose : ---------------- COMMENTS : WRITE
772 //=======================================================================
774 Storage_Error FSD_File::BeginWriteCommentSection()
776 myStream << "BEGIN_COMMENT_SECTION\n";
777 if (myStream.bad()) throw Storage_StreamWriteError();
781 //=======================================================================
782 //function : WriteComment
784 //=======================================================================
786 void FSD_File::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
788 Standard_Integer i,aSize;
790 aSize = aCom.Length();
791 myStream << aSize << "\n";
792 if (myStream.bad()) throw Storage_StreamWriteError();
794 for (i = 1; i <= aSize; i++) {
795 WriteExtendedLine(aCom.Value(i));
796 if (myStream.bad()) throw Storage_StreamWriteError();
800 //=======================================================================
801 //function : EndWriteCommentSection
803 //=======================================================================
805 Storage_Error FSD_File::EndWriteCommentSection()
807 myStream << "END_COMMENT_SECTION\n";
808 if (myStream.bad()) throw Storage_StreamWriteError();
812 //=======================================================================
813 //function : BeginReadCommentSection
814 //purpose : ---------------- COMMENTS : READ
815 //=======================================================================
817 Storage_Error FSD_File::BeginReadCommentSection()
819 return FindTag("BEGIN_COMMENT_SECTION");
822 //=======================================================================
823 //function : ReadComment
825 //=======================================================================
827 void FSD_File::ReadComment(TColStd_SequenceOfExtendedString& aCom)
829 TCollection_ExtendedString line;
830 Standard_Integer len,i;
832 if (!(myStream >> len)) throw Storage_StreamTypeMismatchError();
836 for (i = 1; i <= len && !IsEnd(); i++) {
837 ReadExtendedLine(line);
843 //=======================================================================
844 //function : EndReadCommentSection
846 //=======================================================================
848 Storage_Error FSD_File::EndReadCommentSection()
850 return FindTag("END_COMMENT_SECTION");
853 //=======================================================================
854 //function : BeginWriteTypeSection
855 //purpose : --------------- TYPE : WRITE
856 //=======================================================================
858 Storage_Error FSD_File::BeginWriteTypeSection()
860 myStream << "BEGIN_TYPE_SECTION\n";
861 if (myStream.bad()) throw Storage_StreamWriteError();
865 //=======================================================================
866 //function : SetTypeSectionSize
868 //=======================================================================
870 void FSD_File::SetTypeSectionSize(const Standard_Integer aSize)
872 myStream << aSize << "\n";
873 if (myStream.bad()) throw Storage_StreamWriteError();
876 //=======================================================================
877 //function : WriteTypeInformations
879 //=======================================================================
881 void FSD_File::WriteTypeInformations(const Standard_Integer typeNum,
882 const TCollection_AsciiString& typeName)
884 myStream << typeNum << " " << typeName.ToCString() << "\n";
885 if (myStream.bad()) throw Storage_StreamWriteError();
888 //=======================================================================
889 //function : EndWriteTypeSection
891 //=======================================================================
893 Storage_Error FSD_File::EndWriteTypeSection()
895 myStream << "END_TYPE_SECTION\n";
896 if (myStream.bad()) throw Storage_StreamWriteError();
900 //=======================================================================
901 //function : BeginReadTypeSection
902 //purpose : ------------------- TYPE : READ
903 //=======================================================================
905 Storage_Error FSD_File::BeginReadTypeSection()
907 return FindTag("BEGIN_TYPE_SECTION");
910 //=======================================================================
911 //function : TypeSectionSize
913 //=======================================================================
915 Standard_Integer FSD_File::TypeSectionSize()
919 if (!(myStream >> i)) throw Storage_StreamTypeMismatchError();
926 //=======================================================================
927 //function : ReadTypeInformations
929 //=======================================================================
931 void FSD_File::ReadTypeInformations(Standard_Integer& typeNum,
932 TCollection_AsciiString& typeName)
934 if (!(myStream >> typeNum)) throw Storage_StreamTypeMismatchError();
935 if (!(myStream >> typeName)) throw Storage_StreamTypeMismatchError();
939 //=======================================================================
940 //function : EndReadTypeSection
941 //purpose : ROOT SECTION
943 //=======================================================================
945 Storage_Error FSD_File::EndReadTypeSection()
947 return FindTag("END_TYPE_SECTION");
950 //=======================================================================
951 //function : BeginWriteRootSection
952 //purpose : -------------------- ROOT : WRITE
953 //=======================================================================
955 Storage_Error FSD_File::BeginWriteRootSection()
957 myStream << "BEGIN_ROOT_SECTION\n";
958 if (myStream.bad()) throw Storage_StreamWriteError();
962 //=======================================================================
963 //function : SetRootSectionSize
965 //=======================================================================
967 void FSD_File::SetRootSectionSize(const Standard_Integer aSize)
969 myStream << aSize << "\n";
970 if (myStream.bad()) throw Storage_StreamWriteError();
973 //=======================================================================
974 //function : WriteRoot
976 //=======================================================================
978 void FSD_File::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
980 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
981 if (myStream.bad()) throw Storage_StreamWriteError();
984 //=======================================================================
985 //function : EndWriteRootSection
987 //=======================================================================
989 Storage_Error FSD_File::EndWriteRootSection()
991 myStream << "END_ROOT_SECTION\n";
992 if (myStream.bad()) throw Storage_StreamWriteError();
996 //=======================================================================
997 //function : BeginReadRootSection
998 //purpose : ----------------------- ROOT : READ
999 //=======================================================================
1001 Storage_Error FSD_File::BeginReadRootSection()
1003 return FindTag("BEGIN_ROOT_SECTION");
1006 //=======================================================================
1007 //function : RootSectionSize
1009 //=======================================================================
1011 Standard_Integer FSD_File::RootSectionSize()
1015 if (!(myStream >> i)) throw Storage_StreamTypeMismatchError();
1022 //=======================================================================
1023 //function : ReadRoot
1025 //=======================================================================
1027 void FSD_File::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1029 if (!(myStream >> aRef)) throw Storage_StreamTypeMismatchError();
1034 //=======================================================================
1035 //function : EndReadRootSection
1036 //purpose : REF SECTION
1038 //=======================================================================
1040 Storage_Error FSD_File::EndReadRootSection()
1042 return FindTag("END_ROOT_SECTION");
1045 //=======================================================================
1046 //function : BeginWriteRefSection
1047 //purpose : -------------------------- REF : WRITE
1048 //=======================================================================
1050 Storage_Error FSD_File::BeginWriteRefSection()
1052 myStream << "BEGIN_REF_SECTION\n";
1053 if (myStream.bad()) throw Storage_StreamWriteError();
1054 return Storage_VSOk;
1057 //=======================================================================
1058 //function : SetRefSectionSize
1060 //=======================================================================
1062 void FSD_File::SetRefSectionSize(const Standard_Integer aSize)
1064 myStream << aSize << "\n";
1065 if (myStream.bad()) throw Storage_StreamWriteError();
1068 //=======================================================================
1069 //function : WriteReferenceType
1071 //=======================================================================
1073 void FSD_File::WriteReferenceType(const Standard_Integer reference,
1074 const Standard_Integer typeNum)
1076 myStream << reference << " " << typeNum << "\n";
1077 if (myStream.bad()) throw Storage_StreamWriteError();
1080 //=======================================================================
1081 //function : EndWriteRefSection
1083 //=======================================================================
1085 Storage_Error FSD_File::EndWriteRefSection()
1087 myStream << "END_REF_SECTION\n";
1088 if (myStream.bad()) throw Storage_StreamWriteError();
1089 return Storage_VSOk;
1092 //=======================================================================
1093 //function : BeginReadRefSection
1094 //purpose : ----------------------- REF : READ
1095 //=======================================================================
1097 Storage_Error FSD_File::BeginReadRefSection()
1099 return FindTag("BEGIN_REF_SECTION");
1102 //=======================================================================
1103 //function : RefSectionSize
1105 //=======================================================================
1107 Standard_Integer FSD_File::RefSectionSize()
1111 if (!(myStream >> i)) throw Storage_StreamTypeMismatchError();
1117 //=======================================================================
1118 //function : ReadReferenceType
1120 //=======================================================================
1122 void FSD_File::ReadReferenceType(Standard_Integer& reference,
1123 Standard_Integer& typeNum)
1125 if (!(myStream >> reference)) throw Storage_StreamTypeMismatchError();
1126 if (!(myStream >> typeNum)) throw Storage_StreamTypeMismatchError();
1130 //=======================================================================
1131 //function : EndReadRefSection
1132 //purpose : DATA SECTION
1134 //=======================================================================
1136 Storage_Error FSD_File::EndReadRefSection()
1138 return FindTag("END_REF_SECTION");
1141 //=======================================================================
1142 //function : BeginWriteDataSection
1143 //purpose : -------------------- DATA : WRITE
1144 //=======================================================================
1146 Storage_Error FSD_File::BeginWriteDataSection()
1148 myStream << "BEGIN_DATA_SECTION";
1149 if (myStream.bad()) throw Storage_StreamWriteError();
1150 return Storage_VSOk;
1153 //=======================================================================
1154 //function : WritePersistentObjectHeader
1156 //=======================================================================
1158 void FSD_File::WritePersistentObjectHeader(const Standard_Integer aRef,
1159 const Standard_Integer aType)
1161 myStream << "\n#" << aRef << "=%" << aType;
1162 if (myStream.bad()) throw Storage_StreamWriteError();
1165 //=======================================================================
1166 //function : BeginWritePersistentObjectData
1168 //=======================================================================
1170 void FSD_File::BeginWritePersistentObjectData()
1173 if (myStream.bad()) throw Storage_StreamWriteError();
1176 //=======================================================================
1177 //function : BeginWriteObjectData
1179 //=======================================================================
1181 void FSD_File::BeginWriteObjectData()
1184 if (myStream.bad()) throw Storage_StreamWriteError();
1187 //=======================================================================
1188 //function : EndWriteObjectData
1190 //=======================================================================
1192 void FSD_File::EndWriteObjectData()
1195 if (myStream.bad()) throw Storage_StreamWriteError();
1198 //=======================================================================
1199 //function : EndWritePersistentObjectData
1201 //=======================================================================
1203 void FSD_File::EndWritePersistentObjectData()
1206 if (myStream.bad()) throw Storage_StreamWriteError();
1209 //=======================================================================
1210 //function : EndWriteDataSection
1212 //=======================================================================
1214 Storage_Error FSD_File::EndWriteDataSection()
1216 myStream << "\nEND_DATA_SECTION\n";
1217 if (myStream.bad()) throw Storage_StreamWriteError();
1218 return Storage_VSOk;
1221 //=======================================================================
1222 //function : BeginReadDataSection
1223 //purpose : ---------------------- DATA : READ
1224 //=======================================================================
1226 Storage_Error FSD_File::BeginReadDataSection()
1228 return FindTag("BEGIN_DATA_SECTION");
1231 //=======================================================================
1232 //function : ReadPersistentObjectHeader
1234 //=======================================================================
1236 void FSD_File::ReadPersistentObjectHeader(Standard_Integer& aRef,
1237 Standard_Integer& aType)
1244 if (IsEnd() || (c != ' ') || (c == '\n')) {
1245 throw Storage_StreamFormatError();
1250 if (!(myStream >> aRef)) throw Storage_StreamTypeMismatchError();
1256 if (IsEnd() || (c != ' ') || (c == '\n')) {
1257 throw Storage_StreamFormatError();
1265 if (IsEnd() || (c != ' ') || (c == '\n')) {
1266 throw Storage_StreamFormatError();
1271 if (!(myStream >> aType)) throw Storage_StreamTypeMismatchError();
1272 // std::cout << "REF:" << aRef << " TYPE:"<< aType << std::endl;
1275 //=======================================================================
1276 //function : BeginReadPersistentObjectData
1278 //=======================================================================
1280 void FSD_File::BeginReadPersistentObjectData()
1285 if (IsEnd() || (c != ' ') || (c == '\n')) {
1286 throw Storage_StreamFormatError();
1291 //std::cout << "BeginReadPersistentObjectData" << std::endl;
1294 //=======================================================================
1295 //function : BeginReadObjectData
1297 //=======================================================================
1299 void FSD_File::BeginReadObjectData()
1304 if (IsEnd() || (c != ' ') || (c == '\n')) {
1305 throw Storage_StreamFormatError();
1310 // std::cout << "BeginReadObjectData" << std::endl;
1313 //=======================================================================
1314 //function : EndReadObjectData
1316 //=======================================================================
1318 void FSD_File::EndReadObjectData()
1323 if (IsEnd() || (c != ' ') || (c == '\n')) {
1324 throw Storage_StreamFormatError();
1329 // std::cout << "EndReadObjectData" << std::endl;
1332 //=======================================================================
1333 //function : EndReadPersistentObjectData
1335 //=======================================================================
1337 void FSD_File::EndReadPersistentObjectData()
1343 if (IsEnd() || (c != ' ') || (c == '\n')) {
1344 throw Storage_StreamFormatError();
1351 if (IsEnd() || (c != ' ')) {
1352 throw Storage_StreamFormatError();
1356 // std::cout << "EndReadPersistentObjectData" << std::endl;
1359 //=======================================================================
1360 //function : EndReadDataSection
1362 //=======================================================================
1364 Storage_Error FSD_File::EndReadDataSection()
1366 return FindTag("END_DATA_SECTION");
1369 //=======================================================================
1371 //purpose : return position in the file. Return -1 upon error.
1372 //=======================================================================
1374 Storage_Position FSD_File::Tell()
1376 switch (OpenMode()) {
1377 case Storage_VSRead:
1378 return (Storage_Position) myStream.tellp();
1379 case Storage_VSWrite:
1380 return (Storage_Position) myStream.tellg();
1381 case Storage_VSReadWrite: {
1382 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1383 Storage_Position aPosW = (Storage_Position) myStream.tellg();