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-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-file-system.cpp')
| -rw-r--r-- | source/core/slang-file-system.cpp | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/source/core/slang-file-system.cpp b/source/core/slang-file-system.cpp index 208c4d834..283dab712 100644 --- a/source/core/slang-file-system.cpp +++ b/source/core/slang-file-system.cpp @@ -7,14 +7,14 @@ namespace Slang { -// Allocate static const storage for the various interface IDs that the Slang API needs to expose - SLANG_FORCE_INLINE static SlangResult _checkExt(FileSystemStyle style) { return Index(style) >= Index(FileSystemStyle::Ext) ? SLANG_OK : SLANG_E_NOT_IMPLEMENTED; } SLANG_FORCE_INLINE static SlangResult _checkMutable(FileSystemStyle style) { return Index(style) >= Index(FileSystemStyle::Mutable) ? SLANG_OK : SLANG_E_NOT_IMPLEMENTED; } SLANG_FORCE_INLINE static bool _canCast(FileSystemStyle style, const Guid& guid) { - if (guid == ISlangUnknown::getTypeGuid() || guid == ISlangFileSystem::getTypeGuid()) + if (guid == ISlangUnknown::getTypeGuid() || + guid == ISlangCastable::getTypeGuid() || + guid == ISlangFileSystem::getTypeGuid()) { return true; } @@ -81,11 +81,26 @@ static SlangResult _calcCombinedPath(SlangPathType fromPathType, const char* fro /* static */OSFileSystem OSFileSystem::g_ext(FileSystemStyle::Ext); /* static */OSFileSystem OSFileSystem::g_mutable(FileSystemStyle::Mutable); +void* OSFileSystem::castAs(const Guid& guid) +{ + if (auto ptr = getInterface(guid)) + { + return ptr; + } + return getObject(guid); +} + ISlangUnknown* OSFileSystem::getInterface(const Guid& guid) { return _canCast(m_style, guid) ? static_cast<ISlangFileSystem*>(this) : nullptr; } +void* OSFileSystem::getObject(const Guid& guid) +{ + SLANG_UNUSED(guid); + return nullptr; +} + static String _fixPathDelimiters(const char* pathIn) { #if SLANG_WINDOWS_FAMILY @@ -245,21 +260,31 @@ SlangResult OSFileSystem::createDirectory(const char* path) } } -SLANG_NO_THROW SlangResult SLANG_MCALL CacheFileSystem::queryInterface(SlangUUID const& uuid, void** outObject) +void* CacheFileSystem::castAs(const Guid& guid) +{ + if (auto ptr = getInterface(guid)) + { + return ptr; + } + return getObject(guid); +} + +void* CacheFileSystem::getInterface(const Guid& guid) { - if (uuid == CacheFileSystem::getTypeGuid()) + if (_canCast(FileSystemStyle::Ext, guid)) { - *outObject = this; - return SLANG_OK; + return static_cast<ISlangFileSystemExt*>(this); } + return nullptr; +} - if (_canCast(FileSystemStyle::Ext, uuid)) +void* CacheFileSystem::getObject(const Guid& guid) +{ + if (guid == CacheFileSystem::getTypeGuid()) { - addReference(); - *outObject = static_cast<ISlangFileSystemExt*>(this); - return SLANG_OK; + return this; } - return SLANG_E_NO_INTERFACE; + return nullptr; } CacheFileSystem::CacheFileSystem(ISlangFileSystem* fileSystem, UniqueIdentityMode uniqueIdentityMode, PathStyle pathStyle) @@ -770,6 +795,21 @@ ISlangUnknown* RelativeFileSystem::getInterface(const Guid& guid) return _canCast(m_style, guid) ? static_cast<ISlangMutableFileSystem*>(this) : nullptr; } +void* RelativeFileSystem::getObject(const Guid& guid) +{ + SLANG_UNUSED(guid); + return nullptr; +} + +void* RelativeFileSystem::castAs(const Guid& guid) +{ + if (auto ptr = getInterface(guid)) + { + return ptr; + } + return getObject(guid); +} + SlangResult RelativeFileSystem::_calcCombinedPathInner(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** outPath) { ISlangFileSystemExt* fileSystem = _getExt(); |
