summaryrefslogtreecommitdiff
path: root/source/core/slang-memory-file-system.h
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/core/slang-memory-file-system.h
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/core/slang-memory-file-system.h')
-rw-r--r--source/core/slang-memory-file-system.h93
1 files changed, 54 insertions, 39 deletions
diff --git a/source/core/slang-memory-file-system.h b/source/core/slang-memory-file-system.h
index 321f7fe74..ebf6e239a 100644
--- a/source/core/slang-memory-file-system.h
+++ b/source/core/slang-memory-file-system.h
@@ -2,66 +2,81 @@
#define SLANG_CORE_MEMORY_FILE_SYSTEM_H
#include "slang-basic.h"
-
-#include "slang-com-ptr.h"
#include "slang-com-object.h"
+#include "slang-com-ptr.h"
namespace Slang
{
-/* MemoryFileSystem is an implementation of ISlangMutableFileSystem that stores file contents in 'blobs' (typically) in memory.
+/* MemoryFileSystem is an implementation of ISlangMutableFileSystem that stores file contents in
+'blobs' (typically) in memory.
-A derived class can change how the contents of the contents blob is interpretted (so for example the RiffFileSystem is implemented
-such that the Entry.m_contents is the files contents compressed).
+A derived class can change how the contents of the contents blob is interpretted (so for example the
+RiffFileSystem is implemented such that the Entry.m_contents is the files contents compressed).
-The implementation uses a map to store the file/directory based on their canonical path. This makes access relatively fast and simple -
-an access only requires a path being converted into a canonical path, and then a lookup. Whilst this makes typical access fast, it means
-doing an enumeration of a directory slower as it requires traversing all entries to find which are in the path.
+The implementation uses a map to store the file/directory based on their canonical path. This makes
+access relatively fast and simple - an access only requires a path being converted into a canonical
+path, and then a lookup. Whilst this makes typical access fast, it means doing an enumeration of a
+directory slower as it requires traversing all entries to find which are in the path.
-This is in contrast with an implementation that held items in directories 'objects'. In that scenario the path through the hierarchy
-would need to be traversed to find the item. Finding all of the items in a directory is very fast - it's all the items held
-in the the directory 'object'.
+This is in contrast with an implementation that held items in directories 'objects'. In that
+scenario the path through the hierarchy would need to be traversed to find the item. Finding all of
+the items in a directory is very fast - it's all the items held in the the directory 'object'.
TODO(JS):
-* We may want to make saveFile take a blob, or have a version that does. Doing so would allow the application to handle memory management
-around the blob.
+* We may want to make saveFile take a blob, or have a version that does. Doing so would allow the
+application to handle memory management around the blob.
*/
class MemoryFileSystem : public ISlangMutableFileSystem, public ComBaseObject
{
public:
-
- // ISlangUnknown
+ // ISlangUnknown
SLANG_COM_BASE_IUNKNOWN_ALL
// ISlangCastable
virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE;
// ISlangFileSystem
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile(char const* path, ISlangBlob** outBlob) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile(char const* path, ISlangBlob** outBlob)
+ SLANG_OVERRIDE;
// ISlangFileSystemExt
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL getFileUniqueIdentity(const char* path, ISlangBlob** uniqueIdentityOut) SLANG_OVERRIDE;
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcCombinedPath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) SLANG_OVERRIDE;
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPathType(const char* path, SlangPathType* pathTypeOut) SLANG_OVERRIDE;
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPath(PathKind pathKind, const char* path, ISlangBlob** outPath) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ getFileUniqueIdentity(const char* path, ISlangBlob** uniqueIdentityOut) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcCombinedPath(
+ SlangPathType fromPathType,
+ const char* fromPath,
+ const char* path,
+ ISlangBlob** pathOut) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ getPathType(const char* path, SlangPathType* pathTypeOut) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ getPath(PathKind pathKind, const char* path, ISlangBlob** outPath) SLANG_OVERRIDE;
virtual SLANG_NO_THROW void SLANG_MCALL clearCache() SLANG_OVERRIDE {}
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL enumeratePathContents(const char* path, FileSystemContentsCallBack callback, void* userData) SLANG_OVERRIDE;
- virtual SLANG_NO_THROW OSPathKind SLANG_MCALL getOSPathKind() SLANG_OVERRIDE { return OSPathKind::None; }
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL enumeratePathContents(
+ const char* path,
+ FileSystemContentsCallBack callback,
+ void* userData) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW OSPathKind SLANG_MCALL getOSPathKind() SLANG_OVERRIDE
+ {
+ return OSPathKind::None;
+ }
// ISlangModifyableFileSystem
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveFile(const char* path, const void* data, size_t size) SLANG_OVERRIDE;
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveFileBlob(const char* path, ISlangBlob* dataBlob) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ saveFile(const char* path, const void* data, size_t size) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ saveFileBlob(const char* path, ISlangBlob* dataBlob) SLANG_OVERRIDE;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL remove(const char* path) SLANG_OVERRIDE;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL createDirectory(const char* path) SLANG_OVERRIDE;
- /// Ctor
+ /// Ctor
MemoryFileSystem();
protected:
-
struct Entry
{
- void reset()
+ void reset()
{
m_type = SLANG_PATH_TYPE_FILE;
m_canonicalPath = String();
@@ -100,10 +115,10 @@ protected:
SlangPathType m_type;
String m_canonicalPath;
- /// The size as seen on the file system. Might be different from the size of m_contents
+ /// The size as seen on the file system. Might be different from the size of m_contents
/// if it's actually being stored in some other representation (such as compressed)
- size_t m_uncompressedSizeInBytes;
- ComPtr<ISlangBlob> m_contents; ///< Can be compressed or not
+ size_t m_uncompressedSizeInBytes;
+ ComPtr<ISlangBlob> m_contents; ///< Can be compressed or not
};
void* getInterface(const Guid& guid);
@@ -111,28 +126,28 @@ protected:
Entry* _getEntryFromPath(const char* path, String* outPath = nullptr);
Entry* _getEntryFromCanonicalPath(const String& canonicalPath);
- /// Creates or returns a file entry for the given path.
- /// If created the entry is empty.
+ /// Creates or returns a file entry for the given path.
+ /// If created the entry is empty.
SlangResult _requireFile(const char* path, Entry** outEntry);
- /// Given the path returns the entry if it's a file, or returns an error
+ /// Given the path returns the entry if it's a file, or returns an error
SlangResult _loadFile(const char* path, Entry** outEntry);
- /// Given a path returns a canonical path.
- /// The canonical path must have *existing* parent paths.
+ /// Given a path returns a canonical path.
+ /// The canonical path must have *existing* parent paths.
SlangResult _getCanonicalWithExistingParent(const char* path, StringBuilder& canonicalPath);
- /// Given a path returns a canonical path.
+ /// Given a path returns a canonical path.
SlangResult _getCanonical(const char* path, StringBuilder& canonicalPath);
- /// Clear, ensures any backing memory is also freed
+ /// Clear, ensures any backing memory is also freed
void _clear();
// Maps canonical paths to an entries (which could be files or directories)
Dictionary<String, Entry> m_entries;
- Entry m_rootEntry;
+ Entry m_rootEntry;
};
-}
+} // namespace Slang
#endif