summaryrefslogtreecommitdiff
path: root/source/slang/include-file-system.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-10-16 18:49:11 -0400
committerGitHub <noreply@github.com>2018-10-16 18:49:11 -0400
commit3e74d39f24fdfaa547ce900be177863e2bfe2dea (patch)
tree9a5143e6de4caa27b23fc870003011e96129905f /source/slang/include-file-system.h
parent204fb3c75b520a2cbb1c25f995a8c424ec2753f3 (diff)
Feature/include refactor (#675)
* Refactor of path handling. * Added PathInfo * Changed ISlangFileSystem - such that has separate concepts of reading a file, getting a relative path and getting a canonical path * Added support for getting a canonical path for windows/linux * Made maps/testing around canonicalPaths * User output remains around 'foundPath' - which is the same as before * Small improvements around PathInfo * Added a type and make constructors to make clear the different 'path' uses * Fixed bug in findViewRecursively * Checking and reporting for ignored #pragma once. * Removed SLANG_PATH_TYPE_NONE as doesn't serve any useful purpose. * Improve comments in slang.h aroung ISlangFileSystem * Remove the need for <windows.h> in slang-io.cpp * Ran premake5. * Improvements and fixes around PathInfo. * Fix typo on linix GetCanonical * Make the ISlangFileSystem the same as before, and ISlangFileSystem contain the new methods. Internally it always uses the ISlangFileSystemExt, and will wrap a ISlangFileSystem with WrapFileSystem, if it is determined (via queryInterface) that it doesn't implement the full interface.
Diffstat (limited to 'source/slang/include-file-system.h')
-rw-r--r--source/slang/include-file-system.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/source/slang/include-file-system.h b/source/slang/include-file-system.h
new file mode 100644
index 000000000..4b34c2a0f
--- /dev/null
+++ b/source/slang/include-file-system.h
@@ -0,0 +1,81 @@
+#ifndef SLANG_INCLUDE_FILE_SYSTEM_H_INCLUDED
+#define SLANG_INCLUDE_FILE_SYSTEM_H_INCLUDED
+
+#include "../../slang.h"
+#include "../../slang-com-helper.h"
+#include "../../slang-com-ptr.h"
+
+namespace Slang
+{
+
+class IncludeFileSystem : public ISlangFileSystemExt
+{
+public:
+ // ISlangUnknown
+ SLANG_IUNKNOWN_ALL
+
+ // ISlangFileSystem
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile(
+ char const* path,
+ ISlangBlob** outBlob) SLANG_OVERRIDE;
+
+ // ISlangFileSystemExt
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getCanoncialPath(
+ const char* path,
+ ISlangBlob** canonicalPathOut) SLANG_OVERRIDE;
+
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcRelativePath(
+ SlangPathType fromPathType,
+ const char* fromPath,
+ const char* path,
+ ISlangBlob** pathOut) SLANG_OVERRIDE;
+
+ /// Get a default instance
+ static ISlangFileSystemExt* getDefault();
+
+protected:
+
+ /// If no ref, add one to the ref
+ void ensureRef() { m_refCount += (m_refCount == 0); }
+
+ ISlangUnknown* getInterface(const Guid& guid);
+ uint32_t m_refCount = 0;
+};
+
+/* Wraps an ISlangFileSystem, and provides the extra methods required to make a ISlangFileSystemExt
+interface, deferring to the contained file system to do reading.
+
+NOTE! That this behavior is the same as previously in that....
+1) getRelativePath, just returns the path as processed by the Path:: methods
+2) getCanonicalPath, just returns the input path as the 'canonical' path. This will be wrong with a file multiply referenced through paths with .. and or . but
+doing it this way means it works as before and requires no new functions.
+*/
+class WrapFileSystem : public IncludeFileSystem
+{
+public:
+ // So we don't need virtual dtor
+ SLANG_IUNKNOWN_RELEASE
+
+ // ISlangFileSystem
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile(
+ char const* path,
+ ISlangBlob** outBlob) SLANG_OVERRIDE;
+
+ // ISlangFileSystemExt
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getCanoncialPath(
+ const char* path,
+ ISlangBlob** canonicalPathOut) SLANG_OVERRIDE;
+
+ /// Ctor
+ WrapFileSystem(ISlangFileSystem* fileSystem):
+ m_fileSystem(fileSystem)
+ {
+ }
+
+protected:
+ ComPtr<ISlangFileSystem> m_fileSystem; ///< The wrapped file system
+};
+
+}
+
+#endif \ No newline at end of file