diff --git a/src/OSD/OSD_CachedFileSystem.cxx b/src/OSD/OSD_CachedFileSystem.cxx index e7c119a784..123e54ec85 100644 --- a/src/OSD/OSD_CachedFileSystem.cxx +++ b/src/OSD/OSD_CachedFileSystem.cxx @@ -16,13 +16,23 @@ IMPLEMENT_STANDARD_RTTIEXT(OSD_CachedFileSystem, OSD_FileSystem) +//======================================================================= +// function : OSD_CachedFileSystem +// purpose : +//======================================================================= +OSD_CachedFileSystem::OSD_CachedFileSystem (const Handle(OSD_FileSystem)& theLinkedFileSystem) +: myLinkedFS (!theLinkedFileSystem.IsNull() ? theLinkedFileSystem : OSD_FileSystem::DefaultFileSystem()) +{ + // +} + //======================================================================= // function : IsSupportedPath // purpose : //======================================================================= Standard_Boolean OSD_CachedFileSystem::IsSupportedPath (const TCollection_AsciiString& theUrl) const { - return OSD_FileSystem::DefaultFileSystem()->IsSupportedPath (theUrl); + return myLinkedFS->IsSupportedPath (theUrl); } //======================================================================= @@ -31,7 +41,7 @@ Standard_Boolean OSD_CachedFileSystem::IsSupportedPath (const TCollection_AsciiS //======================================================================= Standard_Boolean OSD_CachedFileSystem::IsOpenIStream (const opencascade::std::shared_ptr& theStream) const { - return OSD_FileSystem::DefaultFileSystem()->IsOpenIStream (theStream); + return myLinkedFS->IsOpenIStream (theStream); } //======================================================================= @@ -40,7 +50,7 @@ Standard_Boolean OSD_CachedFileSystem::IsOpenIStream (const opencascade::std::sh //======================================================================= Standard_Boolean OSD_CachedFileSystem::IsOpenOStream (const opencascade::std::shared_ptr& theStream) const { - return OSD_FileSystem::DefaultFileSystem()->IsOpenOStream (theStream); + return myLinkedFS->IsOpenOStream (theStream); } //======================================================================= @@ -57,7 +67,7 @@ opencascade::std::shared_ptr OSD_CachedFileSystem::OpenIStream (co myStream.Url = theUrl; myStream.Reset(); } - myStream.Stream = OSD_FileSystem::DefaultFileSystem()->OpenIStream (theUrl, theParams, theOffset, myStream.Stream); + myStream.Stream = myLinkedFS->OpenIStream (theUrl, theParams, theOffset, myStream.Stream); return myStream.Stream; } @@ -68,7 +78,7 @@ opencascade::std::shared_ptr OSD_CachedFileSystem::OpenIStream (co opencascade::std::shared_ptr OSD_CachedFileSystem::OpenOStream (const TCollection_AsciiString& theUrl, const std::ios_base::openmode theMode) { - return OSD_FileSystem::DefaultFileSystem()->OpenOStream (theUrl, theMode); + return myLinkedFS->OpenOStream (theUrl, theMode); } //======================================================================= @@ -82,13 +92,13 @@ opencascade::std::shared_ptr OSD_CachedFileSystem::OpenStreamBuf { if ((theMode & std::ios::out) == std::ios::out) { - return OSD_FileSystem::DefaultFileSystem()->OpenStreamBuffer (theUrl, theMode, theOffset, theOutBufSize); + return myLinkedFS->OpenStreamBuffer (theUrl, theMode, theOffset, theOutBufSize); } if (myStream.Url != theUrl) { myStream.Url = theUrl; myStream.Reset(); } - myStream.StreamBuf = OSD_FileSystem::DefaultFileSystem()->OpenStreamBuffer (theUrl, theMode, theOffset, theOutBufSize); + myStream.StreamBuf = myLinkedFS->OpenStreamBuffer (theUrl, theMode, theOffset, theOutBufSize); return myStream.StreamBuf; } diff --git a/src/OSD/OSD_CachedFileSystem.hxx b/src/OSD/OSD_CachedFileSystem.hxx index b7389ec890..170edcf7a9 100644 --- a/src/OSD/OSD_CachedFileSystem.hxx +++ b/src/OSD/OSD_CachedFileSystem.hxx @@ -16,7 +16,7 @@ #include -//! File system keeping last stream created by OSD_FileSystem::DefaultFileSystem() to be reused for opening a stream with the same URL. +//! File system keeping last stream created by linked file system (OSD_FileSystem::DefaultFileSystem() by default) to be reused for opening a stream with the same URL. //! Note that as file is kept in opened state, application will need destroying this object to ensure all files being closed. //! This interface could be handy in context of reading numerous objects pointing to the same file (at different offset). //! Make sure to create a dedicated OSD_CachedFileSystem for each working thread to avoid data races. @@ -26,7 +26,13 @@ class OSD_CachedFileSystem : public OSD_FileSystem public: //! Constructor. - OSD_CachedFileSystem() {} + Standard_EXPORT OSD_CachedFileSystem (const Handle(OSD_FileSystem)& theLinkedFileSystem = Handle(OSD_FileSystem)()); + + //! Return linked file system; initialized with OSD_FileSystem::DefaultFileSystem() by default. + const Handle(OSD_FileSystem)& LinkedFileSystem() const { return myLinkedFS; } + + //! Sets linked file system. + void SetLinkedFileSystem (const Handle(OSD_FileSystem)& theLinkedFileSystem) { myLinkedFS = theLinkedFileSystem; } //! Returns TRUE if URL defines a supported protocol. Standard_EXPORT virtual Standard_Boolean IsSupportedPath (const TCollection_AsciiString& theUrl) const Standard_OVERRIDE; @@ -73,7 +79,8 @@ protected: protected: - OSD_CachedStream myStream; + OSD_CachedStream myStream; //!< active cached stream + Handle(OSD_FileSystem) myLinkedFS; //!< linked file system to open files };