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 << 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)
578 char realbuffer[100];
580 realbuffer[0] = '\0';
581 if (!(myStream >> realbuffer)) {
583 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
584 cerr << "\t buffer is" << realbuffer<< endl;
586 Storage_StreamTypeMismatchError::Raise();
588 if (!OSD::CStringToReal(realbuffer,aValue)) {
590 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
591 cerr << "\t buffer is" << realbuffer<< endl;
593 Storage_StreamTypeMismatchError::Raise();
599 //=======================================================================
600 //function : GetShortReal
602 //=======================================================================
604 Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
606 char realbuffer[100];
607 Standard_Real r = 0.0;
609 realbuffer[0] = '\0';
610 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
611 if (!OSD::CStringToReal(realbuffer,r))
612 Storage_StreamTypeMismatchError::Raise();
614 aValue = (Standard_ShortReal)r;
619 //=======================================================================
622 //=======================================================================
624 void FSD_CmpFile::Destroy()
626 if (OpenMode() != Storage_VSNone) {
631 //=======================================================================
632 //function : BeginWriteInfoSection
633 //purpose : -------------------------- INFO : WRITE
634 //=======================================================================
636 Storage_Error FSD_CmpFile::BeginWriteInfoSection()
638 myStream << FSD_CmpFile::MagicNumber() << '\n';
639 myStream << "BEGIN_INFO_SECTION\n";
640 if (myStream.bad()) Storage_StreamWriteError::Raise();
645 //=======================================================================
646 //function : WriteInfo
648 //=======================================================================
650 void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
651 const TCollection_AsciiString& dbVersion,
652 const TCollection_AsciiString& date,
653 const TCollection_AsciiString& schemaName,
654 const TCollection_AsciiString& schemaVersion,
655 const TCollection_ExtendedString& appName,
656 const TCollection_AsciiString& appVersion,
657 const TCollection_ExtendedString& dataType,
658 const TColStd_SequenceOfAsciiString& userInfo)
664 myStream << dbVersion.ToCString() << "\n";
665 myStream << date.ToCString() << "\n";
666 myStream << schemaName.ToCString() << "\n";
667 myStream << schemaVersion.ToCString() << "\n";
668 WriteExtendedLine(appName);
669 myStream << appVersion.ToCString() << "\n";
670 WriteExtendedLine(dataType);
671 myStream << userInfo.Length() << "\n";
673 if (myStream.bad()) Storage_StreamWriteError::Raise();
675 for (i = 1; i <= userInfo.Length(); i++) {
676 myStream << userInfo.Value(i).ToCString() << "\n";
677 if (myStream.bad()) Storage_StreamWriteError::Raise();
681 //=======================================================================
682 //function : EndWriteInfoSection
684 //=======================================================================
686 Storage_Error FSD_CmpFile::EndWriteInfoSection()
688 myStream << "END_INFO_SECTION\n";
689 if (myStream.bad()) Storage_StreamWriteError::Raise();
693 //=======================================================================
694 //function : BeginReadInfoSection
696 //=======================================================================
698 Storage_Error FSD_CmpFile::BeginReadInfoSection()
701 TCollection_AsciiString l;
702 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
706 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
707 s = Storage_VSFormatError;
710 s = FindTag("BEGIN_INFO_SECTION");
716 //=======================================================================
717 //function : ReadInfo
718 //purpose : ------------------- INFO : READ
719 //=======================================================================
721 void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
722 TCollection_AsciiString& dbVersion,
723 TCollection_AsciiString& date,
724 TCollection_AsciiString& schemaName,
725 TCollection_AsciiString& schemaVersion,
726 TCollection_ExtendedString& appName,
727 TCollection_AsciiString& appVersion,
728 TCollection_ExtendedString& dataType,
729 TColStd_SequenceOfAsciiString& userInfo)
731 if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
737 ReadLine(schemaName);
738 ReadLine(schemaVersion);
739 ReadExtendedLine(appName);
740 ReadLine(appVersion);
741 ReadExtendedLine(dataType);
743 Standard_Integer i,len = 0;
745 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
749 TCollection_AsciiString line;
751 for (i = 1; i <= len && !IsEnd(); i++) {
753 userInfo.Append(line);
758 //=======================================================================
759 //function : ReadCompleteInfo
762 //=======================================================================
763 void FSD_CmpFile::ReadCompleteInfo( Standard_IStream& /*theIStream*/, Handle(Storage_Data)& /*theData*/)
768 //=======================================================================
769 //function : EndReadInfoSection
770 //purpose : COMMENTS SECTION
772 //=======================================================================
774 Storage_Error FSD_CmpFile::EndReadInfoSection()
776 return FindTag("END_INFO_SECTION");
779 //=======================================================================
780 //function : BeginWriteCommentSection
781 //purpose : ---------------- COMMENTS : WRITE
782 //=======================================================================
784 Storage_Error FSD_CmpFile::BeginWriteCommentSection()
786 myStream << "BEGIN_COMMENT_SECTION\n";
787 if (myStream.bad()) Storage_StreamWriteError::Raise();
791 //=======================================================================
792 //function : WriteComment
794 //=======================================================================
796 void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
798 Standard_Integer i,aSize;
800 aSize = aCom.Length();
801 myStream << aSize << "\n";
802 if (myStream.bad()) Storage_StreamWriteError::Raise();
804 for (i = 1; i <= aSize; i++) {
805 WriteExtendedLine(aCom.Value(i));
806 if (myStream.bad()) Storage_StreamWriteError::Raise();
810 //=======================================================================
811 //function : EndWriteCommentSection
813 //=======================================================================
815 Storage_Error FSD_CmpFile::EndWriteCommentSection()
817 myStream << "END_COMMENT_SECTION\n";
818 if (myStream.bad()) Storage_StreamWriteError::Raise();
822 //=======================================================================
823 //function : BeginReadCommentSection
824 //purpose : ---------------- COMMENTS : READ
825 //=======================================================================
827 Storage_Error FSD_CmpFile::BeginReadCommentSection()
829 return FindTag("BEGIN_COMMENT_SECTION");
832 //=======================================================================
833 //function : ReadComment
835 //=======================================================================
837 void FSD_CmpFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
839 TCollection_ExtendedString line;
840 Standard_Integer len,i;
842 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
846 for (i = 1; i <= len && !IsEnd(); i++) {
847 ReadExtendedLine(line);
853 //=======================================================================
854 //function : EndReadCommentSection
856 //=======================================================================
858 Storage_Error FSD_CmpFile::EndReadCommentSection()
860 return FindTag("END_COMMENT_SECTION");
863 //=======================================================================
864 //function : BeginWriteTypeSection
865 //purpose : --------------- TYPE : WRITE
866 //=======================================================================
868 Storage_Error FSD_CmpFile::BeginWriteTypeSection()
870 myStream << "BEGIN_TYPE_SECTION\n";
871 if (myStream.bad()) Storage_StreamWriteError::Raise();
875 //=======================================================================
876 //function : SetTypeSectionSize
878 //=======================================================================
880 void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
882 myStream << aSize << "\n";
883 if (myStream.bad()) Storage_StreamWriteError::Raise();
886 //=======================================================================
887 //function : WriteTypeInformations
889 //=======================================================================
891 void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
892 const TCollection_AsciiString& typeName)
894 myStream << typeNum << " " << typeName.ToCString() << "\n";
895 if (myStream.bad()) Storage_StreamWriteError::Raise();
898 //=======================================================================
899 //function : EndWriteTypeSection
901 //=======================================================================
903 Storage_Error FSD_CmpFile::EndWriteTypeSection()
905 myStream << "END_TYPE_SECTION\n";
906 if (myStream.bad()) Storage_StreamWriteError::Raise();
910 //=======================================================================
911 //function : BeginReadTypeSection
912 //purpose : ------------------- TYPE : READ
913 //=======================================================================
915 Storage_Error FSD_CmpFile::BeginReadTypeSection()
917 return FindTag("BEGIN_TYPE_SECTION");
920 //=======================================================================
921 //function : TypeSectionSize
923 //=======================================================================
925 Standard_Integer FSD_CmpFile::TypeSectionSize()
929 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
936 //=======================================================================
937 //function : ReadTypeInformations
939 //=======================================================================
941 void FSD_CmpFile::ReadTypeInformations(Standard_Integer& typeNum,
942 TCollection_AsciiString& typeName)
944 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
945 if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
949 //=======================================================================
950 //function : EndReadTypeSection
951 //purpose : ROOT SECTION
953 //=======================================================================
955 Storage_Error FSD_CmpFile::EndReadTypeSection()
957 return FindTag("END_TYPE_SECTION");
960 //=======================================================================
961 //function : BeginWriteRootSection
962 //purpose : -------------------- ROOT : WRITE
963 //=======================================================================
965 Storage_Error FSD_CmpFile::BeginWriteRootSection()
967 myStream << "BEGIN_ROOT_SECTION\n";
968 if (myStream.bad()) Storage_StreamWriteError::Raise();
972 //=======================================================================
973 //function : SetRootSectionSize
975 //=======================================================================
977 void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
979 myStream << aSize << "\n";
980 if (myStream.bad()) Storage_StreamWriteError::Raise();
983 //=======================================================================
984 //function : WriteRoot
986 //=======================================================================
988 void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
990 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
991 if (myStream.bad()) Storage_StreamWriteError::Raise();
994 //=======================================================================
995 //function : EndWriteRootSection
997 //=======================================================================
999 Storage_Error FSD_CmpFile::EndWriteRootSection()
1001 myStream << "END_ROOT_SECTION\n";
1002 if (myStream.bad()) Storage_StreamWriteError::Raise();
1003 return Storage_VSOk;
1006 //=======================================================================
1007 //function : BeginReadRootSection
1008 //purpose : ----------------------- ROOT : READ
1009 //=======================================================================
1011 Storage_Error FSD_CmpFile::BeginReadRootSection()
1013 return FindTag("BEGIN_ROOT_SECTION");
1016 //=======================================================================
1017 //function : RootSectionSize
1019 //=======================================================================
1021 Standard_Integer FSD_CmpFile::RootSectionSize()
1025 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1032 //=======================================================================
1033 //function : ReadRoot
1035 //=======================================================================
1037 void FSD_CmpFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1039 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1044 //=======================================================================
1045 //function : EndReadRootSection
1046 //purpose : REF SECTION
1048 //=======================================================================
1050 Storage_Error FSD_CmpFile::EndReadRootSection()
1052 return FindTag("END_ROOT_SECTION");
1055 //=======================================================================
1056 //function : BeginWriteRefSection
1057 //purpose : -------------------------- REF : WRITE
1058 //=======================================================================
1060 Storage_Error FSD_CmpFile::BeginWriteRefSection()
1062 myStream << "BEGIN_REF_SECTION\n";
1063 if (myStream.bad()) Storage_StreamWriteError::Raise();
1064 return Storage_VSOk;
1067 //=======================================================================
1068 //function : SetRefSectionSize
1070 //=======================================================================
1072 void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
1074 myStream << aSize << "\n";
1075 if (myStream.bad()) Storage_StreamWriteError::Raise();
1078 //=======================================================================
1079 //function : WriteReferenceType
1081 //=======================================================================
1083 void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
1084 const Standard_Integer typeNum)
1086 myStream << reference << " " << typeNum << "\n";
1087 if (myStream.bad()) Storage_StreamWriteError::Raise();
1090 //=======================================================================
1091 //function : EndWriteRefSection
1093 //=======================================================================
1095 Storage_Error FSD_CmpFile::EndWriteRefSection()
1097 myStream << "END_REF_SECTION\n";
1098 if (myStream.bad()) Storage_StreamWriteError::Raise();
1099 return Storage_VSOk;
1102 //=======================================================================
1103 //function : BeginReadRefSection
1104 //purpose : ----------------------- REF : READ
1105 //=======================================================================
1107 Storage_Error FSD_CmpFile::BeginReadRefSection()
1109 return FindTag("BEGIN_REF_SECTION");
1112 //=======================================================================
1113 //function : RefSectionSize
1115 //=======================================================================
1117 Standard_Integer FSD_CmpFile::RefSectionSize()
1121 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1127 //=======================================================================
1128 //function : ReadReferenceType
1130 //=======================================================================
1132 void FSD_CmpFile::ReadReferenceType(Standard_Integer& reference,
1133 Standard_Integer& typeNum)
1135 if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
1136 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1140 //=======================================================================
1141 //function : EndReadRefSection
1142 //purpose : DATA SECTION
1144 //=======================================================================
1146 Storage_Error FSD_CmpFile::EndReadRefSection()
1148 return FindTag("END_REF_SECTION");
1151 //=======================================================================
1152 //function : BeginWriteDataSection
1153 //purpose : -------------------- DATA : WRITE
1154 //=======================================================================
1156 Storage_Error FSD_CmpFile::BeginWriteDataSection()
1158 myStream << "BEGIN_DATA_SECTION";
1159 if (myStream.bad()) Storage_StreamWriteError::Raise();
1160 return Storage_VSOk;
1163 //=======================================================================
1164 //function : WritePersistentObjectHeader
1166 //=======================================================================
1168 void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
1169 const Standard_Integer aType)
1171 myStream << "\n#" << aRef << "%" << aType << " ";
1172 if (myStream.bad()) Storage_StreamWriteError::Raise();
1175 //=======================================================================
1176 //function : BeginWritePersistentObjectData
1178 //=======================================================================
1180 void FSD_CmpFile::BeginWritePersistentObjectData()
1182 if (myStream.bad()) Storage_StreamWriteError::Raise();
1185 //=======================================================================
1186 //function : BeginWriteObjectData
1188 //=======================================================================
1190 void FSD_CmpFile::BeginWriteObjectData()
1192 if (myStream.bad()) Storage_StreamWriteError::Raise();
1195 //=======================================================================
1196 //function : EndWriteObjectData
1198 //=======================================================================
1200 void FSD_CmpFile::EndWriteObjectData()
1202 if (myStream.bad()) Storage_StreamWriteError::Raise();
1205 //=======================================================================
1206 //function : EndWritePersistentObjectData
1208 //=======================================================================
1210 void FSD_CmpFile::EndWritePersistentObjectData()
1212 if (myStream.bad()) Storage_StreamWriteError::Raise();
1215 //=======================================================================
1216 //function : EndWriteDataSection
1218 //=======================================================================
1220 Storage_Error FSD_CmpFile::EndWriteDataSection()
1222 myStream << "\nEND_DATA_SECTION\n";
1223 if (myStream.bad()) Storage_StreamWriteError::Raise();
1224 return Storage_VSOk;
1227 //=======================================================================
1228 //function : BeginReadDataSection
1229 //purpose : ---------------------- DATA : READ
1230 //=======================================================================
1232 Storage_Error FSD_CmpFile::BeginReadDataSection()
1234 return FindTag("BEGIN_DATA_SECTION");
1237 //=======================================================================
1238 //function : ReadPersistentObjectHeader
1240 //=======================================================================
1242 void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
1243 Standard_Integer& aType)
1250 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1251 Storage_StreamFormatError::Raise();
1256 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1261 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1262 Storage_StreamFormatError::Raise();
1267 if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
1268 // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
1271 //=======================================================================
1272 //function : BeginReadPersistentObjectData
1274 //=======================================================================
1276 void FSD_CmpFile::BeginReadPersistentObjectData()
1278 //cout << "BeginReadPersistentObjectData" << endl;
1281 //=======================================================================
1282 //function : BeginReadObjectData
1284 //=======================================================================
1286 void FSD_CmpFile::BeginReadObjectData()
1288 // cout << "BeginReadObjectData" << endl;
1291 //=======================================================================
1292 //function : EndReadObjectData
1294 //=======================================================================
1296 void FSD_CmpFile::EndReadObjectData()
1298 // cout << "EndReadObjectData" << endl;
1301 //=======================================================================
1302 //function : EndReadPersistentObjectData
1304 //=======================================================================
1306 void FSD_CmpFile::EndReadPersistentObjectData()
1311 while (c != '\n' && (c != '\r')) {
1312 if (IsEnd() || (c != ' ')) {
1313 Storage_StreamFormatError::Raise();
1320 // cout << "EndReadPersistentObjectData" << endl;
1323 //=======================================================================
1324 //function : EndReadDataSection
1326 //=======================================================================
1328 Storage_Error FSD_CmpFile::EndReadDataSection()
1330 return FindTag("END_DATA_SECTION");
1333 //=======================================================================
1335 //purpose : return position in the file. Return -1 upon error.
1336 //=======================================================================
1338 Storage_Position FSD_CmpFile::Tell()
1340 switch (OpenMode()) {
1341 case Storage_VSRead:
1342 return (Storage_Position) myStream.tellp();
1343 case Storage_VSWrite:
1344 return (Storage_Position) myStream.tellg();
1345 case Storage_VSReadWrite: {
1346 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1347 Storage_Position aPosW = (Storage_Position) myStream.tellg();