summaryrefslogtreecommitdiffstats
path: root/source/core/slang-file-system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-file-system.cpp')
-rw-r--r--source/core/slang-file-system.cpp64
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();