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);
}
//=======================================================================
//=======================================================================
Standard_Boolean OSD_CachedFileSystem::IsOpenIStream (const opencascade::std::shared_ptr<std::istream>& theStream) const
{
- return OSD_FileSystem::DefaultFileSystem()->IsOpenIStream (theStream);
+ return myLinkedFS->IsOpenIStream (theStream);
}
//=======================================================================
//=======================================================================
Standard_Boolean OSD_CachedFileSystem::IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const
{
- return OSD_FileSystem::DefaultFileSystem()->IsOpenOStream (theStream);
+ return myLinkedFS->IsOpenOStream (theStream);
}
//=======================================================================
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;
}
opencascade::std::shared_ptr<std::ostream> 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);
}
//=======================================================================
{
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;
}
#include <OSD_FileSystem.hxx>
-//! 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.
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;
protected:
- OSD_CachedStream myStream;
+ OSD_CachedStream myStream; //!< active cached stream
+ Handle(OSD_FileSystem) myLinkedFS; //!< linked file system to open files
};