1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
19 //Version Date Purpose
20 // 0.0 Aug 22 1997 Creation
22 #include <Standard_Stream.hxx>
24 #include <DDF_IOStream.hxx>
26 // This file has been written using FSD_File.cxx as template.
27 // This is a specific adaptation for Draw use (save & restore commands).
28 // It is not sure at all this code is portable on any other plateform than
29 // SUN OS. Don't use it anywhere else.
30 // Thanks for comprehension. (22 august 97)
33 #include <Storage_StreamTypeMismatchError.hxx>
34 #include <Storage_StreamFormatError.hxx>
35 #include <Storage_StreamWriteError.hxx>
36 #include <Storage_StreamExtCharParityError.hxx>
38 #include <TCollection_AsciiString.hxx>
39 #include <TCollection_ExtendedString.hxx>
41 #include <TColStd_SequenceOfAsciiString.hxx>
42 #include <TColStd_SequenceOfExtendedString.hxx>
44 const Standard_CString MAGICNUMBER = "FSDFILE";
47 //=======================================================================
48 //function : DDF_IOStream
50 //=======================================================================
52 DDF_IOStream::DDF_IOStream() :
57 //=======================================================================
60 //=======================================================================
62 Storage_Error DDF_IOStream::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
66 //return Storage_VSOk;
68 Storage_Error result = Storage_VSOk;
72 if (OpenMode() == Storage_VSNone) {
73 if (aMode == Storage_VSRead) {
74 if (myIStream != NULL) delete myIStream;
75 myIStream = new ifstream(aName.ToCString(),ios::in); // ios::nocreate is not portable
76 if (myIStream->fail()) {
77 result = Storage_VSOpenError;
80 myIStream->precision(17);
81 myIStream->imbue (std::locale::classic()); // always use C locale
85 else if (aMode == Storage_VSWrite) {
86 if (myOStream != NULL) delete myOStream;
87 myOStream = new ofstream(aName.ToCString(),ios::out);
88 if (myOStream->fail()) {
89 result = Storage_VSOpenError;
92 myOStream->precision(17);
93 myOStream->imbue (std::locale::classic()); // make sure to always use C locale
99 result = Storage_VSAlreadyOpen;
105 //=======================================================================
107 //purpose : "Opens" an istream.
108 //=======================================================================
110 Storage_Error DDF_IOStream::Open(istream* anIStream)
113 SetOpenMode(Storage_VSRead);
114 myIStream = anIStream;
115 myIStream->precision(17);
116 myIStream->imbue (std::locale::classic()); // use always C locale
117 SetName("DDF_IOStream");
118 return Storage_VSOk; // ou Storage_VSAlreadyOpen ?
121 //=======================================================================
123 //purpose : "Opens" an ostream.
124 //=======================================================================
126 Storage_Error DDF_IOStream::Open(ostream* anOStream)
129 SetOpenMode(Storage_VSWrite);
130 myOStream = anOStream;
131 myOStream->precision(17);
132 myOStream->imbue (std::locale::classic()); // use always C locale
133 SetName("DDF_IOStream");
134 return Storage_VSOk; // ou Storage_VSAlreadyOpen ?
137 //=======================================================================
140 //=======================================================================
142 Standard_Boolean DDF_IOStream::IsEnd()
144 if (OpenMode() == Storage_VSRead) return myIStream->eof();
145 else return myOStream->eof();
148 //=======================================================================
151 //=======================================================================
153 Storage_Error DDF_IOStream::Close()
154 { return Storage_VSOk; }
157 // ------------------ PROTECTED
160 //=======================================================================
161 //function : MagicNumber
163 //=======================================================================
165 const Standard_CString DDF_IOStream::MagicNumber()
166 { return MAGICNUMBER; }
168 //=======================================================================
169 //function : FlushEndOfLine
171 //=======================================================================
173 void DDF_IOStream::FlushEndOfLine()
175 static char Buffer[8192];
177 Standard_Boolean IsEnd = Standard_False;
179 while (!IsEnd && !DDF_IOStream::IsEnd()) {
181 myIStream->get(Buffer,8192,'\n');
183 if (myIStream->get(c) && c != '\n') {
186 IsEnd = Standard_True;
191 //=======================================================================
192 //function : ReadLine
194 //=======================================================================
196 void DDF_IOStream::ReadLine(TCollection_AsciiString& buffer)
198 static char Buffer[8193];
200 Standard_Boolean IsEnd = Standard_False;
204 while (!IsEnd && !DDF_IOStream::IsEnd()) {
206 myIStream->get(Buffer,8192,'\n');
208 if (myIStream->get(c) && c != '\n') {
214 IsEnd = Standard_True;
220 //=======================================================================
221 //function : WriteExtendedLine
223 //=======================================================================
225 void DDF_IOStream::WriteExtendedLine(const TCollection_ExtendedString& buffer)
227 Standard_ExtString extBuffer;
228 Standard_Integer i,c,d;
230 extBuffer = buffer.ToExtString();
232 for (i = 0; i < buffer.Length(); i++) {
233 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
234 d = extBuffer[i] & 0x000000FF;
236 *myOStream << (char)c << (char)d;
239 *myOStream << (char)0 << "\n";
242 //=======================================================================
243 //function : ReadExtendedLine
245 //=======================================================================
247 void DDF_IOStream::ReadExtendedLine(TCollection_ExtendedString& buffer)
250 Standard_ExtCharacter i = 0,j,check = 0;
251 Standard_Boolean fin = Standard_False;
255 while (!fin && !IsEnd()) {
258 // if (!(check % 2)) Storage_StreamExtCharParityError::Raise();
259 i = (Standard_ExtCharacter)c;
260 if (c == '\0') fin = Standard_True;
265 // if ((check % 2) != 0) Storage_StreamExtCharParityError::Raise();
266 // cout << check << endl;
267 j = (Standard_ExtCharacter)c;
268 if (c != '\n') fin = Standard_False;
270 buffer += (Standard_ExtCharacter)i;
273 // if ((check % 2) != 0) Storage_StreamExtCharParityError::Raise();
274 // cout << check << endl;
277 //=======================================================================
278 //function : ReadChar
280 //=======================================================================
282 void DDF_IOStream::ReadChar(TCollection_AsciiString& buffer, const Standard_Integer rsize)
285 Standard_Integer ccount = 0;
289 while (!IsEnd() && (ccount < rsize)) {
296 //=======================================================================
297 //function : ReadString
299 //=======================================================================
301 void DDF_IOStream::ReadString(TCollection_AsciiString& buffer)
304 Standard_Boolean IsEnd = Standard_False;
308 while (!IsEnd && !DDF_IOStream::IsEnd()) {
310 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
313 IsEnd = Standard_False;
315 while (!IsEnd && !DDF_IOStream::IsEnd()) {
318 if (c == '\n') IsEnd = Standard_True;
322 //=======================================================================
323 //function : ReadWord
325 //=======================================================================
327 void DDF_IOStream::ReadWord(TCollection_AsciiString& buffer)
330 Standard_Boolean IsEnd = Standard_False;
334 while (!IsEnd && !DDF_IOStream::IsEnd()) {
336 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
339 IsEnd = Standard_False;
341 while (!IsEnd && !DDF_IOStream::IsEnd()) {
344 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
348 //=======================================================================
351 //=======================================================================
353 Storage_Error DDF_IOStream::FindTag(const Standard_CString aTag)
355 TCollection_AsciiString l;
359 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
364 return Storage_VSSectionNotFound;
371 //=======================================================================
372 //function : SkipObject
374 //=======================================================================
376 void DDF_IOStream::SkipObject()
382 // ---------------------- PUBLIC : PUT
385 //=======================================================================
386 //function : PutReference
388 //=======================================================================
390 Storage_BaseDriver& DDF_IOStream::PutReference(const Standard_Integer aValue)
392 *myOStream << aValue << " ";
393 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutReference");
397 //=======================================================================
398 //function : PutCharacter
400 //=======================================================================
402 Storage_BaseDriver& DDF_IOStream::PutCharacter(const Standard_Character aValue)
404 *myOStream << aValue << " ";
405 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutCharacter");
409 //=======================================================================
410 //function : PutExtCharacter
412 //=======================================================================
414 Storage_BaseDriver& DDF_IOStream::PutExtCharacter(const Standard_ExtCharacter aValue)
416 *myOStream << aValue << " ";
417 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutExtCharacter");
421 //=======================================================================
422 //function : PutInteger
424 //=======================================================================
426 Storage_BaseDriver& DDF_IOStream::PutInteger(const Standard_Integer aValue)
428 *myOStream << aValue << " ";
429 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutInteger");
433 //=======================================================================
434 //function : PutBoolean
436 //=======================================================================
438 Storage_BaseDriver& DDF_IOStream::PutBoolean(const Standard_Boolean aValue)
440 *myOStream << ((Standard_Integer)aValue) << " ";
441 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutBoolean");
445 //=======================================================================
448 //=======================================================================
450 Storage_BaseDriver& DDF_IOStream::PutReal(const Standard_Real aValue)
452 *myOStream << ((Standard_Real)aValue) << " ";
453 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutReal");
457 //=======================================================================
458 //function : PutShortReal
460 //=======================================================================
462 Storage_BaseDriver& DDF_IOStream::PutShortReal(const Standard_ShortReal aValue)
464 *myOStream << aValue << " ";
465 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutShortReal");
470 // ----------------- PUBLIC : GET
473 //=======================================================================
474 //function : GetReference
476 //=======================================================================
478 Storage_BaseDriver& DDF_IOStream::GetReference(Standard_Integer& aValue)
480 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetReference");
484 //=======================================================================
485 //function : GetCharacter
487 //=======================================================================
489 Storage_BaseDriver& DDF_IOStream::GetCharacter(Standard_Character& aValue)
491 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetCharacter");
495 //=======================================================================
496 //function : GetExtCharacter
498 //=======================================================================
500 Storage_BaseDriver& DDF_IOStream::GetExtCharacter(Standard_ExtCharacter& aValue)
502 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetExtCharacter");
506 //=======================================================================
507 //function : GetInteger
509 //=======================================================================
511 Storage_BaseDriver& DDF_IOStream::GetInteger(Standard_Integer& aValue)
513 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetInteger");
517 //=======================================================================
518 //function : GetBoolean
520 //=======================================================================
522 Storage_BaseDriver& DDF_IOStream::GetBoolean(Standard_Boolean& aValue)
524 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetBoolean");
528 //=======================================================================
531 //=======================================================================
533 Storage_BaseDriver& DDF_IOStream::GetReal(Standard_Real& aValue)
535 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetReal");
539 //=======================================================================
540 //function : GetShortReal
542 //=======================================================================
544 Storage_BaseDriver& DDF_IOStream::GetShortReal(Standard_ShortReal& aValue)
546 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetShortReal");
550 // -------------------------- DESTROY
552 //=======================================================================
555 //=======================================================================
557 void DDF_IOStream::Destroy()
559 if (OpenMode() != Storage_VSNone) Close();
563 // -------------------------- INFO : WRITE
566 //=======================================================================
567 //function : BeginWriteInfoSection
569 //=======================================================================
571 Storage_Error DDF_IOStream::BeginWriteInfoSection()
573 *myOStream << DDF_IOStream::MagicNumber() << '\n';
574 *myOStream << "BEGIN_INFO_SECTION\n";
575 if (myOStream->bad()) Storage_StreamWriteError::Raise();
580 //=======================================================================
581 //function : WriteInfo
583 //=======================================================================
585 void DDF_IOStream::WriteInfo(const Standard_Integer nbObj,
586 const TCollection_AsciiString& dbVersion,
587 const TCollection_AsciiString& date,
588 const TCollection_AsciiString& schemaName,
589 const TCollection_AsciiString& schemaVersion,
590 const TCollection_ExtendedString& appName,
591 const TCollection_AsciiString& appVersion,
592 const TCollection_ExtendedString& dataType,
593 const TColStd_SequenceOfAsciiString& userInfo)
600 *myOStream << dbVersion.ToCString() << "\n";
601 *myOStream << date.ToCString() << "\n";
602 *myOStream << schemaName.ToCString() << "\n";
603 *myOStream << schemaVersion.ToCString() << "\n";
604 WriteExtendedLine(appName);
605 *myOStream << appVersion.ToCString() << "\n";
606 WriteExtendedLine(dataType);
607 *myOStream << userInfo.Length() << "\n";
609 if (myOStream->bad()) Storage_StreamWriteError::Raise();
611 for (i = 1; i <= userInfo.Length(); i++) {
612 *myOStream << userInfo.Value(i).ToCString() << "\n";
613 if (myOStream->bad()) Storage_StreamWriteError::Raise();
618 //=======================================================================
619 //function : EndWriteInfoSection
621 //=======================================================================
623 Storage_Error DDF_IOStream::EndWriteInfoSection()
625 *myOStream << "END_INFO_SECTION\n";
626 if (myOStream->bad()) Storage_StreamWriteError::Raise();
630 //=======================================================================
631 //function : BeginReadInfoSection
633 //=======================================================================
635 Storage_Error DDF_IOStream::BeginReadInfoSection()
638 TCollection_AsciiString l;
639 Standard_Integer len = (Standard_Integer) strlen(DDF_IOStream::MagicNumber());
641 // Added because of Draw:
642 // It don't go to next line after reading its own header line information!
646 if (strncmp(DDF_IOStream::MagicNumber(),l.ToCString(),len) != 0) {
648 cout<<"BeginReadInfoSection: format error"<<endl;
650 s = Storage_VSFormatError;
653 s = FindTag("BEGIN_INFO_SECTION");
660 // ------------------- INFO : READ
663 //=======================================================================
664 //function : ReadInfo
666 //=======================================================================
668 void DDF_IOStream::ReadInfo(Standard_Integer& nbObj,
669 TCollection_AsciiString& dbVersion,
670 TCollection_AsciiString& date,
671 TCollection_AsciiString& schemaName,
672 TCollection_AsciiString& schemaVersion,
673 TCollection_ExtendedString& appName,
674 TCollection_AsciiString& appVersion,
675 TCollection_ExtendedString& dataType,
676 TColStd_SequenceOfAsciiString& userInfo)
678 if (!(*myIStream >> nbObj)) Storage_StreamTypeMismatchError::Raise("ReadInfo 1");
684 ReadLine(schemaName);
685 ReadLine(schemaVersion);
686 ReadExtendedLine(appName);
687 ReadLine(appVersion);
688 ReadExtendedLine(dataType);
690 Standard_Integer i,len = 0;
692 if (!(*myIStream >> len)) Storage_StreamTypeMismatchError::Raise("ReadInfo 2");
696 TCollection_AsciiString line;
698 for (i = 1; i <= len && !IsEnd(); i++) {
700 userInfo.Append(line);
705 //=======================================================================
706 //function : EndReadInfoSection
708 //=======================================================================
710 Storage_Error DDF_IOStream::EndReadInfoSection()
711 { return FindTag("END_INFO_SECTION"); }
714 // ---------------- COMMENTS : WRITE
717 //=======================================================================
718 //function : BeginWriteCommentSection
720 //=======================================================================
722 Storage_Error DDF_IOStream::BeginWriteCommentSection()
724 *myOStream << "BEGIN_COMMENT_SECTION\n";
725 if (myOStream->bad()) Storage_StreamWriteError::Raise();
729 //=======================================================================
730 //function : WriteComment
732 //=======================================================================
734 void DDF_IOStream::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
736 Standard_Integer i,aSize;
738 aSize = aCom.Length();
739 *myOStream << aSize << "\n";
740 if (myOStream->bad()) Storage_StreamWriteError::Raise();
742 for (i = 1; i <= aSize; i++) {
743 WriteExtendedLine(aCom.Value(i));
744 if (myOStream->bad()) Storage_StreamWriteError::Raise();
748 //=======================================================================
749 //function : EndWriteCommentSection
751 //=======================================================================
753 Storage_Error DDF_IOStream::EndWriteCommentSection()
755 *myOStream << "END_COMMENT_SECTION\n";
756 if (myOStream->bad()) Storage_StreamWriteError::Raise();
761 // ---------------- COMMENTS : READ
764 //=======================================================================
765 //function : BeginReadCommentSection
767 //=======================================================================
769 Storage_Error DDF_IOStream::BeginReadCommentSection()
771 return FindTag("BEGIN_COMMENT_SECTION");
774 //=======================================================================
775 //function : ReadComment
777 //=======================================================================
779 void DDF_IOStream::ReadComment(TColStd_SequenceOfExtendedString& aCom)
781 TCollection_ExtendedString line;
782 Standard_Integer len,i;
784 if (!(*myIStream >> len)) Storage_StreamTypeMismatchError::Raise("ReadComment");
788 for (i = 1; i <= len && !IsEnd(); i++) {
789 ReadExtendedLine(line);
795 //=======================================================================
796 //function : EndReadCommentSection
798 //=======================================================================
800 Storage_Error DDF_IOStream::EndReadCommentSection()
801 { return FindTag("END_COMMENT_SECTION"); }
804 // --------------- TYPE : WRITE
807 //=======================================================================
808 //function : BeginWriteTypeSection
810 //=======================================================================
812 Storage_Error DDF_IOStream::BeginWriteTypeSection()
814 *myOStream << "BEGIN_TYPE_SECTION\n";
815 if (myOStream->bad()) Storage_StreamWriteError::Raise();
819 //=======================================================================
820 //function : SetTypeSectionSize
822 //=======================================================================
824 void DDF_IOStream::SetTypeSectionSize(const Standard_Integer aSize)
826 *myOStream << aSize << "\n";
827 if (myOStream->bad()) Storage_StreamWriteError::Raise();
830 //=======================================================================
831 //function : WriteTypeInformations
833 //=======================================================================
835 void DDF_IOStream::WriteTypeInformations(const Standard_Integer typeNum,
836 const TCollection_AsciiString& typeName)
838 *myOStream << typeNum << " " << typeName.ToCString() << "\n";
839 if (myOStream->bad()) Storage_StreamWriteError::Raise();
842 //=======================================================================
843 //function : EndWriteTypeSection
845 //=======================================================================
847 Storage_Error DDF_IOStream::EndWriteTypeSection()
849 *myOStream << "END_TYPE_SECTION\n";
850 if (myOStream->bad()) Storage_StreamWriteError::Raise();
855 // ------------------- TYPE : READ
858 //=======================================================================
859 //function : BeginReadTypeSection
861 //=======================================================================
863 Storage_Error DDF_IOStream::BeginReadTypeSection()
864 { return FindTag("BEGIN_TYPE_SECTION"); }
866 //=======================================================================
867 //function : TypeSectionSize
869 //=======================================================================
871 Standard_Integer DDF_IOStream::TypeSectionSize()
875 if (!(*myIStream >> i)) Storage_StreamTypeMismatchError::Raise("TypeSectionSize");
882 //=======================================================================
883 //function : ReadTypeInformations
885 //=======================================================================
887 void DDF_IOStream::ReadTypeInformations(Standard_Integer& typeNum,
888 TCollection_AsciiString& typeName)
890 if (!(*myIStream >> typeNum)) Storage_StreamTypeMismatchError::Raise("ReadTypeInformations 1");
891 if (!(*myIStream >> typeName)) Storage_StreamTypeMismatchError::Raise("ReadTypeInformations 2");
895 //=======================================================================
896 //function : EndReadTypeSection
898 //=======================================================================
900 Storage_Error DDF_IOStream::EndReadTypeSection()
902 return FindTag("END_TYPE_SECTION");
906 // -------------------- ROOT : WRITE
909 //=======================================================================
910 //function : BeginWriteRootSection
912 //=======================================================================
914 Storage_Error DDF_IOStream::BeginWriteRootSection()
916 *myOStream << "BEGIN_ROOT_SECTION\n";
917 if (myOStream->bad()) Storage_StreamWriteError::Raise();
921 //=======================================================================
922 //function : SetRootSectionSize
924 //=======================================================================
926 void DDF_IOStream::SetRootSectionSize(const Standard_Integer aSize)
928 *myOStream << aSize << "\n";
929 if (myOStream->bad()) Storage_StreamWriteError::Raise();
932 //=======================================================================
933 //function : WriteRoot
935 //=======================================================================
937 void DDF_IOStream::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
939 *myOStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
940 if (myOStream->bad()) Storage_StreamWriteError::Raise();
943 //=======================================================================
944 //function : EndWriteRootSection
946 //=======================================================================
948 Storage_Error DDF_IOStream::EndWriteRootSection()
950 *myOStream << "END_ROOT_SECTION\n";
951 if (myOStream->bad()) Storage_StreamWriteError::Raise();
956 // ----------------------- ROOT : READ
959 //=======================================================================
960 //function : BeginReadRootSection
962 //=======================================================================
964 Storage_Error DDF_IOStream::BeginReadRootSection()
965 { return FindTag("BEGIN_ROOT_SECTION"); }
967 //=======================================================================
968 //function : RootSectionSize
970 //=======================================================================
972 Standard_Integer DDF_IOStream::RootSectionSize()
976 if (!(*myIStream >> i)) Storage_StreamTypeMismatchError::Raise("RootSectionSize");
983 //=======================================================================
984 //function : ReadRoot
986 //=======================================================================
988 void DDF_IOStream::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
990 if (!(*myIStream >> aRef)) Storage_StreamTypeMismatchError::Raise("ReadRoot");
995 //=======================================================================
996 //function : EndReadRootSection
998 //=======================================================================
1000 Storage_Error DDF_IOStream::EndReadRootSection()
1001 { return FindTag("END_ROOT_SECTION"); }
1004 // -------------------------- REF : WRITE
1007 //=======================================================================
1008 //function : BeginWriteRefSection
1010 //=======================================================================
1012 Storage_Error DDF_IOStream::BeginWriteRefSection()
1014 *myOStream << "BEGIN_REF_SECTION\n";
1015 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1016 return Storage_VSOk;
1019 //=======================================================================
1020 //function : SetRefSectionSize
1022 //=======================================================================
1024 void DDF_IOStream::SetRefSectionSize(const Standard_Integer aSize)
1026 *myOStream << aSize << "\n";
1027 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1030 //=======================================================================
1031 //function : WriteReferenceType
1033 //=======================================================================
1035 void DDF_IOStream::WriteReferenceType(const Standard_Integer reference,
1036 const Standard_Integer typeNum)
1038 *myOStream << reference << " " << typeNum << "\n";
1039 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1042 //=======================================================================
1043 //function : EndWriteRefSection
1045 //=======================================================================
1047 Storage_Error DDF_IOStream::EndWriteRefSection()
1049 *myOStream << "END_REF_SECTION\n";
1050 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1051 return Storage_VSOk;
1055 // ----------------------- REF : READ
1058 //=======================================================================
1059 //function : BeginReadRefSection
1061 //=======================================================================
1063 Storage_Error DDF_IOStream::BeginReadRefSection()
1064 { return FindTag("BEGIN_REF_SECTION"); }
1066 //=======================================================================
1067 //function : RefSectionSize
1069 //=======================================================================
1071 Standard_Integer DDF_IOStream::RefSectionSize()
1075 if (!(*myIStream >> i)) Storage_StreamTypeMismatchError::Raise("RefSectionSize");
1081 //=======================================================================
1082 //function : ReadReferenceType
1084 //=======================================================================
1086 void DDF_IOStream::ReadReferenceType(Standard_Integer& reference,
1087 Standard_Integer& typeNum)
1089 if (!(*myIStream >> reference)) Storage_StreamTypeMismatchError::Raise("ReadReferenceType 1");
1090 if (!(*myIStream >> typeNum)) Storage_StreamTypeMismatchError::Raise("ReadReferenceType 2");
1094 //=======================================================================
1095 //function : EndReadRefSection
1097 //=======================================================================
1099 Storage_Error DDF_IOStream::EndReadRefSection()
1101 return FindTag("END_REF_SECTION");
1105 // -------------------- DATA : WRITE
1108 //=======================================================================
1109 //function : BeginWriteDataSection
1111 //=======================================================================
1113 Storage_Error DDF_IOStream::BeginWriteDataSection()
1115 *myOStream << "BEGIN_DATA_SECTION";
1116 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1117 return Storage_VSOk;
1120 //=======================================================================
1121 //function : WritePersistentObjectHeader
1123 //=======================================================================
1125 void DDF_IOStream::WritePersistentObjectHeader(const Standard_Integer aRef,
1126 const Standard_Integer aType)
1128 *myOStream << "\n#" << aRef << "=%" << aType;
1129 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1132 //=======================================================================
1133 //function : BeginWritePersistentObjectData
1135 //=======================================================================
1137 void DDF_IOStream::BeginWritePersistentObjectData()
1140 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1143 //=======================================================================
1144 //function : BeginWriteObjectData
1146 //=======================================================================
1148 void DDF_IOStream::BeginWriteObjectData()
1151 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1154 //=======================================================================
1155 //function : EndWriteObjectData
1157 //=======================================================================
1159 void DDF_IOStream::EndWriteObjectData()
1162 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1165 //=======================================================================
1166 //function : EndWritePersistentObjectData
1168 //=======================================================================
1170 void DDF_IOStream::EndWritePersistentObjectData()
1173 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1176 //=======================================================================
1177 //function : EndWriteDataSection
1179 //=======================================================================
1181 Storage_Error DDF_IOStream::EndWriteDataSection()
1183 *myOStream << "\nEND_DATA_SECTION\n";
1184 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1185 return Storage_VSOk;
1189 // ---------------------- DATA : READ
1192 //=======================================================================
1193 //function : BeginReadDataSection
1195 //=======================================================================
1197 Storage_Error DDF_IOStream::BeginReadDataSection()
1198 { return FindTag("BEGIN_DATA_SECTION"); }
1200 //=======================================================================
1201 //function : ReadPersistentObjectHeader
1203 //=======================================================================
1205 void DDF_IOStream::ReadPersistentObjectHeader(Standard_Integer& aRef,
1206 Standard_Integer& aType)
1213 if (IsEnd() || (c != ' ') || (c == '\n')) {
1214 Storage_StreamFormatError::Raise();
1219 if (!(*myIStream >> aRef)) Storage_StreamTypeMismatchError::Raise("ReadPersistentObjectHeader 1");
1223 if (IsEnd() || (c != ' ') || (c == '\n')) {
1224 Storage_StreamFormatError::Raise();
1232 if (IsEnd() || (c != ' ') || (c == '\n')) {
1233 Storage_StreamFormatError::Raise();
1238 if (!(*myIStream >> aType)) Storage_StreamTypeMismatchError::Raise("ReadPersistentObjectHeader 2");
1241 //=======================================================================
1242 //function : BeginReadPersistentObjectData
1244 //=======================================================================
1246 void DDF_IOStream::BeginReadPersistentObjectData()
1251 if (IsEnd() || (c != ' ') || (c == '\n')) {
1252 Storage_StreamFormatError::Raise();
1258 //=======================================================================
1259 //function : BeginReadObjectData
1261 //=======================================================================
1263 void DDF_IOStream::BeginReadObjectData()
1268 if (IsEnd() || (c != ' ') || (c == '\n')) {
1269 Storage_StreamFormatError::Raise("BeginReadObjectData");
1275 //=======================================================================
1276 //function : EndReadObjectData
1278 //=======================================================================
1280 void DDF_IOStream::EndReadObjectData()
1285 if (IsEnd() || (c != ' ') || (c == '\n')) {
1286 Storage_StreamFormatError::Raise("EndReadObjectData");
1292 //=======================================================================
1293 //function : EndReadPersistentObjectData
1295 //=======================================================================
1297 void DDF_IOStream::EndReadPersistentObjectData()
1303 if (IsEnd() || (c != ' ') || (c == '\n')) {
1304 Storage_StreamFormatError::Raise("EndReadPersistentObjectData");
1311 if (IsEnd() || (c != ' ')) {
1312 Storage_StreamFormatError::Raise();
1318 //=======================================================================
1319 //function : EndReadDataSection
1321 //=======================================================================
1323 Storage_Error DDF_IOStream::EndReadDataSection()
1324 { return FindTag("END_DATA_SECTION"); }
1326 //=======================================================================
1327 //function : IsGoodFileType
1329 //=======================================================================
1331 Storage_Error DDF_IOStream::IsGoodFileType(istream* anIStream)
1336 s = f.Open(anIStream);
1338 if (s == Storage_VSOk) {
1339 TCollection_AsciiString l;
1340 Standard_Integer len = (Standard_Integer) strlen(DDF_IOStream::MagicNumber());
1346 if (strncmp(DDF_IOStream::MagicNumber(),l.ToCString(),len) != 0) {
1348 cout<<"IsGoodFileType: format error"<<endl;
1350 s = Storage_VSFormatError;