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";
42 //=======================================================================
43 //function : FSD_CmpFile
45 //=======================================================================
47 FSD_CmpFile::FSD_CmpFile()
52 //=======================================================================
53 //function : IsGoodFileType
54 //purpose : INFO SECTION
56 //=======================================================================
58 Storage_Error FSD_CmpFile::IsGoodFileType(const TCollection_AsciiString& aName)
63 s = f.Open(aName,Storage_VSRead);
65 if (s == Storage_VSOk) {
66 TCollection_AsciiString l;
67 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
73 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
74 s = Storage_VSFormatError;
81 //=======================================================================
84 //=======================================================================
86 Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
88 Storage_Error result = Storage_VSOk;
92 if (OpenMode() == Storage_VSNone) {
94 #if !defined(IRIX) && !defined(DECOSF1)
95 if (aMode == Storage_VSRead) {
96 myStream.open(aName.ToCString(),ios::in|ios::binary); // ios::nocreate is not portable
98 else if (aMode == Storage_VSWrite) {
99 myStream.open(aName.ToCString(),ios::out|ios::binary);
101 else if (aMode == Storage_VSReadWrite) {
102 myStream.open(aName.ToCString(),ios::in|ios::out|ios::binary);
105 if (aMode == Storage_VSRead) {
106 myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
108 else if (aMode == Storage_VSWrite) {
109 myStream.open(aName.ToCString(),ios::out);
111 else if (aMode == Storage_VSReadWrite) {
112 myStream.open(aName.ToCString(),ios::in|ios::out);
116 if (myStream.fail()) {
117 result = Storage_VSOpenError;
120 myStream.precision(17);
121 myStream.imbue (std::locale::classic()); // use always C locale
126 result = Storage_VSAlreadyOpen;
131 //=======================================================================
134 //=======================================================================
136 Standard_Boolean FSD_CmpFile::IsEnd()
138 return myStream.eof();
141 //=======================================================================
144 //=======================================================================
146 Storage_Error FSD_CmpFile::Close()
148 Storage_Error result = Storage_VSOk;
150 if (OpenMode() != Storage_VSNone) {
152 SetOpenMode(Storage_VSNone);
155 result = Storage_VSNotOpen;
161 //=======================================================================
162 //function : MagicNumber
163 //purpose : ------------------ PROTECTED
164 //=======================================================================
166 const Standard_CString FSD_CmpFile::MagicNumber()
171 //=======================================================================
172 //function : FlushEndOfLine
174 //=======================================================================
176 void FSD_CmpFile::FlushEndOfLine()
178 TCollection_AsciiString aDummy;
179 ReadLine (aDummy); // flush is nothing more than to read till the line-break
181 static char Buffer[8192];
183 Standard_Boolean IsEnd = Standard_False;
185 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
187 myStream.get(Buffer,8192,'\n');
189 if (myStream.get(c) && c != '\r' && c != '\n') {
192 IsEnd = Standard_True;
198 //=======================================================================
199 //function : ReadLine
200 //purpose : read from the current position to the end of line.
201 //=======================================================================
203 void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer)
207 Standard_Boolean IsEnd = Standard_False;
211 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
213 //myStream.get(Buffer,8192,'\n');
214 myStream.getline(Buffer,8192,'\n');
215 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
219 // if (myStream.get(c) && c != '\r' && c != '\n') {
225 IsEnd = Standard_True;
230 //=======================================================================
231 //function : WriteExtendedLine
232 //purpose : write from the current position to the end of line.
233 //=======================================================================
235 void FSD_CmpFile::WriteExtendedLine(const TCollection_ExtendedString& buffer)
238 Standard_ExtString extBuffer;
239 Standard_Integer i,c,d;
241 extBuffer = buffer.ToExtString();
243 for (i = 0; i < buffer.Length(); i++) {
244 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
245 d = extBuffer[i] & 0x000000FF;
247 myStream << (char)c << (char)d;
250 myStream << (char)0 << "\n";
252 Standard_ExtString extBuffer;
255 extBuffer = buffer.ToExtString();
256 PutInteger(buffer.Length());
257 for (i = 0; i < buffer.Length(); i++) {
258 PutExtCharacter(extBuffer[i]);
264 //=======================================================================
265 //function : ReadExtendedLine
267 //=======================================================================
269 void FSD_CmpFile::ReadExtendedLine(TCollection_ExtendedString& buffer)
271 Standard_ExtCharacter c;
276 for (i = 0; i < buffer.Length(); i++) {
284 //=======================================================================
285 //function : ReadChar
286 //purpose : read <rsize> character from the current position.
287 //=======================================================================
289 void FSD_CmpFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsize)
292 Standard_Size ccount = 0;
296 while (!IsEnd() && (ccount < rsize)) {
303 //=======================================================================
304 //function : ReadString
305 //purpose : read from the first none space character position to the end of line.
306 //=======================================================================
308 void FSD_CmpFile::ReadString(TCollection_AsciiString& buffer)
312 Standard_Boolean IsEnd = Standard_False,isFirstTime = Standard_True;
316 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
318 //myStream.get(Buffer,8192,'\n');
319 myStream.getline(Buffer,8192,'\n');
320 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
328 isFirstTime = Standard_False;
329 while (*bpos == '\n' || *bpos == ' ') bpos++;
332 // if (myStream.get(c) && c != '\n') {
338 IsEnd = Standard_True;
343 //=======================================================================
344 //function : ReadWord
345 //purpose : read from the current position to the next white space or end of line.
346 //=======================================================================
348 void FSD_CmpFile::ReadWord(TCollection_AsciiString& buffer)
352 Standard_Boolean IsEnd = Standard_False;
359 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
361 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
364 IsEnd = Standard_False;
367 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
377 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
383 //=======================================================================
386 //=======================================================================
388 Storage_Error FSD_CmpFile::FindTag(const Standard_CString aTag)
390 TCollection_AsciiString l;
394 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
399 return Storage_VSSectionNotFound;
406 //=======================================================================
407 //function : SkipObject
409 //=======================================================================
411 void FSD_CmpFile::SkipObject()
416 //=======================================================================
417 //function : PutReference
418 //purpose : ---------------------- PUBLIC : PUT
419 //=======================================================================
421 Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
423 myStream << aValue << " ";
424 if (myStream.bad()) Storage_StreamWriteError::Raise();
428 //=======================================================================
429 //function : PutCharacter
431 //=======================================================================
433 Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
438 myStream << i << " ";
439 if (myStream.bad()) Storage_StreamWriteError::Raise();
443 //=======================================================================
444 //function : PutExtCharacter
446 //=======================================================================
448 Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue)
450 myStream << aValue << " ";
451 if (myStream.bad()) Storage_StreamWriteError::Raise();
455 //=======================================================================
456 //function : PutInteger
458 //=======================================================================
460 Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
462 myStream << aValue << " ";
463 if (myStream.bad()) Storage_StreamWriteError::Raise();
467 //=======================================================================
468 //function : PutBoolean
470 //=======================================================================
472 Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
474 myStream << ((Standard_Integer)aValue) << " ";
475 if (myStream.bad()) Storage_StreamWriteError::Raise();
479 //=======================================================================
482 //=======================================================================
484 Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
486 myStream << ((Standard_Real)aValue) << " ";
487 if (myStream.bad()) Storage_StreamWriteError::Raise();
491 //=======================================================================
492 //function : PutShortReal
494 //=======================================================================
496 Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue)
498 myStream << aValue << " ";
499 if (myStream.bad()) Storage_StreamWriteError::Raise();
503 //=======================================================================
504 //function : GetReference
505 //purpose : ----------------- PUBLIC : GET
506 //=======================================================================
508 Storage_BaseDriver& FSD_CmpFile::GetReference(Standard_Integer& aValue)
510 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
515 //=======================================================================
516 //function : GetCharacter
518 //=======================================================================
520 Storage_BaseDriver& FSD_CmpFile::GetCharacter(Standard_Character& aValue)
522 unsigned short i = 0;
523 if (!(myStream >> i)) {
524 // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
525 // signes (-80 fait ios::badbit, mais la variable i est initialisee)
527 if (i == 0) Storage_StreamTypeMismatchError::Raise();
528 myStream.clear(ios::goodbit);
535 //=======================================================================
536 //function : GetExtCharacter
538 //=======================================================================
540 Storage_BaseDriver& FSD_CmpFile::GetExtCharacter(Standard_ExtCharacter& aValue)
542 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
547 //=======================================================================
548 //function : GetInteger
550 //=======================================================================
552 Storage_BaseDriver& FSD_CmpFile::GetInteger(Standard_Integer& aValue)
554 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
559 //=======================================================================
560 //function : GetBoolean
562 //=======================================================================
564 Storage_BaseDriver& FSD_CmpFile::GetBoolean(Standard_Boolean& aValue)
566 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
571 //=======================================================================
574 //=======================================================================
576 Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
579 char realbuffer[100];
581 realbuffer[0] = '\0';
582 if (!(myStream >> realbuffer)) {
583 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
584 cerr << "\t buffer is" << realbuffer<< endl;
585 Storage_StreamTypeMismatchError::Raise();
587 if (!OSD::CStringToReal(realbuffer,aValue)) {
588 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
589 cerr << "\t buffer is" << realbuffer<< endl;
590 Storage_StreamTypeMismatchError::Raise();
595 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
601 //=======================================================================
602 //function : GetShortReal
604 //=======================================================================
606 Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
609 char realbuffer[100];
610 Standard_Real r = 0.0;
612 realbuffer[0] = '\0';
613 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
614 if (!OSD::CStringToReal(realbuffer,r))
615 Storage_StreamTypeMismatchError::Raise();
617 aValue = (Standard_ShortReal)r;
621 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
626 //=======================================================================
629 //=======================================================================
631 void FSD_CmpFile::Destroy()
633 if (OpenMode() != Storage_VSNone) {
638 //=======================================================================
639 //function : BeginWriteInfoSection
640 //purpose : -------------------------- INFO : WRITE
641 //=======================================================================
643 Storage_Error FSD_CmpFile::BeginWriteInfoSection()
645 myStream << FSD_CmpFile::MagicNumber() << '\n';
646 myStream << "BEGIN_INFO_SECTION\n";
647 if (myStream.bad()) Storage_StreamWriteError::Raise();
652 //=======================================================================
653 //function : WriteInfo
655 //=======================================================================
657 void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
658 const TCollection_AsciiString& dbVersion,
659 const TCollection_AsciiString& date,
660 const TCollection_AsciiString& schemaName,
661 const TCollection_AsciiString& schemaVersion,
662 const TCollection_ExtendedString& appName,
663 const TCollection_AsciiString& appVersion,
664 const TCollection_ExtendedString& dataType,
665 const TColStd_SequenceOfAsciiString& userInfo)
671 myStream << dbVersion.ToCString() << "\n";
672 myStream << date.ToCString() << "\n";
673 myStream << schemaName.ToCString() << "\n";
674 myStream << schemaVersion.ToCString() << "\n";
675 WriteExtendedLine(appName);
676 myStream << appVersion.ToCString() << "\n";
677 WriteExtendedLine(dataType);
678 myStream << userInfo.Length() << "\n";
680 if (myStream.bad()) Storage_StreamWriteError::Raise();
682 for (i = 1; i <= userInfo.Length(); i++) {
683 myStream << userInfo.Value(i).ToCString() << "\n";
684 if (myStream.bad()) Storage_StreamWriteError::Raise();
688 //=======================================================================
689 //function : EndWriteInfoSection
691 //=======================================================================
693 Storage_Error FSD_CmpFile::EndWriteInfoSection()
695 myStream << "END_INFO_SECTION\n";
696 if (myStream.bad()) Storage_StreamWriteError::Raise();
700 //=======================================================================
701 //function : BeginReadInfoSection
703 //=======================================================================
705 Storage_Error FSD_CmpFile::BeginReadInfoSection()
708 TCollection_AsciiString l;
709 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
713 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
714 s = Storage_VSFormatError;
717 s = FindTag("BEGIN_INFO_SECTION");
723 //=======================================================================
724 //function : ReadInfo
725 //purpose : ------------------- INFO : READ
726 //=======================================================================
728 void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
729 TCollection_AsciiString& dbVersion,
730 TCollection_AsciiString& date,
731 TCollection_AsciiString& schemaName,
732 TCollection_AsciiString& schemaVersion,
733 TCollection_ExtendedString& appName,
734 TCollection_AsciiString& appVersion,
735 TCollection_ExtendedString& dataType,
736 TColStd_SequenceOfAsciiString& userInfo)
738 if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
744 ReadLine(schemaName);
745 ReadLine(schemaVersion);
746 ReadExtendedLine(appName);
747 ReadLine(appVersion);
748 ReadExtendedLine(dataType);
750 Standard_Integer i,len = 0;
752 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
756 TCollection_AsciiString line;
758 for (i = 1; i <= len && !IsEnd(); i++) {
760 userInfo.Append(line);
765 //=======================================================================
766 //function : EndReadInfoSection
767 //purpose : COMMENTS SECTION
769 //=======================================================================
771 Storage_Error FSD_CmpFile::EndReadInfoSection()
773 return FindTag("END_INFO_SECTION");
776 //=======================================================================
777 //function : BeginWriteCommentSection
778 //purpose : ---------------- COMMENTS : WRITE
779 //=======================================================================
781 Storage_Error FSD_CmpFile::BeginWriteCommentSection()
783 myStream << "BEGIN_COMMENT_SECTION\n";
784 if (myStream.bad()) Storage_StreamWriteError::Raise();
788 //=======================================================================
789 //function : WriteComment
791 //=======================================================================
793 void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
795 Standard_Integer i,aSize;
797 aSize = aCom.Length();
798 myStream << aSize << "\n";
799 if (myStream.bad()) Storage_StreamWriteError::Raise();
801 for (i = 1; i <= aSize; i++) {
802 WriteExtendedLine(aCom.Value(i));
803 if (myStream.bad()) Storage_StreamWriteError::Raise();
807 //=======================================================================
808 //function : EndWriteCommentSection
810 //=======================================================================
812 Storage_Error FSD_CmpFile::EndWriteCommentSection()
814 myStream << "END_COMMENT_SECTION\n";
815 if (myStream.bad()) Storage_StreamWriteError::Raise();
819 //=======================================================================
820 //function : BeginReadCommentSection
821 //purpose : ---------------- COMMENTS : READ
822 //=======================================================================
824 Storage_Error FSD_CmpFile::BeginReadCommentSection()
826 return FindTag("BEGIN_COMMENT_SECTION");
829 //=======================================================================
830 //function : ReadComment
832 //=======================================================================
834 void FSD_CmpFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
836 TCollection_ExtendedString line;
837 Standard_Integer len,i;
839 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
843 for (i = 1; i <= len && !IsEnd(); i++) {
844 ReadExtendedLine(line);
850 //=======================================================================
851 //function : EndReadCommentSection
853 //=======================================================================
855 Storage_Error FSD_CmpFile::EndReadCommentSection()
857 return FindTag("END_COMMENT_SECTION");
860 //=======================================================================
861 //function : BeginWriteTypeSection
862 //purpose : --------------- TYPE : WRITE
863 //=======================================================================
865 Storage_Error FSD_CmpFile::BeginWriteTypeSection()
867 myStream << "BEGIN_TYPE_SECTION\n";
868 if (myStream.bad()) Storage_StreamWriteError::Raise();
872 //=======================================================================
873 //function : SetTypeSectionSize
875 //=======================================================================
877 void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
879 myStream << aSize << "\n";
880 if (myStream.bad()) Storage_StreamWriteError::Raise();
883 //=======================================================================
884 //function : WriteTypeInformations
886 //=======================================================================
888 void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
889 const TCollection_AsciiString& typeName)
891 myStream << typeNum << " " << typeName.ToCString() << "\n";
892 if (myStream.bad()) Storage_StreamWriteError::Raise();
895 //=======================================================================
896 //function : EndWriteTypeSection
898 //=======================================================================
900 Storage_Error FSD_CmpFile::EndWriteTypeSection()
902 myStream << "END_TYPE_SECTION\n";
903 if (myStream.bad()) Storage_StreamWriteError::Raise();
907 //=======================================================================
908 //function : BeginReadTypeSection
909 //purpose : ------------------- TYPE : READ
910 //=======================================================================
912 Storage_Error FSD_CmpFile::BeginReadTypeSection()
914 return FindTag("BEGIN_TYPE_SECTION");
917 //=======================================================================
918 //function : TypeSectionSize
920 //=======================================================================
922 Standard_Integer FSD_CmpFile::TypeSectionSize()
926 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
933 //=======================================================================
934 //function : ReadTypeInformations
936 //=======================================================================
938 void FSD_CmpFile::ReadTypeInformations(Standard_Integer& typeNum,
939 TCollection_AsciiString& typeName)
941 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
942 if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
946 //=======================================================================
947 //function : EndReadTypeSection
948 //purpose : ROOT SECTION
950 //=======================================================================
952 Storage_Error FSD_CmpFile::EndReadTypeSection()
954 return FindTag("END_TYPE_SECTION");
957 //=======================================================================
958 //function : BeginWriteRootSection
959 //purpose : -------------------- ROOT : WRITE
960 //=======================================================================
962 Storage_Error FSD_CmpFile::BeginWriteRootSection()
964 myStream << "BEGIN_ROOT_SECTION\n";
965 if (myStream.bad()) Storage_StreamWriteError::Raise();
969 //=======================================================================
970 //function : SetRootSectionSize
972 //=======================================================================
974 void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
976 myStream << aSize << "\n";
977 if (myStream.bad()) Storage_StreamWriteError::Raise();
980 //=======================================================================
981 //function : WriteRoot
983 //=======================================================================
985 void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
987 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
988 if (myStream.bad()) Storage_StreamWriteError::Raise();
991 //=======================================================================
992 //function : EndWriteRootSection
994 //=======================================================================
996 Storage_Error FSD_CmpFile::EndWriteRootSection()
998 myStream << "END_ROOT_SECTION\n";
999 if (myStream.bad()) Storage_StreamWriteError::Raise();
1000 return Storage_VSOk;
1003 //=======================================================================
1004 //function : BeginReadRootSection
1005 //purpose : ----------------------- ROOT : READ
1006 //=======================================================================
1008 Storage_Error FSD_CmpFile::BeginReadRootSection()
1010 return FindTag("BEGIN_ROOT_SECTION");
1013 //=======================================================================
1014 //function : RootSectionSize
1016 //=======================================================================
1018 Standard_Integer FSD_CmpFile::RootSectionSize()
1022 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1029 //=======================================================================
1030 //function : ReadRoot
1032 //=======================================================================
1034 void FSD_CmpFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1036 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1041 //=======================================================================
1042 //function : EndReadRootSection
1043 //purpose : REF SECTION
1045 //=======================================================================
1047 Storage_Error FSD_CmpFile::EndReadRootSection()
1049 return FindTag("END_ROOT_SECTION");
1052 //=======================================================================
1053 //function : BeginWriteRefSection
1054 //purpose : -------------------------- REF : WRITE
1055 //=======================================================================
1057 Storage_Error FSD_CmpFile::BeginWriteRefSection()
1059 myStream << "BEGIN_REF_SECTION\n";
1060 if (myStream.bad()) Storage_StreamWriteError::Raise();
1061 return Storage_VSOk;
1064 //=======================================================================
1065 //function : SetRefSectionSize
1067 //=======================================================================
1069 void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
1071 myStream << aSize << "\n";
1072 if (myStream.bad()) Storage_StreamWriteError::Raise();
1075 //=======================================================================
1076 //function : WriteReferenceType
1078 //=======================================================================
1080 void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
1081 const Standard_Integer typeNum)
1083 myStream << reference << " " << typeNum << "\n";
1084 if (myStream.bad()) Storage_StreamWriteError::Raise();
1087 //=======================================================================
1088 //function : EndWriteRefSection
1090 //=======================================================================
1092 Storage_Error FSD_CmpFile::EndWriteRefSection()
1094 myStream << "END_REF_SECTION\n";
1095 if (myStream.bad()) Storage_StreamWriteError::Raise();
1096 return Storage_VSOk;
1099 //=======================================================================
1100 //function : BeginReadRefSection
1101 //purpose : ----------------------- REF : READ
1102 //=======================================================================
1104 Storage_Error FSD_CmpFile::BeginReadRefSection()
1106 return FindTag("BEGIN_REF_SECTION");
1109 //=======================================================================
1110 //function : RefSectionSize
1112 //=======================================================================
1114 Standard_Integer FSD_CmpFile::RefSectionSize()
1118 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1124 //=======================================================================
1125 //function : ReadReferenceType
1127 //=======================================================================
1129 void FSD_CmpFile::ReadReferenceType(Standard_Integer& reference,
1130 Standard_Integer& typeNum)
1132 if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
1133 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1137 //=======================================================================
1138 //function : EndReadRefSection
1139 //purpose : DATA SECTION
1141 //=======================================================================
1143 Storage_Error FSD_CmpFile::EndReadRefSection()
1145 return FindTag("END_REF_SECTION");
1148 //=======================================================================
1149 //function : BeginWriteDataSection
1150 //purpose : -------------------- DATA : WRITE
1151 //=======================================================================
1153 Storage_Error FSD_CmpFile::BeginWriteDataSection()
1155 myStream << "BEGIN_DATA_SECTION";
1156 if (myStream.bad()) Storage_StreamWriteError::Raise();
1157 return Storage_VSOk;
1160 //=======================================================================
1161 //function : WritePersistentObjectHeader
1163 //=======================================================================
1165 void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
1166 const Standard_Integer aType)
1168 myStream << "\n#" << aRef << "%" << aType << " ";
1169 if (myStream.bad()) Storage_StreamWriteError::Raise();
1172 //=======================================================================
1173 //function : BeginWritePersistentObjectData
1175 //=======================================================================
1177 void FSD_CmpFile::BeginWritePersistentObjectData()
1179 if (myStream.bad()) Storage_StreamWriteError::Raise();
1182 //=======================================================================
1183 //function : BeginWriteObjectData
1185 //=======================================================================
1187 void FSD_CmpFile::BeginWriteObjectData()
1189 if (myStream.bad()) Storage_StreamWriteError::Raise();
1192 //=======================================================================
1193 //function : EndWriteObjectData
1195 //=======================================================================
1197 void FSD_CmpFile::EndWriteObjectData()
1199 if (myStream.bad()) Storage_StreamWriteError::Raise();
1202 //=======================================================================
1203 //function : EndWritePersistentObjectData
1205 //=======================================================================
1207 void FSD_CmpFile::EndWritePersistentObjectData()
1209 if (myStream.bad()) Storage_StreamWriteError::Raise();
1212 //=======================================================================
1213 //function : EndWriteDataSection
1215 //=======================================================================
1217 Storage_Error FSD_CmpFile::EndWriteDataSection()
1219 myStream << "\nEND_DATA_SECTION\n";
1220 if (myStream.bad()) Storage_StreamWriteError::Raise();
1221 return Storage_VSOk;
1224 //=======================================================================
1225 //function : BeginReadDataSection
1226 //purpose : ---------------------- DATA : READ
1227 //=======================================================================
1229 Storage_Error FSD_CmpFile::BeginReadDataSection()
1231 return FindTag("BEGIN_DATA_SECTION");
1234 //=======================================================================
1235 //function : ReadPersistentObjectHeader
1237 //=======================================================================
1239 void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
1240 Standard_Integer& aType)
1247 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1248 Storage_StreamFormatError::Raise();
1253 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1258 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1259 Storage_StreamFormatError::Raise();
1264 if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
1265 // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
1268 //=======================================================================
1269 //function : BeginReadPersistentObjectData
1271 //=======================================================================
1273 void FSD_CmpFile::BeginReadPersistentObjectData()
1275 //cout << "BeginReadPersistentObjectData" << endl;
1278 //=======================================================================
1279 //function : BeginReadObjectData
1281 //=======================================================================
1283 void FSD_CmpFile::BeginReadObjectData()
1285 // cout << "BeginReadObjectData" << endl;
1288 //=======================================================================
1289 //function : EndReadObjectData
1291 //=======================================================================
1293 void FSD_CmpFile::EndReadObjectData()
1295 // cout << "EndReadObjectData" << endl;
1298 //=======================================================================
1299 //function : EndReadPersistentObjectData
1301 //=======================================================================
1303 void FSD_CmpFile::EndReadPersistentObjectData()
1308 while (c != '\n' && (c != '\r')) {
1309 if (IsEnd() || (c != ' ')) {
1310 Storage_StreamFormatError::Raise();
1317 // cout << "EndReadPersistentObjectData" << endl;
1320 //=======================================================================
1321 //function : EndReadDataSection
1323 //=======================================================================
1325 Storage_Error FSD_CmpFile::EndReadDataSection()
1327 return FindTag("END_DATA_SECTION");
1330 //=======================================================================
1332 //purpose : return position in the file. Return -1 upon error.
1333 //=======================================================================
1335 Storage_Position FSD_CmpFile::Tell()
1337 switch (OpenMode()) {
1338 case Storage_VSRead:
1339 return (Storage_Position) myStream.tellp();
1340 case Storage_VSWrite:
1341 return (Storage_Position) myStream.tellg();
1342 case Storage_VSReadWrite: {
1343 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1344 Storage_Position aPosW = (Storage_Position) myStream.tellg();