From ad3f20c684d2fad65f8cc401b3d7aa1e7307df60 Mon Sep 17 00:00:00 2001 From: mkrylova Date: Wed, 14 Jul 2021 15:06:35 +0300 Subject: [PATCH] 0032455: Data Exchange - replace OSD_OpenStream() usage with OSD_FileSystem::DefaultFileSystem() - replaced OSD_OpenStream() usage with OSD_FileSystem::DefaultFileSystem() --- src/BRepTools/BRepTools.cxx | 15 ++++--- .../BinLDrivers_DocumentRetrievalDriver.cxx | 12 +++--- src/BinTools/BinTools.cxx | 14 +++--- src/DBRep/DBRep.cxx | 12 +++--- src/DDocStd/DDocStd_ApplicationCommands.cxx | 7 +-- src/Draw/Draw_VariableCommands.cxx | 21 +++++---- src/Image/Image_DDSParser.cxx | 22 +++++----- src/Image/Image_Texture.cxx | 43 ++++++++++--------- src/LDOM/LDOMParser.cxx | 10 ++--- src/QABugs/QABugs_1.cxx | 21 +++++---- src/QABugs/QABugs_20.cxx | 18 ++++---- src/RWGltf/RWGltf_CafReader.cxx | 37 ++++++++-------- src/RWGltf/RWGltf_CafWriter.cxx | 14 +++--- src/RWStl/RWStl.cxx | 10 ++--- src/RWStl/RWStl_Reader.cxx | 29 ++++++------- src/TObjDRAW/TObjDRAW.cxx | 7 +-- .../XmlLDrivers_DocumentRetrievalDriver.cxx | 10 ++--- 17 files changed, 150 insertions(+), 152 deletions(-) diff --git a/src/BRepTools/BRepTools.cxx b/src/BRepTools/BRepTools.cxx index 61e7a9035e..156ca3fb21 100644 --- a/src/BRepTools/BRepTools.cxx +++ b/src/BRepTools/BRepTools.cxx @@ -747,15 +747,16 @@ Standard_Boolean BRepTools::Read(TopoDS_Shape& Sh, const BRep_Builder& B, const Message_ProgressRange& theProgress) { - std::filebuf fic; - std::istream in(&fic); - OSD_OpenStream (fic, File, std::ios::in); - if(!fic.is_open()) return Standard_False; - + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aStream = aFileSystem->OpenIStream (File, std::ios::in); + if (aStream.get() == NULL) + { + return Standard_False; + } BRepTools_ShapeSet SS(B); - SS.Read(in, theProgress); + SS.Read (*aStream, theProgress); if(!SS.NbShapes()) return Standard_False; - SS.Read(Sh,in); + SS.Read (Sh,*aStream); return Standard_True; } diff --git a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx index e50c315654..b55f032ebc 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -77,15 +77,15 @@ void BinLDrivers_DocumentRetrievalDriver::Read const Handle(PCDM_ReaderFilter)& theFilter, const Message_ProgressRange& theRange) { - std::ifstream aFileStream; - OSD_OpenStream (aFileStream, theFileName, std::ios::in | std::ios::binary); + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFileStream = aFileSystem->OpenIStream (theFileName, std::ios::in | std::ios::binary); - if (aFileStream.is_open() && aFileStream.good()) + if (aFileStream.get() != NULL && aFileStream->good()) { Handle(Storage_Data) dData; - TCollection_ExtendedString aFormat = PCDM_ReadWriter::FileFormat (aFileStream, dData); + TCollection_ExtendedString aFormat = PCDM_ReadWriter::FileFormat (*aFileStream, dData); - Read (aFileStream, dData, theNewDocument, theApplication, theFilter, theRange); + Read (*aFileStream, dData, theNewDocument, theApplication, theFilter, theRange); if (!theRange.More()) { myReaderStatus = PCDM_RS_UserBreak; diff --git a/src/BinTools/BinTools.cxx b/src/BinTools/BinTools.cxx index d5c5d3a1ee..9bffcea881 100644 --- a/src/BinTools/BinTools.cxx +++ b/src/BinTools/BinTools.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -233,12 +234,13 @@ Standard_Boolean BinTools::Write (const TopoDS_Shape& theShape, Standard_Boolean BinTools::Read (TopoDS_Shape& theShape, const Standard_CString theFile, const Message_ProgressRange& theRange) { - std::filebuf aBuf; - OSD_OpenStream (aBuf, theFile, std::ios::in | std::ios::binary); - if (!aBuf.is_open()) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aStream = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary); + if (aStream.get() == NULL) + { return Standard_False; + } - Standard_IStream aStream (&aBuf); - Read (theShape, aStream, theRange); - return aStream.good(); + Read (theShape, *aStream, theRange); + return aStream->good(); } diff --git a/src/DBRep/DBRep.cxx b/src/DBRep/DBRep.cxx index 8e7e90943b..a13d58683d 100644 --- a/src/DBRep/DBRep.cxx +++ b/src/DBRep/DBRep.cxx @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -1584,17 +1584,17 @@ static Standard_Integer readbrep (Draw_Interpretor& theDI, bool isBinaryFormat = true; { // probe file header to recognize format - std::ifstream aFile; - OSD_OpenStream (aFile, aFileName, std::ios::in | std::ios::binary); - if (!aFile.is_open()) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFile = aFileSystem->OpenIStream (aFileName, std::ios::in | std::ios::binary); + if (aFile.get() == NULL) { theDI << "Error: cannot read the file '" << aFileName << "'"; return 1; } char aStringBuf[255] = {}; - aFile.read (aStringBuf, 255); - if (aFile.fail()) + aFile->read (aStringBuf, 255); + if (aFile->fail()) { theDI << "Error: cannot read the file '" << aFileName << "'"; return 1; diff --git a/src/DDocStd/DDocStd_ApplicationCommands.cxx b/src/DDocStd/DDocStd_ApplicationCommands.cxx index c923df9cf5..a035d99562 100644 --- a/src/DDocStd/DDocStd_ApplicationCommands.cxx +++ b/src/DDocStd/DDocStd_ApplicationCommands.cxx @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -179,10 +180,10 @@ static Standard_Integer DDocStd_Open (Draw_Interpretor& di, Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1); if (anUseStream) { - std::ifstream aFileStream; - OSD_OpenStream (aFileStream, path, std::ios::in | std::ios::binary); + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFileStream = aFileSystem->OpenIStream (path, std::ios::in | std::ios::binary); - theStatus = A->Open (aFileStream, D, aFilter, aProgress->Start()); + theStatus = A->Open (*aFileStream, D, aFilter, aProgress->Start()); } else { diff --git a/src/Draw/Draw_VariableCommands.cxx b/src/Draw/Draw_VariableCommands.cxx index 2dd7d81a29..bb502d777e 100644 --- a/src/Draw/Draw_VariableCommands.cxx +++ b/src/Draw/Draw_VariableCommands.cxx @@ -41,6 +41,7 @@ extern Draw_Viewer dout; #include #include +#include #include Standard_Boolean Draw_ParseFailed = Standard_True; @@ -142,19 +143,17 @@ static Standard_Integer restore (Draw_Interpretor& theDI, const char* aFileName = theArgVec[1]; const char* aVarName = theArgVec[2]; - - std::filebuf aFileBuf; - std::istream aStream (&aFileBuf); - OSD_OpenStream (aFileBuf, aFileName, std::ios::in); - if (!aFileBuf.is_open()) + + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aStream = aFileSystem->OpenIStream (aFileName, std::ios::in); + if (aStream.get() == NULL) { theDI << "Error: cannot open file for reading: '" << aFileName << "'"; return 1; } - char aType[255] = {}; - aStream >> aType; - if (aStream.fail()) + *aStream >> aType; + if (aStream->fail()) { theDI << "Error: cannot read file: '" << aFileName << "'"; return 1; @@ -163,12 +162,12 @@ static Standard_Integer restore (Draw_Interpretor& theDI, { Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1); Draw::SetProgressBar (aProgress); - Handle(Draw_Drawable3D) aDrawable = Draw_Drawable3D::Restore (aType, aStream); + Handle(Draw_Drawable3D) aDrawable = Draw_Drawable3D::Restore (aType, *aStream); if (aDrawable.IsNull()) { // assume that this file stores a DBRep_DrawableShape variable - aStream.seekg (0, std::ios::beg); - aDrawable = Draw_Drawable3D::Restore ("DBRep_DrawableShape", aStream); + aStream->seekg (0, std::ios::beg); + aDrawable = Draw_Drawable3D::Restore ("DBRep_DrawableShape", *aStream); } if (aDrawable.IsNull()) { diff --git a/src/Image/Image_DDSParser.cxx b/src/Image/Image_DDSParser.cxx index 7addc9361c..c2716f4eb0 100644 --- a/src/Image/Image_DDSParser.cxx +++ b/src/Image/Image_DDSParser.cxx @@ -16,7 +16,7 @@ #include #include #include -#include +#include IMPLEMENT_STANDARD_RTTIEXT(Image_CompressedPixMap, Standard_Transient) @@ -67,21 +67,19 @@ Handle(Image_CompressedPixMap) Image_DDSParser::Load (const Handle(Image_Support const Standard_Integer theFaceIndex, const int64_t theFileOffset) { - std::ifstream aFile; - OSD_OpenStream (aFile, theFile.ToCString(), std::ios::in | std::ios::binary); - + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFile = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary); char aHeader[128] = {}; - if (!aFile.is_open() - || !aFile.good()) + if (aFile.get() == NULL || !aFile->good()) { return Handle(Image_CompressedPixMap)(); } if (theFileOffset != 0) { - aFile.seekg ((std::streamoff )theFileOffset, std::ios::beg); + aFile->seekg ((std::streamoff )theFileOffset, std::ios::beg); } - aFile.read (aHeader, 128); - Standard_Size aNbReadBytes = (Standard_Size )aFile.gcount(); + aFile->read (aHeader, 128); + Standard_Size aNbReadBytes = (Standard_Size )aFile->gcount(); if (aNbReadBytes < 128 || ::memcmp (aHeader, "DDS ", 4) != 0) { @@ -115,11 +113,11 @@ Handle(Image_CompressedPixMap) Image_DDSParser::Load (const Handle(Image_Support const Standard_Size anOffset = aDef->FaceBytes() * theFaceIndex; if (anOffset != 0) { - aFile.seekg ((std::streamoff )anOffset, std::ios::cur); + aFile->seekg ((std::streamoff )anOffset, std::ios::cur); } Handle(NCollection_Buffer) aBuffer = new NCollection_Buffer (Image_PixMap::DefaultAllocator(), aDef->FaceBytes()); - aFile.read ((char* )aBuffer->ChangeData(), aDef->FaceBytes()); - aNbReadBytes = (Standard_Size )aFile.gcount(); + aFile->read ((char* )aBuffer->ChangeData(), aDef->FaceBytes()); + aNbReadBytes = (Standard_Size )aFile->gcount(); if (aNbReadBytes < aDef->FaceBytes()) { Message::SendFail (TCollection_AsciiString ("DDS Reader error - unable to read face #") + theFaceIndex + " data from file\n" + theFile); diff --git a/src/Image/Image_Texture.cxx b/src/Image/Image_Texture.cxx index 7d1a168ac0..df635ce381 100644 --- a/src/Image/Image_Texture.cxx +++ b/src/Image/Image_Texture.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #include IMPLEMENT_STANDARD_RTTIEXT(Image_Texture, Standard_Transient) @@ -185,22 +186,22 @@ Handle(Image_PixMap) Image_Texture::loadImageOffset (const TCollection_AsciiStri return Handle(Image_PixMap)(); } - std::ifstream aFile; - OSD_OpenStream (aFile, thePath.ToCString(), std::ios::in | std::ios::binary); - if (!aFile) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFile = aFileSystem->OpenIStream (thePath, std::ios::in | std::ios::binary); + if (aFile.get() == NULL) { Message::SendFail (TCollection_AsciiString ("Error: Image file '") + thePath + "' cannot be opened"); return Handle(Image_PixMap)(); } - aFile.seekg ((std::streamoff )theOffset, std::ios_base::beg); - if (!aFile.good()) + aFile->seekg ((std::streamoff )theOffset, std::ios_base::beg); + if (!aFile->good()) { Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + thePath + "'"); return Handle(Image_PixMap)(); } Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap(); - if (!anImage->Load (aFile, thePath)) + if (!anImage->Load (*aFile, thePath)) { return Handle(Image_PixMap)(); } @@ -251,24 +252,24 @@ TCollection_AsciiString Image_Texture::ProbeImageFileFormat() const } else { - std::ifstream aFileIn; - OSD_OpenStream (aFileIn, myImagePath.ToCString(), std::ios::in | std::ios::binary); - if (!aFileIn) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFileIn = aFileSystem->OpenIStream (myImagePath, std::ios::in | std::ios::binary); + if (aFileIn.get() == NULL) { Message::SendFail (TCollection_AsciiString ("Error: Unable to open file '") + myImagePath + "'"); return false; } if (myOffset >= 0) { - aFileIn.seekg ((std::streamoff )myOffset, std::ios_base::beg); - if (!aFileIn.good()) + aFileIn->seekg ((std::streamoff )myOffset, std::ios_base::beg); + if (!aFileIn->good()) { Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + myImagePath + "'"); return false; } } - if (!aFileIn.read (aBuffer, THE_PROBE_SIZE)) + if (!aFileIn->read (aBuffer, THE_PROBE_SIZE)) { Message::SendFail (TCollection_AsciiString ("Error: unable to read image file '") + myImagePath + "'"); return false; @@ -355,9 +356,9 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream, return true; } - std::ifstream aFileIn; - OSD_OpenStream (aFileIn, myImagePath.ToCString(), std::ios::in | std::ios::binary); - if (!aFileIn) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFileIn = aFileSystem->OpenIStream (myImagePath, std::ios::in | std::ios::binary); + if (aFileIn.get() == NULL) { Message::SendFail (TCollection_AsciiString ("Error: Unable to open file ") + myImagePath + "!"); return false; @@ -366,8 +367,8 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream, int64_t aLen = myLength; if (myOffset >= 0) { - aFileIn.seekg ((std::streamoff )myOffset, std::ios_base::beg); - if (!aFileIn.good()) + aFileIn->seekg ((std::streamoff )myOffset, std::ios_base::beg); + if (!aFileIn->good()) { Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + myImagePath + "'"); return false; @@ -375,9 +376,9 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream, } else { - aFileIn.seekg (0, std::ios_base::end); - aLen = (int64_t )aFileIn.tellg(); - aFileIn.seekg (0, std::ios_base::beg); + aFileIn->seekg (0, std::ios_base::end); + aLen = (int64_t )aFileIn->tellg(); + aFileIn->seekg (0, std::ios_base::beg); } Standard_Integer aChunkSize = 4096; @@ -388,7 +389,7 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream, { aChunkSize = Standard_Integer(aLen - aChunkIter); } - if (!aFileIn.read ((char* )&aBuffer.ChangeFirst(), aChunkSize)) + if (!aFileIn->read ((char* )&aBuffer.ChangeFirst(), aChunkSize)) { Message::SendFail (TCollection_AsciiString ("Error: unable to read image file '") + myImagePath + "'"); return false; diff --git a/src/LDOM/LDOMParser.cxx b/src/LDOM/LDOMParser.cxx index adf8d9b883..6ee1ecfe7a 100644 --- a/src/LDOM/LDOMParser.cxx +++ b/src/LDOM/LDOMParser.cxx @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #ifdef _MSC_VER @@ -147,12 +147,12 @@ Standard_Boolean LDOMParser::parse (std::istream& anInput, Standard_Boolean LDOMParser::parse (const char * const aFileName) { - std::ifstream aFileStream; - OSD_OpenStream (aFileStream, aFileName, std::ios::in); + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFileStream = aFileSystem->OpenIStream (aFileName, std::ios::in); - if (aFileStream.good()) + if (aFileStream.get() != NULL && aFileStream->good()) { - return parse (aFileStream); + return parse (*aFileStream); } else { diff --git a/src/QABugs/QABugs_1.cxx b/src/QABugs/QABugs_1.cxx index 000446cf63..7890b3c807 100644 --- a/src/QABugs/QABugs_1.cxx +++ b/src/QABugs/QABugs_1.cxx @@ -389,7 +389,7 @@ static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, co #include #include -#include +#include #include #include //======================================================================= @@ -459,35 +459,34 @@ static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs } else { - std::ifstream aFile; - OSD_OpenStream (aFile, anImgPath.ToCString(), std::ios::in | std::ios::binary); - if (!aFile.is_open()) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFile = aFileSystem->OpenIStream (anImgPath, std::ios::in | std::ios::binary); + if (aFile.get() == NULL) { std::cout << "Syntax error: image file '" << anImgPath << "' cannot be found\n"; return 1; } if (anOffset != 0) { - aFile.seekg (anOffset); + aFile->seekg (anOffset); } if (aSrc == 2) { - aFile.seekg (0, std::ios::end); - Standard_Integer aLen = (Standard_Integer )aFile.tellg() - anOffset; - aFile.seekg (anOffset); + aFile->seekg (0, std::ios::end); + Standard_Integer aLen = (Standard_Integer )aFile->tellg() - anOffset; + aFile->seekg (anOffset); if (aLen <= 0) { std::cout << "Syntax error: wrong offset\n"; return 1; } NCollection_Array1 aBuff (1, aLen); - if (!aFile.read ((char* )&aBuff.ChangeFirst(), aBuff.Size())) + if (!aFile->read ((char* )&aBuff.ChangeFirst(), aBuff.Size())) { std::cout << "Error: unable to read file\n"; return 1; } - aFile.close(); if (!anImage->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath)) { return 0; @@ -495,7 +494,7 @@ static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs } else { - if (!anImage->Load (aFile, anImgPath)) + if (!anImage->Load (*aFile, anImgPath)) { return 0; } diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx index 7c8391c77d..67da0fa80f 100644 --- a/src/QABugs/QABugs_20.cxx +++ b/src/QABugs/QABugs_20.cxx @@ -2269,7 +2269,7 @@ static Standard_Integer OCC28829 (Draw_Interpretor&, Standard_Integer, const cha #include #include -#include +#include #include #include #include @@ -2290,22 +2290,22 @@ static Standard_Integer OCC28887 (Draw_Interpretor&, Standard_Integer theNbArgs, const TCollection_AsciiString aName (theArgVec[2]); Handle(NCollection_Buffer) aBuffer; { - std::ifstream aFile; - OSD_OpenStream (aFile, aFilePath.ToCString(), std::ios::binary | std::ios::in); - if (!aFile.is_open()) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFile = aFileSystem->OpenIStream (aFilePath, std::ios::binary | std::ios::in); + if (aFile.get() == NULL) { std::cout << "Error: input file '" << aFilePath << "' cannot be read\n"; return 1; } - aFile.seekg (0, std::ios_base::end); - const int64_t aFileLength = int64_t (aFile.tellg()); + aFile->seekg (0, std::ios_base::end); + const int64_t aFileLength = int64_t (aFile->tellg()); if (aFileLength > int64_t (std::numeric_limits::max()) || aFileLength < 1) { std::cout << "Error: input file '" << aFilePath << "' is too large\n"; return 1; } - aFile.seekg (0, std::ios_base::beg); + aFile->seekg (0, std::ios_base::beg); aBuffer = new NCollection_Buffer (NCollection_BaseAllocator::CommonBaseAllocator()); if (!aBuffer->Allocate (size_t(aFileLength))) @@ -2314,8 +2314,8 @@ static Standard_Integer OCC28887 (Draw_Interpretor&, Standard_Integer theNbArgs, return 1; } - aFile.read ((char* )aBuffer->ChangeData(), aBuffer->Size()); - if (!aFile.good()) + aFile->read ((char* )aBuffer->ChangeData(), aBuffer->Size()); + if (!aFile->good()) { std::cout << "Error: input file '" << aFilePath << "' reading failure\n"; return 1; diff --git a/src/RWGltf/RWGltf_CafReader.cxx b/src/RWGltf/RWGltf_CafReader.cxx index 90f1b01736..499ffdb0e8 100644 --- a/src/RWGltf/RWGltf_CafReader.cxx +++ b/src/RWGltf/RWGltf_CafReader.cxx @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include @@ -189,10 +189,9 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t Message_ProgressScope aPSentry (theProgress, "Reading glTF", 2); aPSentry.Show(); - std::ifstream aFile; - OSD_OpenStream (aFile, theFile.ToCString(), std::ios::in | std::ios::binary); - if (!aFile.is_open() - || !aFile.good()) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFile = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary); + if (aFile.get() == NULL || !aFile->good()) { Message::SendFail (TCollection_AsciiString ("File '") + theFile + "' is not found"); return false; @@ -200,7 +199,7 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t bool isBinaryFile = false; char aGlbHeader[12] = {}; - aFile.read (aGlbHeader, sizeof(aGlbHeader)); + aFile->read (aGlbHeader, sizeof (aGlbHeader)); int64_t aBinBodyOffset = 0; int64_t aBinBodyLen = 0; int64_t aJsonBodyOffset = 0; @@ -219,7 +218,7 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t } char aHeader1[8] = {}; - aFile.read (aHeader1, sizeof(aHeader1)); + aFile->read (aHeader1, sizeof (aHeader1)); const uint32_t* aSceneLen = (const uint32_t* )(aHeader1 + 0); const uint32_t* aSceneFormat = (const uint32_t* )(aHeader1 + 4); @@ -241,16 +240,16 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t Message::SendWarning (TCollection_AsciiString ("File '") + theFile + "' is written using unknown version " + int(*aVer)); } - for (int aChunkIter = 0; !aFile.eof() && aChunkIter < 2; ++aChunkIter) + for (int aChunkIter = 0; !aFile->eof() && aChunkIter < 2; ++aChunkIter) { char aChunkHeader2[8] = {}; - if (int64_t(aFile.tellg()) + int64_t(sizeof(aChunkHeader2)) > int64_t(*aLen)) + if (int64_t (aFile->tellg()) + int64_t (sizeof (aChunkHeader2)) > int64_t (*aLen)) { break; } - aFile.read (aChunkHeader2, sizeof(aChunkHeader2)); - if (!aFile.good()) + aFile->read (aChunkHeader2, sizeof (aChunkHeader2)); + if (!aFile->good()) { Message::SendFail (TCollection_AsciiString ("File '") + theFile + "' is written using unsupported format"); return false; @@ -260,26 +259,26 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t const uint32_t* aChunkType = (const uint32_t* )(aChunkHeader2 + 4); if (*aChunkType == 0x4E4F534A) { - aJsonBodyOffset = int64_t(aFile.tellg()); - aJsonBodyLen = int64_t(*aChunkLen); + aJsonBodyOffset = int64_t (aFile->tellg()); + aJsonBodyLen = int64_t (*aChunkLen); } else if (*aChunkType == 0x004E4942) { - aBinBodyOffset = int64_t(aFile.tellg()); - aBinBodyLen = int64_t(*aChunkLen); + aBinBodyOffset = int64_t (aFile->tellg()); + aBinBodyLen = int64_t (*aChunkLen); } if (*aChunkLen != 0) { - aFile.seekg (*aChunkLen, std::ios_base::cur); + aFile->seekg (*aChunkLen, std::ios_base::cur); } } - aFile.seekg ((std::streamoff )aJsonBodyOffset, std::ios_base::beg); + aFile->seekg ((std::streamoff )aJsonBodyOffset, std::ios_base::beg); } } else { - aFile.seekg (0, std::ios_base::beg); + aFile->seekg (0, std::ios_base::beg); } TCollection_AsciiString anErrPrefix = TCollection_AsciiString ("File '") + theFile + "' defines invalid glTF!\n"; @@ -303,7 +302,7 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t #ifdef HAVE_RAPIDJSON rapidjson::ParseResult aRes; - rapidjson::IStreamWrapper aFileStream (aFile); + rapidjson::IStreamWrapper aFileStream (*aFile); if (isBinaryFile) { aRes = aDoc.ParseStream, rapidjson::IStreamWrapper> (aFileStream); diff --git a/src/RWGltf/RWGltf_CafWriter.cxx b/src/RWGltf/RWGltf_CafWriter.cxx index 3dedb7f8f7..bf4e8d7d62 100644 --- a/src/RWGltf/RWGltf_CafWriter.cxx +++ b/src/RWGltf/RWGltf_CafWriter.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -724,19 +725,18 @@ bool RWGltf_CafWriter::writeJson (const Handle(TDocStd_Document)& theDocument, if (aFullLen64 < std::numeric_limits::max()) { { - std::ifstream aBinFile; - OSD_OpenStream (aBinFile, myBinFileNameFull.ToCString(), std::ios::in | std::ios::binary); - if (!aBinFile.is_open() - || !aBinFile.good()) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aBinFile = aFileSystem->OpenIStream (myBinFileNameFull, std::ios::in | std::ios::binary); + if (aBinFile.get() == NULL || !aBinFile->good()) { Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' cannot be opened"); return false; } char aBuffer[4096]; - for (; aBinFile.good();) + for (; aBinFile->good();) { - aBinFile.read (aBuffer, 4096); - const Standard_Integer aReadLen = (Standard_Integer )aBinFile.gcount(); + aBinFile->read (aBuffer, 4096); + const Standard_Integer aReadLen = (Standard_Integer )aBinFile->gcount(); if (aReadLen == 0) { break; diff --git a/src/RWStl/RWStl.cxx b/src/RWStl/RWStl.cxx index dd8cace64c..c830d7715c 100644 --- a/src/RWStl/RWStl.cxx +++ b/src/RWStl/RWStl.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -153,16 +154,15 @@ Handle(Poly_Triangulation) RWStl::ReadBinary (const OSD_Path& theFile, TCollection_AsciiString aPath; theFile.SystemName (aPath); - std::filebuf aBuf; - OSD_OpenStream (aBuf, aPath, std::ios::in | std::ios::binary); - if (!aBuf.is_open()) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aStream = aFileSystem->OpenIStream (aPath, std::ios::in | std::ios::binary); + if (aStream.get() == NULL) { return Handle(Poly_Triangulation)(); } - Standard_IStream aStream (&aBuf); Reader aReader; - if (!aReader.ReadBinary (aStream, theProgress)) + if (!aReader.ReadBinary (*aStream, theProgress)) { return Handle(Poly_Triangulation)(); } diff --git a/src/RWStl/RWStl_Reader.cxx b/src/RWStl/RWStl_Reader.cxx index 1ebfe92725..69a70dcc3b 100644 --- a/src/RWStl/RWStl_Reader.cxx +++ b/src/RWStl/RWStl_Reader.cxx @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -131,26 +131,23 @@ namespace Standard_Boolean RWStl_Reader::Read (const char* theFile, const Message_ProgressRange& theProgress) { - std::filebuf aBuf; - OSD_OpenStream (aBuf, theFile, std::ios::in | std::ios::binary); - if (!aBuf.is_open()) + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aStream = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary); + if (aStream.get() == NULL) { Message::SendFail (TCollection_AsciiString("Error: file '") + theFile + "' is not found"); return Standard_False; } - - Standard_IStream aStream (&aBuf); - // get length of file to feed progress indicator in Ascii mode - aStream.seekg (0, aStream.end); - std::streampos theEnd = aStream.tellg(); - aStream.seekg (0, aStream.beg); + aStream->seekg (0, aStream->end); + std::streampos theEnd = aStream->tellg(); + aStream->seekg (0, aStream->beg); // binary STL files cannot be shorter than 134 bytes // (80 bytes header + 4 bytes facet count + 50 bytes for one facet); // thus assume files shorter than 134 as Ascii without probing // (probing may bring stream to fail state if EOF is reached) - bool isAscii = ((size_t)theEnd < THE_STL_MIN_FILE_SIZE || IsAscii (aStream, true)); + bool isAscii = ((size_t)theEnd < THE_STL_MIN_FILE_SIZE || IsAscii (*aStream, true)); Standard_ReadLineBuffer aBuffer (THE_BUFFER_SIZE); @@ -160,25 +157,25 @@ Standard_Boolean RWStl_Reader::Read (const char* theFile, // For this reason use infinite (logarithmic) progress scale, // but in special mode so that the first cycle will take ~ 70% of it Message_ProgressScope aPS (theProgress, NULL, 1, true); - while (aStream.good()) + while (aStream->good()) { if (isAscii) { - if (!ReadAscii (aStream, aBuffer, theEnd, aPS.Next(2))) + if (!ReadAscii (*aStream, aBuffer, theEnd, aPS.Next (2))) { break; } } else { - if (!ReadBinary (aStream, aPS.Next(2))) + if (!ReadBinary (*aStream, aPS.Next (2))) { break; } } - aStream >> std::ws; // skip any white spaces + *aStream >> std::ws; // skip any white spaces } - return ! aStream.fail(); + return ! aStream->fail(); } //============================================================================== diff --git a/src/TObjDRAW/TObjDRAW.cxx b/src/TObjDRAW/TObjDRAW.cxx index 1a400735f3..a42e88f16f 100644 --- a/src/TObjDRAW/TObjDRAW.cxx +++ b/src/TObjDRAW/TObjDRAW.cxx @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -251,9 +252,9 @@ static Standard_Integer loadModel (Draw_Interpretor& di, Standard_Integer argc, aModel = new TObjDRAW_Model(); if (anUseStream) { - std::ifstream aFileStream; - OSD_OpenStream (aFileStream, aPath, std::ios::in | std::ios::binary); - isLoaded = aModel->Load (aFileStream); + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFileStream = aFileSystem->OpenIStream (aPath, std::ios::in | std::ios::binary); + isLoaded = aModel->Load (*aFileStream); } else isLoaded = aModel->Load (aPath); diff --git a/src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx b/src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx index b554232c54..b931737026 100644 --- a/src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx +++ b/src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx @@ -22,8 +22,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -175,12 +175,12 @@ void XmlLDrivers_DocumentRetrievalDriver::Read myReaderStatus = PCDM_RS_DriverFailure; myFileName = theFileName; - std::ifstream aFileStream; - OSD_OpenStream (aFileStream, myFileName, std::ios::in); + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + opencascade::std::shared_ptr aFileStream = aFileSystem->OpenIStream (myFileName, std::ios::in); - if (aFileStream.is_open() && aFileStream.good()) + if (aFileStream.get() != NULL && aFileStream->good()) { - Read (aFileStream, NULL, theNewDocument, theApplication, theFilter, theRange); + Read (*aFileStream, NULL, theNewDocument, theApplication, theFilter, theRange); } else {