1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <FSD_CmpFile.ixx>
22 #include <OSD_Real2String.hxx>
24 #include <Storage_StreamModeError.hxx>
25 #include <Storage_StreamUnknownTypeError.hxx>
26 #include <Standard_PCharacter.hxx>
28 // Propagate the improvement (BUC60808) on all platforms
31 // BUC60808 : standard output in MS Visual C++ limites the quantity of figures (digits)
32 // in part of number after fixed point. The quantity of figures after fixed point
33 // could not be more than 15 when we output double number using standard MS VS output operator '<<'.
34 // For example, the maximum double value DBL_MAX = 1.7976931348623157e+308 (see float.h) after
35 // cout<<setprecision(17)<<DBL_MAX becomes 1.79769313486232e+308 in stream of output
36 // (it could be a file stream). When the number 1.79769313486232e+308 is read from the
37 // i/o streame (file, for example) it occurs more than allowed maximum value of double
38 // type - 1.7976931348623157e+308. Such value is considered as infinite. When it is written
39 // to file (for example) again it is written as 1.#INF. Such value can't be read from file next time.
42 const Standard_CString MAGICNUMBER = "CMPFILE";
43 const Standard_CString ENDOFNORMALEXTENDEDSECTION = "BEGIN_REF_SECTION";
44 const Standard_Integer SIZEOFNORMALEXTENDEDSECTION = 16;
46 //=======================================================================
47 //function : FSD_CmpFile
49 //=======================================================================
51 FSD_CmpFile::FSD_CmpFile()
56 //=======================================================================
57 //function : IsGoodFileType
58 //purpose : INFO SECTION
60 //=======================================================================
62 Storage_Error FSD_CmpFile::IsGoodFileType(const TCollection_AsciiString& aName)
67 s = f.Open(aName,Storage_VSRead);
69 if (s == Storage_VSOk) {
70 TCollection_AsciiString l;
71 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
77 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
78 s = Storage_VSFormatError;
85 //=======================================================================
88 //=======================================================================
90 Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
92 Storage_Error result = Storage_VSOk;
96 if (OpenMode() == Storage_VSNone) {
98 #if !defined(IRIX) && !defined(DECOSF1)
99 if (aMode == Storage_VSRead) {
100 myStream.open(aName.ToCString(),ios::in|ios::binary); // ios::nocreate is not portable
102 else if (aMode == Storage_VSWrite) {
103 myStream.open(aName.ToCString(),ios::out|ios::binary);
105 else if (aMode == Storage_VSReadWrite) {
106 myStream.open(aName.ToCString(),ios::in|ios::out|ios::binary);
109 if (aMode == Storage_VSRead) {
110 myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
112 else if (aMode == Storage_VSWrite) {
113 myStream.open(aName.ToCString(),ios::out);
115 else if (aMode == Storage_VSReadWrite) {
116 myStream.open(aName.ToCString(),ios::in|ios::out);
120 if (myStream.fail()) {
121 result = Storage_VSOpenError;
124 myStream.precision(17);
129 result = Storage_VSAlreadyOpen;
134 //=======================================================================
137 //=======================================================================
139 Standard_Boolean FSD_CmpFile::IsEnd()
141 return myStream.eof();
144 //=======================================================================
147 //=======================================================================
149 Storage_Error FSD_CmpFile::Close()
151 Storage_Error result = Storage_VSOk;
153 if (OpenMode() != Storage_VSNone) {
155 SetOpenMode(Storage_VSNone);
158 result = Storage_VSNotOpen;
164 //=======================================================================
165 //function : MagicNumber
166 //purpose : ------------------ PROTECTED
167 //=======================================================================
169 const Standard_CString FSD_CmpFile::MagicNumber()
174 //=======================================================================
175 //function : FlushEndOfLine
177 //=======================================================================
179 void FSD_CmpFile::FlushEndOfLine()
181 TCollection_AsciiString aDummy;
182 ReadLine (aDummy); // flush is nothing more than to read till the line-break
184 static char Buffer[8192];
186 Standard_Boolean IsEnd = Standard_False;
188 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
190 myStream.get(Buffer,8192,'\n');
192 if (myStream.get(c) && c != '\r' && c != '\n') {
195 IsEnd = Standard_True;
201 //=======================================================================
202 //function : ReadLine
203 //purpose : read from the current position to the end of line.
204 //=======================================================================
206 void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer)
210 Standard_Boolean IsEnd = Standard_False;
214 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
216 //myStream.get(Buffer,8192,'\n');
217 myStream.getline(Buffer,8192,'\n');
218 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
222 // if (myStream.get(c) && c != '\r' && c != '\n') {
228 IsEnd = Standard_True;
233 //=======================================================================
234 //function : WriteExtendedLine
235 //purpose : write from the current position to the end of line.
236 //=======================================================================
238 void FSD_CmpFile::WriteExtendedLine(const TCollection_ExtendedString& buffer)
241 Standard_ExtString extBuffer;
242 Standard_Integer i,c,d;
244 extBuffer = buffer.ToExtString();
246 for (i = 0; i < buffer.Length(); i++) {
247 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
248 d = extBuffer[i] & 0x000000FF;
250 myStream << (char)c << (char)d;
253 myStream << (char)0 << "\n";
255 Standard_ExtString extBuffer;
258 extBuffer = buffer.ToExtString();
259 PutInteger(buffer.Length());
260 for (i = 0; i < buffer.Length(); i++) {
261 PutExtCharacter(extBuffer[i]);
267 //=======================================================================
268 //function : ReadExtendedLine
270 //=======================================================================
272 void FSD_CmpFile::ReadExtendedLine(TCollection_ExtendedString& buffer)
274 Standard_ExtCharacter c;
279 for (i = 0; i < buffer.Length(); i++) {
287 Standard_ExtCharacter i = 0,j,count = 0;
288 Standard_Boolean fin = Standard_False;
289 Standard_CString tg = ENDOFNORMALEXTENDEDSECTION;
293 while (!fin && !IsEnd()) {
296 if (c == tg[count]) count++;
298 if (count < SIZEOFNORMALEXTENDEDSECTION) {
300 i += (Standard_ExtCharacter)c;
301 if (c == '\0') fin = Standard_True;
305 if (c == tg[count]) count++;
307 if (count < SIZEOFNORMALEXTENDEDSECTION) {
309 j += (Standard_ExtCharacter)c;
310 if (c != '\n' && c != '\r') {
311 fin = Standard_False;
313 buffer += (Standard_ExtCharacter)i;
319 Storage_StreamExtCharParityError::Raise();
323 Storage_StreamExtCharParityError::Raise();
330 //=======================================================================
331 //function : ReadChar
332 //purpose : read <rsize> character from the current position.
333 //=======================================================================
335 void FSD_CmpFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsize)
338 Standard_Size ccount = 0;
342 while (!IsEnd() && (ccount < rsize)) {
349 //=======================================================================
350 //function : ReadString
351 //purpose : read from the first none space character position to the end of line.
352 //=======================================================================
354 void FSD_CmpFile::ReadString(TCollection_AsciiString& buffer)
358 Standard_Boolean IsEnd = Standard_False,isFirstTime = Standard_True;
362 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
364 //myStream.get(Buffer,8192,'\n');
365 myStream.getline(Buffer,8192,'\n');
366 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
374 isFirstTime = Standard_False;
375 while (*bpos == '\n' || *bpos == ' ') bpos++;
378 // if (myStream.get(c) && c != '\n') {
384 IsEnd = Standard_True;
389 //=======================================================================
390 //function : ReadWord
391 //purpose : read from the current position to the next white space or end of line.
392 //=======================================================================
394 void FSD_CmpFile::ReadWord(TCollection_AsciiString& buffer)
398 Standard_Boolean IsEnd = Standard_False;
405 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
407 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
410 IsEnd = Standard_False;
413 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
423 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
429 //=======================================================================
432 //=======================================================================
434 Storage_Error FSD_CmpFile::FindTag(const Standard_CString aTag)
436 TCollection_AsciiString l;
440 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
445 return Storage_VSSectionNotFound;
452 //=======================================================================
453 //function : SkipObject
455 //=======================================================================
457 void FSD_CmpFile::SkipObject()
462 //=======================================================================
463 //function : PutReference
464 //purpose : ---------------------- PUBLIC : PUT
465 //=======================================================================
467 Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
469 myStream << aValue << " ";
470 if (myStream.bad()) Storage_StreamWriteError::Raise();
474 //=======================================================================
475 //function : PutCharacter
477 //=======================================================================
479 Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
484 myStream << i << " ";
485 if (myStream.bad()) Storage_StreamWriteError::Raise();
489 //=======================================================================
490 //function : PutExtCharacter
492 //=======================================================================
494 Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue)
496 myStream << aValue << " ";
497 if (myStream.bad()) Storage_StreamWriteError::Raise();
501 //=======================================================================
502 //function : PutInteger
504 //=======================================================================
506 Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
508 myStream << aValue << " ";
509 if (myStream.bad()) Storage_StreamWriteError::Raise();
513 //=======================================================================
514 //function : PutBoolean
516 //=======================================================================
518 Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
520 myStream << ((Standard_Integer)aValue) << " ";
521 if (myStream.bad()) Storage_StreamWriteError::Raise();
525 //=======================================================================
528 //=======================================================================
530 Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
533 char realbuffer[100];
534 Standard_PCharacter pChar;
537 realbuffer[0] = '\0';
539 if (myRealConv.RealToCString(aValue,pChar)) {
540 myStream << realbuffer << " ";
543 Storage_StreamWriteError::Raise();
545 if (myStream.bad()) Storage_StreamWriteError::Raise();
550 myStream << ((Standard_Real)aValue) << " ";
552 if (myStream.bad()) Storage_StreamWriteError::Raise();
557 //=======================================================================
558 //function : PutShortReal
560 //=======================================================================
562 Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue)
565 char realbuffer[100];
566 Standard_PCharacter pStr;
569 realbuffer[0] = '\0';
571 if (myRealConv.RealToCString(aValue,pStr)) {
572 myStream << realbuffer << " ";
575 Storage_StreamWriteError::Raise();
577 if (myStream.bad()) Storage_StreamWriteError::Raise();
581 myStream << aValue << " ";
583 if (myStream.bad()) Storage_StreamWriteError::Raise();
588 //=======================================================================
589 //function : GetReference
590 //purpose : ----------------- PUBLIC : GET
591 //=======================================================================
593 Storage_BaseDriver& FSD_CmpFile::GetReference(Standard_Integer& aValue)
595 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
600 //=======================================================================
601 //function : GetCharacter
603 //=======================================================================
605 Storage_BaseDriver& FSD_CmpFile::GetCharacter(Standard_Character& aValue)
607 unsigned short i = 0;
608 if (!(myStream >> i)) {
609 // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
610 // signes (-80 fait ios::badbit, mais la variable i est initialisee)
612 if (i == 0) Storage_StreamTypeMismatchError::Raise();
613 myStream.clear(ios::goodbit);
620 //=======================================================================
621 //function : GetExtCharacter
623 //=======================================================================
625 Storage_BaseDriver& FSD_CmpFile::GetExtCharacter(Standard_ExtCharacter& aValue)
627 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
632 //=======================================================================
633 //function : GetInteger
635 //=======================================================================
637 Storage_BaseDriver& FSD_CmpFile::GetInteger(Standard_Integer& aValue)
639 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
644 //=======================================================================
645 //function : GetBoolean
647 //=======================================================================
649 Storage_BaseDriver& FSD_CmpFile::GetBoolean(Standard_Boolean& aValue)
651 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
656 //=======================================================================
659 //=======================================================================
661 Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
664 char realbuffer[100];
666 realbuffer[0] = '\0';
667 if (!(myStream >> realbuffer)) {
668 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
669 cerr << "\t buffer is" << realbuffer<< endl;
670 Storage_StreamTypeMismatchError::Raise();
672 if (!myRealConv.CStringToReal(realbuffer,aValue)) {
673 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
674 cerr << "\t buffer is" << realbuffer<< endl;
675 //if (!OSD::CStringToReal(realbuffer,aValue))
676 Storage_StreamTypeMismatchError::Raise();
681 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
687 //=======================================================================
688 //function : GetShortReal
690 //=======================================================================
692 Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
695 char realbuffer[100];
696 Standard_Real r = 0.0;
698 realbuffer[0] = '\0';
699 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
700 // if (!OSD::CStringToReal(realbuffer,r))
701 if (!myRealConv.CStringToReal(realbuffer,r)) Storage_StreamTypeMismatchError::Raise();
703 aValue = (Standard_ShortReal)r;
707 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
712 //=======================================================================
715 //=======================================================================
717 void FSD_CmpFile::Destroy()
719 if (OpenMode() != Storage_VSNone) {
724 //=======================================================================
725 //function : BeginWriteInfoSection
726 //purpose : -------------------------- INFO : WRITE
727 //=======================================================================
729 Storage_Error FSD_CmpFile::BeginWriteInfoSection()
731 myStream << FSD_CmpFile::MagicNumber() << '\n';
732 myStream << "BEGIN_INFO_SECTION\n";
733 if (myStream.bad()) Storage_StreamWriteError::Raise();
738 //=======================================================================
739 //function : WriteInfo
741 //=======================================================================
743 void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
744 const TCollection_AsciiString& dbVersion,
745 const TCollection_AsciiString& date,
746 const TCollection_AsciiString& schemaName,
747 const TCollection_AsciiString& schemaVersion,
748 const TCollection_ExtendedString& appName,
749 const TCollection_AsciiString& appVersion,
750 const TCollection_ExtendedString& dataType,
751 const TColStd_SequenceOfAsciiString& userInfo)
757 myStream << dbVersion.ToCString() << "\n";
758 myStream << date.ToCString() << "\n";
759 myStream << schemaName.ToCString() << "\n";
760 myStream << schemaVersion.ToCString() << "\n";
761 WriteExtendedLine(appName);
762 myStream << appVersion.ToCString() << "\n";
763 WriteExtendedLine(dataType);
764 myStream << userInfo.Length() << "\n";
766 if (myStream.bad()) Storage_StreamWriteError::Raise();
768 for (i = 1; i <= userInfo.Length(); i++) {
769 myStream << userInfo.Value(i).ToCString() << "\n";
770 if (myStream.bad()) Storage_StreamWriteError::Raise();
774 //=======================================================================
775 //function : EndWriteInfoSection
777 //=======================================================================
779 Storage_Error FSD_CmpFile::EndWriteInfoSection()
781 myStream << "END_INFO_SECTION\n";
782 if (myStream.bad()) Storage_StreamWriteError::Raise();
786 //=======================================================================
787 //function : BeginReadInfoSection
789 //=======================================================================
791 Storage_Error FSD_CmpFile::BeginReadInfoSection()
794 TCollection_AsciiString l;
795 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
799 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
800 s = Storage_VSFormatError;
803 s = FindTag("BEGIN_INFO_SECTION");
809 //=======================================================================
810 //function : ReadInfo
811 //purpose : ------------------- INFO : READ
812 //=======================================================================
814 void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
815 TCollection_AsciiString& dbVersion,
816 TCollection_AsciiString& date,
817 TCollection_AsciiString& schemaName,
818 TCollection_AsciiString& schemaVersion,
819 TCollection_ExtendedString& appName,
820 TCollection_AsciiString& appVersion,
821 TCollection_ExtendedString& dataType,
822 TColStd_SequenceOfAsciiString& userInfo)
824 if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
830 ReadLine(schemaName);
831 ReadLine(schemaVersion);
832 ReadExtendedLine(appName);
833 ReadLine(appVersion);
834 ReadExtendedLine(dataType);
836 Standard_Integer i,len = 0;
838 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
842 TCollection_AsciiString line;
844 for (i = 1; i <= len && !IsEnd(); i++) {
846 userInfo.Append(line);
851 //=======================================================================
852 //function : EndReadInfoSection
853 //purpose : COMMENTS SECTION
855 //=======================================================================
857 Storage_Error FSD_CmpFile::EndReadInfoSection()
859 return FindTag("END_INFO_SECTION");
862 //=======================================================================
863 //function : BeginWriteCommentSection
864 //purpose : ---------------- COMMENTS : WRITE
865 //=======================================================================
867 Storage_Error FSD_CmpFile::BeginWriteCommentSection()
869 myStream << "BEGIN_COMMENT_SECTION\n";
870 if (myStream.bad()) Storage_StreamWriteError::Raise();
874 //=======================================================================
875 //function : WriteComment
877 //=======================================================================
879 void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
881 Standard_Integer i,aSize;
883 aSize = aCom.Length();
884 myStream << aSize << "\n";
885 if (myStream.bad()) Storage_StreamWriteError::Raise();
887 for (i = 1; i <= aSize; i++) {
888 WriteExtendedLine(aCom.Value(i));
889 if (myStream.bad()) Storage_StreamWriteError::Raise();
893 //=======================================================================
894 //function : EndWriteCommentSection
896 //=======================================================================
898 Storage_Error FSD_CmpFile::EndWriteCommentSection()
900 myStream << "END_COMMENT_SECTION\n";
901 if (myStream.bad()) Storage_StreamWriteError::Raise();
905 //=======================================================================
906 //function : BeginReadCommentSection
907 //purpose : ---------------- COMMENTS : READ
908 //=======================================================================
910 Storage_Error FSD_CmpFile::BeginReadCommentSection()
912 return FindTag("BEGIN_COMMENT_SECTION");
915 //=======================================================================
916 //function : ReadComment
918 //=======================================================================
920 void FSD_CmpFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
922 TCollection_ExtendedString line;
923 Standard_Integer len,i;
925 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
929 for (i = 1; i <= len && !IsEnd(); i++) {
930 ReadExtendedLine(line);
936 //=======================================================================
937 //function : EndReadCommentSection
939 //=======================================================================
941 Storage_Error FSD_CmpFile::EndReadCommentSection()
943 return FindTag("END_COMMENT_SECTION");
946 //=======================================================================
947 //function : BeginWriteTypeSection
948 //purpose : --------------- TYPE : WRITE
949 //=======================================================================
951 Storage_Error FSD_CmpFile::BeginWriteTypeSection()
953 myStream << "BEGIN_TYPE_SECTION\n";
954 if (myStream.bad()) Storage_StreamWriteError::Raise();
958 //=======================================================================
959 //function : SetTypeSectionSize
961 //=======================================================================
963 void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
965 myStream << aSize << "\n";
966 if (myStream.bad()) Storage_StreamWriteError::Raise();
969 //=======================================================================
970 //function : WriteTypeInformations
972 //=======================================================================
974 void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
975 const TCollection_AsciiString& typeName)
977 myStream << typeNum << " " << typeName.ToCString() << "\n";
978 if (myStream.bad()) Storage_StreamWriteError::Raise();
981 //=======================================================================
982 //function : EndWriteTypeSection
984 //=======================================================================
986 Storage_Error FSD_CmpFile::EndWriteTypeSection()
988 myStream << "END_TYPE_SECTION\n";
989 if (myStream.bad()) Storage_StreamWriteError::Raise();
993 //=======================================================================
994 //function : BeginReadTypeSection
995 //purpose : ------------------- TYPE : READ
996 //=======================================================================
998 Storage_Error FSD_CmpFile::BeginReadTypeSection()
1000 return FindTag("BEGIN_TYPE_SECTION");
1003 //=======================================================================
1004 //function : TypeSectionSize
1006 //=======================================================================
1008 Standard_Integer FSD_CmpFile::TypeSectionSize()
1012 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1019 //=======================================================================
1020 //function : ReadTypeInformations
1022 //=======================================================================
1024 void FSD_CmpFile::ReadTypeInformations(Standard_Integer& typeNum,
1025 TCollection_AsciiString& typeName)
1027 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1028 if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
1032 //=======================================================================
1033 //function : EndReadTypeSection
1034 //purpose : ROOT SECTION
1036 //=======================================================================
1038 Storage_Error FSD_CmpFile::EndReadTypeSection()
1040 return FindTag("END_TYPE_SECTION");
1043 //=======================================================================
1044 //function : BeginWriteRootSection
1045 //purpose : -------------------- ROOT : WRITE
1046 //=======================================================================
1048 Storage_Error FSD_CmpFile::BeginWriteRootSection()
1050 myStream << "BEGIN_ROOT_SECTION\n";
1051 if (myStream.bad()) Storage_StreamWriteError::Raise();
1052 return Storage_VSOk;
1055 //=======================================================================
1056 //function : SetRootSectionSize
1058 //=======================================================================
1060 void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
1062 myStream << aSize << "\n";
1063 if (myStream.bad()) Storage_StreamWriteError::Raise();
1066 //=======================================================================
1067 //function : WriteRoot
1069 //=======================================================================
1071 void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
1073 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
1074 if (myStream.bad()) Storage_StreamWriteError::Raise();
1077 //=======================================================================
1078 //function : EndWriteRootSection
1080 //=======================================================================
1082 Storage_Error FSD_CmpFile::EndWriteRootSection()
1084 myStream << "END_ROOT_SECTION\n";
1085 if (myStream.bad()) Storage_StreamWriteError::Raise();
1086 return Storage_VSOk;
1089 //=======================================================================
1090 //function : BeginReadRootSection
1091 //purpose : ----------------------- ROOT : READ
1092 //=======================================================================
1094 Storage_Error FSD_CmpFile::BeginReadRootSection()
1096 return FindTag("BEGIN_ROOT_SECTION");
1099 //=======================================================================
1100 //function : RootSectionSize
1102 //=======================================================================
1104 Standard_Integer FSD_CmpFile::RootSectionSize()
1108 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1115 //=======================================================================
1116 //function : ReadRoot
1118 //=======================================================================
1120 void FSD_CmpFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1122 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1127 //=======================================================================
1128 //function : EndReadRootSection
1129 //purpose : REF SECTION
1131 //=======================================================================
1133 Storage_Error FSD_CmpFile::EndReadRootSection()
1135 return FindTag("END_ROOT_SECTION");
1138 //=======================================================================
1139 //function : BeginWriteRefSection
1140 //purpose : -------------------------- REF : WRITE
1141 //=======================================================================
1143 Storage_Error FSD_CmpFile::BeginWriteRefSection()
1145 myStream << "BEGIN_REF_SECTION\n";
1146 if (myStream.bad()) Storage_StreamWriteError::Raise();
1147 return Storage_VSOk;
1150 //=======================================================================
1151 //function : SetRefSectionSize
1153 //=======================================================================
1155 void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
1157 myStream << aSize << "\n";
1158 if (myStream.bad()) Storage_StreamWriteError::Raise();
1161 //=======================================================================
1162 //function : WriteReferenceType
1164 //=======================================================================
1166 void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
1167 const Standard_Integer typeNum)
1169 myStream << reference << " " << typeNum << "\n";
1170 if (myStream.bad()) Storage_StreamWriteError::Raise();
1173 //=======================================================================
1174 //function : EndWriteRefSection
1176 //=======================================================================
1178 Storage_Error FSD_CmpFile::EndWriteRefSection()
1180 myStream << "END_REF_SECTION\n";
1181 if (myStream.bad()) Storage_StreamWriteError::Raise();
1182 return Storage_VSOk;
1185 //=======================================================================
1186 //function : BeginReadRefSection
1187 //purpose : ----------------------- REF : READ
1188 //=======================================================================
1190 Storage_Error FSD_CmpFile::BeginReadRefSection()
1192 return FindTag("BEGIN_REF_SECTION");
1195 //=======================================================================
1196 //function : RefSectionSize
1198 //=======================================================================
1200 Standard_Integer FSD_CmpFile::RefSectionSize()
1204 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1210 //=======================================================================
1211 //function : ReadReferenceType
1213 //=======================================================================
1215 void FSD_CmpFile::ReadReferenceType(Standard_Integer& reference,
1216 Standard_Integer& typeNum)
1218 if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
1219 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1223 //=======================================================================
1224 //function : EndReadRefSection
1225 //purpose : DATA SECTION
1227 //=======================================================================
1229 Storage_Error FSD_CmpFile::EndReadRefSection()
1231 return FindTag("END_REF_SECTION");
1234 //=======================================================================
1235 //function : BeginWriteDataSection
1236 //purpose : -------------------- DATA : WRITE
1237 //=======================================================================
1239 Storage_Error FSD_CmpFile::BeginWriteDataSection()
1241 myStream << "BEGIN_DATA_SECTION";
1242 if (myStream.bad()) Storage_StreamWriteError::Raise();
1243 return Storage_VSOk;
1246 //=======================================================================
1247 //function : WritePersistentObjectHeader
1249 //=======================================================================
1251 void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
1252 const Standard_Integer aType)
1254 myStream << "\n#" << aRef << "%" << aType << " ";
1255 if (myStream.bad()) Storage_StreamWriteError::Raise();
1258 //=======================================================================
1259 //function : BeginWritePersistentObjectData
1261 //=======================================================================
1263 void FSD_CmpFile::BeginWritePersistentObjectData()
1265 if (myStream.bad()) Storage_StreamWriteError::Raise();
1268 //=======================================================================
1269 //function : BeginWriteObjectData
1271 //=======================================================================
1273 void FSD_CmpFile::BeginWriteObjectData()
1275 if (myStream.bad()) Storage_StreamWriteError::Raise();
1278 //=======================================================================
1279 //function : EndWriteObjectData
1281 //=======================================================================
1283 void FSD_CmpFile::EndWriteObjectData()
1285 if (myStream.bad()) Storage_StreamWriteError::Raise();
1288 //=======================================================================
1289 //function : EndWritePersistentObjectData
1291 //=======================================================================
1293 void FSD_CmpFile::EndWritePersistentObjectData()
1295 if (myStream.bad()) Storage_StreamWriteError::Raise();
1298 //=======================================================================
1299 //function : EndWriteDataSection
1301 //=======================================================================
1303 Storage_Error FSD_CmpFile::EndWriteDataSection()
1305 myStream << "\nEND_DATA_SECTION\n";
1306 if (myStream.bad()) Storage_StreamWriteError::Raise();
1307 return Storage_VSOk;
1310 //=======================================================================
1311 //function : BeginReadDataSection
1312 //purpose : ---------------------- DATA : READ
1313 //=======================================================================
1315 Storage_Error FSD_CmpFile::BeginReadDataSection()
1317 return FindTag("BEGIN_DATA_SECTION");
1320 //=======================================================================
1321 //function : ReadPersistentObjectHeader
1323 //=======================================================================
1325 void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
1326 Standard_Integer& aType)
1333 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1334 Storage_StreamFormatError::Raise();
1339 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1344 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1345 Storage_StreamFormatError::Raise();
1350 if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
1351 // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
1354 //=======================================================================
1355 //function : BeginReadPersistentObjectData
1357 //=======================================================================
1359 void FSD_CmpFile::BeginReadPersistentObjectData()
1361 //cout << "BeginReadPersistentObjectData" << endl;
1364 //=======================================================================
1365 //function : BeginReadObjectData
1367 //=======================================================================
1369 void FSD_CmpFile::BeginReadObjectData()
1371 // cout << "BeginReadObjectData" << endl;
1374 //=======================================================================
1375 //function : EndReadObjectData
1377 //=======================================================================
1379 void FSD_CmpFile::EndReadObjectData()
1381 // cout << "EndReadObjectData" << endl;
1384 //=======================================================================
1385 //function : EndReadPersistentObjectData
1387 //=======================================================================
1389 void FSD_CmpFile::EndReadPersistentObjectData()
1394 while (c != '\n' && (c != '\r')) {
1395 if (IsEnd() || (c != ' ')) {
1396 Storage_StreamFormatError::Raise();
1403 // cout << "EndReadPersistentObjectData" << endl;
1406 //=======================================================================
1407 //function : EndReadDataSection
1409 //=======================================================================
1411 Storage_Error FSD_CmpFile::EndReadDataSection()
1413 return FindTag("END_DATA_SECTION");
1416 //=======================================================================
1418 //purpose : return position in the file. Return -1 upon error.
1419 //=======================================================================
1421 Storage_Position FSD_CmpFile::Tell()
1423 switch (OpenMode()) {
1424 case Storage_VSRead:
1425 return (Storage_Position) myStream.tellp();
1426 case Storage_VSWrite:
1427 return (Storage_Position) myStream.tellg();
1428 case Storage_VSReadWrite: {
1429 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1430 Storage_Position aPosW = (Storage_Position) myStream.tellg();