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();
262 i += (Standard_ExtCharacter)c;
263 if (c == '\0') fin = Standard_True;
268 // if ((check % 2) != 0) Storage_StreamExtCharParityError::Raise();
269 // cout << check << endl;
270 j += (Standard_ExtCharacter)c;
271 if (c != '\n') fin = Standard_False;
273 buffer += (Standard_ExtCharacter)i;
276 // if ((check % 2) != 0) Storage_StreamExtCharParityError::Raise();
277 // cout << check << endl;
280 //=======================================================================
281 //function : ReadChar
283 //=======================================================================
285 void DDF_IOStream::ReadChar(TCollection_AsciiString& buffer, const Standard_Integer rsize)
288 Standard_Integer ccount = 0;
292 while (!IsEnd() && (ccount < rsize)) {
299 //=======================================================================
300 //function : ReadString
302 //=======================================================================
304 void DDF_IOStream::ReadString(TCollection_AsciiString& buffer)
307 Standard_Boolean IsEnd = Standard_False;
311 while (!IsEnd && !DDF_IOStream::IsEnd()) {
313 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
316 IsEnd = Standard_False;
318 while (!IsEnd && !DDF_IOStream::IsEnd()) {
321 if (c == '\n') IsEnd = Standard_True;
325 //=======================================================================
326 //function : ReadWord
328 //=======================================================================
330 void DDF_IOStream::ReadWord(TCollection_AsciiString& buffer)
333 Standard_Boolean IsEnd = Standard_False;
337 while (!IsEnd && !DDF_IOStream::IsEnd()) {
339 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
342 IsEnd = Standard_False;
344 while (!IsEnd && !DDF_IOStream::IsEnd()) {
347 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
351 //=======================================================================
354 //=======================================================================
356 Storage_Error DDF_IOStream::FindTag(const Standard_CString aTag)
358 TCollection_AsciiString l;
362 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
367 return Storage_VSSectionNotFound;
374 //=======================================================================
375 //function : SkipObject
377 //=======================================================================
379 void DDF_IOStream::SkipObject()
385 // ---------------------- PUBLIC : PUT
388 //=======================================================================
389 //function : PutReference
391 //=======================================================================
393 Storage_BaseDriver& DDF_IOStream::PutReference(const Standard_Integer aValue)
395 *myOStream << aValue << " ";
396 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutReference");
400 //=======================================================================
401 //function : PutCharacter
403 //=======================================================================
405 Storage_BaseDriver& DDF_IOStream::PutCharacter(const Standard_Character aValue)
407 *myOStream << aValue << " ";
408 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutCharacter");
412 //=======================================================================
413 //function : PutExtCharacter
415 //=======================================================================
417 Storage_BaseDriver& DDF_IOStream::PutExtCharacter(const Standard_ExtCharacter aValue)
419 *myOStream << aValue << " ";
420 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutExtCharacter");
424 //=======================================================================
425 //function : PutInteger
427 //=======================================================================
429 Storage_BaseDriver& DDF_IOStream::PutInteger(const Standard_Integer aValue)
431 *myOStream << aValue << " ";
432 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutInteger");
436 //=======================================================================
437 //function : PutBoolean
439 //=======================================================================
441 Storage_BaseDriver& DDF_IOStream::PutBoolean(const Standard_Boolean aValue)
443 *myOStream << ((Standard_Integer)aValue) << " ";
444 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutBoolean");
448 //=======================================================================
451 //=======================================================================
453 Storage_BaseDriver& DDF_IOStream::PutReal(const Standard_Real aValue)
455 *myOStream << ((Standard_Real)aValue) << " ";
456 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutReal");
460 //=======================================================================
461 //function : PutShortReal
463 //=======================================================================
465 Storage_BaseDriver& DDF_IOStream::PutShortReal(const Standard_ShortReal aValue)
467 *myOStream << aValue << " ";
468 if (myOStream->bad()) Storage_StreamWriteError::Raise("PutShortReal");
473 // ----------------- PUBLIC : GET
476 //=======================================================================
477 //function : GetReference
479 //=======================================================================
481 Storage_BaseDriver& DDF_IOStream::GetReference(Standard_Integer& aValue)
483 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetReference");
487 //=======================================================================
488 //function : GetCharacter
490 //=======================================================================
492 Storage_BaseDriver& DDF_IOStream::GetCharacter(Standard_Character& aValue)
494 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetCharacter");
498 //=======================================================================
499 //function : GetExtCharacter
501 //=======================================================================
503 Storage_BaseDriver& DDF_IOStream::GetExtCharacter(Standard_ExtCharacter& aValue)
505 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetExtCharacter");
509 //=======================================================================
510 //function : GetInteger
512 //=======================================================================
514 Storage_BaseDriver& DDF_IOStream::GetInteger(Standard_Integer& aValue)
516 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetInteger");
520 //=======================================================================
521 //function : GetBoolean
523 //=======================================================================
525 Storage_BaseDriver& DDF_IOStream::GetBoolean(Standard_Boolean& aValue)
527 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetBoolean");
531 //=======================================================================
534 //=======================================================================
536 Storage_BaseDriver& DDF_IOStream::GetReal(Standard_Real& aValue)
538 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetReal");
542 //=======================================================================
543 //function : GetShortReal
545 //=======================================================================
547 Storage_BaseDriver& DDF_IOStream::GetShortReal(Standard_ShortReal& aValue)
549 if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetShortReal");
553 // -------------------------- DESTROY
555 //=======================================================================
558 //=======================================================================
560 void DDF_IOStream::Destroy()
562 if (OpenMode() != Storage_VSNone) Close();
566 // -------------------------- INFO : WRITE
569 //=======================================================================
570 //function : BeginWriteInfoSection
572 //=======================================================================
574 Storage_Error DDF_IOStream::BeginWriteInfoSection()
576 *myOStream << DDF_IOStream::MagicNumber() << '\n';
577 *myOStream << "BEGIN_INFO_SECTION\n";
578 if (myOStream->bad()) Storage_StreamWriteError::Raise();
583 //=======================================================================
584 //function : WriteInfo
586 //=======================================================================
588 void DDF_IOStream::WriteInfo(const Standard_Integer nbObj,
589 const TCollection_AsciiString& dbVersion,
590 const TCollection_AsciiString& date,
591 const TCollection_AsciiString& schemaName,
592 const TCollection_AsciiString& schemaVersion,
593 const TCollection_ExtendedString& appName,
594 const TCollection_AsciiString& appVersion,
595 const TCollection_ExtendedString& dataType,
596 const TColStd_SequenceOfAsciiString& userInfo)
603 *myOStream << dbVersion.ToCString() << "\n";
604 *myOStream << date.ToCString() << "\n";
605 *myOStream << schemaName.ToCString() << "\n";
606 *myOStream << schemaVersion.ToCString() << "\n";
607 WriteExtendedLine(appName);
608 *myOStream << appVersion.ToCString() << "\n";
609 WriteExtendedLine(dataType);
610 *myOStream << userInfo.Length() << "\n";
612 if (myOStream->bad()) Storage_StreamWriteError::Raise();
614 for (i = 1; i <= userInfo.Length(); i++) {
615 *myOStream << userInfo.Value(i).ToCString() << "\n";
616 if (myOStream->bad()) Storage_StreamWriteError::Raise();
621 //=======================================================================
622 //function : EndWriteInfoSection
624 //=======================================================================
626 Storage_Error DDF_IOStream::EndWriteInfoSection()
628 *myOStream << "END_INFO_SECTION\n";
629 if (myOStream->bad()) Storage_StreamWriteError::Raise();
633 //=======================================================================
634 //function : BeginReadInfoSection
636 //=======================================================================
638 Storage_Error DDF_IOStream::BeginReadInfoSection()
641 TCollection_AsciiString l;
642 Standard_Integer len = (Standard_Integer) strlen(DDF_IOStream::MagicNumber());
644 // Added because of Draw:
645 // It don't go to next line after reading its own header line information!
649 if (strncmp(DDF_IOStream::MagicNumber(),l.ToCString(),len) != 0) {
651 cout<<"BeginReadInfoSection: format error"<<endl;
653 s = Storage_VSFormatError;
656 s = FindTag("BEGIN_INFO_SECTION");
663 // ------------------- INFO : READ
666 //=======================================================================
667 //function : ReadInfo
669 //=======================================================================
671 void DDF_IOStream::ReadInfo(Standard_Integer& nbObj,
672 TCollection_AsciiString& dbVersion,
673 TCollection_AsciiString& date,
674 TCollection_AsciiString& schemaName,
675 TCollection_AsciiString& schemaVersion,
676 TCollection_ExtendedString& appName,
677 TCollection_AsciiString& appVersion,
678 TCollection_ExtendedString& dataType,
679 TColStd_SequenceOfAsciiString& userInfo)
681 if (!(*myIStream >> nbObj)) Storage_StreamTypeMismatchError::Raise("ReadInfo 1");
687 ReadLine(schemaName);
688 ReadLine(schemaVersion);
689 ReadExtendedLine(appName);
690 ReadLine(appVersion);
691 ReadExtendedLine(dataType);
693 Standard_Integer i,len = 0;
695 if (!(*myIStream >> len)) Storage_StreamTypeMismatchError::Raise("ReadInfo 2");
699 TCollection_AsciiString line;
701 for (i = 1; i <= len && !IsEnd(); i++) {
703 userInfo.Append(line);
708 //=======================================================================
709 //function : EndReadInfoSection
711 //=======================================================================
713 Storage_Error DDF_IOStream::EndReadInfoSection()
714 { return FindTag("END_INFO_SECTION"); }
717 // ---------------- COMMENTS : WRITE
720 //=======================================================================
721 //function : BeginWriteCommentSection
723 //=======================================================================
725 Storage_Error DDF_IOStream::BeginWriteCommentSection()
727 *myOStream << "BEGIN_COMMENT_SECTION\n";
728 if (myOStream->bad()) Storage_StreamWriteError::Raise();
732 //=======================================================================
733 //function : WriteComment
735 //=======================================================================
737 void DDF_IOStream::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
739 Standard_Integer i,aSize;
741 aSize = aCom.Length();
742 *myOStream << aSize << "\n";
743 if (myOStream->bad()) Storage_StreamWriteError::Raise();
745 for (i = 1; i <= aSize; i++) {
746 WriteExtendedLine(aCom.Value(i));
747 if (myOStream->bad()) Storage_StreamWriteError::Raise();
751 //=======================================================================
752 //function : EndWriteCommentSection
754 //=======================================================================
756 Storage_Error DDF_IOStream::EndWriteCommentSection()
758 *myOStream << "END_COMMENT_SECTION\n";
759 if (myOStream->bad()) Storage_StreamWriteError::Raise();
764 // ---------------- COMMENTS : READ
767 //=======================================================================
768 //function : BeginReadCommentSection
770 //=======================================================================
772 Storage_Error DDF_IOStream::BeginReadCommentSection()
774 return FindTag("BEGIN_COMMENT_SECTION");
777 //=======================================================================
778 //function : ReadComment
780 //=======================================================================
782 void DDF_IOStream::ReadComment(TColStd_SequenceOfExtendedString& aCom)
784 TCollection_ExtendedString line;
785 Standard_Integer len,i;
787 if (!(*myIStream >> len)) Storage_StreamTypeMismatchError::Raise("ReadComment");
791 for (i = 1; i <= len && !IsEnd(); i++) {
792 ReadExtendedLine(line);
798 //=======================================================================
799 //function : EndReadCommentSection
801 //=======================================================================
803 Storage_Error DDF_IOStream::EndReadCommentSection()
804 { return FindTag("END_COMMENT_SECTION"); }
807 // --------------- TYPE : WRITE
810 //=======================================================================
811 //function : BeginWriteTypeSection
813 //=======================================================================
815 Storage_Error DDF_IOStream::BeginWriteTypeSection()
817 *myOStream << "BEGIN_TYPE_SECTION\n";
818 if (myOStream->bad()) Storage_StreamWriteError::Raise();
822 //=======================================================================
823 //function : SetTypeSectionSize
825 //=======================================================================
827 void DDF_IOStream::SetTypeSectionSize(const Standard_Integer aSize)
829 *myOStream << aSize << "\n";
830 if (myOStream->bad()) Storage_StreamWriteError::Raise();
833 //=======================================================================
834 //function : WriteTypeInformations
836 //=======================================================================
838 void DDF_IOStream::WriteTypeInformations(const Standard_Integer typeNum,
839 const TCollection_AsciiString& typeName)
841 *myOStream << typeNum << " " << typeName.ToCString() << "\n";
842 if (myOStream->bad()) Storage_StreamWriteError::Raise();
845 //=======================================================================
846 //function : EndWriteTypeSection
848 //=======================================================================
850 Storage_Error DDF_IOStream::EndWriteTypeSection()
852 *myOStream << "END_TYPE_SECTION\n";
853 if (myOStream->bad()) Storage_StreamWriteError::Raise();
858 // ------------------- TYPE : READ
861 //=======================================================================
862 //function : BeginReadTypeSection
864 //=======================================================================
866 Storage_Error DDF_IOStream::BeginReadTypeSection()
867 { return FindTag("BEGIN_TYPE_SECTION"); }
869 //=======================================================================
870 //function : TypeSectionSize
872 //=======================================================================
874 Standard_Integer DDF_IOStream::TypeSectionSize()
878 if (!(*myIStream >> i)) Storage_StreamTypeMismatchError::Raise("TypeSectionSize");
885 //=======================================================================
886 //function : ReadTypeInformations
888 //=======================================================================
890 void DDF_IOStream::ReadTypeInformations(Standard_Integer& typeNum,
891 TCollection_AsciiString& typeName)
893 if (!(*myIStream >> typeNum)) Storage_StreamTypeMismatchError::Raise("ReadTypeInformations 1");
894 if (!(*myIStream >> typeName)) Storage_StreamTypeMismatchError::Raise("ReadTypeInformations 2");
898 //=======================================================================
899 //function : EndReadTypeSection
901 //=======================================================================
903 Storage_Error DDF_IOStream::EndReadTypeSection()
905 return FindTag("END_TYPE_SECTION");
909 // -------------------- ROOT : WRITE
912 //=======================================================================
913 //function : BeginWriteRootSection
915 //=======================================================================
917 Storage_Error DDF_IOStream::BeginWriteRootSection()
919 *myOStream << "BEGIN_ROOT_SECTION\n";
920 if (myOStream->bad()) Storage_StreamWriteError::Raise();
924 //=======================================================================
925 //function : SetRootSectionSize
927 //=======================================================================
929 void DDF_IOStream::SetRootSectionSize(const Standard_Integer aSize)
931 *myOStream << aSize << "\n";
932 if (myOStream->bad()) Storage_StreamWriteError::Raise();
935 //=======================================================================
936 //function : WriteRoot
938 //=======================================================================
940 void DDF_IOStream::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
942 *myOStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
943 if (myOStream->bad()) Storage_StreamWriteError::Raise();
946 //=======================================================================
947 //function : EndWriteRootSection
949 //=======================================================================
951 Storage_Error DDF_IOStream::EndWriteRootSection()
953 *myOStream << "END_ROOT_SECTION\n";
954 if (myOStream->bad()) Storage_StreamWriteError::Raise();
959 // ----------------------- ROOT : READ
962 //=======================================================================
963 //function : BeginReadRootSection
965 //=======================================================================
967 Storage_Error DDF_IOStream::BeginReadRootSection()
968 { return FindTag("BEGIN_ROOT_SECTION"); }
970 //=======================================================================
971 //function : RootSectionSize
973 //=======================================================================
975 Standard_Integer DDF_IOStream::RootSectionSize()
979 if (!(*myIStream >> i)) Storage_StreamTypeMismatchError::Raise("RootSectionSize");
986 //=======================================================================
987 //function : ReadRoot
989 //=======================================================================
991 void DDF_IOStream::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
993 if (!(*myIStream >> aRef)) Storage_StreamTypeMismatchError::Raise("ReadRoot");
998 //=======================================================================
999 //function : EndReadRootSection
1001 //=======================================================================
1003 Storage_Error DDF_IOStream::EndReadRootSection()
1004 { return FindTag("END_ROOT_SECTION"); }
1007 // -------------------------- REF : WRITE
1010 //=======================================================================
1011 //function : BeginWriteRefSection
1013 //=======================================================================
1015 Storage_Error DDF_IOStream::BeginWriteRefSection()
1017 *myOStream << "BEGIN_REF_SECTION\n";
1018 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1019 return Storage_VSOk;
1022 //=======================================================================
1023 //function : SetRefSectionSize
1025 //=======================================================================
1027 void DDF_IOStream::SetRefSectionSize(const Standard_Integer aSize)
1029 *myOStream << aSize << "\n";
1030 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1033 //=======================================================================
1034 //function : WriteReferenceType
1036 //=======================================================================
1038 void DDF_IOStream::WriteReferenceType(const Standard_Integer reference,
1039 const Standard_Integer typeNum)
1041 *myOStream << reference << " " << typeNum << "\n";
1042 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1045 //=======================================================================
1046 //function : EndWriteRefSection
1048 //=======================================================================
1050 Storage_Error DDF_IOStream::EndWriteRefSection()
1052 *myOStream << "END_REF_SECTION\n";
1053 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1054 return Storage_VSOk;
1058 // ----------------------- REF : READ
1061 //=======================================================================
1062 //function : BeginReadRefSection
1064 //=======================================================================
1066 Storage_Error DDF_IOStream::BeginReadRefSection()
1067 { return FindTag("BEGIN_REF_SECTION"); }
1069 //=======================================================================
1070 //function : RefSectionSize
1072 //=======================================================================
1074 Standard_Integer DDF_IOStream::RefSectionSize()
1078 if (!(*myIStream >> i)) Storage_StreamTypeMismatchError::Raise("RefSectionSize");
1084 //=======================================================================
1085 //function : ReadReferenceType
1087 //=======================================================================
1089 void DDF_IOStream::ReadReferenceType(Standard_Integer& reference,
1090 Standard_Integer& typeNum)
1092 if (!(*myIStream >> reference)) Storage_StreamTypeMismatchError::Raise("ReadReferenceType 1");
1093 if (!(*myIStream >> typeNum)) Storage_StreamTypeMismatchError::Raise("ReadReferenceType 2");
1097 //=======================================================================
1098 //function : EndReadRefSection
1100 //=======================================================================
1102 Storage_Error DDF_IOStream::EndReadRefSection()
1104 return FindTag("END_REF_SECTION");
1108 // -------------------- DATA : WRITE
1111 //=======================================================================
1112 //function : BeginWriteDataSection
1114 //=======================================================================
1116 Storage_Error DDF_IOStream::BeginWriteDataSection()
1118 *myOStream << "BEGIN_DATA_SECTION";
1119 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1120 return Storage_VSOk;
1123 //=======================================================================
1124 //function : WritePersistentObjectHeader
1126 //=======================================================================
1128 void DDF_IOStream::WritePersistentObjectHeader(const Standard_Integer aRef,
1129 const Standard_Integer aType)
1131 *myOStream << "\n#" << aRef << "=%" << aType;
1132 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1135 //=======================================================================
1136 //function : BeginWritePersistentObjectData
1138 //=======================================================================
1140 void DDF_IOStream::BeginWritePersistentObjectData()
1143 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1146 //=======================================================================
1147 //function : BeginWriteObjectData
1149 //=======================================================================
1151 void DDF_IOStream::BeginWriteObjectData()
1154 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1157 //=======================================================================
1158 //function : EndWriteObjectData
1160 //=======================================================================
1162 void DDF_IOStream::EndWriteObjectData()
1165 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1168 //=======================================================================
1169 //function : EndWritePersistentObjectData
1171 //=======================================================================
1173 void DDF_IOStream::EndWritePersistentObjectData()
1176 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1179 //=======================================================================
1180 //function : EndWriteDataSection
1182 //=======================================================================
1184 Storage_Error DDF_IOStream::EndWriteDataSection()
1186 *myOStream << "\nEND_DATA_SECTION\n";
1187 if (myOStream->bad()) Storage_StreamWriteError::Raise();
1188 return Storage_VSOk;
1192 // ---------------------- DATA : READ
1195 //=======================================================================
1196 //function : BeginReadDataSection
1198 //=======================================================================
1200 Storage_Error DDF_IOStream::BeginReadDataSection()
1201 { return FindTag("BEGIN_DATA_SECTION"); }
1203 //=======================================================================
1204 //function : ReadPersistentObjectHeader
1206 //=======================================================================
1208 void DDF_IOStream::ReadPersistentObjectHeader(Standard_Integer& aRef,
1209 Standard_Integer& aType)
1216 if (IsEnd() || (c != ' ') || (c == '\n')) {
1217 Storage_StreamFormatError::Raise();
1222 if (!(*myIStream >> aRef)) Storage_StreamTypeMismatchError::Raise("ReadPersistentObjectHeader 1");
1226 if (IsEnd() || (c != ' ') || (c == '\n')) {
1227 Storage_StreamFormatError::Raise();
1235 if (IsEnd() || (c != ' ') || (c == '\n')) {
1236 Storage_StreamFormatError::Raise();
1241 if (!(*myIStream >> aType)) Storage_StreamTypeMismatchError::Raise("ReadPersistentObjectHeader 2");
1244 //=======================================================================
1245 //function : BeginReadPersistentObjectData
1247 //=======================================================================
1249 void DDF_IOStream::BeginReadPersistentObjectData()
1254 if (IsEnd() || (c != ' ') || (c == '\n')) {
1255 Storage_StreamFormatError::Raise();
1261 //=======================================================================
1262 //function : BeginReadObjectData
1264 //=======================================================================
1266 void DDF_IOStream::BeginReadObjectData()
1271 if (IsEnd() || (c != ' ') || (c == '\n')) {
1272 Storage_StreamFormatError::Raise("BeginReadObjectData");
1278 //=======================================================================
1279 //function : EndReadObjectData
1281 //=======================================================================
1283 void DDF_IOStream::EndReadObjectData()
1288 if (IsEnd() || (c != ' ') || (c == '\n')) {
1289 Storage_StreamFormatError::Raise("EndReadObjectData");
1295 //=======================================================================
1296 //function : EndReadPersistentObjectData
1298 //=======================================================================
1300 void DDF_IOStream::EndReadPersistentObjectData()
1306 if (IsEnd() || (c != ' ') || (c == '\n')) {
1307 Storage_StreamFormatError::Raise("EndReadPersistentObjectData");
1314 if (IsEnd() || (c != ' ')) {
1315 Storage_StreamFormatError::Raise();
1321 //=======================================================================
1322 //function : EndReadDataSection
1324 //=======================================================================
1326 Storage_Error DDF_IOStream::EndReadDataSection()
1327 { return FindTag("END_DATA_SECTION"); }
1329 //=======================================================================
1330 //function : IsGoodFileType
1332 //=======================================================================
1334 Storage_Error DDF_IOStream::IsGoodFileType(istream* anIStream)
1339 s = f.Open(anIStream);
1341 if (s == Storage_VSOk) {
1342 TCollection_AsciiString l;
1343 Standard_Integer len = (Standard_Integer) strlen(DDF_IOStream::MagicNumber());
1349 if (strncmp(DDF_IOStream::MagicNumber(),l.ToCString(),len) != 0) {
1351 cout<<"IsGoodFileType: format error"<<endl;
1353 s = Storage_VSFormatError;