1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <FSD_CmpFile.hxx>
18 #include <Standard_PCharacter.hxx>
19 #include <Storage_BaseDriver.hxx>
20 #include <Storage_StreamExtCharParityError.hxx>
21 #include <Storage_StreamFormatError.hxx>
22 #include <Storage_StreamModeError.hxx>
23 #include <Storage_StreamTypeMismatchError.hxx>
24 #include <Storage_StreamUnknownTypeError.hxx>
25 #include <Storage_StreamWriteError.hxx>
26 #include <TCollection_AsciiString.hxx>
27 #include <TCollection_ExtendedString.hxx>
29 const Standard_CString MAGICNUMBER = "CMPFILE";
31 //=======================================================================
32 //function : FSD_CmpFile
34 //=======================================================================
36 FSD_CmpFile::FSD_CmpFile()
41 //=======================================================================
42 //function : IsGoodFileType
43 //purpose : INFO SECTION
45 //=======================================================================
47 Storage_Error FSD_CmpFile::IsGoodFileType(const TCollection_AsciiString& aName)
52 s = f.Open(aName,Storage_VSRead);
54 if (s == Storage_VSOk) {
55 TCollection_AsciiString l;
56 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
62 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
63 s = Storage_VSFormatError;
70 //=======================================================================
73 //=======================================================================
75 Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
77 Storage_Error result = Storage_VSOk;
81 if (OpenMode() == Storage_VSNone) {
84 TCollection_ExtendedString aWName(aName);
85 if (aMode == Storage_VSRead) {
86 myStream.open((const wchar_t*)aWName.ToExtString(),ios::in|ios::binary); // ios::nocreate is not portable
88 else if (aMode == Storage_VSWrite) {
89 myStream.open((const wchar_t*)aWName.ToExtString(),ios::out|ios::binary);
91 else if (aMode == Storage_VSReadWrite) {
92 myStream.open((const wchar_t*)aWName.ToExtString(),ios::in|ios::out|ios::binary);
94 #elif !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 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 << (short )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)
543 if (!(myStream >> aChar)) Storage_StreamTypeMismatchError::Raise();
548 //=======================================================================
549 //function : GetInteger
551 //=======================================================================
553 Storage_BaseDriver& FSD_CmpFile::GetInteger(Standard_Integer& aValue)
555 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
560 //=======================================================================
561 //function : GetBoolean
563 //=======================================================================
565 Storage_BaseDriver& FSD_CmpFile::GetBoolean(Standard_Boolean& aValue)
567 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
572 //=======================================================================
575 //=======================================================================
577 Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
579 char realbuffer[100];
581 realbuffer[0] = '\0';
582 if (!(myStream >> realbuffer)) {
584 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
585 cerr << "\t buffer is" << realbuffer<< endl;
587 Storage_StreamTypeMismatchError::Raise();
589 if (!OSD::CStringToReal(realbuffer,aValue)) {
591 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
592 cerr << "\t buffer is" << realbuffer<< endl;
594 Storage_StreamTypeMismatchError::Raise();
600 //=======================================================================
601 //function : GetShortReal
603 //=======================================================================
605 Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
607 char realbuffer[100];
608 Standard_Real r = 0.0;
610 realbuffer[0] = '\0';
611 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
612 if (!OSD::CStringToReal(realbuffer,r))
613 Storage_StreamTypeMismatchError::Raise();
615 aValue = (Standard_ShortReal)r;
620 //=======================================================================
623 //=======================================================================
625 void FSD_CmpFile::Destroy()
627 if (OpenMode() != Storage_VSNone) {
632 //=======================================================================
633 //function : BeginWriteInfoSection
634 //purpose : -------------------------- INFO : WRITE
635 //=======================================================================
637 Storage_Error FSD_CmpFile::BeginWriteInfoSection()
639 myStream << FSD_CmpFile::MagicNumber() << '\n';
640 myStream << "BEGIN_INFO_SECTION\n";
641 if (myStream.bad()) Storage_StreamWriteError::Raise();
646 //=======================================================================
647 //function : WriteInfo
649 //=======================================================================
651 void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
652 const TCollection_AsciiString& dbVersion,
653 const TCollection_AsciiString& date,
654 const TCollection_AsciiString& schemaName,
655 const TCollection_AsciiString& schemaVersion,
656 const TCollection_ExtendedString& appName,
657 const TCollection_AsciiString& appVersion,
658 const TCollection_ExtendedString& dataType,
659 const TColStd_SequenceOfAsciiString& userInfo)
665 myStream << dbVersion.ToCString() << "\n";
666 myStream << date.ToCString() << "\n";
667 myStream << schemaName.ToCString() << "\n";
668 myStream << schemaVersion.ToCString() << "\n";
669 WriteExtendedLine(appName);
670 myStream << appVersion.ToCString() << "\n";
671 WriteExtendedLine(dataType);
672 myStream << userInfo.Length() << "\n";
674 if (myStream.bad()) Storage_StreamWriteError::Raise();
676 for (i = 1; i <= userInfo.Length(); i++) {
677 myStream << userInfo.Value(i).ToCString() << "\n";
678 if (myStream.bad()) Storage_StreamWriteError::Raise();
682 //=======================================================================
683 //function : EndWriteInfoSection
685 //=======================================================================
687 Storage_Error FSD_CmpFile::EndWriteInfoSection()
689 myStream << "END_INFO_SECTION\n";
690 if (myStream.bad()) Storage_StreamWriteError::Raise();
694 //=======================================================================
695 //function : BeginReadInfoSection
697 //=======================================================================
699 Storage_Error FSD_CmpFile::BeginReadInfoSection()
702 TCollection_AsciiString l;
703 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
707 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
708 s = Storage_VSFormatError;
711 s = FindTag("BEGIN_INFO_SECTION");
717 //=======================================================================
718 //function : ReadInfo
719 //purpose : ------------------- INFO : READ
720 //=======================================================================
722 void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
723 TCollection_AsciiString& dbVersion,
724 TCollection_AsciiString& date,
725 TCollection_AsciiString& schemaName,
726 TCollection_AsciiString& schemaVersion,
727 TCollection_ExtendedString& appName,
728 TCollection_AsciiString& appVersion,
729 TCollection_ExtendedString& dataType,
730 TColStd_SequenceOfAsciiString& userInfo)
732 if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
738 ReadLine(schemaName);
739 ReadLine(schemaVersion);
740 ReadExtendedLine(appName);
741 ReadLine(appVersion);
742 ReadExtendedLine(dataType);
744 Standard_Integer i,len = 0;
746 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
750 TCollection_AsciiString line;
752 for (i = 1; i <= len && !IsEnd(); i++) {
754 userInfo.Append(line);
759 //=======================================================================
760 //function : ReadCompleteInfo
763 //=======================================================================
764 void FSD_CmpFile::ReadCompleteInfo( Standard_IStream& /*theIStream*/, Handle(Storage_Data)& /*theData*/)
769 //=======================================================================
770 //function : EndReadInfoSection
771 //purpose : COMMENTS SECTION
773 //=======================================================================
775 Storage_Error FSD_CmpFile::EndReadInfoSection()
777 return FindTag("END_INFO_SECTION");
780 //=======================================================================
781 //function : BeginWriteCommentSection
782 //purpose : ---------------- COMMENTS : WRITE
783 //=======================================================================
785 Storage_Error FSD_CmpFile::BeginWriteCommentSection()
787 myStream << "BEGIN_COMMENT_SECTION\n";
788 if (myStream.bad()) Storage_StreamWriteError::Raise();
792 //=======================================================================
793 //function : WriteComment
795 //=======================================================================
797 void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
799 Standard_Integer i,aSize;
801 aSize = aCom.Length();
802 myStream << aSize << "\n";
803 if (myStream.bad()) Storage_StreamWriteError::Raise();
805 for (i = 1; i <= aSize; i++) {
806 WriteExtendedLine(aCom.Value(i));
807 if (myStream.bad()) Storage_StreamWriteError::Raise();
811 //=======================================================================
812 //function : EndWriteCommentSection
814 //=======================================================================
816 Storage_Error FSD_CmpFile::EndWriteCommentSection()
818 myStream << "END_COMMENT_SECTION\n";
819 if (myStream.bad()) Storage_StreamWriteError::Raise();
823 //=======================================================================
824 //function : BeginReadCommentSection
825 //purpose : ---------------- COMMENTS : READ
826 //=======================================================================
828 Storage_Error FSD_CmpFile::BeginReadCommentSection()
830 return FindTag("BEGIN_COMMENT_SECTION");
833 //=======================================================================
834 //function : ReadComment
836 //=======================================================================
838 void FSD_CmpFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
840 TCollection_ExtendedString line;
841 Standard_Integer len,i;
843 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
847 for (i = 1; i <= len && !IsEnd(); i++) {
848 ReadExtendedLine(line);
854 //=======================================================================
855 //function : EndReadCommentSection
857 //=======================================================================
859 Storage_Error FSD_CmpFile::EndReadCommentSection()
861 return FindTag("END_COMMENT_SECTION");
864 //=======================================================================
865 //function : BeginWriteTypeSection
866 //purpose : --------------- TYPE : WRITE
867 //=======================================================================
869 Storage_Error FSD_CmpFile::BeginWriteTypeSection()
871 myStream << "BEGIN_TYPE_SECTION\n";
872 if (myStream.bad()) Storage_StreamWriteError::Raise();
876 //=======================================================================
877 //function : SetTypeSectionSize
879 //=======================================================================
881 void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
883 myStream << aSize << "\n";
884 if (myStream.bad()) Storage_StreamWriteError::Raise();
887 //=======================================================================
888 //function : WriteTypeInformations
890 //=======================================================================
892 void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
893 const TCollection_AsciiString& typeName)
895 myStream << typeNum << " " << typeName.ToCString() << "\n";
896 if (myStream.bad()) Storage_StreamWriteError::Raise();
899 //=======================================================================
900 //function : EndWriteTypeSection
902 //=======================================================================
904 Storage_Error FSD_CmpFile::EndWriteTypeSection()
906 myStream << "END_TYPE_SECTION\n";
907 if (myStream.bad()) Storage_StreamWriteError::Raise();
911 //=======================================================================
912 //function : BeginReadTypeSection
913 //purpose : ------------------- TYPE : READ
914 //=======================================================================
916 Storage_Error FSD_CmpFile::BeginReadTypeSection()
918 return FindTag("BEGIN_TYPE_SECTION");
921 //=======================================================================
922 //function : TypeSectionSize
924 //=======================================================================
926 Standard_Integer FSD_CmpFile::TypeSectionSize()
930 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
937 //=======================================================================
938 //function : ReadTypeInformations
940 //=======================================================================
942 void FSD_CmpFile::ReadTypeInformations(Standard_Integer& typeNum,
943 TCollection_AsciiString& typeName)
945 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
946 if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
950 //=======================================================================
951 //function : EndReadTypeSection
952 //purpose : ROOT SECTION
954 //=======================================================================
956 Storage_Error FSD_CmpFile::EndReadTypeSection()
958 return FindTag("END_TYPE_SECTION");
961 //=======================================================================
962 //function : BeginWriteRootSection
963 //purpose : -------------------- ROOT : WRITE
964 //=======================================================================
966 Storage_Error FSD_CmpFile::BeginWriteRootSection()
968 myStream << "BEGIN_ROOT_SECTION\n";
969 if (myStream.bad()) Storage_StreamWriteError::Raise();
973 //=======================================================================
974 //function : SetRootSectionSize
976 //=======================================================================
978 void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
980 myStream << aSize << "\n";
981 if (myStream.bad()) Storage_StreamWriteError::Raise();
984 //=======================================================================
985 //function : WriteRoot
987 //=======================================================================
989 void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
991 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
992 if (myStream.bad()) Storage_StreamWriteError::Raise();
995 //=======================================================================
996 //function : EndWriteRootSection
998 //=======================================================================
1000 Storage_Error FSD_CmpFile::EndWriteRootSection()
1002 myStream << "END_ROOT_SECTION\n";
1003 if (myStream.bad()) Storage_StreamWriteError::Raise();
1004 return Storage_VSOk;
1007 //=======================================================================
1008 //function : BeginReadRootSection
1009 //purpose : ----------------------- ROOT : READ
1010 //=======================================================================
1012 Storage_Error FSD_CmpFile::BeginReadRootSection()
1014 return FindTag("BEGIN_ROOT_SECTION");
1017 //=======================================================================
1018 //function : RootSectionSize
1020 //=======================================================================
1022 Standard_Integer FSD_CmpFile::RootSectionSize()
1026 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1033 //=======================================================================
1034 //function : ReadRoot
1036 //=======================================================================
1038 void FSD_CmpFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1040 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1045 //=======================================================================
1046 //function : EndReadRootSection
1047 //purpose : REF SECTION
1049 //=======================================================================
1051 Storage_Error FSD_CmpFile::EndReadRootSection()
1053 return FindTag("END_ROOT_SECTION");
1056 //=======================================================================
1057 //function : BeginWriteRefSection
1058 //purpose : -------------------------- REF : WRITE
1059 //=======================================================================
1061 Storage_Error FSD_CmpFile::BeginWriteRefSection()
1063 myStream << "BEGIN_REF_SECTION\n";
1064 if (myStream.bad()) Storage_StreamWriteError::Raise();
1065 return Storage_VSOk;
1068 //=======================================================================
1069 //function : SetRefSectionSize
1071 //=======================================================================
1073 void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
1075 myStream << aSize << "\n";
1076 if (myStream.bad()) Storage_StreamWriteError::Raise();
1079 //=======================================================================
1080 //function : WriteReferenceType
1082 //=======================================================================
1084 void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
1085 const Standard_Integer typeNum)
1087 myStream << reference << " " << typeNum << "\n";
1088 if (myStream.bad()) Storage_StreamWriteError::Raise();
1091 //=======================================================================
1092 //function : EndWriteRefSection
1094 //=======================================================================
1096 Storage_Error FSD_CmpFile::EndWriteRefSection()
1098 myStream << "END_REF_SECTION\n";
1099 if (myStream.bad()) Storage_StreamWriteError::Raise();
1100 return Storage_VSOk;
1103 //=======================================================================
1104 //function : BeginReadRefSection
1105 //purpose : ----------------------- REF : READ
1106 //=======================================================================
1108 Storage_Error FSD_CmpFile::BeginReadRefSection()
1110 return FindTag("BEGIN_REF_SECTION");
1113 //=======================================================================
1114 //function : RefSectionSize
1116 //=======================================================================
1118 Standard_Integer FSD_CmpFile::RefSectionSize()
1122 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1128 //=======================================================================
1129 //function : ReadReferenceType
1131 //=======================================================================
1133 void FSD_CmpFile::ReadReferenceType(Standard_Integer& reference,
1134 Standard_Integer& typeNum)
1136 if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
1137 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1141 //=======================================================================
1142 //function : EndReadRefSection
1143 //purpose : DATA SECTION
1145 //=======================================================================
1147 Storage_Error FSD_CmpFile::EndReadRefSection()
1149 return FindTag("END_REF_SECTION");
1152 //=======================================================================
1153 //function : BeginWriteDataSection
1154 //purpose : -------------------- DATA : WRITE
1155 //=======================================================================
1157 Storage_Error FSD_CmpFile::BeginWriteDataSection()
1159 myStream << "BEGIN_DATA_SECTION";
1160 if (myStream.bad()) Storage_StreamWriteError::Raise();
1161 return Storage_VSOk;
1164 //=======================================================================
1165 //function : WritePersistentObjectHeader
1167 //=======================================================================
1169 void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
1170 const Standard_Integer aType)
1172 myStream << "\n#" << aRef << "%" << aType << " ";
1173 if (myStream.bad()) Storage_StreamWriteError::Raise();
1176 //=======================================================================
1177 //function : BeginWritePersistentObjectData
1179 //=======================================================================
1181 void FSD_CmpFile::BeginWritePersistentObjectData()
1183 if (myStream.bad()) Storage_StreamWriteError::Raise();
1186 //=======================================================================
1187 //function : BeginWriteObjectData
1189 //=======================================================================
1191 void FSD_CmpFile::BeginWriteObjectData()
1193 if (myStream.bad()) Storage_StreamWriteError::Raise();
1196 //=======================================================================
1197 //function : EndWriteObjectData
1199 //=======================================================================
1201 void FSD_CmpFile::EndWriteObjectData()
1203 if (myStream.bad()) Storage_StreamWriteError::Raise();
1206 //=======================================================================
1207 //function : EndWritePersistentObjectData
1209 //=======================================================================
1211 void FSD_CmpFile::EndWritePersistentObjectData()
1213 if (myStream.bad()) Storage_StreamWriteError::Raise();
1216 //=======================================================================
1217 //function : EndWriteDataSection
1219 //=======================================================================
1221 Storage_Error FSD_CmpFile::EndWriteDataSection()
1223 myStream << "\nEND_DATA_SECTION\n";
1224 if (myStream.bad()) Storage_StreamWriteError::Raise();
1225 return Storage_VSOk;
1228 //=======================================================================
1229 //function : BeginReadDataSection
1230 //purpose : ---------------------- DATA : READ
1231 //=======================================================================
1233 Storage_Error FSD_CmpFile::BeginReadDataSection()
1235 return FindTag("BEGIN_DATA_SECTION");
1238 //=======================================================================
1239 //function : ReadPersistentObjectHeader
1241 //=======================================================================
1243 void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
1244 Standard_Integer& aType)
1251 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1252 Storage_StreamFormatError::Raise();
1257 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1262 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1263 Storage_StreamFormatError::Raise();
1268 if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
1269 // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
1272 //=======================================================================
1273 //function : BeginReadPersistentObjectData
1275 //=======================================================================
1277 void FSD_CmpFile::BeginReadPersistentObjectData()
1279 //cout << "BeginReadPersistentObjectData" << endl;
1282 //=======================================================================
1283 //function : BeginReadObjectData
1285 //=======================================================================
1287 void FSD_CmpFile::BeginReadObjectData()
1289 // cout << "BeginReadObjectData" << endl;
1292 //=======================================================================
1293 //function : EndReadObjectData
1295 //=======================================================================
1297 void FSD_CmpFile::EndReadObjectData()
1299 // cout << "EndReadObjectData" << endl;
1302 //=======================================================================
1303 //function : EndReadPersistentObjectData
1305 //=======================================================================
1307 void FSD_CmpFile::EndReadPersistentObjectData()
1312 while (c != '\n' && (c != '\r')) {
1313 if (IsEnd() || (c != ' ')) {
1314 Storage_StreamFormatError::Raise();
1321 // cout << "EndReadPersistentObjectData" << endl;
1324 //=======================================================================
1325 //function : EndReadDataSection
1327 //=======================================================================
1329 Storage_Error FSD_CmpFile::EndReadDataSection()
1331 return FindTag("END_DATA_SECTION");
1334 //=======================================================================
1336 //purpose : return position in the file. Return -1 upon error.
1337 //=======================================================================
1339 Storage_Position FSD_CmpFile::Tell()
1341 switch (OpenMode()) {
1342 case Storage_VSRead:
1343 return (Storage_Position) myStream.tellp();
1344 case Storage_VSWrite:
1345 return (Storage_Position) myStream.tellg();
1346 case Storage_VSReadWrite: {
1347 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1348 Storage_Position aPosW = (Storage_Position) myStream.tellg();