Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:36

0001 // Copyright (c) 2021 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _OSD_CachedFileSystem_HeaderFile
0015 #define _OSD_CachedFileSystem_HeaderFile
0016 
0017 #include <OSD_FileSystem.hxx>
0018 
0019 //! 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.
0020 //! Note that as file is kept in opened state, application will need destroying this object to ensure all files being closed.
0021 //! This interface could be handy in context of reading numerous objects pointing to the same file (at different offset).
0022 //! Make sure to create a dedicated OSD_CachedFileSystem for each working thread to avoid data races.
0023 class OSD_CachedFileSystem : public OSD_FileSystem
0024 {
0025   DEFINE_STANDARD_RTTIEXT(OSD_CachedFileSystem, OSD_FileSystem)
0026 public:
0027 
0028   //! Constructor.
0029   Standard_EXPORT OSD_CachedFileSystem (const Handle(OSD_FileSystem)& theLinkedFileSystem = Handle(OSD_FileSystem)());
0030 
0031   //! Return linked file system; initialized with OSD_FileSystem::DefaultFileSystem() by default.
0032   const Handle(OSD_FileSystem)& LinkedFileSystem() const { return myLinkedFS; }
0033 
0034   //! Sets linked file system.
0035   void SetLinkedFileSystem (const Handle(OSD_FileSystem)& theLinkedFileSystem) { myLinkedFS = theLinkedFileSystem; }
0036 
0037   //! Returns TRUE if URL defines a supported protocol.
0038   Standard_EXPORT virtual Standard_Boolean IsSupportedPath (const TCollection_AsciiString& theUrl) const Standard_OVERRIDE;
0039 
0040   //! Returns TRUE if current input stream is opened for reading operations.
0041   Standard_EXPORT virtual Standard_Boolean IsOpenIStream (const std::shared_ptr<std::istream>& theStream) const Standard_OVERRIDE;
0042 
0043   //! Returns TRUE if current output stream is opened for writing operations.
0044   Standard_EXPORT virtual Standard_Boolean IsOpenOStream (const std::shared_ptr<std::ostream>& theStream) const Standard_OVERRIDE;
0045 
0046   //! Opens stream for specified file URL for reading operations or returns previously created stream pointing to the same URL.
0047   Standard_EXPORT virtual std::shared_ptr<std::istream> OpenIStream
0048                           (const TCollection_AsciiString& theUrl,
0049                            const std::ios_base::openmode theParams,
0050                            const int64_t theOffset,
0051                            const std::shared_ptr<std::istream>& theOldStream) Standard_OVERRIDE;
0052 
0053   //! Opens stream for specified file URL for writing operations (std::ostream) by calling parent's method.
0054   Standard_EXPORT virtual std::shared_ptr<std::ostream> OpenOStream (const TCollection_AsciiString& theUrl,
0055                                                                      const std::ios_base::openmode theMode) Standard_OVERRIDE;
0056 
0057   //! Opens stream buffer for specified file URL.
0058   Standard_EXPORT virtual std::shared_ptr<std::streambuf> OpenStreamBuffer
0059                           (const TCollection_AsciiString& theUrl,
0060                            const std::ios_base::openmode theMode,
0061                            const int64_t theOffset = 0,
0062                            int64_t* theOutBufSize = NULL) Standard_OVERRIDE;
0063 
0064 protected:
0065 
0066   // Auxiliary structure to save shared stream with path to it.
0067   struct OSD_CachedStream
0068   {
0069     TCollection_AsciiString         Url;
0070     std::shared_ptr<std::istream>   Stream;
0071     std::shared_ptr<std::streambuf> StreamBuf;
0072 
0073     void Reset()
0074     {
0075       Stream.reset();
0076       StreamBuf.reset();
0077     }
0078   };
0079 
0080 protected:
0081 
0082   OSD_CachedStream       myStream;   //!< active cached stream
0083   Handle(OSD_FileSystem) myLinkedFS; //!< linked file system to open files
0084 
0085 };
0086 
0087 #endif // _OSD_CachedFileSystem_HeaderFile