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) {
91 TCollection_ExtendedString aWName(aName);
92 if (aMode == Storage_VSRead) {
93 myStream.open((const wchar_t*)aWName.ToExtString(),ios::in|ios::binary); // ios::nocreate is not portable
95 else if (aMode == Storage_VSWrite) {
96 myStream.open((const wchar_t*)aWName.ToExtString(),ios::out|ios::binary);
98 else if (aMode == Storage_VSReadWrite) {
99 myStream.open((const wchar_t*)aWName.ToExtString(),ios::in|ios::out|ios::binary);
101 #elif !defined(IRIX) && !defined(DECOSF1)
102 if (aMode == Storage_VSRead) {
103 myStream.open(aName.ToCString(),ios::in|ios::binary); // ios::nocreate is not portable
105 else if (aMode == Storage_VSWrite) {
106 myStream.open(aName.ToCString(),ios::out|ios::binary);
108 else if (aMode == Storage_VSReadWrite) {
109 myStream.open(aName.ToCString(),ios::in|ios::out|ios::binary);
112 if (aMode == Storage_VSRead) {
113 myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
115 else if (aMode == Storage_VSWrite) {
116 myStream.open(aName.ToCString(),ios::out);
118 else if (aMode == Storage_VSReadWrite) {
119 myStream.open(aName.ToCString(),ios::in|ios::out);
123 if (myStream.fail()) {
124 result = Storage_VSOpenError;
127 myStream.precision(17);
128 myStream.imbue (std::locale::classic()); // use always C locale
133 result = Storage_VSAlreadyOpen;
138 //=======================================================================
141 //=======================================================================
143 Standard_Boolean FSD_CmpFile::IsEnd()
145 return myStream.eof();
148 //=======================================================================
151 //=======================================================================
153 Storage_Error FSD_CmpFile::Close()
155 Storage_Error result = Storage_VSOk;
157 if (OpenMode() != Storage_VSNone) {
159 SetOpenMode(Storage_VSNone);
162 result = Storage_VSNotOpen;
168 //=======================================================================
169 //function : MagicNumber
170 //purpose : ------------------ PROTECTED
171 //=======================================================================
173 const Standard_CString FSD_CmpFile::MagicNumber()
178 //=======================================================================
179 //function : FlushEndOfLine
181 //=======================================================================
183 void FSD_CmpFile::FlushEndOfLine()
185 TCollection_AsciiString aDummy;
186 ReadLine (aDummy); // flush is nothing more than to read till the line-break
188 static char Buffer[8192];
190 Standard_Boolean IsEnd = Standard_False;
192 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
194 myStream.get(Buffer,8192,'\n');
196 if (myStream.get(c) && c != '\r' && c != '\n') {
199 IsEnd = Standard_True;
205 //=======================================================================
206 //function : ReadLine
207 //purpose : read from the current position to the end of line.
208 //=======================================================================
210 void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer)
214 Standard_Boolean IsEnd = Standard_False;
218 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
220 //myStream.get(Buffer,8192,'\n');
221 myStream.getline(Buffer,8192,'\n');
222 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
226 // if (myStream.get(c) && c != '\r' && c != '\n') {
232 IsEnd = Standard_True;
237 //=======================================================================
238 //function : WriteExtendedLine
239 //purpose : write from the current position to the end of line.
240 //=======================================================================
242 void FSD_CmpFile::WriteExtendedLine(const TCollection_ExtendedString& buffer)
245 Standard_ExtString extBuffer;
246 Standard_Integer i,c,d;
248 extBuffer = buffer.ToExtString();
250 for (i = 0; i < buffer.Length(); i++) {
251 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
252 d = extBuffer[i] & 0x000000FF;
254 myStream << (char)c << (char)d;
257 myStream << (char)0 << "\n";
259 Standard_ExtString extBuffer;
262 extBuffer = buffer.ToExtString();
263 PutInteger(buffer.Length());
264 for (i = 0; i < buffer.Length(); i++) {
265 PutExtCharacter(extBuffer[i]);
271 //=======================================================================
272 //function : ReadExtendedLine
274 //=======================================================================
276 void FSD_CmpFile::ReadExtendedLine(TCollection_ExtendedString& buffer)
278 Standard_ExtCharacter c;
283 for (i = 0; i < buffer.Length(); i++) {
291 //=======================================================================
292 //function : ReadChar
293 //purpose : read <rsize> character from the current position.
294 //=======================================================================
296 void FSD_CmpFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsize)
299 Standard_Size ccount = 0;
303 while (!IsEnd() && (ccount < rsize)) {
310 //=======================================================================
311 //function : ReadString
312 //purpose : read from the first none space character position to the end of line.
313 //=======================================================================
315 void FSD_CmpFile::ReadString(TCollection_AsciiString& buffer)
319 Standard_Boolean IsEnd = Standard_False,isFirstTime = Standard_True;
323 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
325 //myStream.get(Buffer,8192,'\n');
326 myStream.getline(Buffer,8192,'\n');
327 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
335 isFirstTime = Standard_False;
336 while (*bpos == '\n' || *bpos == ' ') bpos++;
339 // if (myStream.get(c) && c != '\n') {
345 IsEnd = Standard_True;
350 //=======================================================================
351 //function : ReadWord
352 //purpose : read from the current position to the next white space or end of line.
353 //=======================================================================
355 void FSD_CmpFile::ReadWord(TCollection_AsciiString& buffer)
359 Standard_Boolean IsEnd = Standard_False;
366 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
368 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
371 IsEnd = Standard_False;
374 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
384 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
390 //=======================================================================
393 //=======================================================================
395 Storage_Error FSD_CmpFile::FindTag(const Standard_CString aTag)
397 TCollection_AsciiString l;
401 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
406 return Storage_VSSectionNotFound;
413 //=======================================================================
414 //function : SkipObject
416 //=======================================================================
418 void FSD_CmpFile::SkipObject()
423 //=======================================================================
424 //function : PutReference
425 //purpose : ---------------------- PUBLIC : PUT
426 //=======================================================================
428 Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
430 myStream << aValue << " ";
431 if (myStream.bad()) Storage_StreamWriteError::Raise();
435 //=======================================================================
436 //function : PutCharacter
438 //=======================================================================
440 Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
445 myStream << i << " ";
446 if (myStream.bad()) Storage_StreamWriteError::Raise();
450 //=======================================================================
451 //function : PutExtCharacter
453 //=======================================================================
455 Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue)
457 myStream << aValue << " ";
458 if (myStream.bad()) Storage_StreamWriteError::Raise();
462 //=======================================================================
463 //function : PutInteger
465 //=======================================================================
467 Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
469 myStream << aValue << " ";
470 if (myStream.bad()) Storage_StreamWriteError::Raise();
474 //=======================================================================
475 //function : PutBoolean
477 //=======================================================================
479 Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
481 myStream << ((Standard_Integer)aValue) << " ";
482 if (myStream.bad()) Storage_StreamWriteError::Raise();
486 //=======================================================================
489 //=======================================================================
491 Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
493 myStream << ((Standard_Real)aValue) << " ";
494 if (myStream.bad()) Storage_StreamWriteError::Raise();
498 //=======================================================================
499 //function : PutShortReal
501 //=======================================================================
503 Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue)
505 myStream << aValue << " ";
506 if (myStream.bad()) Storage_StreamWriteError::Raise();
510 //=======================================================================
511 //function : GetReference
512 //purpose : ----------------- PUBLIC : GET
513 //=======================================================================
515 Storage_BaseDriver& FSD_CmpFile::GetReference(Standard_Integer& aValue)
517 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
522 //=======================================================================
523 //function : GetCharacter
525 //=======================================================================
527 Storage_BaseDriver& FSD_CmpFile::GetCharacter(Standard_Character& aValue)
529 unsigned short i = 0;
530 if (!(myStream >> i)) {
531 // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
532 // signes (-80 fait ios::badbit, mais la variable i est initialisee)
534 if (i == 0) Storage_StreamTypeMismatchError::Raise();
535 myStream.clear(ios::goodbit);
542 //=======================================================================
543 //function : GetExtCharacter
545 //=======================================================================
547 Storage_BaseDriver& FSD_CmpFile::GetExtCharacter(Standard_ExtCharacter& aValue)
549 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
554 //=======================================================================
555 //function : GetInteger
557 //=======================================================================
559 Storage_BaseDriver& FSD_CmpFile::GetInteger(Standard_Integer& aValue)
561 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
566 //=======================================================================
567 //function : GetBoolean
569 //=======================================================================
571 Storage_BaseDriver& FSD_CmpFile::GetBoolean(Standard_Boolean& aValue)
573 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
578 //=======================================================================
581 //=======================================================================
583 Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
586 char realbuffer[100];
588 realbuffer[0] = '\0';
589 if (!(myStream >> realbuffer)) {
590 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
591 cerr << "\t buffer is" << realbuffer<< endl;
592 Storage_StreamTypeMismatchError::Raise();
594 if (!OSD::CStringToReal(realbuffer,aValue)) {
595 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
596 cerr << "\t buffer is" << realbuffer<< endl;
597 Storage_StreamTypeMismatchError::Raise();
602 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
608 //=======================================================================
609 //function : GetShortReal
611 //=======================================================================
613 Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
616 char realbuffer[100];
617 Standard_Real r = 0.0;
619 realbuffer[0] = '\0';
620 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
621 if (!OSD::CStringToReal(realbuffer,r))
622 Storage_StreamTypeMismatchError::Raise();
624 aValue = (Standard_ShortReal)r;
628 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
633 //=======================================================================
636 //=======================================================================
638 void FSD_CmpFile::Destroy()
640 if (OpenMode() != Storage_VSNone) {
645 //=======================================================================
646 //function : BeginWriteInfoSection
647 //purpose : -------------------------- INFO : WRITE
648 //=======================================================================
650 Storage_Error FSD_CmpFile::BeginWriteInfoSection()
652 myStream << FSD_CmpFile::MagicNumber() << '\n';
653 myStream << "BEGIN_INFO_SECTION\n";
654 if (myStream.bad()) Storage_StreamWriteError::Raise();
659 //=======================================================================
660 //function : WriteInfo
662 //=======================================================================
664 void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
665 const TCollection_AsciiString& dbVersion,
666 const TCollection_AsciiString& date,
667 const TCollection_AsciiString& schemaName,
668 const TCollection_AsciiString& schemaVersion,
669 const TCollection_ExtendedString& appName,
670 const TCollection_AsciiString& appVersion,
671 const TCollection_ExtendedString& dataType,
672 const TColStd_SequenceOfAsciiString& userInfo)
678 myStream << dbVersion.ToCString() << "\n";
679 myStream << date.ToCString() << "\n";
680 myStream << schemaName.ToCString() << "\n";
681 myStream << schemaVersion.ToCString() << "\n";
682 WriteExtendedLine(appName);
683 myStream << appVersion.ToCString() << "\n";
684 WriteExtendedLine(dataType);
685 myStream << userInfo.Length() << "\n";
687 if (myStream.bad()) Storage_StreamWriteError::Raise();
689 for (i = 1; i <= userInfo.Length(); i++) {
690 myStream << userInfo.Value(i).ToCString() << "\n";
691 if (myStream.bad()) Storage_StreamWriteError::Raise();
695 //=======================================================================
696 //function : EndWriteInfoSection
698 //=======================================================================
700 Storage_Error FSD_CmpFile::EndWriteInfoSection()
702 myStream << "END_INFO_SECTION\n";
703 if (myStream.bad()) Storage_StreamWriteError::Raise();
707 //=======================================================================
708 //function : BeginReadInfoSection
710 //=======================================================================
712 Storage_Error FSD_CmpFile::BeginReadInfoSection()
715 TCollection_AsciiString l;
716 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
720 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
721 s = Storage_VSFormatError;
724 s = FindTag("BEGIN_INFO_SECTION");
730 //=======================================================================
731 //function : ReadInfo
732 //purpose : ------------------- INFO : READ
733 //=======================================================================
735 void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
736 TCollection_AsciiString& dbVersion,
737 TCollection_AsciiString& date,
738 TCollection_AsciiString& schemaName,
739 TCollection_AsciiString& schemaVersion,
740 TCollection_ExtendedString& appName,
741 TCollection_AsciiString& appVersion,
742 TCollection_ExtendedString& dataType,
743 TColStd_SequenceOfAsciiString& userInfo)
745 if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
751 ReadLine(schemaName);
752 ReadLine(schemaVersion);
753 ReadExtendedLine(appName);
754 ReadLine(appVersion);
755 ReadExtendedLine(dataType);
757 Standard_Integer i,len = 0;
759 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
763 TCollection_AsciiString line;
765 for (i = 1; i <= len && !IsEnd(); i++) {
767 userInfo.Append(line);
772 //=======================================================================
773 //function : EndReadInfoSection
774 //purpose : COMMENTS SECTION
776 //=======================================================================
778 Storage_Error FSD_CmpFile::EndReadInfoSection()
780 return FindTag("END_INFO_SECTION");
783 //=======================================================================
784 //function : BeginWriteCommentSection
785 //purpose : ---------------- COMMENTS : WRITE
786 //=======================================================================
788 Storage_Error FSD_CmpFile::BeginWriteCommentSection()
790 myStream << "BEGIN_COMMENT_SECTION\n";
791 if (myStream.bad()) Storage_StreamWriteError::Raise();
795 //=======================================================================
796 //function : WriteComment
798 //=======================================================================
800 void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
802 Standard_Integer i,aSize;
804 aSize = aCom.Length();
805 myStream << aSize << "\n";
806 if (myStream.bad()) Storage_StreamWriteError::Raise();
808 for (i = 1; i <= aSize; i++) {
809 WriteExtendedLine(aCom.Value(i));
810 if (myStream.bad()) Storage_StreamWriteError::Raise();
814 //=======================================================================
815 //function : EndWriteCommentSection
817 //=======================================================================
819 Storage_Error FSD_CmpFile::EndWriteCommentSection()
821 myStream << "END_COMMENT_SECTION\n";
822 if (myStream.bad()) Storage_StreamWriteError::Raise();
826 //=======================================================================
827 //function : BeginReadCommentSection
828 //purpose : ---------------- COMMENTS : READ
829 //=======================================================================
831 Storage_Error FSD_CmpFile::BeginReadCommentSection()
833 return FindTag("BEGIN_COMMENT_SECTION");
836 //=======================================================================
837 //function : ReadComment
839 //=======================================================================
841 void FSD_CmpFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
843 TCollection_ExtendedString line;
844 Standard_Integer len,i;
846 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
850 for (i = 1; i <= len && !IsEnd(); i++) {
851 ReadExtendedLine(line);
857 //=======================================================================
858 //function : EndReadCommentSection
860 //=======================================================================
862 Storage_Error FSD_CmpFile::EndReadCommentSection()
864 return FindTag("END_COMMENT_SECTION");
867 //=======================================================================
868 //function : BeginWriteTypeSection
869 //purpose : --------------- TYPE : WRITE
870 //=======================================================================
872 Storage_Error FSD_CmpFile::BeginWriteTypeSection()
874 myStream << "BEGIN_TYPE_SECTION\n";
875 if (myStream.bad()) Storage_StreamWriteError::Raise();
879 //=======================================================================
880 //function : SetTypeSectionSize
882 //=======================================================================
884 void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
886 myStream << aSize << "\n";
887 if (myStream.bad()) Storage_StreamWriteError::Raise();
890 //=======================================================================
891 //function : WriteTypeInformations
893 //=======================================================================
895 void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
896 const TCollection_AsciiString& typeName)
898 myStream << typeNum << " " << typeName.ToCString() << "\n";
899 if (myStream.bad()) Storage_StreamWriteError::Raise();
902 //=======================================================================
903 //function : EndWriteTypeSection
905 //=======================================================================
907 Storage_Error FSD_CmpFile::EndWriteTypeSection()
909 myStream << "END_TYPE_SECTION\n";
910 if (myStream.bad()) Storage_StreamWriteError::Raise();
914 //=======================================================================
915 //function : BeginReadTypeSection
916 //purpose : ------------------- TYPE : READ
917 //=======================================================================
919 Storage_Error FSD_CmpFile::BeginReadTypeSection()
921 return FindTag("BEGIN_TYPE_SECTION");
924 //=======================================================================
925 //function : TypeSectionSize
927 //=======================================================================
929 Standard_Integer FSD_CmpFile::TypeSectionSize()
933 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
940 //=======================================================================
941 //function : ReadTypeInformations
943 //=======================================================================
945 void FSD_CmpFile::ReadTypeInformations(Standard_Integer& typeNum,
946 TCollection_AsciiString& typeName)
948 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
949 if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
953 //=======================================================================
954 //function : EndReadTypeSection
955 //purpose : ROOT SECTION
957 //=======================================================================
959 Storage_Error FSD_CmpFile::EndReadTypeSection()
961 return FindTag("END_TYPE_SECTION");
964 //=======================================================================
965 //function : BeginWriteRootSection
966 //purpose : -------------------- ROOT : WRITE
967 //=======================================================================
969 Storage_Error FSD_CmpFile::BeginWriteRootSection()
971 myStream << "BEGIN_ROOT_SECTION\n";
972 if (myStream.bad()) Storage_StreamWriteError::Raise();
976 //=======================================================================
977 //function : SetRootSectionSize
979 //=======================================================================
981 void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
983 myStream << aSize << "\n";
984 if (myStream.bad()) Storage_StreamWriteError::Raise();
987 //=======================================================================
988 //function : WriteRoot
990 //=======================================================================
992 void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
994 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
995 if (myStream.bad()) Storage_StreamWriteError::Raise();
998 //=======================================================================
999 //function : EndWriteRootSection
1001 //=======================================================================
1003 Storage_Error FSD_CmpFile::EndWriteRootSection()
1005 myStream << "END_ROOT_SECTION\n";
1006 if (myStream.bad()) Storage_StreamWriteError::Raise();
1007 return Storage_VSOk;
1010 //=======================================================================
1011 //function : BeginReadRootSection
1012 //purpose : ----------------------- ROOT : READ
1013 //=======================================================================
1015 Storage_Error FSD_CmpFile::BeginReadRootSection()
1017 return FindTag("BEGIN_ROOT_SECTION");
1020 //=======================================================================
1021 //function : RootSectionSize
1023 //=======================================================================
1025 Standard_Integer FSD_CmpFile::RootSectionSize()
1029 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1036 //=======================================================================
1037 //function : ReadRoot
1039 //=======================================================================
1041 void FSD_CmpFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1043 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1048 //=======================================================================
1049 //function : EndReadRootSection
1050 //purpose : REF SECTION
1052 //=======================================================================
1054 Storage_Error FSD_CmpFile::EndReadRootSection()
1056 return FindTag("END_ROOT_SECTION");
1059 //=======================================================================
1060 //function : BeginWriteRefSection
1061 //purpose : -------------------------- REF : WRITE
1062 //=======================================================================
1064 Storage_Error FSD_CmpFile::BeginWriteRefSection()
1066 myStream << "BEGIN_REF_SECTION\n";
1067 if (myStream.bad()) Storage_StreamWriteError::Raise();
1068 return Storage_VSOk;
1071 //=======================================================================
1072 //function : SetRefSectionSize
1074 //=======================================================================
1076 void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
1078 myStream << aSize << "\n";
1079 if (myStream.bad()) Storage_StreamWriteError::Raise();
1082 //=======================================================================
1083 //function : WriteReferenceType
1085 //=======================================================================
1087 void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
1088 const Standard_Integer typeNum)
1090 myStream << reference << " " << typeNum << "\n";
1091 if (myStream.bad()) Storage_StreamWriteError::Raise();
1094 //=======================================================================
1095 //function : EndWriteRefSection
1097 //=======================================================================
1099 Storage_Error FSD_CmpFile::EndWriteRefSection()
1101 myStream << "END_REF_SECTION\n";
1102 if (myStream.bad()) Storage_StreamWriteError::Raise();
1103 return Storage_VSOk;
1106 //=======================================================================
1107 //function : BeginReadRefSection
1108 //purpose : ----------------------- REF : READ
1109 //=======================================================================
1111 Storage_Error FSD_CmpFile::BeginReadRefSection()
1113 return FindTag("BEGIN_REF_SECTION");
1116 //=======================================================================
1117 //function : RefSectionSize
1119 //=======================================================================
1121 Standard_Integer FSD_CmpFile::RefSectionSize()
1125 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1131 //=======================================================================
1132 //function : ReadReferenceType
1134 //=======================================================================
1136 void FSD_CmpFile::ReadReferenceType(Standard_Integer& reference,
1137 Standard_Integer& typeNum)
1139 if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
1140 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1144 //=======================================================================
1145 //function : EndReadRefSection
1146 //purpose : DATA SECTION
1148 //=======================================================================
1150 Storage_Error FSD_CmpFile::EndReadRefSection()
1152 return FindTag("END_REF_SECTION");
1155 //=======================================================================
1156 //function : BeginWriteDataSection
1157 //purpose : -------------------- DATA : WRITE
1158 //=======================================================================
1160 Storage_Error FSD_CmpFile::BeginWriteDataSection()
1162 myStream << "BEGIN_DATA_SECTION";
1163 if (myStream.bad()) Storage_StreamWriteError::Raise();
1164 return Storage_VSOk;
1167 //=======================================================================
1168 //function : WritePersistentObjectHeader
1170 //=======================================================================
1172 void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
1173 const Standard_Integer aType)
1175 myStream << "\n#" << aRef << "%" << aType << " ";
1176 if (myStream.bad()) Storage_StreamWriteError::Raise();
1179 //=======================================================================
1180 //function : BeginWritePersistentObjectData
1182 //=======================================================================
1184 void FSD_CmpFile::BeginWritePersistentObjectData()
1186 if (myStream.bad()) Storage_StreamWriteError::Raise();
1189 //=======================================================================
1190 //function : BeginWriteObjectData
1192 //=======================================================================
1194 void FSD_CmpFile::BeginWriteObjectData()
1196 if (myStream.bad()) Storage_StreamWriteError::Raise();
1199 //=======================================================================
1200 //function : EndWriteObjectData
1202 //=======================================================================
1204 void FSD_CmpFile::EndWriteObjectData()
1206 if (myStream.bad()) Storage_StreamWriteError::Raise();
1209 //=======================================================================
1210 //function : EndWritePersistentObjectData
1212 //=======================================================================
1214 void FSD_CmpFile::EndWritePersistentObjectData()
1216 if (myStream.bad()) Storage_StreamWriteError::Raise();
1219 //=======================================================================
1220 //function : EndWriteDataSection
1222 //=======================================================================
1224 Storage_Error FSD_CmpFile::EndWriteDataSection()
1226 myStream << "\nEND_DATA_SECTION\n";
1227 if (myStream.bad()) Storage_StreamWriteError::Raise();
1228 return Storage_VSOk;
1231 //=======================================================================
1232 //function : BeginReadDataSection
1233 //purpose : ---------------------- DATA : READ
1234 //=======================================================================
1236 Storage_Error FSD_CmpFile::BeginReadDataSection()
1238 return FindTag("BEGIN_DATA_SECTION");
1241 //=======================================================================
1242 //function : ReadPersistentObjectHeader
1244 //=======================================================================
1246 void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
1247 Standard_Integer& aType)
1254 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1255 Storage_StreamFormatError::Raise();
1260 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1265 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1266 Storage_StreamFormatError::Raise();
1271 if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
1272 // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
1275 //=======================================================================
1276 //function : BeginReadPersistentObjectData
1278 //=======================================================================
1280 void FSD_CmpFile::BeginReadPersistentObjectData()
1282 //cout << "BeginReadPersistentObjectData" << endl;
1285 //=======================================================================
1286 //function : BeginReadObjectData
1288 //=======================================================================
1290 void FSD_CmpFile::BeginReadObjectData()
1292 // cout << "BeginReadObjectData" << endl;
1295 //=======================================================================
1296 //function : EndReadObjectData
1298 //=======================================================================
1300 void FSD_CmpFile::EndReadObjectData()
1302 // cout << "EndReadObjectData" << endl;
1305 //=======================================================================
1306 //function : EndReadPersistentObjectData
1308 //=======================================================================
1310 void FSD_CmpFile::EndReadPersistentObjectData()
1315 while (c != '\n' && (c != '\r')) {
1316 if (IsEnd() || (c != ' ')) {
1317 Storage_StreamFormatError::Raise();
1324 // cout << "EndReadPersistentObjectData" << endl;
1327 //=======================================================================
1328 //function : EndReadDataSection
1330 //=======================================================================
1332 Storage_Error FSD_CmpFile::EndReadDataSection()
1334 return FindTag("END_DATA_SECTION");
1337 //=======================================================================
1339 //purpose : return position in the file. Return -1 upon error.
1340 //=======================================================================
1342 Storage_Position FSD_CmpFile::Tell()
1344 switch (OpenMode()) {
1345 case Storage_VSRead:
1346 return (Storage_Position) myStream.tellp();
1347 case Storage_VSWrite:
1348 return (Storage_Position) myStream.tellg();
1349 case Storage_VSReadWrite: {
1350 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1351 Storage_Position aPosW = (Storage_Position) myStream.tellg();