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 <Storage_StreamModeError.hxx>
23 #include <Storage_StreamUnknownTypeError.hxx>
24 #include <Standard_PCharacter.hxx>
26 // Propagate the improvement (BUC60808) on all platforms
29 // BUC60808 : standard output in MS Visual C++ limites the quantity of figures (digits)
30 // in part of number after fixed point. The quantity of figures after fixed point
31 // could not be more than 15 when we output double number using standard MS VS output operator '<<'.
32 // For example, the maximum double value DBL_MAX = 1.7976931348623157e+308 (see float.h) after
33 // cout<<setprecision(17)<<DBL_MAX becomes 1.79769313486232e+308 in stream of output
34 // (it could be a file stream). When the number 1.79769313486232e+308 is read from the
35 // i/o streame (file, for example) it occurs more than allowed maximum value of double
36 // type - 1.7976931348623157e+308. Such value is considered as infinite. When it is written
37 // to file (for example) again it is written as 1.#INF. Such value can't be read from file next time.
40 const Standard_CString MAGICNUMBER = "CMPFILE";
41 const Standard_CString ENDOFNORMALEXTENDEDSECTION = "BEGIN_REF_SECTION";
42 const Standard_Integer SIZEOFNORMALEXTENDEDSECTION = 16;
44 //=======================================================================
45 //function : FSD_CmpFile
47 //=======================================================================
49 FSD_CmpFile::FSD_CmpFile()
54 //=======================================================================
55 //function : IsGoodFileType
56 //purpose : INFO SECTION
58 //=======================================================================
60 Storage_Error FSD_CmpFile::IsGoodFileType(const TCollection_AsciiString& aName)
65 s = f.Open(aName,Storage_VSRead);
67 if (s == Storage_VSOk) {
68 TCollection_AsciiString l;
69 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
75 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
76 s = Storage_VSFormatError;
83 //=======================================================================
86 //=======================================================================
88 Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
90 Storage_Error result = Storage_VSOk;
94 if (OpenMode() == Storage_VSNone) {
96 #if !defined(IRIX) && !defined(DECOSF1)
97 if (aMode == Storage_VSRead) {
98 myStream.open(aName.ToCString(),ios::in|ios::binary); // ios::nocreate is not portable
100 else if (aMode == Storage_VSWrite) {
101 myStream.open(aName.ToCString(),ios::out|ios::binary);
103 else if (aMode == Storage_VSReadWrite) {
104 myStream.open(aName.ToCString(),ios::in|ios::out|ios::binary);
107 if (aMode == Storage_VSRead) {
108 myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
110 else if (aMode == Storage_VSWrite) {
111 myStream.open(aName.ToCString(),ios::out);
113 else if (aMode == Storage_VSReadWrite) {
114 myStream.open(aName.ToCString(),ios::in|ios::out);
118 if (myStream.fail()) {
119 result = Storage_VSOpenError;
122 myStream.precision(17);
123 myStream.imbue (std::locale::classic()); // use always C locale
128 result = Storage_VSAlreadyOpen;
133 //=======================================================================
136 //=======================================================================
138 Standard_Boolean FSD_CmpFile::IsEnd()
140 return myStream.eof();
143 //=======================================================================
146 //=======================================================================
148 Storage_Error FSD_CmpFile::Close()
150 Storage_Error result = Storage_VSOk;
152 if (OpenMode() != Storage_VSNone) {
154 SetOpenMode(Storage_VSNone);
157 result = Storage_VSNotOpen;
163 //=======================================================================
164 //function : MagicNumber
165 //purpose : ------------------ PROTECTED
166 //=======================================================================
168 const Standard_CString FSD_CmpFile::MagicNumber()
173 //=======================================================================
174 //function : FlushEndOfLine
176 //=======================================================================
178 void FSD_CmpFile::FlushEndOfLine()
180 TCollection_AsciiString aDummy;
181 ReadLine (aDummy); // flush is nothing more than to read till the line-break
183 static char Buffer[8192];
185 Standard_Boolean IsEnd = Standard_False;
187 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
189 myStream.get(Buffer,8192,'\n');
191 if (myStream.get(c) && c != '\r' && c != '\n') {
194 IsEnd = Standard_True;
200 //=======================================================================
201 //function : ReadLine
202 //purpose : read from the current position to the end of line.
203 //=======================================================================
205 void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer)
209 Standard_Boolean IsEnd = Standard_False;
213 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
215 //myStream.get(Buffer,8192,'\n');
216 myStream.getline(Buffer,8192,'\n');
217 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
221 // if (myStream.get(c) && c != '\r' && c != '\n') {
227 IsEnd = Standard_True;
232 //=======================================================================
233 //function : WriteExtendedLine
234 //purpose : write from the current position to the end of line.
235 //=======================================================================
237 void FSD_CmpFile::WriteExtendedLine(const TCollection_ExtendedString& buffer)
240 Standard_ExtString extBuffer;
241 Standard_Integer i,c,d;
243 extBuffer = buffer.ToExtString();
245 for (i = 0; i < buffer.Length(); i++) {
246 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
247 d = extBuffer[i] & 0x000000FF;
249 myStream << (char)c << (char)d;
252 myStream << (char)0 << "\n";
254 Standard_ExtString extBuffer;
257 extBuffer = buffer.ToExtString();
258 PutInteger(buffer.Length());
259 for (i = 0; i < buffer.Length(); i++) {
260 PutExtCharacter(extBuffer[i]);
266 //=======================================================================
267 //function : ReadExtendedLine
269 //=======================================================================
271 void FSD_CmpFile::ReadExtendedLine(TCollection_ExtendedString& buffer)
273 Standard_ExtCharacter c;
278 for (i = 0; i < buffer.Length(); i++) {
286 Standard_ExtCharacter i = 0,j,count = 0;
287 Standard_Boolean fin = Standard_False;
288 Standard_CString tg = ENDOFNORMALEXTENDEDSECTION;
292 while (!fin && !IsEnd()) {
295 if (c == tg[count]) count++;
297 if (count < SIZEOFNORMALEXTENDEDSECTION) {
299 i += (Standard_ExtCharacter)c;
300 if (c == '\0') fin = Standard_True;
304 if (c == tg[count]) count++;
306 if (count < SIZEOFNORMALEXTENDEDSECTION) {
308 j += (Standard_ExtCharacter)c;
309 if (c != '\n' && c != '\r') {
310 fin = Standard_False;
312 buffer += (Standard_ExtCharacter)i;
318 Storage_StreamExtCharParityError::Raise();
322 Storage_StreamExtCharParityError::Raise();
329 //=======================================================================
330 //function : ReadChar
331 //purpose : read <rsize> character from the current position.
332 //=======================================================================
334 void FSD_CmpFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsize)
337 Standard_Size ccount = 0;
341 while (!IsEnd() && (ccount < rsize)) {
348 //=======================================================================
349 //function : ReadString
350 //purpose : read from the first none space character position to the end of line.
351 //=======================================================================
353 void FSD_CmpFile::ReadString(TCollection_AsciiString& buffer)
357 Standard_Boolean IsEnd = Standard_False,isFirstTime = Standard_True;
361 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
363 //myStream.get(Buffer,8192,'\n');
364 myStream.getline(Buffer,8192,'\n');
365 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
373 isFirstTime = Standard_False;
374 while (*bpos == '\n' || *bpos == ' ') bpos++;
377 // if (myStream.get(c) && c != '\n') {
383 IsEnd = Standard_True;
388 //=======================================================================
389 //function : ReadWord
390 //purpose : read from the current position to the next white space or end of line.
391 //=======================================================================
393 void FSD_CmpFile::ReadWord(TCollection_AsciiString& buffer)
397 Standard_Boolean IsEnd = Standard_False;
404 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
406 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
409 IsEnd = Standard_False;
412 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
422 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
428 //=======================================================================
431 //=======================================================================
433 Storage_Error FSD_CmpFile::FindTag(const Standard_CString aTag)
435 TCollection_AsciiString l;
439 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
444 return Storage_VSSectionNotFound;
451 //=======================================================================
452 //function : SkipObject
454 //=======================================================================
456 void FSD_CmpFile::SkipObject()
461 //=======================================================================
462 //function : PutReference
463 //purpose : ---------------------- PUBLIC : PUT
464 //=======================================================================
466 Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
468 myStream << aValue << " ";
469 if (myStream.bad()) Storage_StreamWriteError::Raise();
473 //=======================================================================
474 //function : PutCharacter
476 //=======================================================================
478 Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
483 myStream << i << " ";
484 if (myStream.bad()) Storage_StreamWriteError::Raise();
488 //=======================================================================
489 //function : PutExtCharacter
491 //=======================================================================
493 Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue)
495 myStream << aValue << " ";
496 if (myStream.bad()) Storage_StreamWriteError::Raise();
500 //=======================================================================
501 //function : PutInteger
503 //=======================================================================
505 Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
507 myStream << aValue << " ";
508 if (myStream.bad()) Storage_StreamWriteError::Raise();
512 //=======================================================================
513 //function : PutBoolean
515 //=======================================================================
517 Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
519 myStream << ((Standard_Integer)aValue) << " ";
520 if (myStream.bad()) Storage_StreamWriteError::Raise();
524 //=======================================================================
527 //=======================================================================
529 Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
531 myStream << ((Standard_Real)aValue) << " ";
532 if (myStream.bad()) Storage_StreamWriteError::Raise();
536 //=======================================================================
537 //function : PutShortReal
539 //=======================================================================
541 Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue)
543 myStream << aValue << " ";
544 if (myStream.bad()) Storage_StreamWriteError::Raise();
548 //=======================================================================
549 //function : GetReference
550 //purpose : ----------------- PUBLIC : GET
551 //=======================================================================
553 Storage_BaseDriver& FSD_CmpFile::GetReference(Standard_Integer& aValue)
555 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
560 //=======================================================================
561 //function : GetCharacter
563 //=======================================================================
565 Storage_BaseDriver& FSD_CmpFile::GetCharacter(Standard_Character& aValue)
567 unsigned short i = 0;
568 if (!(myStream >> i)) {
569 // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
570 // signes (-80 fait ios::badbit, mais la variable i est initialisee)
572 if (i == 0) Storage_StreamTypeMismatchError::Raise();
573 myStream.clear(ios::goodbit);
580 //=======================================================================
581 //function : GetExtCharacter
583 //=======================================================================
585 Storage_BaseDriver& FSD_CmpFile::GetExtCharacter(Standard_ExtCharacter& aValue)
587 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
592 //=======================================================================
593 //function : GetInteger
595 //=======================================================================
597 Storage_BaseDriver& FSD_CmpFile::GetInteger(Standard_Integer& aValue)
599 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
604 //=======================================================================
605 //function : GetBoolean
607 //=======================================================================
609 Storage_BaseDriver& FSD_CmpFile::GetBoolean(Standard_Boolean& aValue)
611 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
616 //=======================================================================
619 //=======================================================================
621 Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
624 char realbuffer[100];
626 realbuffer[0] = '\0';
627 if (!(myStream >> realbuffer)) {
628 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
629 cerr << "\t buffer is" << realbuffer<< endl;
630 Storage_StreamTypeMismatchError::Raise();
632 if (!OSD::CStringToReal(realbuffer,aValue)) {
633 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
634 cerr << "\t buffer is" << realbuffer<< endl;
635 Storage_StreamTypeMismatchError::Raise();
640 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
646 //=======================================================================
647 //function : GetShortReal
649 //=======================================================================
651 Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
654 char realbuffer[100];
655 Standard_Real r = 0.0;
657 realbuffer[0] = '\0';
658 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
659 if (!OSD::CStringToReal(realbuffer,r))
660 Storage_StreamTypeMismatchError::Raise();
662 aValue = (Standard_ShortReal)r;
666 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
671 //=======================================================================
674 //=======================================================================
676 void FSD_CmpFile::Destroy()
678 if (OpenMode() != Storage_VSNone) {
683 //=======================================================================
684 //function : BeginWriteInfoSection
685 //purpose : -------------------------- INFO : WRITE
686 //=======================================================================
688 Storage_Error FSD_CmpFile::BeginWriteInfoSection()
690 myStream << FSD_CmpFile::MagicNumber() << '\n';
691 myStream << "BEGIN_INFO_SECTION\n";
692 if (myStream.bad()) Storage_StreamWriteError::Raise();
697 //=======================================================================
698 //function : WriteInfo
700 //=======================================================================
702 void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
703 const TCollection_AsciiString& dbVersion,
704 const TCollection_AsciiString& date,
705 const TCollection_AsciiString& schemaName,
706 const TCollection_AsciiString& schemaVersion,
707 const TCollection_ExtendedString& appName,
708 const TCollection_AsciiString& appVersion,
709 const TCollection_ExtendedString& dataType,
710 const TColStd_SequenceOfAsciiString& userInfo)
716 myStream << dbVersion.ToCString() << "\n";
717 myStream << date.ToCString() << "\n";
718 myStream << schemaName.ToCString() << "\n";
719 myStream << schemaVersion.ToCString() << "\n";
720 WriteExtendedLine(appName);
721 myStream << appVersion.ToCString() << "\n";
722 WriteExtendedLine(dataType);
723 myStream << userInfo.Length() << "\n";
725 if (myStream.bad()) Storage_StreamWriteError::Raise();
727 for (i = 1; i <= userInfo.Length(); i++) {
728 myStream << userInfo.Value(i).ToCString() << "\n";
729 if (myStream.bad()) Storage_StreamWriteError::Raise();
733 //=======================================================================
734 //function : EndWriteInfoSection
736 //=======================================================================
738 Storage_Error FSD_CmpFile::EndWriteInfoSection()
740 myStream << "END_INFO_SECTION\n";
741 if (myStream.bad()) Storage_StreamWriteError::Raise();
745 //=======================================================================
746 //function : BeginReadInfoSection
748 //=======================================================================
750 Storage_Error FSD_CmpFile::BeginReadInfoSection()
753 TCollection_AsciiString l;
754 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
758 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
759 s = Storage_VSFormatError;
762 s = FindTag("BEGIN_INFO_SECTION");
768 //=======================================================================
769 //function : ReadInfo
770 //purpose : ------------------- INFO : READ
771 //=======================================================================
773 void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
774 TCollection_AsciiString& dbVersion,
775 TCollection_AsciiString& date,
776 TCollection_AsciiString& schemaName,
777 TCollection_AsciiString& schemaVersion,
778 TCollection_ExtendedString& appName,
779 TCollection_AsciiString& appVersion,
780 TCollection_ExtendedString& dataType,
781 TColStd_SequenceOfAsciiString& userInfo)
783 if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
789 ReadLine(schemaName);
790 ReadLine(schemaVersion);
791 ReadExtendedLine(appName);
792 ReadLine(appVersion);
793 ReadExtendedLine(dataType);
795 Standard_Integer i,len = 0;
797 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
801 TCollection_AsciiString line;
803 for (i = 1; i <= len && !IsEnd(); i++) {
805 userInfo.Append(line);
810 //=======================================================================
811 //function : EndReadInfoSection
812 //purpose : COMMENTS SECTION
814 //=======================================================================
816 Storage_Error FSD_CmpFile::EndReadInfoSection()
818 return FindTag("END_INFO_SECTION");
821 //=======================================================================
822 //function : BeginWriteCommentSection
823 //purpose : ---------------- COMMENTS : WRITE
824 //=======================================================================
826 Storage_Error FSD_CmpFile::BeginWriteCommentSection()
828 myStream << "BEGIN_COMMENT_SECTION\n";
829 if (myStream.bad()) Storage_StreamWriteError::Raise();
833 //=======================================================================
834 //function : WriteComment
836 //=======================================================================
838 void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
840 Standard_Integer i,aSize;
842 aSize = aCom.Length();
843 myStream << aSize << "\n";
844 if (myStream.bad()) Storage_StreamWriteError::Raise();
846 for (i = 1; i <= aSize; i++) {
847 WriteExtendedLine(aCom.Value(i));
848 if (myStream.bad()) Storage_StreamWriteError::Raise();
852 //=======================================================================
853 //function : EndWriteCommentSection
855 //=======================================================================
857 Storage_Error FSD_CmpFile::EndWriteCommentSection()
859 myStream << "END_COMMENT_SECTION\n";
860 if (myStream.bad()) Storage_StreamWriteError::Raise();
864 //=======================================================================
865 //function : BeginReadCommentSection
866 //purpose : ---------------- COMMENTS : READ
867 //=======================================================================
869 Storage_Error FSD_CmpFile::BeginReadCommentSection()
871 return FindTag("BEGIN_COMMENT_SECTION");
874 //=======================================================================
875 //function : ReadComment
877 //=======================================================================
879 void FSD_CmpFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
881 TCollection_ExtendedString line;
882 Standard_Integer len,i;
884 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
888 for (i = 1; i <= len && !IsEnd(); i++) {
889 ReadExtendedLine(line);
895 //=======================================================================
896 //function : EndReadCommentSection
898 //=======================================================================
900 Storage_Error FSD_CmpFile::EndReadCommentSection()
902 return FindTag("END_COMMENT_SECTION");
905 //=======================================================================
906 //function : BeginWriteTypeSection
907 //purpose : --------------- TYPE : WRITE
908 //=======================================================================
910 Storage_Error FSD_CmpFile::BeginWriteTypeSection()
912 myStream << "BEGIN_TYPE_SECTION\n";
913 if (myStream.bad()) Storage_StreamWriteError::Raise();
917 //=======================================================================
918 //function : SetTypeSectionSize
920 //=======================================================================
922 void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
924 myStream << aSize << "\n";
925 if (myStream.bad()) Storage_StreamWriteError::Raise();
928 //=======================================================================
929 //function : WriteTypeInformations
931 //=======================================================================
933 void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
934 const TCollection_AsciiString& typeName)
936 myStream << typeNum << " " << typeName.ToCString() << "\n";
937 if (myStream.bad()) Storage_StreamWriteError::Raise();
940 //=======================================================================
941 //function : EndWriteTypeSection
943 //=======================================================================
945 Storage_Error FSD_CmpFile::EndWriteTypeSection()
947 myStream << "END_TYPE_SECTION\n";
948 if (myStream.bad()) Storage_StreamWriteError::Raise();
952 //=======================================================================
953 //function : BeginReadTypeSection
954 //purpose : ------------------- TYPE : READ
955 //=======================================================================
957 Storage_Error FSD_CmpFile::BeginReadTypeSection()
959 return FindTag("BEGIN_TYPE_SECTION");
962 //=======================================================================
963 //function : TypeSectionSize
965 //=======================================================================
967 Standard_Integer FSD_CmpFile::TypeSectionSize()
971 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
978 //=======================================================================
979 //function : ReadTypeInformations
981 //=======================================================================
983 void FSD_CmpFile::ReadTypeInformations(Standard_Integer& typeNum,
984 TCollection_AsciiString& typeName)
986 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
987 if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
991 //=======================================================================
992 //function : EndReadTypeSection
993 //purpose : ROOT SECTION
995 //=======================================================================
997 Storage_Error FSD_CmpFile::EndReadTypeSection()
999 return FindTag("END_TYPE_SECTION");
1002 //=======================================================================
1003 //function : BeginWriteRootSection
1004 //purpose : -------------------- ROOT : WRITE
1005 //=======================================================================
1007 Storage_Error FSD_CmpFile::BeginWriteRootSection()
1009 myStream << "BEGIN_ROOT_SECTION\n";
1010 if (myStream.bad()) Storage_StreamWriteError::Raise();
1011 return Storage_VSOk;
1014 //=======================================================================
1015 //function : SetRootSectionSize
1017 //=======================================================================
1019 void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
1021 myStream << aSize << "\n";
1022 if (myStream.bad()) Storage_StreamWriteError::Raise();
1025 //=======================================================================
1026 //function : WriteRoot
1028 //=======================================================================
1030 void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
1032 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
1033 if (myStream.bad()) Storage_StreamWriteError::Raise();
1036 //=======================================================================
1037 //function : EndWriteRootSection
1039 //=======================================================================
1041 Storage_Error FSD_CmpFile::EndWriteRootSection()
1043 myStream << "END_ROOT_SECTION\n";
1044 if (myStream.bad()) Storage_StreamWriteError::Raise();
1045 return Storage_VSOk;
1048 //=======================================================================
1049 //function : BeginReadRootSection
1050 //purpose : ----------------------- ROOT : READ
1051 //=======================================================================
1053 Storage_Error FSD_CmpFile::BeginReadRootSection()
1055 return FindTag("BEGIN_ROOT_SECTION");
1058 //=======================================================================
1059 //function : RootSectionSize
1061 //=======================================================================
1063 Standard_Integer FSD_CmpFile::RootSectionSize()
1067 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1074 //=======================================================================
1075 //function : ReadRoot
1077 //=======================================================================
1079 void FSD_CmpFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1081 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1086 //=======================================================================
1087 //function : EndReadRootSection
1088 //purpose : REF SECTION
1090 //=======================================================================
1092 Storage_Error FSD_CmpFile::EndReadRootSection()
1094 return FindTag("END_ROOT_SECTION");
1097 //=======================================================================
1098 //function : BeginWriteRefSection
1099 //purpose : -------------------------- REF : WRITE
1100 //=======================================================================
1102 Storage_Error FSD_CmpFile::BeginWriteRefSection()
1104 myStream << "BEGIN_REF_SECTION\n";
1105 if (myStream.bad()) Storage_StreamWriteError::Raise();
1106 return Storage_VSOk;
1109 //=======================================================================
1110 //function : SetRefSectionSize
1112 //=======================================================================
1114 void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
1116 myStream << aSize << "\n";
1117 if (myStream.bad()) Storage_StreamWriteError::Raise();
1120 //=======================================================================
1121 //function : WriteReferenceType
1123 //=======================================================================
1125 void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
1126 const Standard_Integer typeNum)
1128 myStream << reference << " " << typeNum << "\n";
1129 if (myStream.bad()) Storage_StreamWriteError::Raise();
1132 //=======================================================================
1133 //function : EndWriteRefSection
1135 //=======================================================================
1137 Storage_Error FSD_CmpFile::EndWriteRefSection()
1139 myStream << "END_REF_SECTION\n";
1140 if (myStream.bad()) Storage_StreamWriteError::Raise();
1141 return Storage_VSOk;
1144 //=======================================================================
1145 //function : BeginReadRefSection
1146 //purpose : ----------------------- REF : READ
1147 //=======================================================================
1149 Storage_Error FSD_CmpFile::BeginReadRefSection()
1151 return FindTag("BEGIN_REF_SECTION");
1154 //=======================================================================
1155 //function : RefSectionSize
1157 //=======================================================================
1159 Standard_Integer FSD_CmpFile::RefSectionSize()
1163 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1169 //=======================================================================
1170 //function : ReadReferenceType
1172 //=======================================================================
1174 void FSD_CmpFile::ReadReferenceType(Standard_Integer& reference,
1175 Standard_Integer& typeNum)
1177 if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
1178 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1182 //=======================================================================
1183 //function : EndReadRefSection
1184 //purpose : DATA SECTION
1186 //=======================================================================
1188 Storage_Error FSD_CmpFile::EndReadRefSection()
1190 return FindTag("END_REF_SECTION");
1193 //=======================================================================
1194 //function : BeginWriteDataSection
1195 //purpose : -------------------- DATA : WRITE
1196 //=======================================================================
1198 Storage_Error FSD_CmpFile::BeginWriteDataSection()
1200 myStream << "BEGIN_DATA_SECTION";
1201 if (myStream.bad()) Storage_StreamWriteError::Raise();
1202 return Storage_VSOk;
1205 //=======================================================================
1206 //function : WritePersistentObjectHeader
1208 //=======================================================================
1210 void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
1211 const Standard_Integer aType)
1213 myStream << "\n#" << aRef << "%" << aType << " ";
1214 if (myStream.bad()) Storage_StreamWriteError::Raise();
1217 //=======================================================================
1218 //function : BeginWritePersistentObjectData
1220 //=======================================================================
1222 void FSD_CmpFile::BeginWritePersistentObjectData()
1224 if (myStream.bad()) Storage_StreamWriteError::Raise();
1227 //=======================================================================
1228 //function : BeginWriteObjectData
1230 //=======================================================================
1232 void FSD_CmpFile::BeginWriteObjectData()
1234 if (myStream.bad()) Storage_StreamWriteError::Raise();
1237 //=======================================================================
1238 //function : EndWriteObjectData
1240 //=======================================================================
1242 void FSD_CmpFile::EndWriteObjectData()
1244 if (myStream.bad()) Storage_StreamWriteError::Raise();
1247 //=======================================================================
1248 //function : EndWritePersistentObjectData
1250 //=======================================================================
1252 void FSD_CmpFile::EndWritePersistentObjectData()
1254 if (myStream.bad()) Storage_StreamWriteError::Raise();
1257 //=======================================================================
1258 //function : EndWriteDataSection
1260 //=======================================================================
1262 Storage_Error FSD_CmpFile::EndWriteDataSection()
1264 myStream << "\nEND_DATA_SECTION\n";
1265 if (myStream.bad()) Storage_StreamWriteError::Raise();
1266 return Storage_VSOk;
1269 //=======================================================================
1270 //function : BeginReadDataSection
1271 //purpose : ---------------------- DATA : READ
1272 //=======================================================================
1274 Storage_Error FSD_CmpFile::BeginReadDataSection()
1276 return FindTag("BEGIN_DATA_SECTION");
1279 //=======================================================================
1280 //function : ReadPersistentObjectHeader
1282 //=======================================================================
1284 void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
1285 Standard_Integer& aType)
1292 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1293 Storage_StreamFormatError::Raise();
1298 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1303 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1304 Storage_StreamFormatError::Raise();
1309 if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
1310 // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
1313 //=======================================================================
1314 //function : BeginReadPersistentObjectData
1316 //=======================================================================
1318 void FSD_CmpFile::BeginReadPersistentObjectData()
1320 //cout << "BeginReadPersistentObjectData" << endl;
1323 //=======================================================================
1324 //function : BeginReadObjectData
1326 //=======================================================================
1328 void FSD_CmpFile::BeginReadObjectData()
1330 // cout << "BeginReadObjectData" << endl;
1333 //=======================================================================
1334 //function : EndReadObjectData
1336 //=======================================================================
1338 void FSD_CmpFile::EndReadObjectData()
1340 // cout << "EndReadObjectData" << endl;
1343 //=======================================================================
1344 //function : EndReadPersistentObjectData
1346 //=======================================================================
1348 void FSD_CmpFile::EndReadPersistentObjectData()
1353 while (c != '\n' && (c != '\r')) {
1354 if (IsEnd() || (c != ' ')) {
1355 Storage_StreamFormatError::Raise();
1362 // cout << "EndReadPersistentObjectData" << endl;
1365 //=======================================================================
1366 //function : EndReadDataSection
1368 //=======================================================================
1370 Storage_Error FSD_CmpFile::EndReadDataSection()
1372 return FindTag("END_DATA_SECTION");
1375 //=======================================================================
1377 //purpose : return position in the file. Return -1 upon error.
1378 //=======================================================================
1380 Storage_Position FSD_CmpFile::Tell()
1382 switch (OpenMode()) {
1383 case Storage_VSRead:
1384 return (Storage_Position) myStream.tellp();
1385 case Storage_VSWrite:
1386 return (Storage_Position) myStream.tellg();
1387 case Storage_VSReadWrite: {
1388 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1389 Storage_Position aPosW = (Storage_Position) myStream.tellg();