From f9710d50bc675ddba51cc6d94b125ba1549708a8 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 17 Oct 2018 11:57:33 -0400 Subject: IncludeFileSystem -> DefaultFileSystem (#677) Improvements in 'singleton'ness of DefaultFileSystem Made WrapFileSystem a stand alone type - to remove 'odd' aspects of deriving from DefaultFileSystem (such as inheriting getSingleton method/fixing ref counting) Simplified CompileRequest::loadFile - becauce fileSystemExt is always available. --- source/slang/include-file-system.cpp | 101 ----------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 source/slang/include-file-system.cpp (limited to 'source/slang/include-file-system.cpp') diff --git a/source/slang/include-file-system.cpp b/source/slang/include-file-system.cpp deleted file mode 100644 index d2c1670fe..000000000 --- a/source/slang/include-file-system.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "include-file-system.h" - -#include "../../slang-com-ptr.h" -#include "../core/slang-io.h" -#include "compiler.h" - -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; - -/* !!!!!!!!!!!!!!!!!!!!!!!!!! IncludeFileSystem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ - -/* static */ISlangFileSystemExt* IncludeFileSystem::getDefault() -{ - static IncludeFileSystem s_includeFileSystem; - s_includeFileSystem.ensureRef(); - return &s_includeFileSystem; -} - -ISlangUnknown* IncludeFileSystem::getInterface(const Guid& guid) -{ - return (guid == IID_ISlangUnknown || guid == IID_ISlangFileSystem || guid == IID_ISlangFileSystemExt) ? static_cast(this) : nullptr; -} - -SlangResult IncludeFileSystem::getCanoncialPath(const char* path, ISlangBlob** canonicalPathOut) -{ - String canonicalPath; - SLANG_RETURN_ON_FAIL(Path::GetCanonical(path, canonicalPath)); - - *canonicalPathOut = createStringBlob(canonicalPath).detach(); - return SLANG_OK; -} - -SlangResult IncludeFileSystem::calcRelativePath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) -{ - String relPath; - switch (fromPathType) - { - case SLANG_PATH_TYPE_FILE: - { - relPath = Path::Combine(Path::GetDirectoryName(fromPath), path); - break; - } - case SLANG_PATH_TYPE_DIRECTORY: - { - relPath = Path::Combine(fromPath, path); - break; - } - } - - *pathOut = createStringBlob(relPath).detach(); - return SLANG_OK; -} - -SlangResult SLANG_MCALL IncludeFileSystem::loadFile(char const* path, ISlangBlob** outBlob) -{ - // Otherwise, fall back to a default implementation that uses the `core` - // libraries facilities for talking to the OS filesystem. - // - // TODO: we might want to conditionally compile these in, so that - // a user could create a build of Slang that doesn't include any OS - // filesystem calls. - // - - if (!File::Exists(path)) - { - return SLANG_E_NOT_FOUND; - } - - try - { - String sourceString = File::ReadAllText(path); - ComPtr sourceBlob = createStringBlob(sourceString); - *outBlob = sourceBlob.detach(); - return SLANG_OK; - } - catch (...) - { - } - return SLANG_E_CANNOT_OPEN; -} - -/* !!!!!!!!!!!!!!!!!!!!!!!!!! WrapFileSystem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ - -SlangResult SLANG_MCALL WrapFileSystem::loadFile(char const* path, ISlangBlob** outBlob) -{ - return m_fileSystem->loadFile(path, outBlob); -} - -SlangResult WrapFileSystem::getCanoncialPath(const char* path, ISlangBlob** canonicalPathOut) -{ - String canonicalPath(path); - *canonicalPathOut = createStringBlob(canonicalPath).detach(); - return SLANG_OK; -} - -} \ No newline at end of file -- cgit v1.2.3