1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
23 //Version Date Purpose
24 // 0.0 Aug 22 1997 Creation
26 #include <Standard_Stream.hxx>
28 #include <DDF_IOStream.hxx>
30 // This file has been written using FSD_File.cxx as template.
31 // This is a specific adaptation for Draw use (save & restore commands).
32 // It is not sure at all this code is portable on any other plateform than
33 // SUN OS. Don't use it anywhere else.
34 // Thanks for comprehension. (22 august 97)
37 #include <Storage_StreamTypeMismatchError.hxx>
38 #include <Storage_StreamFormatError.hxx>
39 #include <Storage_StreamWriteError.hxx>
40 #include <Storage_StreamExtCharParityError.hxx>
42 #include <TCollection_AsciiString.hxx>
43 #include <TCollection_ExtendedString.hxx>
45 #include <TColStd_SequenceOfAsciiString.hxx>
46 #include <TColStd_SequenceOfExtendedString.hxx>
48 const Standard_CString MAGICNUMBER = "FSDFILE";
51 //=======================================================================
52 //function : DDF_IOStream
54 //=======================================================================
56 DDF_IOStream::DDF_IOStream()
59 //=======================================================================
62 //=======================================================================
64 Storage_Error DDF_IOStream::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
68 //return Storage_VSOk;
70 Storage_Error result = Storage_VSOk;
74 if (OpenMode() == Storage_VSNone) {
75 if (aMode == Storage_VSRead) {
76 if (myIStream != NULL) delete myIStream;
77 myIStream = new ifstream(aName.ToCString(),ios::in); // ios::nocreate is not portable
78 if (myIStream->fail()) {
79 result = Storage_VSOpenError;
82 myIStream->precision(17);
83 myIStream->imbue (std::locale::classic()); // always use C locale
87 else if (aMode == Storage_VSWrite) {
88 if (myOStream != NULL) delete myOStream;
89 myOStream = new ofstream(aName.ToCString(),ios::out);
90 if (myOStream->fail()) {
91 result = Storage_VSOpenError;
94 myOStream->precision(17);
95 myOStream->imbue (std::locale::classic()); // make sure to always use C locale
101 result = Storage_VSAlreadyOpen;
107 //=======================================================================
109 //purpose : "Opens" an istream.
110 //=======================================================================
112 Storage_Error DDF_IOStream::Open(istream* anIStream)
115 SetOpenMode(Storage_VSRead);
116 myIStream = anIStream;
117 myIStream->precision(17);
118 myIStream->imbue (std::locale::classic()); // use always C locale
119 SetName("DDF_IOStream");
120 return Storage_VSOk; // ou Storage_VSAlreadyOpen ?
123 //=======================================================================
125 //purpose : "Opens" an ostream.
126 //=======================================================================
128 Storage_Error DDF_IOStream::Open(ostream* anOStream)
131 SetOpenMode(Storage_VSWrite);
132 myOStream = anOStream;
133 myOStream->precision(17);
134 myOStream->imbue (std::locale::classic()); // use always C locale
135 SetName("DDF_IOStream");
136 return Storage_VSOk; // ou Storage_VSAlreadyOpen ?
139 //=======================================================================
142 //=======================================================================
144 Standard_Boolean DDF_IOStream::IsEnd()
146 if (OpenMode() == Storage_VSRead) return myIStream->eof();
147 else return myOStream->eof();
150 //=======================================================================
153 //=======================================================================
155 Storage_Error DDF_IOStream::Close()
156 { return Storage_VSOk; }
159 // ------------------ PROTECTED
162 //=======================================================================
163 //function : MagicNumber
165 //=======================================================================
167 const Standard_CString DDF_IOStream::MagicNumber()
168 { return MAGICNUMBER; }
170 //=======================================================================
171 //function : FlushEndOfLine
173 //=======================================================================
175 void DDF_IOStream::FlushEndOfLine()
177 static char Buffer[8192];
179 Standard_Boolean IsEnd = Standard_False;
181 while (!IsEnd && !DDF_IOStream::IsEnd()) {
183 myIStream->get(Buffer,8192,'\n');
185 if (myIStream->get(c) && c != '\n') {
188 IsEnd = Standard_True;
193 //=======================================================================
194 //function : ReadLine
196 //=======================================================================
198 void DDF_IOStream::ReadLine(TCollection_AsciiString& buffer)
200 static char Buffer[8193];
202 Standard_Boolean IsEnd = Standard_False;
206 while (!IsEnd && !DDF_IOStream::IsEnd()) {
208 myIStream->get(Buffer,8192,'\n');
210 if (myIStream->get(c) && c != '\n') {
216 IsEnd = Standard_True;
222 //=======================================================================
223 //function : WriteExtendedLine
225 //=======================================================================
227 void DDF_IOStream::WriteExtendedLine(const TCollection_ExtendedString& buffer)
229 Standard_ExtString extBuffer;
230 Standard_Integer i,c,d;
232 extBuffer = buffer.ToExtString();
234 for (i = 0; i < buffer.Length(); i++) {
235 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
236 d = extBuffer[i] & 0x000000FF;
238 *myOStream << (char)c << (char)d;
241 *myOStream << (char)0 << "\n";
244 //=======================================================================
245 //function : ReadExtendedLine
247 //=======================================================================
249 void DDF_IOStream::ReadExtendedLine(TCollection_ExtendedString& buffer)
252 Standard_ExtCharacter i = 0,j,check = 0;
253 Standard_Boolean fin = Standard_False;
257 while (!fin && !IsEnd()) {
260 // if (!(check % 2)) Storage_StreamExtCharParityError::Raise();
261 i = (Standard_ExtCharacter)c;
262 if (c == '\0') fin = Standard_True;
267 // if ((check % 2) != 0) Storage_StreamExtCharParityError::Raise();
268 // cout << check << endl;
269 j = (Standard_ExtCharacter)c;
270 if (c != '\n') fin = Standard_False;
272 buffer += (Standard_ExtCharacter)i;
275 // if ((check % 2) != 0) Storage_StreamExtCharParityError::Raise();
276 // cout << check << endl;
279 //=======================================================================
280 //function : ReadChar
282 //=======================================================================
284 void DDF_IOStream::ReadChar(TCollection_AsciiString& buffer, const Standard_Integer rsize)
287 Standard_Integer ccount = 0;
291 while (!IsEnd() && (ccount < rsize)) {
298 //=======================================================================
299 //function : ReadString
301 //=======================================================================
303 void DDF_IOStream::ReadString(TCollection_AsciiString& buffer)
306 Standard_Boolean IsEnd = Standard_False;
310 while (!IsEnd && !DDF_IOStream::IsEnd()) {
312 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
315 IsEnd = Standard_False;
317 while (!IsEnd && !DDF_IOStream::IsEnd()) {
320 if (c == '\n') IsEnd = Standard_True;
324 //=======================================================================
325 //function : ReadWord
327 //=======================================================================
329 void DDF_IOStream::ReadWord(TCollection_AsciiString& buffer)
332 Standard_Boolean IsEnd = Standard_False;
336 while (!IsEnd && !DDF_IOStream::IsEnd()) {
338 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
341 IsEnd = Standard_False;
343 while (!IsEnd && !DDF_IOStream::IsEnd()) {
346 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
350 //=======================================================================
353 //=======================================================================
355 Storage_Error DDF_IOStream::FindTag(const Standard_CString aTag)
357 TCollection_AsciiString l;
361 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
366 return Storage_VSSectionNotFound;
373 //=======================================================================
374 //function : SkipObject
376 //=======================================================================
378 void DDF_IOStream::SkipObject()
384 // ---------------------- PUBLIC : PUT
387 //=======================================================================
388 //function : PutReference
390 //=======================================================================
392 Storage_BaseDriver& DDF_IOStream::PutReference(const Standard_Integer aValue)
394 *myOStream << aValue << " ";
395 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutReference");
399 //=======================================================================
400 //function : PutCharacter
402 //=======================================================================
404 Storage_BaseDriver& DDF_IOStream::PutCharacter(const Standard_Character aValue)
406 *myOStream << aValue << " ";
407 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutCharacter");
411 //=======================================================================
412 //function : PutExtCharacter
414 //=======================================================================
416 Storage_BaseDriver& DDF_IOStream::PutExtCharacter(const Standard_ExtCharacter aValue)
418 *myOStream << aValue << " ";
419 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutExtCharacter");
423 //=======================================================================
424 //function : PutInteger
426 //=======================================================================
428 Storage_BaseDriver& DDF_IOStream::PutInteger(const Standard_Integer aValue)
430 *myOStream << aValue << " ";
431 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutInteger");
435 //=======================================================================
436 //function : PutBoolean
438 //=======================================================================
440 Storage_BaseDriver& DDF_IOStream::PutBoolean(const Standard_Boolean aValue)
442 *myOStream << ((Standard_Integer)aValue) << " ";
443 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutBoolean");
447 //=======================================================================
450 //=======================================================================
452 Storage_BaseDriver& DDF_IOStream::PutReal(const Standard_Real aValue)
454 *myOStream << ((Standard_Real)aValue) << " ";
455 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutReal");
459 //=======================================================================
460 //function : PutShortReal
462 //=======================================================================
464 Storage_BaseDriver& DDF_IOStream::PutShortReal(const Standard_ShortReal aValue)
466 *myOStream << aValue << " ";
467 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutShortReal");
472 // ----------------- PUBLIC : GET
475 //=======================================================================
476 //function : GetReference
478 //=======================================================================
480 Storage_BaseDriver& DDF_IOStream::GetReference(Standard_Integer& aValue)
482 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetReference");
486 //=======================================================================
487 //function : GetCharacter
489 //=======================================================================
491 Storage_BaseDriver& DDF_IOStream::GetCharacter(Standard_Character& aValue)
493 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetCharacter");
497 //=======================================================================
498 //function : GetExtCharacter
500 //=======================================================================
502 Storage_BaseDriver& DDF_IOStream::GetExtCharacter(Standard_ExtCharacter& aValue)
504 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetExtCharacter");
508 //=======================================================================
509 //function : GetInteger
511 //=======================================================================
513 Storage_BaseDriver& DDF_IOStream::GetInteger(Standard_Integer& aValue)
515 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetInteger");
519 //=======================================================================
520 //function : GetBoolean
522 //=======================================================================
524 Storage_BaseDriver& DDF_IOStream::GetBoolean(Standard_Boolean& aValue)
526 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetBoolean");
530 //=======================================================================
533 //=======================================================================
535 Storage_BaseDriver& DDF_IOStream::GetReal(Standard_Real& aValue)
537 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetReal");
541 //=======================================================================
542 //function : GetShortReal
544 //=======================================================================
546 Storage_BaseDriver& DDF_IOStream::GetShortReal(Standard_ShortReal& aValue)
548 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetShortReal");
552 // -------------------------- DESTROY
554 //=======================================================================
557 //=======================================================================
559 void DDF_IOStream::Destroy()
561 if (OpenMode() != Storage_VSNone) Close();
565 // -------------------------- INFO : WRITE
568 //=======================================================================
569 //function : BeginWriteInfoSection
571 //=======================================================================
573 Storage_Error DDF_IOStream::BeginWriteInfoSection()
575 *myOStream << DDF_IOStream::MagicNumber() << '\n';
576 *myOStream << "BEGIN_INFO_SECTION\n";
577 if (myOStream->bad()) Storage_StreamWriteError::Raise();
582 //=======================================================================
583 //function : WriteInfo
585 //=======================================================================
587 void DDF_IOStream::WriteInfo(const Standard_Integer nbObj,
588 const TCollection_AsciiString& dbVersion,
589 const TCollection_AsciiString& date,
590 const TCollection_AsciiString& schemaName,
591 const TCollection_AsciiString& schemaVersion,
592 const TCollection_ExtendedString& appName,
593 const TCollection_AsciiString& appVersion,
594 const TCollection_ExtendedString& dataType,
595 const TColStd_SequenceOfAsciiString& userInfo)
602 *myOStream << dbVersion.ToCString() << "\n";
603 *myOStream << date.ToCString() << "\n";
604 *myOStream << schemaName.ToCString() << "\n";
605 *myOStream << schemaVersion.ToCString() << "\n";
606 WriteExtendedLine(appName);
607 *myOStream << appVersion.ToCString() << "\n";
608 WriteExtendedLine(dataType);
609 *myOStream << userInfo.Length() << "\n";
611 if (myOStream->bad()) Storage_StreamWriteError::Raise();
613 for (i = 1; i <= userInfo.Length(); i++) {
614 *myOStream << userInfo.Value(i).ToCString() << "\n";
615 if (myOStream->bad()) Storage_StreamWriteError::Raise();
620 //=======================================================================
621 //function : EndWriteInfoSection
623 //=======================================================================
625 Storage_Error DDF_IOStream::EndWriteInfoSection()
627 *myOStream << "END_INFO_SECTION\n";
628 if (myOStream->bad()) Storage_StreamWriteError::Raise();
632 //=======================================================================
633 //function : BeginReadInfoSection
635 //=======================================================================
637 Storage_Error DDF_IOStream::BeginReadInfoSection()
640 TCollection_AsciiString l;
641 Standard_Integer len = (Standard_Integer) strlen(DDF_IOStream::MagicNumber());
643 // Added because of Draw:
644 // It don't go to next line after reading its own header line information!
648 if (strncmp(DDF_IOStream::MagicNumber(),l.ToCString(),len) != 0) {
650 cout<<"BeginReadInfoSection: format error"<<endl;
652 s = Storage_VSFormatError;
655 s = FindTag("BEGIN_INFO_SECTION");
662 // ------------------- INFO : READ
665 //=======================================================================
666 //function : ReadInfo
668 //=======================================================================
670 void DDF_IOStream::ReadInfo(Standard_Integer& nbObj,
671 TCollection_AsciiString& dbVersion,
672 TCollection_AsciiString& date,
673 TCollection_AsciiString& schemaName,
674 TCollection_AsciiString& schemaVersion,
675 TCollection_ExtendedString& appName,
676 TCollection_AsciiString& appVersion,
677 TCollection_ExtendedString& dataType,
678 TColStd_SequenceOfAsciiString& userInfo)
680 if (!(*myIStream >> nbObj)) Storage_StreamTypeMismatchError::Raise("ReadInfo 1");
686 ReadLine(schemaName);
687 ReadLine(schemaVersion);
688 ReadExtendedLine(appName);
689 ReadLine(appVersion);
690 ReadExtendedLine(dataType);
692 Standard_Integer i,len = 0;
694 if (!(*myIStream >> len)) Storage_StreamTypeMismatchError::Raise("ReadInfo 2");
698 TCollection_AsciiString line;
700 for (i = 1; i <= len && !IsEnd(); i++) {
702 userInfo.Append(line);
707 //=======================================================================
708 //function : EndReadInfoSection
710 //=======================================================================
712 Storage_Error DDF_IOStream::EndReadInfoSection()
713 { return FindTag("END_INFO_SECTION"); }
716 // ---------------- COMMENTS : WRITE
719 //=======================================================================
720 //function : BeginWriteCommentSection
722 //=======================================================================
724 Storage_Error DDF_IOStream::BeginWriteCommentSection()
726 *myOStream << "BEGIN_COMMENT_SECTION\n";
727 if (myOStream->bad()) Storage_StreamWriteError::Raise();
731 //=======================================================================
732 //function : WriteComment
734 //=======================================================================
736 void DDF_IOStream::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
738 Standard_Integer i,aSize;
740 aSize = aCom.Length();
741 *myOStream << aSize << "\n";
742 if (myOStream->bad()) Storage_StreamWriteError::Raise();
744 for (i = 1; i <= aSize; i++) {
745 WriteExtendedLine(aCom.Value(i));
746 if (myOStream->bad()) Storage_StreamWriteError::Raise();
750 //=======================================================================
751 //function : EndWriteCommentSection
753 //=======================================================================
755 Storage_Error DDF_IOStream::EndWriteCommentSection()
757 *myOStream << "END_COMMENT_SECTION\n";
758 if (myOStream->bad()) Storage_StreamWriteError::Raise();
763 // ---------------- COMMENTS : READ
766 //=======================================================================
767 //function : BeginReadCommentSection
769 //=======================================================================
771 Storage_Error DDF_IOStream::BeginReadCommentSection()
773 return FindTag("BEGIN_COMMENT_SECTION");
776 //=======================================================================
777 //function : ReadComment
779 //=======================================================================
781 void DDF_IOStream::ReadComment(TColStd_SequenceOfExtendedString& aCom)
783 TCollection_ExtendedString line;
784 Standard_Integer len,i;
786 if (!(*myIStream >> len)) Storage_StreamTypeMismatchError::Raise("ReadComment");
790 for (i = 1; i <= len && !IsEnd(); i++) {
791 ReadExtendedLine(line);
797 //=======================================================================
798 //function : EndReadCommentSection
800 //=======================================================================
802 Storage_Error DDF_IOStream::EndReadCommentSection()
803 { return FindTag("END_COMMENT_SECTION"); }
806 // --------------- TYPE : WRITE
809 //=======================================================================
810 //function : BeginWriteTypeSection
812 //=======================================================================
814 Storage_Error DDF_IOStream::BeginWriteTypeSection()
816 *myOStream << "BEGIN_TYPE_SECTION\n";
817 if (myOStream->bad()) Storage_StreamWriteError::Raise();
821 //=======================================================================
822 //function : SetTypeSectionSize
824 //=======================================================================
826 void DDF_IOStream::SetTypeSectionSize(const Standard_Integer aSize)
828 *myOStream << aSize << "\n";
829 if (myOStream->bad()) Storage_StreamWriteError::Raise();
832 //=======================================================================
833 //function : WriteTypeInformations
835 //=======================================================================
837 void DDF_IOStream::WriteTypeInformations(const Standard_Integer typeNum,
838 const TCollection_AsciiString& typeName)
840 *myOStream << typeNum << " " << typeName.ToCString() << "\n";
841 if (myOStream->bad()) Storage_StreamWriteError::Raise();
844 //=======================================================================
845 //function : EndWriteTypeSection
847 //=======================================================================
849 Storage_Error DDF_IOStream::EndWriteTypeSection()
851 *myOStream << "END_TYPE_SECTION\n";
852 if (myOStream->bad()) Storage_StreamWriteError::Raise();
857 // ------------------- TYPE : READ
860 //=======================================================================
861 //function : BeginReadTypeSection
863 //=======================================================================
865 Storage_Error DDF_IOStream::BeginReadTypeSection()
866 { return FindTag("BEGIN_TYPE_SECTION"); }
868 //=======================================================================
869 //function : TypeSectionSize
871 //=======================================================================
873 Standard_Integer DDF_IOStream::TypeSectionSize()
877 if (!(*myIStream >> i)) Storage_StreamTypeMismatchError::Raise("TypeSectionSize");
884 //=======================================================================
885 //function : ReadTypeInformations
887 //=======================================================================
889 void DDF_IOStream::ReadTypeInformations(Standard_Integer& typeNum,
890 TCollection_AsciiString& typeName)
892 if (!(*myIStream >> typeNum)) Storage_StreamTypeMismatchError::Raise("ReadTypeInformations 1");
893 if (!(*myIStream >> typeName)) Storage_StreamTypeMismatchError::Raise("ReadTypeInformations 2");
897 //=======================================================================
898 //function : EndReadTypeSection
900 //=======================================================================
902 Storage_Error DDF_IOStream::EndReadTypeSection()
904 return FindTag("END_TYPE_SECTION");
908 // -------------------- ROOT : WRITE
911 //=======================================================================
912 //function : BeginWriteRootSection
914 //=======================================================================
916 Storage_Error DDF_IOStream::BeginWriteRootSection()
918 *myOStream << "BEGIN_ROOT_SECTION\n";
919 if (myOStream->bad()) Storage_StreamWriteError::Raise();
923 //=======================================================================
924 //function : SetRootSectionSize
926 //=======================================================================
928 void DDF_IOStream::SetRootSectionSize(const Standard_Integer aSize)
930 *myOStream << aSize << "\n";
931 if (myOStream->bad()) Storage_StreamWriteError::Raise();
934 //=======================================================================
935 //function : WriteRoot
937 //=======================================================================
939 void DDF_IOStream::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
941 *myOStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
942 if (myOStream->bad()) Storage_StreamWriteError::Raise();
945 //=======================================================================
946 //function : EndWriteRootSection
948 //=======================================================================
950 Storage_Error DDF_IOStream::EndWriteRootSection()
952 *myOStream << "END_ROOT_SECTION\n";
953 if (myOStream->bad()) Storage_StreamWriteError::Raise();
958 // ----------------------- ROOT : READ
961 //=======================================================================
962 //function : BeginReadRootSection
964 //=======================================================================
966 Storage_Error DDF_IOStream::BeginReadRootSection()
967 { return FindTag("BEGIN_ROOT_SECTION"); }
969 //=======================================================================
970 //function : RootSectionSize
972 //=======================================================================
974 Standard_Integer DDF_IOStream::RootSectionSize()
978 if (!(*myIStream >> i)) Storage_StreamTypeMismatchError::Raise("RootSectionSize");
985 //=======================================================================
986 //function : ReadRoot
988 //=======================================================================
990 void DDF_IOStream::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
992 if (!(*myIStream >> aRef)) Storage_StreamTypeMismatchError::Raise("ReadRoot");
997 //=======================================================================
998 //function : EndReadRootSection
1000 //=======================================================================
1002 Storage_Error DDF_IOStream::EndReadRootSection()
1003 { return FindTag("END_ROOT_SECTION"); }
1006 // -------------------------- REF : WRITE
1009 //=======================================================================
1010 //function : BeginWriteRefSection
1012 //=======================================================================
1014 Storage_Error DDF_IOStream::BeginWriteRefSection()
1016 *myOStream << "BEGIN_REF_SECTION\n";
1017 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1018 return Storage_VSOk;
1021 //=======================================================================
1022 //function : SetRefSectionSize
1024 //=======================================================================
1026 void DDF_IOStream::SetRefSectionSize(const Standard_Integer aSize)
1028 *myOStream << aSize << "\n";
1029 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1032 //=======================================================================
1033 //function : WriteReferenceType
1035 //=======================================================================
1037 void DDF_IOStream::WriteReferenceType(const Standard_Integer reference,
1038 const Standard_Integer typeNum)
1040 *myOStream << reference << " " << typeNum << "\n";
1041 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1044 //=======================================================================
1045 //function : EndWriteRefSection
1047 //=======================================================================
1049 Storage_Error DDF_IOStream::EndWriteRefSection()
1051 *myOStream << "END_REF_SECTION\n";
1052 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1053 return Storage_VSOk;
1057 // ----------------------- REF : READ
1060 //=======================================================================
1061 //function : BeginReadRefSection
1063 //=======================================================================
1065 Storage_Error DDF_IOStream::BeginReadRefSection()
1066 { return FindTag("BEGIN_REF_SECTION"); }
1068 //=======================================================================
1069 //function : RefSectionSize
1071 //=======================================================================
1073 Standard_Integer DDF_IOStream::RefSectionSize()
1077 if (!(*myIStream >> i)) Storage_StreamTypeMismatchError::Raise("RefSectionSize");
1083 //=======================================================================
1084 //function : ReadReferenceType
1086 //=======================================================================
1088 void DDF_IOStream::ReadReferenceType(Standard_Integer& reference,
1089 Standard_Integer& typeNum)
1091 if (!(*myIStream >> reference)) Storage_StreamTypeMismatchError::Raise("ReadReferenceType 1");
1092 if (!(*myIStream >> typeNum)) Storage_StreamTypeMismatchError::Raise("ReadReferenceType 2");
1096 //=======================================================================
1097 //function : EndReadRefSection
1099 //=======================================================================
1101 Storage_Error DDF_IOStream::EndReadRefSection()
1103 return FindTag("END_REF_SECTION");
1107 // -------------------- DATA : WRITE
1110 //=======================================================================
1111 //function : BeginWriteDataSection
1113 //=======================================================================
1115 Storage_Error DDF_IOStream::BeginWriteDataSection()
1117 *myOStream << "BEGIN_DATA_SECTION";
1118 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1119 return Storage_VSOk;
1122 //=======================================================================
1123 //function : WritePersistentObjectHeader
1125 //=======================================================================
1127 void DDF_IOStream::WritePersistentObjectHeader(const Standard_Integer aRef,
1128 const Standard_Integer aType)
1130 *myOStream << "\n#" << aRef << "=%" << aType;
1131 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1134 //=======================================================================
1135 //function : BeginWritePersistentObjectData
1137 //=======================================================================
1139 void DDF_IOStream::BeginWritePersistentObjectData()
1142 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1145 //=======================================================================
1146 //function : BeginWriteObjectData
1148 //=======================================================================
1150 void DDF_IOStream::BeginWriteObjectData()
1153 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1156 //=======================================================================
1157 //function : EndWriteObjectData
1159 //=======================================================================
1161 void DDF_IOStream::EndWriteObjectData()
1164 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1167 //=======================================================================
1168 //function : EndWritePersistentObjectData
1170 //=======================================================================
1172 void DDF_IOStream::EndWritePersistentObjectData()
1175 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1178 //=======================================================================
1179 //function : EndWriteDataSection
1181 //=======================================================================
1183 Storage_Error DDF_IOStream::EndWriteDataSection()
1185 *myOStream << "\nEND_DATA_SECTION\n";
1186 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1187 return Storage_VSOk;
1191 // ---------------------- DATA : READ
1194 //=======================================================================
1195 //function : BeginReadDataSection
1197 //=======================================================================
1199 Storage_Error DDF_IOStream::BeginReadDataSection()
1200 { return FindTag("BEGIN_DATA_SECTION"); }
1202 //=======================================================================
1203 //function : ReadPersistentObjectHeader
1205 //=======================================================================
1207 void DDF_IOStream::ReadPersistentObjectHeader(Standard_Integer& aRef,
1208 Standard_Integer& aType)
1215 if (IsEnd() || (c != ' ') || (c == '\n')) {
1216 Storage_StreamFormatError::Raise();
1221 if (!(*myIStream >> aRef)) Storage_StreamTypeMismatchError::Raise("ReadPersistentObjectHeader 1");
1225 if (IsEnd() || (c != ' ') || (c == '\n')) {
1226 Storage_StreamFormatError::Raise();
1234 if (IsEnd() || (c != ' ') || (c == '\n')) {
1235 Storage_StreamFormatError::Raise();
1240 if (!(*myIStream >> aType)) Storage_StreamTypeMismatchError::Raise("ReadPersistentObjectHeader 2");
1243 //=======================================================================
1244 //function : BeginReadPersistentObjectData
1246 //=======================================================================
1248 void DDF_IOStream::BeginReadPersistentObjectData()
1253 if (IsEnd() || (c != ' ') || (c == '\n')) {
1254 Storage_StreamFormatError::Raise();
1260 //=======================================================================
1261 //function : BeginReadObjectData
1263 //=======================================================================
1265 void DDF_IOStream::BeginReadObjectData()
1270 if (IsEnd() || (c != ' ') || (c == '\n')) {
1271 Storage_StreamFormatError::Raise("BeginReadObjectData");
1277 //=======================================================================
1278 //function : EndReadObjectData
1280 //=======================================================================
1282 void DDF_IOStream::EndReadObjectData()
1287 if (IsEnd() || (c != ' ') || (c == '\n')) {
1288 Storage_StreamFormatError::Raise("EndReadObjectData");
1294 //=======================================================================
1295 //function : EndReadPersistentObjectData
1297 //=======================================================================
1299 void DDF_IOStream::EndReadPersistentObjectData()
1305 if (IsEnd() || (c != ' ') || (c == '\n')) {
1306 Storage_StreamFormatError::Raise("EndReadPersistentObjectData");
1313 if (IsEnd() || (c != ' ')) {
1314 Storage_StreamFormatError::Raise();
1320 //=======================================================================
1321 //function : EndReadDataSection
1323 //=======================================================================
1325 Storage_Error DDF_IOStream::EndReadDataSection()
1326 { return FindTag("END_DATA_SECTION"); }
1328 //=======================================================================
1329 //function : IsGoodFileType
1331 //=======================================================================
1333 Storage_Error DDF_IOStream::IsGoodFileType(istream* anIStream)
1338 s = f.Open(anIStream);
1340 if (s == Storage_VSOk) {
1341 TCollection_AsciiString l;
1342 Standard_Integer len = (Standard_Integer) strlen(DDF_IOStream::MagicNumber());
1348 if (strncmp(DDF_IOStream::MagicNumber(),l.ToCString(),len) != 0) {
1350 cout<<"IsGoodFileType: format error"<<endl;
1352 s = Storage_VSFormatError;