diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-09-01 16:39:08 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-01 16:39:08 -0400 |
| commit | cc0b81350f6b681c794b4ac7c0f3b5fe73cb19eb (patch) | |
| tree | 7fd935748f4da5daa381f6cf4ef5d06c6adfc0a6 /source/core/slang-zip-file-system.cpp | |
| parent | f64d8748d4396a90d27adbdc17db3bac4a58d666 (diff) | |
Make ISlangFileSystem derive from ICastable (#2386)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Make ISlangFileSystem derive from ICastable.
* Make ArchiveFileSystem into an interface
Make file systems atomically reference counted.
* Small fix.
* Some small fixes to work around issues of ICastable on ISlangFileSystem
* Use ISlangFileSystem derived type instead of IArchiveFileSystem. Can always get other interface with castAs.
* Some small fixes around change of interface returned from archive type functions.
* Remove CacheFileSystem member from linkage. Can access easily from m_fileSystemExt if necessary with as cast.
* Fix RiffFileSystem casting issue.
* Add a check around CacheFileSystem.
Diffstat (limited to 'source/core/slang-zip-file-system.cpp')
| -rw-r--r-- | source/core/slang-zip-file-system.cpp | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/source/core/slang-zip-file-system.cpp b/source/core/slang-zip-file-system.cpp index 636fd7d9e..d9c0a900e 100644 --- a/source/core/slang-zip-file-system.cpp +++ b/source/core/slang-zip-file-system.cpp @@ -19,12 +19,14 @@ namespace Slang { -class ZipFileSystemImpl : public ArchiveFileSystem +class ZipFileSystemImpl : public ISlangMutableFileSystem, public IArchiveFileSystem, public ComBaseObject { public: // ISlangUnknown - // override ref counting, as DefaultFileSystem is singleton - SLANG_REF_OBJECT_IUNKNOWN_ALL + SLANG_COM_BASE_IUNKNOWN_ALL + + // ISlangCastable + virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE; // ISlangFileSystem virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile(char const* path, ISlangBlob** outBlob) SLANG_OVERRIDE; @@ -44,10 +46,10 @@ public: virtual SLANG_NO_THROW SlangResult SLANG_MCALL remove(const char* path) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL createDirectory(const char* path) SLANG_OVERRIDE; - // ArchiveFileSystem - SlangResult loadArchive(const void* archive, size_t archiveSizeInBytes) SLANG_OVERRIDE; - virtual SlangResult storeArchive(bool blobOwnsContent, ISlangBlob** outBlob) SLANG_OVERRIDE; - virtual void setCompressionStyle(const CompressionStyle& style) SLANG_OVERRIDE; + // IArchiveFileSystem + virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadArchive(const void* archive, size_t archiveSizeInBytes) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL storeArchive(bool blobOwnsContent, ISlangBlob** outBlob) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setCompressionStyle(const CompressionStyle& style) SLANG_OVERRIDE; ZipFileSystemImpl(); ~ZipFileSystemImpl(); @@ -82,7 +84,8 @@ protected: /// Returns true if the named item is at the index UnownedStringSlice _getPathAtIndex(Index index); - ISlangMutableFileSystem* getInterface(const Guid& guid); + void* getInterface(const Guid& guid); + void* getObject(const Guid& guid); void _initReadWrite(mz_zip_archive& outWriter); @@ -101,9 +104,39 @@ protected: mz_zip_archive m_archive; }; -ISlangMutableFileSystem* ZipFileSystemImpl::getInterface(const Guid& guid) +void* ZipFileSystemImpl::getInterface(const Guid& guid) { - return (guid == ISlangUnknown::getTypeGuid() || guid == ISlangFileSystem::getTypeGuid() || guid == ISlangFileSystemExt::getTypeGuid() || guid == ISlangMutableFileSystem::getTypeGuid()) ? static_cast<ISlangMutableFileSystem*>(this) : nullptr; + if ( guid == ISlangUnknown::getTypeGuid() || + guid == ISlangCastable::getTypeGuid()) + { + return static_cast<ISlangMutableFileSystem*>(this); + } + else if (guid == ISlangFileSystem::getTypeGuid() || + guid == ISlangFileSystemExt::getTypeGuid() || + guid == ISlangMutableFileSystem::getTypeGuid()) + { + return static_cast<ISlangMutableFileSystem*>(this); + } + else if (guid == IArchiveFileSystem::getTypeGuid()) + { + return static_cast<IArchiveFileSystem*>(this); + } + return nullptr; +} + +void* ZipFileSystemImpl::getObject(const Guid& guid) +{ + SLANG_UNUSED(guid); + return nullptr; +} + +void* ZipFileSystemImpl::castAs(const Guid& guid) +{ + if (auto ptr = getInterface(guid)) + { + return ptr; + } + return getObject(guid); } // This is a very awkward hack to make it so we can get a read func, without having to implement all of the tracking etc. @@ -767,7 +800,7 @@ void ZipFileSystemImpl::setCompressionStyle(const CompressionStyle& style) } } -/* static */SlangResult ZipFileSystem::create(RefPtr<ArchiveFileSystem>& out) +/* static */SlangResult ZipFileSystem::create(ComPtr<ISlangMutableFileSystem>& out) { out = new ZipFileSystemImpl; return SLANG_OK; |
