mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-03 17:56:21 +03:00
0032564: Foundation Classes, OSD_CachedFileSystem - allow referring to non-default File System
Linked file system can be now customized within OSD_CachedFileSystem.
This commit is contained in:
parent
7d7541ceeb
commit
801e67bc7b
@ -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<std::istream>& 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<std::ostream>& theStream) const
|
||||
{
|
||||
return OSD_FileSystem::DefaultFileSystem()->IsOpenOStream (theStream);
|
||||
return myLinkedFS->IsOpenOStream (theStream);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@ -57,7 +67,7 @@ opencascade::std::shared_ptr<std::istream> 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<std::istream> OSD_CachedFileSystem::OpenIStream (co
|
||||
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);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@ -82,13 +92,13 @@ opencascade::std::shared_ptr<std::streambuf> 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;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#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.
|
||||
@ -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
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user