1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0032490: Data Exchange - provide OSD_FileSystem::OpenOStream() for output streams

- provided OSD_FileSystem::OpenOStream() for output streams
- replaced OSD_OpenStream() usage with OSD_FileSystem::DefaultFileSystem()
This commit is contained in:
mkrylova
2021-07-26 11:09:57 +03:00
committed by bugmaster
parent e93008abdd
commit 27e64adb38
22 changed files with 387 additions and 252 deletions

View File

@@ -34,6 +34,15 @@ Standard_Boolean OSD_CachedFileSystem::IsOpenIStream (const opencascade::std::sh
return OSD_FileSystem::DefaultFileSystem()->IsOpenIStream (theStream);
}
//=======================================================================
// function : IsOpenOStream
// purpose :
//=======================================================================
Standard_Boolean OSD_CachedFileSystem::IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const
{
return OSD_FileSystem::DefaultFileSystem()->IsOpenOStream (theStream);
}
//=======================================================================
// function : OpenIStream
// purpose :
@@ -52,6 +61,16 @@ opencascade::std::shared_ptr<std::istream> OSD_CachedFileSystem::OpenIStream (co
return myStream.Stream;
}
//=======================================================================
// function : OpenOStream
// purpose :
//=======================================================================
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);
}
//=======================================================================
// function : OpenStreamBuffer
// purpose :
@@ -61,6 +80,10 @@ opencascade::std::shared_ptr<std::streambuf> OSD_CachedFileSystem::OpenStreamBuf
const int64_t theOffset,
int64_t* theOutBufSize)
{
if ((theMode & std::ios::out) == std::ios::out)
{
return OSD_FileSystem::DefaultFileSystem()->OpenStreamBuffer (theUrl, theMode, theOffset, theOutBufSize);
}
if (myStream.Url != theUrl)
{
myStream.Url = theUrl;

View File

@@ -34,6 +34,9 @@ public:
//! Returns TRUE if current input stream is opened for reading operations.
Standard_EXPORT virtual Standard_Boolean IsOpenIStream (const opencascade::std::shared_ptr<std::istream>& theStream) const Standard_OVERRIDE;
//! Returns TRUE if current output stream is opened for writing operations.
Standard_EXPORT virtual Standard_Boolean IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const Standard_OVERRIDE;
//! Opens stream for specified file URL for reading operations or returns previously created stream pointing to the same URL.
Standard_EXPORT virtual opencascade::std::shared_ptr<std::istream> OpenIStream
(const TCollection_AsciiString& theUrl,
@@ -41,6 +44,10 @@ public:
const int64_t theOffset,
const opencascade::std::shared_ptr<std::istream>& theOldStream) Standard_OVERRIDE;
//! Opens stream for specified file URL for writing operations (std::ostream) by calling parent's method.
Standard_EXPORT virtual opencascade::std::shared_ptr<std::ostream> OpenOStream (const TCollection_AsciiString& theUrl,
const std::ios_base::openmode theMode) Standard_OVERRIDE;
//! Opens stream buffer for specified file URL.
Standard_EXPORT virtual opencascade::std::shared_ptr<std::streambuf> OpenStreamBuffer
(const TCollection_AsciiString& theUrl,

View File

@@ -98,3 +98,21 @@ opencascade::std::shared_ptr<std::istream> OSD_FileSystem::OpenIStream (const TC
}
return aNewStream;
}
//=======================================================================
// function : OpenOStream
// purpose :
//=======================================================================
opencascade::std::shared_ptr<std::ostream> OSD_FileSystem::OpenOStream (const TCollection_AsciiString& theUrl,
const std::ios_base::openmode theMode)
{
opencascade::std::shared_ptr<std::ostream> aNewStream;
opencascade::std::shared_ptr<std::streambuf> aFileBuf = OpenStreamBuffer (theUrl, theMode | std::ios_base::out);
if (aFileBuf.get() == NULL)
{
return opencascade::std::shared_ptr<std::ostream>();
}
aNewStream.reset(new OSD_OStreamBuffer (theUrl.ToCString(), aFileBuf));
return aNewStream;
}

View File

@@ -35,6 +35,9 @@ public:
//! Returns TRUE if current input stream is opened for reading operations.
virtual Standard_Boolean IsOpenIStream (const opencascade::std::shared_ptr<std::istream>& theStream) const = 0;
//! Returns TRUE if current output stream is opened for writing operations.
virtual Standard_Boolean IsOpenOStream(const opencascade::std::shared_ptr<std::ostream>& theStream) const = 0;
//! Opens stream for specified file URL for reading operations (std::istream).
//! Default implementation create a stream from file buffer returned by OSD_FileSystem::OpenFileBuffer().
//! @param theUrl [in] path to open
@@ -49,6 +52,14 @@ public:
const int64_t theOffset = 0,
const opencascade::std::shared_ptr<std::istream>& theOldStream = opencascade::std::shared_ptr<std::istream>());
//! Opens stream for specified file URL for writing operations (std::ostream).
//! Default implementation create a stream from file buffer returned by OSD_FileSystem::OpenFileBuffer().
//! @param theUrl [in] path to open
//! @param theMode [in] flags describing the requested output mode for the stream (std::ios_base::out will be implicitly added)
//! @return pointer to newly created opened stream or NULL in case of failure.
Standard_EXPORT virtual opencascade::std::shared_ptr<std::ostream> OpenOStream (const TCollection_AsciiString& theUrl,
const std::ios_base::openmode theMode);
//! Opens stream buffer for specified file URL.
//! @param theUrl [in] path to open
//! @param theMode [in] flags describing the requested input mode for the stream

View File

@@ -82,6 +82,31 @@ Standard_Boolean OSD_FileSystemSelector::IsOpenIStream (const opencascade::std::
return false;
}
//=======================================================================
// function : IsOpenOStream
// purpose :
//=======================================================================
Standard_Boolean OSD_FileSystemSelector::IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const
{
opencascade::std::shared_ptr<OSD_OStreamBuffer> aFileStream = opencascade::std::dynamic_pointer_cast<OSD_OStreamBuffer> (theStream);
if (aFileStream.get() == NULL)
{
return false;
}
for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter (myProtocols); aProtIter.More(); aProtIter.Next())
{
const Handle(OSD_FileSystem)& aFileSystem = aProtIter.Value();
if (aFileSystem->IsSupportedPath (TCollection_AsciiString (aFileStream->Url().c_str())))
{
if (aFileSystem->IsOpenOStream (theStream))
{
return true;
}
}
}
return false;
}
//=======================================================================
// function : OpenIStream
// purpose :
@@ -106,6 +131,27 @@ opencascade::std::shared_ptr<std::istream> OSD_FileSystemSelector::OpenIStream (
return opencascade::std::shared_ptr<std::istream>();
}
//=======================================================================
// function : OpenOStream
// purpose :
//=======================================================================
opencascade::std::shared_ptr<std::ostream> OSD_FileSystemSelector::OpenOStream (const TCollection_AsciiString& theUrl,
const std::ios_base::openmode theMode)
{
for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter (myProtocols); aProtIter.More(); aProtIter.Next())
{
const Handle(OSD_FileSystem)& aFileSystem = aProtIter.Value();
if (aFileSystem->IsSupportedPath (theUrl))
{
opencascade::std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (theUrl, theMode);
if (aStream.get() != NULL)
{
return aStream;
}
}
}
return opencascade::std::shared_ptr<std::ostream>();
}
//=======================================================================
// function : OpenStreamBuffer

View File

@@ -43,6 +43,9 @@ public:
//! Returns TRUE if current input stream is opened for reading operations.
Standard_EXPORT virtual Standard_Boolean IsOpenIStream (const opencascade::std::shared_ptr<std::istream>& theStream) const Standard_OVERRIDE;
//! Returns TRUE if current output stream is opened for writing operations.
Standard_EXPORT virtual Standard_Boolean IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const Standard_OVERRIDE;
//! Opens input stream using one of registered protocols.
Standard_EXPORT virtual opencascade::std::shared_ptr<std::istream> OpenIStream
(const TCollection_AsciiString& theUrl,
@@ -50,6 +53,10 @@ public:
const int64_t theOffset = 0,
const opencascade::std::shared_ptr<std::istream>& theOldStream = opencascade::std::shared_ptr<std::istream>()) Standard_OVERRIDE;
//! Opens output stream using one of registered protocols.
Standard_EXPORT virtual opencascade::std::shared_ptr<std::ostream> OpenOStream (const TCollection_AsciiString& theUrl,
const std::ios_base::openmode theMode) Standard_OVERRIDE;
//! Opens stream buffer using one of registered protocols.
Standard_EXPORT virtual opencascade::std::shared_ptr<std::streambuf> OpenStreamBuffer
(const TCollection_AsciiString& theUrl,

View File

@@ -42,6 +42,21 @@ Standard_Boolean OSD_LocalFileSystem::IsOpenIStream (const opencascade::std::sha
return (aFileBuf != NULL) ? aFileBuf->is_open() : false;
}
//=======================================================================
// function : IsOpenOStream
// purpose :
//=======================================================================
Standard_Boolean OSD_LocalFileSystem::IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const
{
opencascade::std::shared_ptr<OSD_OStreamBuffer> aFileStream = opencascade::std::dynamic_pointer_cast<OSD_OStreamBuffer> (theStream);
if (aFileStream.get() == NULL)
{
return false;
}
const std::filebuf* aFileBuf = dynamic_cast<const std::filebuf*> (aFileStream->rdbuf());
return (aFileBuf != NULL) ? aFileBuf->is_open() : false;
}
//=======================================================================
// function : OpenStreamBuffer
// purpose :

View File

@@ -31,6 +31,9 @@ public:
//! Returns TRUE if current input stream is opened for reading operations.
Standard_EXPORT virtual Standard_Boolean IsOpenIStream (const opencascade::std::shared_ptr<std::istream>& theStream) const Standard_OVERRIDE;
//! Returns TRUE if current output stream is opened for writing operations.
Standard_EXPORT virtual Standard_Boolean IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const Standard_OVERRIDE;
//! Opens stream buffer for specified file URL.
Standard_EXPORT virtual opencascade::std::shared_ptr<std::streambuf> OpenStreamBuffer
(const TCollection_AsciiString& theUrl,