0024284: Some trivial warnings produced by ICC 14
[occt.git] / src / FSD / FSD_CmpFile.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#include <FSD_CmpFile.ixx>
20#include <OSD.hxx>
21
7fd59977 22#include <Storage_StreamModeError.hxx>
23#include <Storage_StreamUnknownTypeError.hxx>
24#include <Standard_PCharacter.hxx>
25
26// Propagate the improvement (BUC60808) on all platforms
27// #ifdef WNT
28#define BUC60808
29// BUC60808 : standard output in MS Visual C++ limites the quantity of figures (digits)
30// in part of number after fixed point. The quantity of figures after fixed point
31// could not be more than 15 when we output double number using standard MS VS output operator '<<'.
32// For example, the maximum double value DBL_MAX = 1.7976931348623157e+308 (see float.h) after
33// cout<<setprecision(17)<<DBL_MAX becomes 1.79769313486232e+308 in stream of output
34// (it could be a file stream). When the number 1.79769313486232e+308 is read from the
35// i/o streame (file, for example) it occurs more than allowed maximum value of double
36// type - 1.7976931348623157e+308. Such value is considered as infinite. When it is written
37// to file (for example) again it is written as 1.#INF. Such value can't be read from file next time.
38//#endif
39
40const Standard_CString MAGICNUMBER = "CMPFILE";
7fd59977 41
42//=======================================================================
43//function : FSD_CmpFile
44//purpose :
45//=======================================================================
46
47FSD_CmpFile::FSD_CmpFile()
48{
49
50}
51
52//=======================================================================
53//function : IsGoodFileType
54//purpose : INFO SECTION
55// write
56//=======================================================================
57
58Storage_Error FSD_CmpFile::IsGoodFileType(const TCollection_AsciiString& aName)
59{
60 FSD_CmpFile f;
61 Storage_Error s;
62
63 s = f.Open(aName,Storage_VSRead);
64
65 if (s == Storage_VSOk) {
66 TCollection_AsciiString l;
fb8a7358 67 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
7fd59977 68
69 f.ReadChar(l,len);
70
71 f.Close();
72
73 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
74 s = Storage_VSFormatError;
75 }
76 }
77
78 return s;
79}
80
81//=======================================================================
82//function : Open
83//purpose :
84//=======================================================================
85
86Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode)
87{
88 Storage_Error result = Storage_VSOk;
89
90 SetName(aName);
91
92 if (OpenMode() == Storage_VSNone) {
93
94#if !defined(IRIX) && !defined(DECOSF1)
95 if (aMode == Storage_VSRead) {
96 myStream.open(aName.ToCString(),ios::in|ios::binary); // ios::nocreate is not portable
97 }
98 else if (aMode == Storage_VSWrite) {
99 myStream.open(aName.ToCString(),ios::out|ios::binary);
100 }
101 else if (aMode == Storage_VSReadWrite) {
102 myStream.open(aName.ToCString(),ios::in|ios::out|ios::binary);
103 }
104#else
105 if (aMode == Storage_VSRead) {
106 myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
107 }
108 else if (aMode == Storage_VSWrite) {
109 myStream.open(aName.ToCString(),ios::out);
110 }
111 else if (aMode == Storage_VSReadWrite) {
112 myStream.open(aName.ToCString(),ios::in|ios::out);
113 }
114#endif
115
116 if (myStream.fail()) {
117 result = Storage_VSOpenError;
118 }
119 else {
120 myStream.precision(17);
91322f44 121 myStream.imbue (std::locale::classic()); // use always C locale
7fd59977 122 SetOpenMode(aMode);
123 }
124 }
125 else {
126 result = Storage_VSAlreadyOpen;
127 }
128 return result;
129}
130
131//=======================================================================
132//function : IsEnd
133//purpose :
134//=======================================================================
135
136Standard_Boolean FSD_CmpFile::IsEnd()
137{
138 return myStream.eof();
139}
140
141//=======================================================================
142//function : Close
143//purpose :
144//=======================================================================
145
146Storage_Error FSD_CmpFile::Close()
147{
148 Storage_Error result = Storage_VSOk;
149
150 if (OpenMode() != Storage_VSNone) {
151 myStream.close();
152 SetOpenMode(Storage_VSNone);
153 }
154 else {
155 result = Storage_VSNotOpen;
156 }
157
158 return result;
159}
160
161//=======================================================================
162//function : MagicNumber
163//purpose : ------------------ PROTECTED
164//=======================================================================
165
166const Standard_CString FSD_CmpFile::MagicNumber()
167{
168 return MAGICNUMBER;
169}
170
171//=======================================================================
172//function : FlushEndOfLine
173//purpose :
174//=======================================================================
175
176void FSD_CmpFile::FlushEndOfLine()
177{
178 TCollection_AsciiString aDummy;
179 ReadLine (aDummy); // flush is nothing more than to read till the line-break
180 /*
181 static char Buffer[8192];
182 char c;
183 Standard_Boolean IsEnd = Standard_False;
184
185 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
186 Buffer[0] = '\0';
187 myStream.get(Buffer,8192,'\n');
188
189 if (myStream.get(c) && c != '\r' && c != '\n') {
190 }
191 else {
192 IsEnd = Standard_True;
193 }
194 }
195 */
196}
197
198//=======================================================================
199//function : ReadLine
200//purpose : read from the current position to the end of line.
201//=======================================================================
202
203void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer)
204{
205 char Buffer[8193];
206 //char c;
207 Standard_Boolean IsEnd = Standard_False;
208
209 buffer.Clear();
210
211 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
212 Buffer[0] = '\0';
213 //myStream.get(Buffer,8192,'\n');
214 myStream.getline(Buffer,8192,'\n');
fb8a7358 215 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
7fd59977 216 Buffer[lv] = '\0';
217 }
218
219// if (myStream.get(c) && c != '\r' && c != '\n') {
220// buffer += Buffer;
221// buffer += c;
222// }
223// else {
224 buffer += Buffer;
225 IsEnd = Standard_True;
226// }
227 }
228}
229
230//=======================================================================
231//function : WriteExtendedLine
232//purpose : write from the current position to the end of line.
233//=======================================================================
234
235void FSD_CmpFile::WriteExtendedLine(const TCollection_ExtendedString& buffer)
236{
237#if 0
238 Standard_ExtString extBuffer;
239 Standard_Integer i,c,d;
240
241 extBuffer = buffer.ToExtString();
242
243 for (i = 0; i < buffer.Length(); i++) {
244 c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
245 d = extBuffer[i] & 0x000000FF;
246
247 myStream << (char)c << (char)d;
248 }
249
250 myStream << (char)0 << "\n";
251#endif
252 Standard_ExtString extBuffer;
253 Standard_Integer i;
254
255 extBuffer = buffer.ToExtString();
256 PutInteger(buffer.Length());
257 for (i = 0; i < buffer.Length(); i++) {
258 PutExtCharacter(extBuffer[i]);
259 }
260
261 myStream << "\n";
262}
263
264//=======================================================================
265//function : ReadExtendedLine
266//purpose :
267//=======================================================================
268
269void FSD_CmpFile::ReadExtendedLine(TCollection_ExtendedString& buffer)
270{
271 Standard_ExtCharacter c;
272 Standard_Integer i;
273
274 GetInteger(i);
275
276 for (i = 0; i < buffer.Length(); i++) {
277 GetExtCharacter(c);
278 buffer += c;
279 }
280
281 FlushEndOfLine();
7fd59977 282}
283
284//=======================================================================
285//function : ReadChar
286//purpose : read <rsize> character from the current position.
287//=======================================================================
288
fb8a7358 289void FSD_CmpFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsize)
7fd59977 290{
291 char c;
fb8a7358 292 Standard_Size ccount = 0;
7fd59977 293
294 buffer.Clear();
295
296 while (!IsEnd() && (ccount < rsize)) {
297 myStream.get(c);
298 buffer += c;
299 ccount++;
300 }
301}
302
303//=======================================================================
304//function : ReadString
305//purpose : read from the first none space character position to the end of line.
306//=======================================================================
307
308void FSD_CmpFile::ReadString(TCollection_AsciiString& buffer)
309{
310 char Buffer[8193];
311 char *bpos;
312 Standard_Boolean IsEnd = Standard_False,isFirstTime = Standard_True;
313
314 buffer.Clear();
315
316 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
317 Buffer[0] = '\0';
318 //myStream.get(Buffer,8192,'\n');
319 myStream.getline(Buffer,8192,'\n');
fb8a7358 320 for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
7fd59977 321 Buffer[lv] = '\0';
322 }
323 bpos = Buffer;
324
325 // LeftAdjust
326 //
327 if (isFirstTime) {
328 isFirstTime = Standard_False;
329 while (*bpos == '\n' || *bpos == ' ') bpos++;
330 }
331// char c;
332// if (myStream.get(c) && c != '\n') {
333// buffer += bpos;
334// buffer += c;
335// }
336// else {
337 buffer += bpos;
338 IsEnd = Standard_True;
339// }
340 }
341}
342
343//=======================================================================
344//function : ReadWord
345//purpose : read from the current position to the next white space or end of line.
346//=======================================================================
347
348void FSD_CmpFile::ReadWord(TCollection_AsciiString& buffer)
349{
302f96fb 350 char c = '\0';
7fd59977 351 char b[8193],*tmpb;
352 Standard_Boolean IsEnd = Standard_False;
353 Standard_Integer i;
354
355 tmpb = b;
356 memset(b,'\0',8193);
357 buffer.Clear();
358
359 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
360 myStream.get(c);
361 if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
362 }
363
364 IsEnd = Standard_False;
365 i = 0;
366
367 while (!IsEnd && !FSD_CmpFile::IsEnd()) {
368 if (i == 8192) {
369 buffer += b;
370 tmpb = b;
371 memset(b,'\0',8193);
372 i = 0;
373 }
374 *tmpb = c;
375 tmpb++; i++;
376 myStream.get(c);
377 if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
378 }
379
380 buffer += b;
381}
382
383//=======================================================================
384//function : FindTag
385//purpose :
386//=======================================================================
387
388Storage_Error FSD_CmpFile::FindTag(const Standard_CString aTag)
389{
390 TCollection_AsciiString l;
391
392 ReadString(l);
393
394 while ((strcmp(l.ToCString(),aTag) != 0) && !IsEnd()) {
395 ReadString(l);
396 }
397
398 if (IsEnd()) {
399 return Storage_VSSectionNotFound;
400 }
401 else {
402 return Storage_VSOk;
403 }
404}
405
406//=======================================================================
407//function : SkipObject
408//purpose :
409//=======================================================================
410
411void FSD_CmpFile::SkipObject()
412{
413 FlushEndOfLine();
414}
415
416//=======================================================================
417//function : PutReference
418//purpose : ---------------------- PUBLIC : PUT
419//=======================================================================
420
421Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
422{
423 myStream << aValue << " ";
424 if (myStream.bad()) Storage_StreamWriteError::Raise();
425 return *this;
426}
427
428//=======================================================================
429//function : PutCharacter
430//purpose :
431//=======================================================================
432
433Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
434{
435 unsigned short i;
436
437 i = aValue;
438 myStream << i << " ";
439 if (myStream.bad()) Storage_StreamWriteError::Raise();
440 return *this;
441}
442
443//=======================================================================
444//function : PutExtCharacter
445//purpose :
446//=======================================================================
447
448Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue)
449{
450 myStream << aValue << " ";
451 if (myStream.bad()) Storage_StreamWriteError::Raise();
452 return *this;
453}
454
455//=======================================================================
456//function : PutInteger
457//purpose :
458//=======================================================================
459
460Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
461{
462 myStream << aValue << " ";
463 if (myStream.bad()) Storage_StreamWriteError::Raise();
464 return *this;
465}
466
467//=======================================================================
468//function : PutBoolean
469//purpose :
470//=======================================================================
471
472Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
473{
474 myStream << ((Standard_Integer)aValue) << " ";
475 if (myStream.bad()) Storage_StreamWriteError::Raise();
476 return *this;
477}
478
479//=======================================================================
480//function : PutReal
481//purpose :
482//=======================================================================
483
484Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
485{
7fd59977 486 myStream << ((Standard_Real)aValue) << " ";
7fd59977 487 if (myStream.bad()) Storage_StreamWriteError::Raise();
488 return *this;
7fd59977 489}
490
491//=======================================================================
492//function : PutShortReal
493//purpose :
494//=======================================================================
495
496Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue)
497{
7fd59977 498 myStream << aValue << " ";
7fd59977 499 if (myStream.bad()) Storage_StreamWriteError::Raise();
500 return *this;
7fd59977 501}
502
503//=======================================================================
504//function : GetReference
505//purpose : ----------------- PUBLIC : GET
506//=======================================================================
507
508Storage_BaseDriver& FSD_CmpFile::GetReference(Standard_Integer& aValue)
509{
510 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
511
512 return *this;
513}
514
515//=======================================================================
516//function : GetCharacter
517//purpose :
518//=======================================================================
519
520Storage_BaseDriver& FSD_CmpFile::GetCharacter(Standard_Character& aValue)
521{
522 unsigned short i = 0;
523 if (!(myStream >> i)) {
524 // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
525 // signes (-80 fait ios::badbit, mais la variable i est initialisee)
526 //
527 if (i == 0) Storage_StreamTypeMismatchError::Raise();
528 myStream.clear(ios::goodbit);
529 }
530 aValue = (char)i;
531
532 return *this;
533}
534
535//=======================================================================
536//function : GetExtCharacter
537//purpose :
538//=======================================================================
539
540Storage_BaseDriver& FSD_CmpFile::GetExtCharacter(Standard_ExtCharacter& aValue)
541{
542 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
543
544 return *this;
545}
546
547//=======================================================================
548//function : GetInteger
549//purpose :
550//=======================================================================
551
552Storage_BaseDriver& FSD_CmpFile::GetInteger(Standard_Integer& aValue)
553{
554 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
555
556 return *this;
557}
558
559//=======================================================================
560//function : GetBoolean
561//purpose :
562//=======================================================================
563
564Storage_BaseDriver& FSD_CmpFile::GetBoolean(Standard_Boolean& aValue)
565{
566 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
567
568 return *this;
569}
570
571//=======================================================================
572//function : GetReal
573//purpose :
574//=======================================================================
575
576Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
577{
578#ifdef BUC60808
579 char realbuffer[100];
580
581 realbuffer[0] = '\0';
582 if (!(myStream >> realbuffer)) {
583 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
584 cerr << "\t buffer is" << realbuffer<< endl;
585 Storage_StreamTypeMismatchError::Raise();
586 }
91322f44 587 if (!OSD::CStringToReal(realbuffer,aValue)) {
7fd59977 588 cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
589 cerr << "\t buffer is" << realbuffer<< endl;
7fd59977 590 Storage_StreamTypeMismatchError::Raise();
591 }
592
593 return *this;
594#else
595 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
596
597 return *this;
598#endif
599}
600
601//=======================================================================
602//function : GetShortReal
603//purpose :
604//=======================================================================
605
606Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
607{
608#ifdef BUC60808
609 char realbuffer[100];
610 Standard_Real r = 0.0;
611
612 realbuffer[0] = '\0';
613 if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
91322f44 614 if (!OSD::CStringToReal(realbuffer,r))
615 Storage_StreamTypeMismatchError::Raise();
7fd59977 616
617 aValue = (Standard_ShortReal)r;
618
619 return *this;
620#else
621 if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
622 return *this;
623#endif
624}
625
626//=======================================================================
627//function : Destroy
628//purpose :
629//=======================================================================
630
631void FSD_CmpFile::Destroy()
632{
633 if (OpenMode() != Storage_VSNone) {
634 Close();
635 }
636}
637
638//=======================================================================
639//function : BeginWriteInfoSection
640//purpose : -------------------------- INFO : WRITE
641//=======================================================================
642
643Storage_Error FSD_CmpFile::BeginWriteInfoSection()
644{
645 myStream << FSD_CmpFile::MagicNumber() << '\n';
646 myStream << "BEGIN_INFO_SECTION\n";
647 if (myStream.bad()) Storage_StreamWriteError::Raise();
648
649 return Storage_VSOk;
650}
651
652//=======================================================================
653//function : WriteInfo
654//purpose :
655//=======================================================================
656
657void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
658 const TCollection_AsciiString& dbVersion,
659 const TCollection_AsciiString& date,
660 const TCollection_AsciiString& schemaName,
661 const TCollection_AsciiString& schemaVersion,
662 const TCollection_ExtendedString& appName,
663 const TCollection_AsciiString& appVersion,
664 const TCollection_ExtendedString& dataType,
665 const TColStd_SequenceOfAsciiString& userInfo)
666{
667 Standard_Integer i;
668
669 myStream << nbObj;
670 myStream << "\n";
671 myStream << dbVersion.ToCString() << "\n";
672 myStream << date.ToCString() << "\n";
673 myStream << schemaName.ToCString() << "\n";
674 myStream << schemaVersion.ToCString() << "\n";
675 WriteExtendedLine(appName);
676 myStream << appVersion.ToCString() << "\n";
677 WriteExtendedLine(dataType);
678 myStream << userInfo.Length() << "\n";
679
680 if (myStream.bad()) Storage_StreamWriteError::Raise();
681
682 for (i = 1; i <= userInfo.Length(); i++) {
683 myStream << userInfo.Value(i).ToCString() << "\n";
684 if (myStream.bad()) Storage_StreamWriteError::Raise();
685 }
686}
687
688//=======================================================================
689//function : EndWriteInfoSection
690//purpose : read
691//=======================================================================
692
693Storage_Error FSD_CmpFile::EndWriteInfoSection()
694{
695 myStream << "END_INFO_SECTION\n";
696 if (myStream.bad()) Storage_StreamWriteError::Raise();
697 return Storage_VSOk;
698}
699
700//=======================================================================
701//function : BeginReadInfoSection
702//purpose :
703//=======================================================================
704
705Storage_Error FSD_CmpFile::BeginReadInfoSection()
706{
707 Storage_Error s;
708 TCollection_AsciiString l;
fb8a7358 709 Standard_Size len = strlen(FSD_CmpFile::MagicNumber());
7fd59977 710
711 ReadChar(l,len);
712
713 if (strncmp(FSD_CmpFile::MagicNumber(),l.ToCString(),len) != 0) {
714 s = Storage_VSFormatError;
715 }
716 else {
717 s = FindTag("BEGIN_INFO_SECTION");
718 }
719
720 return s;
721}
722
723//=======================================================================
724//function : ReadInfo
725//purpose : ------------------- INFO : READ
726//=======================================================================
727
728void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
729 TCollection_AsciiString& dbVersion,
730 TCollection_AsciiString& date,
731 TCollection_AsciiString& schemaName,
732 TCollection_AsciiString& schemaVersion,
733 TCollection_ExtendedString& appName,
734 TCollection_AsciiString& appVersion,
735 TCollection_ExtendedString& dataType,
736 TColStd_SequenceOfAsciiString& userInfo)
737{
738 if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
739
740 FlushEndOfLine();
741
742 ReadLine(dbVersion);
743 ReadLine(date);
744 ReadLine(schemaName);
745 ReadLine(schemaVersion);
746 ReadExtendedLine(appName);
747 ReadLine(appVersion);
748 ReadExtendedLine(dataType);
749
750 Standard_Integer i,len = 0;
751
752 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
753
754 FlushEndOfLine();
755
756 TCollection_AsciiString line;
757
758 for (i = 1; i <= len && !IsEnd(); i++) {
759 ReadLine(line);
760 userInfo.Append(line);
761 line.Clear();
762 }
763}
764
765//=======================================================================
766//function : EndReadInfoSection
767//purpose : COMMENTS SECTION
768// write
769//=======================================================================
770
771Storage_Error FSD_CmpFile::EndReadInfoSection()
772{
773 return FindTag("END_INFO_SECTION");
774}
775
776//=======================================================================
777//function : BeginWriteCommentSection
778//purpose : ---------------- COMMENTS : WRITE
779//=======================================================================
780
781Storage_Error FSD_CmpFile::BeginWriteCommentSection()
782{
783 myStream << "BEGIN_COMMENT_SECTION\n";
784 if (myStream.bad()) Storage_StreamWriteError::Raise();
785 return Storage_VSOk;
786}
787
788//=======================================================================
789//function : WriteComment
790//purpose :
791//=======================================================================
792
793void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
794{
795 Standard_Integer i,aSize;
796
797 aSize = aCom.Length();
798 myStream << aSize << "\n";
799 if (myStream.bad()) Storage_StreamWriteError::Raise();
800
801 for (i = 1; i <= aSize; i++) {
802 WriteExtendedLine(aCom.Value(i));
803 if (myStream.bad()) Storage_StreamWriteError::Raise();
804 }
805}
806
807//=======================================================================
808//function : EndWriteCommentSection
809//purpose : read
810//=======================================================================
811
812Storage_Error FSD_CmpFile::EndWriteCommentSection()
813{
814 myStream << "END_COMMENT_SECTION\n";
815 if (myStream.bad()) Storage_StreamWriteError::Raise();
816 return Storage_VSOk;
817}
818
819//=======================================================================
820//function : BeginReadCommentSection
821//purpose : ---------------- COMMENTS : READ
822//=======================================================================
823
824Storage_Error FSD_CmpFile::BeginReadCommentSection()
825{
826 return FindTag("BEGIN_COMMENT_SECTION");
827}
828
829//=======================================================================
830//function : ReadComment
831//purpose :
832//=======================================================================
833
834void FSD_CmpFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
835{
836 TCollection_ExtendedString line;
837 Standard_Integer len,i;
838
839 if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
840
841 FlushEndOfLine();
842
843 for (i = 1; i <= len && !IsEnd(); i++) {
844 ReadExtendedLine(line);
845 aCom.Append(line);
846 line.Clear();
847 }
848}
849
850//=======================================================================
851//function : EndReadCommentSection
852//purpose :
853//=======================================================================
854
855Storage_Error FSD_CmpFile::EndReadCommentSection()
856{
857 return FindTag("END_COMMENT_SECTION");
858}
859
860//=======================================================================
861//function : BeginWriteTypeSection
862//purpose : --------------- TYPE : WRITE
863//=======================================================================
864
865Storage_Error FSD_CmpFile::BeginWriteTypeSection()
866{
867 myStream << "BEGIN_TYPE_SECTION\n";
868 if (myStream.bad()) Storage_StreamWriteError::Raise();
869 return Storage_VSOk;
870}
871
872//=======================================================================
873//function : SetTypeSectionSize
874//purpose :
875//=======================================================================
876
877void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
878{
879 myStream << aSize << "\n";
880 if (myStream.bad()) Storage_StreamWriteError::Raise();
881}
882
883//=======================================================================
884//function : WriteTypeInformations
885//purpose :
886//=======================================================================
887
888void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
889 const TCollection_AsciiString& typeName)
890{
891 myStream << typeNum << " " << typeName.ToCString() << "\n";
892 if (myStream.bad()) Storage_StreamWriteError::Raise();
893}
894
895//=======================================================================
896//function : EndWriteTypeSection
897//purpose : read
898//=======================================================================
899
900Storage_Error FSD_CmpFile::EndWriteTypeSection()
901{
902 myStream << "END_TYPE_SECTION\n";
903 if (myStream.bad()) Storage_StreamWriteError::Raise();
904 return Storage_VSOk;
905}
906
907//=======================================================================
908//function : BeginReadTypeSection
909//purpose : ------------------- TYPE : READ
910//=======================================================================
911
912Storage_Error FSD_CmpFile::BeginReadTypeSection()
913{
914 return FindTag("BEGIN_TYPE_SECTION");
915}
916
917//=======================================================================
918//function : TypeSectionSize
919//purpose :
920//=======================================================================
921
922Standard_Integer FSD_CmpFile::TypeSectionSize()
923{
924 Standard_Integer i;
925
926 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
927
928 FlushEndOfLine();
929
930 return i;
931}
932
933//=======================================================================
934//function : ReadTypeInformations
935//purpose :
936//=======================================================================
937
938void FSD_CmpFile::ReadTypeInformations(Standard_Integer& typeNum,
939 TCollection_AsciiString& typeName)
940{
941 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
942 if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
943 FlushEndOfLine();
944}
945
946//=======================================================================
947//function : EndReadTypeSection
948//purpose : ROOT SECTION
949// write
950//=======================================================================
951
952Storage_Error FSD_CmpFile::EndReadTypeSection()
953{
954 return FindTag("END_TYPE_SECTION");
955}
956
957//=======================================================================
958//function : BeginWriteRootSection
959//purpose : -------------------- ROOT : WRITE
960//=======================================================================
961
962Storage_Error FSD_CmpFile::BeginWriteRootSection()
963{
964 myStream << "BEGIN_ROOT_SECTION\n";
965 if (myStream.bad()) Storage_StreamWriteError::Raise();
966 return Storage_VSOk;
967}
968
969//=======================================================================
970//function : SetRootSectionSize
971//purpose :
972//=======================================================================
973
974void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
975{
976 myStream << aSize << "\n";
977 if (myStream.bad()) Storage_StreamWriteError::Raise();
978}
979
980//=======================================================================
981//function : WriteRoot
982//purpose :
983//=======================================================================
984
985void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
986{
987 myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
988 if (myStream.bad()) Storage_StreamWriteError::Raise();
989}
990
991//=======================================================================
992//function : EndWriteRootSection
993//purpose : read
994//=======================================================================
995
996Storage_Error FSD_CmpFile::EndWriteRootSection()
997{
998 myStream << "END_ROOT_SECTION\n";
999 if (myStream.bad()) Storage_StreamWriteError::Raise();
1000 return Storage_VSOk;
1001}
1002
1003//=======================================================================
1004//function : BeginReadRootSection
1005//purpose : ----------------------- ROOT : READ
1006//=======================================================================
1007
1008Storage_Error FSD_CmpFile::BeginReadRootSection()
1009{
1010 return FindTag("BEGIN_ROOT_SECTION");
1011}
1012
1013//=======================================================================
1014//function : RootSectionSize
1015//purpose :
1016//=======================================================================
1017
1018Standard_Integer FSD_CmpFile::RootSectionSize()
1019{
1020 Standard_Integer i;
1021
1022 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1023
1024 FlushEndOfLine();
1025
1026 return i;
1027}
1028
1029//=======================================================================
1030//function : ReadRoot
1031//purpose :
1032//=======================================================================
1033
1034void FSD_CmpFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
1035{
1036 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1037 ReadWord(rootName);
1038 ReadWord(rootType);
1039}
1040
1041//=======================================================================
1042//function : EndReadRootSection
1043//purpose : REF SECTION
1044// write
1045//=======================================================================
1046
1047Storage_Error FSD_CmpFile::EndReadRootSection()
1048{
1049 return FindTag("END_ROOT_SECTION");
1050}
1051
1052//=======================================================================
1053//function : BeginWriteRefSection
1054//purpose : -------------------------- REF : WRITE
1055//=======================================================================
1056
1057Storage_Error FSD_CmpFile::BeginWriteRefSection()
1058{
1059 myStream << "BEGIN_REF_SECTION\n";
1060 if (myStream.bad()) Storage_StreamWriteError::Raise();
1061 return Storage_VSOk;
1062}
1063
1064//=======================================================================
1065//function : SetRefSectionSize
1066//purpose :
1067//=======================================================================
1068
1069void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
1070{
1071 myStream << aSize << "\n";
1072 if (myStream.bad()) Storage_StreamWriteError::Raise();
1073}
1074
1075//=======================================================================
1076//function : WriteReferenceType
1077//purpose :
1078//=======================================================================
1079
1080void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
1081 const Standard_Integer typeNum)
1082{
1083 myStream << reference << " " << typeNum << "\n";
1084 if (myStream.bad()) Storage_StreamWriteError::Raise();
1085}
1086
1087//=======================================================================
1088//function : EndWriteRefSection
1089//purpose : read
1090//=======================================================================
1091
1092Storage_Error FSD_CmpFile::EndWriteRefSection()
1093{
1094 myStream << "END_REF_SECTION\n";
1095 if (myStream.bad()) Storage_StreamWriteError::Raise();
1096 return Storage_VSOk;
1097}
1098
1099//=======================================================================
1100//function : BeginReadRefSection
1101//purpose : ----------------------- REF : READ
1102//=======================================================================
1103
1104Storage_Error FSD_CmpFile::BeginReadRefSection()
1105{
1106 return FindTag("BEGIN_REF_SECTION");
1107}
1108
1109//=======================================================================
1110//function : RefSectionSize
1111//purpose :
1112//=======================================================================
1113
1114Standard_Integer FSD_CmpFile::RefSectionSize()
1115{
1116 Standard_Integer i;
1117
1118 if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
1119 FlushEndOfLine();
1120
1121 return i;
1122}
1123
1124//=======================================================================
1125//function : ReadReferenceType
1126//purpose :
1127//=======================================================================
1128
1129void FSD_CmpFile::ReadReferenceType(Standard_Integer& reference,
1130 Standard_Integer& typeNum)
1131{
1132 if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
1133 if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
1134 FlushEndOfLine();
1135}
1136
1137//=======================================================================
1138//function : EndReadRefSection
1139//purpose : DATA SECTION
1140// write
1141//=======================================================================
1142
1143Storage_Error FSD_CmpFile::EndReadRefSection()
1144{
1145 return FindTag("END_REF_SECTION");
1146}
1147
1148//=======================================================================
1149//function : BeginWriteDataSection
1150//purpose : -------------------- DATA : WRITE
1151//=======================================================================
1152
1153Storage_Error FSD_CmpFile::BeginWriteDataSection()
1154{
1155 myStream << "BEGIN_DATA_SECTION";
1156 if (myStream.bad()) Storage_StreamWriteError::Raise();
1157 return Storage_VSOk;
1158}
1159
1160//=======================================================================
1161//function : WritePersistentObjectHeader
1162//purpose :
1163//=======================================================================
1164
1165void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
1166 const Standard_Integer aType)
1167{
1168 myStream << "\n#" << aRef << "%" << aType << " ";
1169 if (myStream.bad()) Storage_StreamWriteError::Raise();
1170}
1171
1172//=======================================================================
1173//function : BeginWritePersistentObjectData
1174//purpose :
1175//=======================================================================
1176
1177void FSD_CmpFile::BeginWritePersistentObjectData()
1178{
1179 if (myStream.bad()) Storage_StreamWriteError::Raise();
1180}
1181
1182//=======================================================================
1183//function : BeginWriteObjectData
1184//purpose :
1185//=======================================================================
1186
1187void FSD_CmpFile::BeginWriteObjectData()
1188{
1189 if (myStream.bad()) Storage_StreamWriteError::Raise();
1190}
1191
1192//=======================================================================
1193//function : EndWriteObjectData
1194//purpose :
1195//=======================================================================
1196
1197void FSD_CmpFile::EndWriteObjectData()
1198{
1199 if (myStream.bad()) Storage_StreamWriteError::Raise();
1200}
1201
1202//=======================================================================
1203//function : EndWritePersistentObjectData
1204//purpose :
1205//=======================================================================
1206
1207void FSD_CmpFile::EndWritePersistentObjectData()
1208{
1209 if (myStream.bad()) Storage_StreamWriteError::Raise();
1210}
1211
1212//=======================================================================
1213//function : EndWriteDataSection
1214//purpose : read
1215//=======================================================================
1216
1217Storage_Error FSD_CmpFile::EndWriteDataSection()
1218{
1219 myStream << "\nEND_DATA_SECTION\n";
1220 if (myStream.bad()) Storage_StreamWriteError::Raise();
1221 return Storage_VSOk;
1222}
1223
1224//=======================================================================
1225//function : BeginReadDataSection
1226//purpose : ---------------------- DATA : READ
1227//=======================================================================
1228
1229Storage_Error FSD_CmpFile::BeginReadDataSection()
1230{
1231 return FindTag("BEGIN_DATA_SECTION");
1232}
1233
1234//=======================================================================
1235//function : ReadPersistentObjectHeader
1236//purpose :
1237//=======================================================================
1238
1239void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
1240 Standard_Integer& aType)
1241{
1242 char c;
1243
1244 myStream.get(c);
1245
1246 while (c != '#') {
1247 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1248 Storage_StreamFormatError::Raise();
1249 }
1250 myStream.get(c);
1251 }
1252
1253 if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
1254
1255 myStream.get(c);
1256
1257 while (c != '%') {
1258 if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
1259 Storage_StreamFormatError::Raise();
1260 }
1261 myStream.get(c);
1262 }
1263
1264 if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
1265// cout << "REF:" << aRef << " TYPE:"<< aType << endl;
1266}
1267
1268//=======================================================================
1269//function : BeginReadPersistentObjectData
1270//purpose :
1271//=======================================================================
1272
1273void FSD_CmpFile::BeginReadPersistentObjectData()
1274{
1275//cout << "BeginReadPersistentObjectData" << endl;
1276}
1277
1278//=======================================================================
1279//function : BeginReadObjectData
1280//purpose :
1281//=======================================================================
1282
1283void FSD_CmpFile::BeginReadObjectData()
1284{
1285// cout << "BeginReadObjectData" << endl;
1286}
1287
1288//=======================================================================
1289//function : EndReadObjectData
1290//purpose :
1291//=======================================================================
1292
1293void FSD_CmpFile::EndReadObjectData()
1294{
1295// cout << "EndReadObjectData" << endl;
1296}
1297
1298//=======================================================================
1299//function : EndReadPersistentObjectData
1300//purpose :
1301//=======================================================================
1302
1303void FSD_CmpFile::EndReadPersistentObjectData()
1304{
1305 char c;
1306
1307 myStream.get(c);
1308 while (c != '\n' && (c != '\r')) {
1309 if (IsEnd() || (c != ' ')) {
1310 Storage_StreamFormatError::Raise();
1311 }
1312 myStream.get(c);
1313 }
1314 if (c == '\r') {
1315 myStream.get(c);
1316 }
1317// cout << "EndReadPersistentObjectData" << endl;
1318}
1319
1320//=======================================================================
1321//function : EndReadDataSection
1322//purpose :
1323//=======================================================================
1324
1325Storage_Error FSD_CmpFile::EndReadDataSection()
1326{
1327 return FindTag("END_DATA_SECTION");
1328}
1329
1330//=======================================================================
1331//function : Tell
1332//purpose : return position in the file. Return -1 upon error.
1333//=======================================================================
1334
1335Storage_Position FSD_CmpFile::Tell()
1336{
1337 switch (OpenMode()) {
1338 case Storage_VSRead:
1339 return (Storage_Position) myStream.tellp();
1340 case Storage_VSWrite:
1341 return (Storage_Position) myStream.tellg();
1342 case Storage_VSReadWrite: {
1343 Storage_Position aPosR = (Storage_Position) myStream.tellp();
1344 Storage_Position aPosW = (Storage_Position) myStream.tellg();
1345 if (aPosR < aPosW)
1346 return aPosW;
1347 else
1348 return aPosR;
1349 }
1350 default: return -1;
1351 }
7fd59977 1352}