diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-04-01 18:59:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-01 15:59:24 -0700 |
| commit | 9475b11045089c9bc9773b16f7eb84f843db70c4 (patch) | |
| tree | f2855e1283a3811fd771d646f6e2532ca9cb5e21 /source/core | |
| parent | 2a32fae2ca766862ad76973ab37605edf9ec0faa (diff) | |
Associating GUID (or UUID) with types (#1776)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Add mechanism to embed guid inside of type.
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-blob.cpp | 8 | ||||
| -rw-r--r-- | source/core/slang-compression-system.h | 4 | ||||
| -rw-r--r-- | source/core/slang-deflate-compression-system.cpp | 4 | ||||
| -rw-r--r-- | source/core/slang-file-system.cpp | 20 | ||||
| -rw-r--r-- | source/core/slang-file-system.h | 3 | ||||
| -rw-r--r-- | source/core/slang-lz4-compression-system.cpp | 4 | ||||
| -rw-r--r-- | source/core/slang-riff-file-system.cpp | 8 | ||||
| -rw-r--r-- | source/core/slang-shared-library.cpp | 9 | ||||
| -rw-r--r-- | source/core/slang-writer.cpp | 4 | ||||
| -rw-r--r-- | source/core/slang-zip-file-system.cpp | 8 |
10 files changed, 18 insertions, 54 deletions
diff --git a/source/core/slang-blob.cpp b/source/core/slang-blob.cpp index becccf51c..569991508 100644 --- a/source/core/slang-blob.cpp +++ b/source/core/slang-blob.cpp @@ -2,18 +2,14 @@ namespace Slang { -// Allocate static const storage for the various interface IDs that the Slang API needs to expose -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; -static const Guid IID_ISlangBlob = SLANG_UUID_ISlangBlob; - ISlangUnknown* BlobBase::getInterface(const Guid& guid) { - return (guid == IID_ISlangUnknown || guid == IID_ISlangBlob) ? static_cast<ISlangBlob*>(this) : nullptr; + return (guid == ISlangUnknown::getTypeGuid() || guid == ISlangBlob::getTypeGuid()) ? static_cast<ISlangBlob*>(this) : nullptr; } SlangResult StaticBlob::queryInterface(SlangUUID const& guid, void** outObject) { - if (guid == IID_ISlangUnknown || guid == IID_ISlangBlob) + if (guid == ISlangUnknown::getTypeGuid() || guid == ISlangBlob::getTypeGuid()) { *outObject = static_cast<ISlangBlob*>(this); return SLANG_OK; diff --git a/source/core/slang-compression-system.h b/source/core/slang-compression-system.h index f9fe9dfe1..ecc5b1be9 100644 --- a/source/core/slang-compression-system.h +++ b/source/core/slang-compression-system.h @@ -29,7 +29,7 @@ enum class CompressionSystemType class ICompressionSystem : public ISlangUnknown { -public: + SLANG_COM_INTERFACE(0xcc935840, 0xe059, 0x4bb8, { 0xa2, 0x2d, 0x92, 0x7b, 0x3c, 0x73, 0x8f, 0x85 }) /** Get the compression system type @return The compression system type */ @@ -51,8 +51,6 @@ public: virtual SLANG_NO_THROW SlangResult SLANG_MCALL decompress(const void* compressed, size_t compressedSizeInBytes, size_t decompressedSizeInBytes, void* outDecompressed) = 0; }; -#define SLANG_UUID_ICompressionSystem { 0xcc935840, 0xe059, 0x4bb8, { 0xa2, 0x2d, 0x92, 0x7b, 0x3c, 0x73, 0x8f, 0x85 } }; - } #endif diff --git a/source/core/slang-deflate-compression-system.cpp b/source/core/slang-deflate-compression-system.cpp index a316be122..dab6654f7 100644 --- a/source/core/slang-deflate-compression-system.cpp +++ b/source/core/slang-deflate-compression-system.cpp @@ -17,8 +17,6 @@ namespace Slang { // Allocate static const storage for the various interface IDs that the Slang API needs to expose -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; -static const Guid IID_ICompressionSystem = SLANG_UUID_ICompressionSystem; class DeflateCompressionSystemImpl : public RefObject, public ICompressionSystem { @@ -42,7 +40,7 @@ protected: ICompressionSystem* DeflateCompressionSystemImpl::getInterface(const Guid& guid) { - return (guid == IID_ISlangUnknown || guid == IID_ICompressionSystem) ? static_cast<ICompressionSystem*>(this) : nullptr; + return (guid == ISlangUnknown::getTypeGuid() || guid == ICompressionSystem::getTypeGuid()) ? static_cast<ICompressionSystem*>(this) : nullptr; } SlangResult DeflateCompressionSystemImpl::compress(const CompressionStyle* style, const void* src, size_t srcSizeInBytes, ISlangBlob** outBlob) diff --git a/source/core/slang-file-system.cpp b/source/core/slang-file-system.cpp index 992ae4155..91dd09ff9 100644 --- a/source/core/slang-file-system.cpp +++ b/source/core/slang-file-system.cpp @@ -8,27 +8,21 @@ namespace Slang { // Allocate static const storage for the various interface IDs that the Slang API needs to expose -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; -static const Guid IID_ISlangFileSystem = SLANG_UUID_ISlangFileSystem; -static const Guid IID_ISlangFileSystemExt = SLANG_UUID_ISlangFileSystemExt; -static const Guid IID_ISlangMutableFileSystem = SLANG_UUID_ISlangMutableFileSystem; - -static const Guid IID_SlangCacheFileSystem = SLANG_UUID_CacheFileSystem; 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 == IID_ISlangUnknown || guid == IID_ISlangFileSystem) + if (guid == ISlangUnknown::getTypeGuid() || guid == ISlangFileSystem::getTypeGuid()) { return true; } - else if (guid == IID_ISlangFileSystemExt) + else if (guid == ISlangFileSystemExt::getTypeGuid()) { return Index(style) >= Index(FileSystemStyle::Ext); } - else if (guid == IID_ISlangMutableFileSystem) + else if (guid == ISlangMutableFileSystem::getTypeGuid()) { return Index(style) >= Index(FileSystemStyle::Mutable); } @@ -41,11 +35,11 @@ static FileSystemStyle _getFileSystemStyle(ISlangFileSystem* system, ComPtr<ISla FileSystemStyle style = FileSystemStyle::Load; - if (SLANG_SUCCEEDED(system->queryInterface(IID_ISlangMutableFileSystem, (void**)out.writeRef()))) + if (SLANG_SUCCEEDED(system->queryInterface(ISlangMutableFileSystem::getTypeGuid(), (void**)out.writeRef()))) { style = FileSystemStyle::Mutable; } - else if (SLANG_SUCCEEDED(system->queryInterface(IID_ISlangFileSystemExt, (void**)out.writeRef()))) + else if (SLANG_SUCCEEDED(system->queryInterface(ISlangFileSystemExt::getTypeGuid(), (void**)out.writeRef()))) { style = FileSystemStyle::Ext; } @@ -269,7 +263,7 @@ SlangResult OSFileSystem::createDirectory(const char* path) SLANG_NO_THROW SlangResult SLANG_MCALL CacheFileSystem::queryInterface(SlangUUID const& uuid, void** outObject) { - if (uuid == IID_SlangCacheFileSystem) + if (uuid == CacheFileSystem::getTypeGuid()) { *outObject = this; return SLANG_OK; @@ -310,7 +304,7 @@ void CacheFileSystem::setInnerFileSystem(ISlangFileSystem* fileSystem, UniqueIde if (fileSystem) { // Try to get the more sophisticated interface - fileSystem->queryInterface(IID_ISlangFileSystemExt, (void**)m_fileSystemExt.writeRef()); + fileSystem->queryInterface(ISlangFileSystemExt::getTypeGuid(), (void**)m_fileSystemExt.writeRef()); } switch (m_uniqueIdentityMode) diff --git a/source/core/slang-file-system.h b/source/core/slang-file-system.h index d5145404d..caf7ffc23 100644 --- a/source/core/slang-file-system.h +++ b/source/core/slang-file-system.h @@ -70,8 +70,6 @@ private: static OSFileSystem g_mutable; }; - #define SLANG_UUID_CacheFileSystem { 0x2f4d1d03, 0xa0d1, 0x434b, { 0x87, 0x7a, 0x65, 0x5, 0xa4, 0xa0, 0x9a, 0x3b } }; - /* Wraps an underlying ISlangFileSystem or ISlangFileSystemExt and provides caching, as well as emulation of methods if only has ISlangFileSystem interface. Will query capabilities of the interface on the constructor. @@ -83,6 +81,7 @@ NOTE! That this behavior is the same as previously in that.... class CacheFileSystem: public ISlangFileSystemExt, public RefObject { public: + SLANG_CLASS_GUID(0x2f4d1d03, 0xa0d1, 0x434b, { 0x87, 0x7a, 0x65, 0x5, 0xa4, 0xa0, 0x9a, 0x3b }) enum class PathStyle { diff --git a/source/core/slang-lz4-compression-system.cpp b/source/core/slang-lz4-compression-system.cpp index fa5c5f5ab..fd360ce2e 100644 --- a/source/core/slang-lz4-compression-system.cpp +++ b/source/core/slang-lz4-compression-system.cpp @@ -11,8 +11,6 @@ namespace Slang { // Allocate static const storage for the various interface IDs that the Slang API needs to expose -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; -static const Guid IID_ICompressionSystem = SLANG_UUID_ICompressionSystem; class LZ4CompressionSystemImpl : public RefObject, public ICompressionSystem { @@ -35,7 +33,7 @@ protected: ICompressionSystem* LZ4CompressionSystemImpl::getInterface(const Guid& guid) { - return (guid == IID_ISlangUnknown || guid == IID_ICompressionSystem) ? static_cast<ICompressionSystem*>(this) : nullptr; + return (guid == ISlangUnknown::getTypeGuid() || guid == ICompressionSystem::getTypeGuid()) ? static_cast<ICompressionSystem*>(this) : nullptr; } SlangResult LZ4CompressionSystemImpl::compress(const CompressionStyle* style, const void* src, size_t srcSizeInBytes, ISlangBlob** outBlob) diff --git a/source/core/slang-riff-file-system.cpp b/source/core/slang-riff-file-system.cpp index 7084e1346..d52015fb3 100644 --- a/source/core/slang-riff-file-system.cpp +++ b/source/core/slang-riff-file-system.cpp @@ -16,12 +16,6 @@ namespace Slang { -// Allocate static const storage for the various interface IDs that the Slang API needs to expose -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; -static const Guid IID_ISlangFileSystem = SLANG_UUID_ISlangFileSystem; -static const Guid IID_ISlangFileSystemExt = SLANG_UUID_ISlangFileSystemExt; -static const Guid IID_ISlangMutableFileSystem = SLANG_UUID_ISlangMutableFileSystem; - RiffFileSystem::RiffFileSystem(ICompressionSystem* compressionSystem): m_compressionSystem(compressionSystem) { @@ -29,7 +23,7 @@ RiffFileSystem::RiffFileSystem(ICompressionSystem* compressionSystem): ISlangMutableFileSystem* RiffFileSystem::getInterface(const Guid& guid) { - return (guid == IID_ISlangUnknown || guid == IID_ISlangFileSystem || guid == IID_ISlangFileSystemExt || guid == IID_ISlangMutableFileSystem) ? static_cast<ISlangMutableFileSystem*>(this) : nullptr; + return (guid == ISlangUnknown::getTypeGuid() || guid == ISlangFileSystem::getTypeGuid() || guid == ISlangFileSystemExt::getTypeGuid() || guid == ISlangMutableFileSystem::getTypeGuid()) ? static_cast<ISlangMutableFileSystem*>(this) : nullptr; } SlangResult RiffFileSystem::_calcCanonicalPath(const char* path, StringBuilder& out) diff --git a/source/core/slang-shared-library.cpp b/source/core/slang-shared-library.cpp index 8d362fd89..17b881540 100644 --- a/source/core/slang-shared-library.cpp +++ b/source/core/slang-shared-library.cpp @@ -20,18 +20,13 @@ namespace Slang { -// Allocate static const storage for the various interface IDs that the Slang API needs to expose -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; -static const Guid IID_ISlangSharedLibrary = SLANG_UUID_ISlangSharedLibrary; -static const Guid IID_ISlangSharedLibraryLoader = SLANG_UUID_ISlangSharedLibraryLoader; - /* !!!!!!!!!!!!!!!!!!!!!!!!!! DefaultSharedLibraryLoader !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ /* static */DefaultSharedLibraryLoader DefaultSharedLibraryLoader::s_singleton; ISlangUnknown* DefaultSharedLibraryLoader::getInterface(const Guid& guid) { - return (guid == IID_ISlangUnknown || guid == IID_ISlangSharedLibraryLoader) ? static_cast<ISlangSharedLibraryLoader*>(this) : nullptr; + return (guid == ISlangUnknown::getTypeGuid() || guid == ISlangSharedLibraryLoader::getTypeGuid()) ? static_cast<ISlangSharedLibraryLoader*>(this) : nullptr; } SlangResult DefaultSharedLibraryLoader::loadSharedLibrary(const char* path, ISlangSharedLibrary** outSharedLibrary) @@ -83,7 +78,7 @@ TemporarySharedLibrary::~TemporarySharedLibrary() ISlangUnknown* DefaultSharedLibrary::getInterface(const Guid& guid) { - return (guid == IID_ISlangUnknown || guid == IID_ISlangSharedLibrary) ? static_cast<ISlangSharedLibrary*>(this) : nullptr; + return (guid == ISlangUnknown::getTypeGuid() || guid == ISlangSharedLibrary::getTypeGuid()) ? static_cast<ISlangSharedLibrary*>(this) : nullptr; } DefaultSharedLibrary::~DefaultSharedLibrary() diff --git a/source/core/slang-writer.cpp b/source/core/slang-writer.cpp index 0f8286553..3b1a5756a 100644 --- a/source/core/slang-writer.cpp +++ b/source/core/slang-writer.cpp @@ -18,8 +18,6 @@ namespace Slang { -static const Guid IID_ISlangWriter = SLANG_UUID_ISlangWriter; -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; /* !!!!!!!!!!!!!!!!!!!!!!!!! WriterHelper !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ @@ -66,7 +64,7 @@ SlangResult WriterHelper::put(const UnownedStringSlice& text) ISlangUnknown* BaseWriter::getInterface(const Guid& guid) { - return (guid == IID_ISlangUnknown || guid == IID_ISlangWriter) ? static_cast<ISlangWriter*>(this) : nullptr; + return (guid == ISlangUnknown::getTypeGuid() || guid == ISlangWriter::getTypeGuid()) ? static_cast<ISlangWriter*>(this) : nullptr; } /* !!!!!!!!!!!!!!!!!!!!!!!!! AppendBufferWriter !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ diff --git a/source/core/slang-zip-file-system.cpp b/source/core/slang-zip-file-system.cpp index a56ba09db..1ed003d55 100644 --- a/source/core/slang-zip-file-system.cpp +++ b/source/core/slang-zip-file-system.cpp @@ -19,12 +19,6 @@ namespace Slang { -// Allocate static const storage for the various interface IDs that the Slang API needs to expose -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; -static const Guid IID_ISlangFileSystem = SLANG_UUID_ISlangFileSystem; -static const Guid IID_ISlangFileSystemExt = SLANG_UUID_ISlangFileSystemExt; -static const Guid IID_ISlangMutableFileSystem = SLANG_UUID_ISlangMutableFileSystem; - class ZipFileSystemImpl : public ArchiveFileSystem { public: @@ -108,7 +102,7 @@ protected: ISlangMutableFileSystem* ZipFileSystemImpl::getInterface(const Guid& guid) { - return (guid == IID_ISlangUnknown || guid == IID_ISlangFileSystem || guid == IID_ISlangFileSystemExt || guid == IID_ISlangMutableFileSystem) ? static_cast<ISlangMutableFileSystem*>(this) : nullptr; + return (guid == ISlangUnknown::getTypeGuid() || guid == ISlangFileSystem::getTypeGuid() || guid == ISlangFileSystemExt::getTypeGuid() || guid == ISlangMutableFileSystem::getTypeGuid()) ? static_cast<ISlangMutableFileSystem*>(this) : nullptr; } // 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. |
