From: mpv Date: Tue, 31 Aug 2021 11:46:23 +0000 (+0300) Subject: 0026981: Application Framework - read a BinOcaf document from С++ stream sequentially X-Git-Tag: V7_6_0~17 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=7e63845c9e305355d3b2ecab4d8c854361a59cf4;p=occt.git 0026981: Application Framework - read a BinOcaf document from С++ stream sequentially The current version of the document supports partial reading. So, as a result, the shapes section is dispersed into attributes and it becomes easy avoid any seekg call during the reading. But this will work only in case whole document is opened. For partial reading seekg functions could be naturally called. --- diff --git a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx index b55f032ebc..9d35102059 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx @@ -226,7 +226,6 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& mySections.Clear(); myPAtt.Init(); Handle(TDF_Data) aData = (!theFilter.IsNull() && theFilter->IsAppendMode()) ? aDoc->GetData() : new TDF_Data(); - std::streampos aDocumentPos = -1; Message_ProgressScope aPS (theRange, "Reading data", 3); Standard_Boolean aQuickPart = IsQuickPart (aFileVer); @@ -246,29 +245,33 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& return; } - aDocumentPos = theIStream.tellg(); // position of root label BinLDrivers_VectorOfDocumentSection::Iterator anIterS (mySections); - for (; anIterS.More(); anIterS.Next()) { - BinLDrivers_DocumentSection& aCurSection = anIterS.ChangeValue(); - if (aCurSection.IsPostRead() == Standard_False) { - theIStream.seekg ((std::streampos) aCurSection.Offset()); - if (aCurSection.Name().IsEqual (SHAPESECTION_POS)) - { - ReadShapeSection (aCurSection, theIStream, false, aPS.Next()); - if (!aPS.More()) + // if there is only empty section, do not call tellg and seekg + if (!mySections.IsEmpty() && (mySections.Size() > 1 || !anIterS.Value().Name().IsEqual(ENDSECTION_POS))) + { + std::streampos aDocumentPos = theIStream.tellg(); // position of root label + for (; anIterS.More(); anIterS.Next()) { + BinLDrivers_DocumentSection& aCurSection = anIterS.ChangeValue(); + if (aCurSection.IsPostRead() == Standard_False) { + theIStream.seekg ((std::streampos) aCurSection.Offset()); + if (aCurSection.Name().IsEqual (SHAPESECTION_POS)) { - myReaderStatus = PCDM_RS_UserBreak; - return; + ReadShapeSection (aCurSection, theIStream, false, aPS.Next()); + if (!aPS.More()) + { + myReaderStatus = PCDM_RS_UserBreak; + return; + } } + else if (!aCurSection.Name().IsEqual (ENDSECTION_POS)) + ReadSection (aCurSection, theDoc, theIStream); } - else if (!aCurSection.Name().IsEqual (ENDSECTION_POS)) - ReadSection (aCurSection, theDoc, theIStream); } + theIStream.seekg(aDocumentPos); } } else { //aFileVer < 3 - aDocumentPos = theIStream.tellg(); // position of root label - + std::streampos aDocumentPos = theIStream.tellg(); // position of root label // retrieve SHAPESECTION_POS string char aShapeSecLabel[SIZEOFSHAPELABEL + 1]; aShapeSecLabel[SIZEOFSHAPELABEL] = 0x00; @@ -309,10 +312,10 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& } } } + theIStream.seekg(aDocumentPos); } // end of reading Sections or shape section // Return to read of the Document structure - theIStream.seekg(aDocumentPos); // read the header (tag) of the root label Standard_Integer aTag;