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_CmpFile.ixx>
18 #include <Storage_StreamModeError.hxx>
19 #include <Storage_StreamUnknownTypeError.hxx>
20 #include <Standard_PCharacter.hxx>
22 // Propagate the improvement (BUC60808) on all platforms
25 // BUC60808 : standard output in MS Visual C++ limites the quantity of figures (digits)
26 // in part of number after fixed point. The quantity of figures after fixed point
27 // could not be more than 15 when we output double number using standard MS VS output operator '<<'.
28 // For example, the maximum double value DBL_MAX = 1.7976931348623157e+308 (see float.h) after
29 // cout<<setprecision(17)<<DBL_MAX becomes 1.79769313486232e+308 in stream of output
30 // (it could be a file stream). When the number 1.79769313486232e+308 is read from the
31 // i/o streame (file, for example) it occurs more than allowed maximum value of double
32 // type - 1.7976931348623157e+308. Such value is considered as infinite. When it is written
33 // to file (for example) again it is written as 1.#INF. Such value can't be read from file next time.
36 const Standard_CString MAGICNUMBER = "CMPFILE";
38 //=======================================================================
39 //function : FSD_CmpFile
41 //=======================================================================
43 FSD_CmpFile::FSD_CmpFile()
48 //=======================================================================
49 //function : IsGoodFileType
50 //purpose : INFO SECTION
52 //=======================================================================
54 Storage_Error FSD_CmpFile::IsGoodFileType(const TCollection_AsciiString& aName)
59 s = f.Open(aName,Storage_VSRead);
61 if (s == Storage_VSOk) {
62 TCollection_AsciiString l;
63 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
69 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
70 s = Storage_VSFormatError;
77 //=======================================================================
80 //=======================================================================
82 Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
84 Storage_Error result = Storage_VSOk;
88 if (OpenMode() == Storage_VSNone) {
90 #if !defined(IRIX) && !defined(DECOSF1)
91 if (aMode == Storage_VSRead) {
92 myStream.open(aName.ToCString(),ios::in|ios::binary); // ios::nocreate is not portable
94 else if (aMode == Storage_VSWrite) {
95 myStream.open(aName.ToCString(),ios::out|ios::binary);
97 else if (aMode == Storage_VSReadWrite) {
98 myStream.open(aName.ToCString(),ios::in|ios::out|ios::binary);
101 if (aMode == Storage_VSRead) {
102 myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
104 else if (aMode == Storage_VSWrite) {
105 myStream.open(aName.ToCString(),ios::out);
107 else if (aMode == Storage_VSReadWrite) {
108 myStream.open(aName.ToCString(),ios::in|ios::out);
112 if (myStream.fail()) {
113 result = Storage_VSOpenError;
116 myStream.precision(17);
117 myStream.imbue (std::locale::classic()); // use always C locale
122 result = Storage_VSAlreadyOpen;
127 //=======================================================================
130 //=======================================================================
132 Standard_Boolean FSD_CmpFile::IsEnd()
134 return myStream.eof();
137 //=======================================================================
140 //=======================================================================
142 Storage_Error FSD_CmpFile::Close()
144 Storage_Error result = Storage_VSOk;
146 if (OpenMode() != Storage_VSNone) {
148 SetOpenMode(Storage_VSNone);
151 result = Storage_VSNotOpen;
157 //=======================================================================
158 //function : MagicNumber
159 //purpose : ------------------ PROTECTED
160 //=======================================================================
162 const Standard_CString FSD_CmpFile::MagicNumber()
167 //=======================================================================
168 //function : FlushEndOfLine
170 //=======================================================================
172 void FSD_CmpFile::FlushEndOfLine()
174 TCollection_AsciiString aDummy;
175 ReadLine (aDummy); // flush is nothing more than to read till the line-break
177 static char Buffer[8192];
179 Standard_Boolean IsEnd = Standard_False;
181 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
183 myStream.get(Buffer,8192,'\n');
185 if (myStream.get(c) && c != '\r' && c != '\n') {
188 IsEnd = Standard_True;
194 //=======================================================================
195 //function : ReadLine
196 //purpose : read from the current position to the end of line.
197 //=======================================================================
199 void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer)
203 Standard_Boolean IsEnd = Standard_False;
207 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
209 //myStream.get(Buffer,8192,'\n');
210 myStream.getline(Buffer,8192,'\n');
211 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
215 // if (myStream.get(c) && c != '\r' && c != '\n') {
221 IsEnd = Standard_True;
226 //=======================================================================
227 //function : WriteExtendedLine
228 //purpose : write from the current position to the end of line.
229 //=======================================================================
231 void FSD_CmpFile::WriteExtendedLine(const TCollection_ExtendedString& buffer)
234 Standard_ExtString extBuffer;
235 Standard_Integer i,c,d;
237 extBuffer = buffer.ToExtString();
239 for (i = 0; i < buffer.Length(); i++) {
240 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
241 d = extBuffer[i] & 0x000000FF;
243 myStream << (char)c << (char)d;
246 myStream << (char)0 << "\n";
248 Standard_ExtString extBuffer;
251 extBuffer = buffer.ToExtString();
252 PutInteger(buffer.Length());
253 for (i = 0; i < buffer.Length(); i++) {
254 PutExtCharacter(extBuffer[i]);
260 //=======================================================================
261 //function : ReadExtendedLine
263 //=======================================================================
265 void FSD_CmpFile::ReadExtendedLine(TCollection_ExtendedString& buffer)
267 Standard_ExtCharacter c;
272 for (i = 0; i < buffer.Length(); i++) {
280 //=======================================================================
281 //function : ReadChar
282 //purpose : read <rsize> character from the current position.
283 //=======================================================================
285 void FSD_CmpFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsize)
288 Standard_Size ccount = 0;
292 while (!IsEnd() && (ccount < rsize)) {
299 //=======================================================================
300 //function : ReadString
301 //purpose : read from the first none space character position to the end of line.
302 //=======================================================================
304 void FSD_CmpFile::ReadString(TCollection_AsciiString& buffer)
308 Standard_Boolean IsEnd = Standard_False,isFirstTime = Standard_True;
312 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
314 //myStream.get(Buffer,8192,'\n');
315 myStream.getline(Buffer,8192,'\n');
316 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
324 isFirstTime = Standard_False;
325 while (*bpos == '\n' || *bpos == ' ') bpos++;
328 // if (myStream.get(c) && c != '\n') {
334 IsEnd = Standard_True;
339 //=======================================================================
340 //function : ReadWord
341 //purpose : read from the current position to the next white space or end of line.
342 //=======================================================================
344 void FSD_CmpFile::ReadWord(TCollection_AsciiString& buffer)
348 Standard_Boolean IsEnd = Standard_False;
355 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
357 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
360 IsEnd = Standard_False;
363 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
373 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
379 //=======================================================================
382 //=======================================================================
384 Storage_Error FSD_CmpFile::FindTag(const Standard_CString aTag)
386 TCollection_AsciiString l;
390 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
395 return Storage_VSSectionNotFound;
402 //=======================================================================
403 //function : SkipObject
405 //=======================================================================
407 void FSD_CmpFile::SkipObject()
412 //=======================================================================
413 //function : PutReference
414 //purpose : ---------------------- PUBLIC : PUT
415 //=======================================================================
417 Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
419 myStream << aValue << " ";
420 if (myStream.bad()) Storage_StreamWriteError::Raise();
424 //=======================================================================
425 //function : PutCharacter
427 //=======================================================================
429 Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
434 myStream << i << " ";
435 if (myStream.bad()) Storage_StreamWriteError::Raise();
439 //=======================================================================
440 //function : PutExtCharacter
442 //=======================================================================
444 Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue)
446 myStream << aValue << " ";
447 if (myStream.bad()) Storage_StreamWriteError::Raise();
451 //=======================================================================
452 //function : PutInteger
454 //=======================================================================
456 Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
458 myStream << aValue << " ";
459 if (myStream.bad()) Storage_StreamWriteError::Raise();
463 //=======================================================================
464 //function : PutBoolean
466 //=======================================================================
468 Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
470 myStream << ((Standard_Integer)aValue) << " ";
471 if (myStream.bad()) Storage_StreamWriteError::Raise();
475 //=======================================================================
478 //=======================================================================
480 Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
482 myStream << ((Standard_Real)aValue) << " ";
483 if (myStream.bad()) Storage_StreamWriteError::Raise();
487 //=======================================================================
488 //function : PutShortReal
490 //=======================================================================
492 Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue)
494 myStream << aValue << " ";
495 if (myStream.bad()) Storage_StreamWriteError::Raise();
499 //=======================================================================
500 //function : GetReference
501 //purpose : ----------------- PUBLIC : GET
502 //=======================================================================
504 Storage_BaseDriver& FSD_CmpFile::GetReference(Standard_Integer& aValue)
506 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
511 //=======================================================================
512 //function : GetCharacter
514 //=======================================================================
516 Storage_BaseDriver& FSD_CmpFile::GetCharacter(Standard_Character& aValue)
518 unsigned short i = 0;
519 if (!(myStream >> i)) {
520 // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
521 // signes (-80 fait ios::badbit, mais la variable i est initialisee)
523 if (i == 0) Storage_StreamTypeMismatchError::Raise();
524 myStream.clear(ios::goodbit);
531 //=======================================================================
532 //function : GetExtCharacter
534 //=======================================================================
536 Storage_BaseDriver& FSD_CmpFile::GetExtCharacter(Standard_ExtCharacter& aValue)
538 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
543 //=======================================================================
544 //function : GetInteger
546 //=======================================================================
548 Storage_BaseDriver& FSD_CmpFile::GetInteger(Standard_Integer& aValue)
550 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
555 //=======================================================================
556 //function : GetBoolean
558 //=======================================================================
560 Storage_BaseDriver& FSD_CmpFile::GetBoolean(Standard_Boolean& aValue)
562 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
567 //=======================================================================
570 //=======================================================================
572 Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
575 char realbuffer[100];
577 realbuffer[0] = '\0';
578 if (!(myStream >> realbuffer)) {
579 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
580 cerr << "\t buffer is" << realbuffer<< endl;
581 Storage_StreamTypeMismatchError::Raise();
583 if (!OSD::CStringToReal(realbuffer,aValue)) {
584 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
585 cerr << "\t buffer is" << realbuffer<< endl;
586 Storage_StreamTypeMismatchError::Raise();
591 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
597 //=======================================================================
598 //function : GetShortReal
600 //=======================================================================
602 Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
605 char realbuffer[100];
606 Standard_Real r = 0.0;
608 realbuffer[0] = '\0';
609 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
610 if (!OSD::CStringToReal(realbuffer,r))
611 Storage_StreamTypeMismatchError::Raise();
613 aValue = (Standard_ShortReal)r;
617 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
622 //=======================================================================
625 //=======================================================================
627 void FSD_CmpFile::Destroy()
629 if (OpenMode() != Storage_VSNone) {
634 //=======================================================================
635 //function : BeginWriteInfoSection
636 //purpose : -------------------------- INFO : WRITE
637 //=======================================================================
639 Storage_Error FSD_CmpFile::BeginWriteInfoSection()
641 myStream << FSD_CmpFile::MagicNumber() << '\n';
642 myStream << "BEGIN_INFO_SECTION\n";
643 if (myStream.bad()) Storage_StreamWriteError::Raise();
648 //=======================================================================
649 //function : WriteInfo
651 //=======================================================================
653 void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
654 const TCollection_AsciiString& dbVersion,
655 const TCollection_AsciiString& date,
656 const TCollection_AsciiString& schemaName,
657 const TCollection_AsciiString& schemaVersion,
658 const TCollection_ExtendedString& appName,
659 const TCollection_AsciiString& appVersion,
660 const TCollection_ExtendedString& dataType,
661 const TColStd_SequenceOfAsciiString& userInfo)
667 myStream << dbVersion.ToCString() << "\n";
668 myStream << date.ToCString() << "\n";
669 myStream << schemaName.ToCString() << "\n";
670 myStream << schemaVersion.ToCString() << "\n";
671 WriteExtendedLine(appName);
672 myStream << appVersion.ToCString() << "\n";
673 WriteExtendedLine(dataType);
674 myStream << userInfo.Length() << "\n";
676 if (myStream.bad()) Storage_StreamWriteError::Raise();
678 for (i = 1; i <= userInfo.Length(); i++) {
679 myStream << userInfo.Value(i).ToCString() << "\n";
680 if (myStream.bad()) Storage_StreamWriteError::Raise();
684 //=======================================================================
685 //function : EndWriteInfoSection
687 //=======================================================================
689 Storage_Error FSD_CmpFile::EndWriteInfoSection()
691 myStream << "END_INFO_SECTION\n";
692 if (myStream.bad()) Storage_StreamWriteError::Raise();
696 //=======================================================================
697 //function : BeginReadInfoSection
699 //=======================================================================
701 Storage_Error FSD_CmpFile::BeginReadInfoSection()
704 TCollection_AsciiString l;
705 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
709 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
710 s = Storage_VSFormatError;
713 s = FindTag("BEGIN_INFO_SECTION");
719 //=======================================================================
720 //function : ReadInfo
721 //purpose : ------------------- INFO : READ
722 //=======================================================================
724 void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
725 TCollection_AsciiString& dbVersion,
726 TCollection_AsciiString& date,
727 TCollection_AsciiString& schemaName,
728 TCollection_AsciiString& schemaVersion,
729 TCollection_ExtendedString& appName,
730 TCollection_AsciiString& appVersion,
731 TCollection_ExtendedString& dataType,
732 TColStd_SequenceOfAsciiString& userInfo)
734 if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
740 ReadLine(schemaName);
741 ReadLine(schemaVersion);
742 ReadExtendedLine(appName);
743 ReadLine(appVersion);
744 ReadExtendedLine(dataType);
746 Standard_Integer i,len = 0;
748 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
752 TCollection_AsciiString line;
754 for (i = 1; i <= len && !IsEnd(); i++) {
756 userInfo.Append(line);
761 //=======================================================================
762 //function : EndReadInfoSection
763 //purpose : COMMENTS SECTION
765 //=======================================================================
767 Storage_Error FSD_CmpFile::EndReadInfoSection()
769 return FindTag("END_INFO_SECTION");
772 //=======================================================================
773 //function : BeginWriteCommentSection
774 //purpose : ---------------- COMMENTS : WRITE
775 //=======================================================================
777 Storage_Error FSD_CmpFile::BeginWriteCommentSection()
779 myStream << "BEGIN_COMMENT_SECTION\n";
780 if (myStream.bad()) Storage_StreamWriteError::Raise();
784 //=======================================================================
785 //function : WriteComment
787 //=======================================================================
789 void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
791 Standard_Integer i,aSize;
793 aSize = aCom.Length();
794 myStream << aSize << "\n";
795 if (myStream.bad()) Storage_StreamWriteError::Raise();
797 for (i = 1; i <= aSize; i++) {
798 WriteExtendedLine(aCom.Value(i));
799 if (myStream.bad()) Storage_StreamWriteError::Raise();
803 //=======================================================================
804 //function : EndWriteCommentSection
806 //=======================================================================
808 Storage_Error FSD_CmpFile::EndWriteCommentSection()
810 myStream << "END_COMMENT_SECTION\n";
811 if (myStream.bad()) Storage_StreamWriteError::Raise();
815 //=======================================================================
816 //function : BeginReadCommentSection
817 //purpose : ---------------- COMMENTS : READ
818 //=======================================================================
820 Storage_Error FSD_CmpFile::BeginReadCommentSection()
822 return FindTag("BEGIN_COMMENT_SECTION");
825 //=======================================================================
826 //function : ReadComment
828 //=======================================================================
830 void FSD_CmpFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
832 TCollection_ExtendedString line;
833 Standard_Integer len,i;
835 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
839 for (i = 1; i <= len && !IsEnd(); i++) {
840 ReadExtendedLine(line);
846 //=======================================================================
847 //function : EndReadCommentSection
849 //=======================================================================
851 Storage_Error FSD_CmpFile::EndReadCommentSection()
853 return FindTag("END_COMMENT_SECTION");
856 //=======================================================================
857 //function : BeginWriteTypeSection
858 //purpose : --------------- TYPE : WRITE
859 //=======================================================================
861 Storage_Error FSD_CmpFile::BeginWriteTypeSection()
863 myStream << "BEGIN_TYPE_SECTION\n";
864 if (myStream.bad()) Storage_StreamWriteError::Raise();
868 //=======================================================================
869 //function : SetTypeSectionSize
871 //=======================================================================
873 void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
875 myStream << aSize << "\n";
876 if (myStream.bad()) Storage_StreamWriteError::Raise();
879 //=======================================================================
880 //function : WriteTypeInformations
882 //=======================================================================
884 void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
885 const TCollection_AsciiString& typeName)
887 myStream << typeNum << " " << typeName.ToCString() << "\n";
888 if (myStream.bad()) Storage_StreamWriteError::Raise();
891 //=======================================================================
892 //function : EndWriteTypeSection
894 //=======================================================================
896 Storage_Error FSD_CmpFile::EndWriteTypeSection()
898 myStream << "END_TYPE_SECTION\n";
899 if (myStream.bad()) Storage_StreamWriteError::Raise();
903 //=======================================================================
904 //function : BeginReadTypeSection
905 //purpose : ------------------- TYPE : READ
906 //=======================================================================
908 Storage_Error FSD_CmpFile::BeginReadTypeSection()
910 return FindTag("BEGIN_TYPE_SECTION");
913 //=======================================================================
914 //function : TypeSectionSize
916 //=======================================================================
918 Standard_Integer FSD_CmpFile::TypeSectionSize()
922 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
929 //=======================================================================
930 //function : ReadTypeInformations
932 //=======================================================================
934 void FSD_CmpFile::ReadTypeInformations(Standard_Integer& typeNum,
935 TCollection_AsciiString& typeName)
937 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
938 if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
942 //=======================================================================
943 //function : EndReadTypeSection
944 //purpose : ROOT SECTION
946 //=======================================================================
948 Storage_Error FSD_CmpFile::EndReadTypeSection()
950 return FindTag("END_TYPE_SECTION");
953 //=======================================================================
954 //function : BeginWriteRootSection
955 //purpose : -------------------- ROOT : WRITE
956 //=======================================================================
958 Storage_Error FSD_CmpFile::BeginWriteRootSection()
960 myStream << "BEGIN_ROOT_SECTION\n";
961 if (myStream.bad()) Storage_StreamWriteError::Raise();
965 //=======================================================================
966 //function : SetRootSectionSize
968 //=======================================================================
970 void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
972 myStream << aSize << "\n";
973 if (myStream.bad()) Storage_StreamWriteError::Raise();
976 //=======================================================================
977 //function : WriteRoot
979 //=======================================================================
981 void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
983 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
984 if (myStream.bad()) Storage_StreamWriteError::Raise();
987 //=======================================================================
988 //function : EndWriteRootSection
990 //=======================================================================
992 Storage_Error FSD_CmpFile::EndWriteRootSection()
994 myStream << "END_ROOT_SECTION\n";
995 if (myStream.bad()) Storage_StreamWriteError::Raise();
999 //=======================================================================
1000 //function : BeginReadRootSection
1001 //purpose : ----------------------- ROOT : READ
1002 //=======================================================================
1004 Storage_Error FSD_CmpFile::BeginReadRootSection()
1006 return FindTag("BEGIN_ROOT_SECTION");
1009 //=======================================================================
1010 //function : RootSectionSize
1012 //=======================================================================
1014 Standard_Integer FSD_CmpFile::RootSectionSize()
1018 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1025 //=======================================================================
1026 //function : ReadRoot
1028 //=======================================================================
1030 void FSD_CmpFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1032 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1037 //=======================================================================
1038 //function : EndReadRootSection
1039 //purpose : REF SECTION
1041 //=======================================================================
1043 Storage_Error FSD_CmpFile::EndReadRootSection()
1045 return FindTag("END_ROOT_SECTION");
1048 //=======================================================================
1049 //function : BeginWriteRefSection
1050 //purpose : -------------------------- REF : WRITE
1051 //=======================================================================
1053 Storage_Error FSD_CmpFile::BeginWriteRefSection()
1055 myStream << "BEGIN_REF_SECTION\n";
1056 if (myStream.bad()) Storage_StreamWriteError::Raise();
1057 return Storage_VSOk;
1060 //=======================================================================
1061 //function : SetRefSectionSize
1063 //=======================================================================
1065 void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
1067 myStream << aSize << "\n";
1068 if (myStream.bad()) Storage_StreamWriteError::Raise();
1071 //=======================================================================
1072 //function : WriteReferenceType
1074 //=======================================================================
1076 void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
1077 const Standard_Integer typeNum)
1079 myStream << reference << " " << typeNum << "\n";
1080 if (myStream.bad()) Storage_StreamWriteError::Raise();
1083 //=======================================================================
1084 //function : EndWriteRefSection
1086 //=======================================================================
1088 Storage_Error FSD_CmpFile::EndWriteRefSection()
1090 myStream << "END_REF_SECTION\n";
1091 if (myStream.bad()) Storage_StreamWriteError::Raise();
1092 return Storage_VSOk;
1095 //=======================================================================
1096 //function : BeginReadRefSection
1097 //purpose : ----------------------- REF : READ
1098 //=======================================================================
1100 Storage_Error FSD_CmpFile::BeginReadRefSection()
1102 return FindTag("BEGIN_REF_SECTION");
1105 //=======================================================================
1106 //function : RefSectionSize
1108 //=======================================================================
1110 Standard_Integer FSD_CmpFile::RefSectionSize()
1114 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1120 //=======================================================================
1121 //function : ReadReferenceType
1123 //=======================================================================
1125 void FSD_CmpFile::ReadReferenceType(Standard_Integer& reference,
1126 Standard_Integer& typeNum)
1128 if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
1129 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1133 //=======================================================================
1134 //function : EndReadRefSection
1135 //purpose : DATA SECTION
1137 //=======================================================================
1139 Storage_Error FSD_CmpFile::EndReadRefSection()
1141 return FindTag("END_REF_SECTION");
1144 //=======================================================================
1145 //function : BeginWriteDataSection
1146 //purpose : -------------------- DATA : WRITE
1147 //=======================================================================
1149 Storage_Error FSD_CmpFile::BeginWriteDataSection()
1151 myStream << "BEGIN_DATA_SECTION";
1152 if (myStream.bad()) Storage_StreamWriteError::Raise();
1153 return Storage_VSOk;
1156 //=======================================================================
1157 //function : WritePersistentObjectHeader
1159 //=======================================================================
1161 void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
1162 const Standard_Integer aType)
1164 myStream << "\n#" << aRef << "%" << aType << " ";
1165 if (myStream.bad()) Storage_StreamWriteError::Raise();
1168 //=======================================================================
1169 //function : BeginWritePersistentObjectData
1171 //=======================================================================
1173 void FSD_CmpFile::BeginWritePersistentObjectData()
1175 if (myStream.bad()) Storage_StreamWriteError::Raise();
1178 //=======================================================================
1179 //function : BeginWriteObjectData
1181 //=======================================================================
1183 void FSD_CmpFile::BeginWriteObjectData()
1185 if (myStream.bad()) Storage_StreamWriteError::Raise();
1188 //=======================================================================
1189 //function : EndWriteObjectData
1191 //=======================================================================
1193 void FSD_CmpFile::EndWriteObjectData()
1195 if (myStream.bad()) Storage_StreamWriteError::Raise();
1198 //=======================================================================
1199 //function : EndWritePersistentObjectData
1201 //=======================================================================
1203 void FSD_CmpFile::EndWritePersistentObjectData()
1205 if (myStream.bad()) Storage_StreamWriteError::Raise();
1208 //=======================================================================
1209 //function : EndWriteDataSection
1211 //=======================================================================
1213 Storage_Error FSD_CmpFile::EndWriteDataSection()
1215 myStream << "\nEND_DATA_SECTION\n";
1216 if (myStream.bad()) Storage_StreamWriteError::Raise();
1217 return Storage_VSOk;
1220 //=======================================================================
1221 //function : BeginReadDataSection
1222 //purpose : ---------------------- DATA : READ
1223 //=======================================================================
1225 Storage_Error FSD_CmpFile::BeginReadDataSection()
1227 return FindTag("BEGIN_DATA_SECTION");
1230 //=======================================================================
1231 //function : ReadPersistentObjectHeader
1233 //=======================================================================
1235 void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
1236 Standard_Integer& aType)
1243 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1244 Storage_StreamFormatError::Raise();
1249 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1254 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1255 Storage_StreamFormatError::Raise();
1260 if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
1261 // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
1264 //=======================================================================
1265 //function : BeginReadPersistentObjectData
1267 //=======================================================================
1269 void FSD_CmpFile::BeginReadPersistentObjectData()
1271 //cout << "BeginReadPersistentObjectData" << endl;
1274 //=======================================================================
1275 //function : BeginReadObjectData
1277 //=======================================================================
1279 void FSD_CmpFile::BeginReadObjectData()
1281 // cout << "BeginReadObjectData" << endl;
1284 //=======================================================================
1285 //function : EndReadObjectData
1287 //=======================================================================
1289 void FSD_CmpFile::EndReadObjectData()
1291 // cout << "EndReadObjectData" << endl;
1294 //=======================================================================
1295 //function : EndReadPersistentObjectData
1297 //=======================================================================
1299 void FSD_CmpFile::EndReadPersistentObjectData()
1304 while (c != '\n' && (c != '\r')) {
1305 if (IsEnd() || (c != ' ')) {
1306 Storage_StreamFormatError::Raise();
1313 // cout << "EndReadPersistentObjectData" << endl;
1316 //=======================================================================
1317 //function : EndReadDataSection
1319 //=======================================================================
1321 Storage_Error FSD_CmpFile::EndReadDataSection()
1323 return FindTag("END_DATA_SECTION");
1326 //=======================================================================
1328 //purpose : return position in the file. Return -1 upon error.
1329 //=======================================================================
1331 Storage_Position FSD_CmpFile::Tell()
1333 switch (OpenMode()) {
1334 case Storage_VSRead:
1335 return (Storage_Position) myStream.tellp();
1336 case Storage_VSWrite:
1337 return (Storage_Position) myStream.tellg();
1338 case Storage_VSReadWrite: {
1339 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1340 Storage_Position aPosW = (Storage_Position) myStream.tellg();