diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-10-03 21:09:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-03 18:09:16 -0700 |
| commit | 0b51ea6bb54b1d8a12695ccc2c259fd591069791 (patch) | |
| tree | 1ff0587eb1454891bf8421a86b95ed5e95419e75 /source/core/slang-implicit-directory-collector.h | |
| parent | cc3548c92b1cf028b94d7a264a55df83e6d4d212 (diff) | |
IMutableFileSystem::saveFileBlob (#2427)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Remove ref count for Entry in RiffFileSystem.
Free up backing Entry types (to work around Dictionary not doing this).
* Some small improvements to RiffFileSystem.
* Add testing for file systems.
* Split out MemoryFileSystem.
* Add some documentation around different FileSystems.
* Small tiry up - removing unused headers, fixing some comments.
Use StringBlob::moveCreate where appropriate.
* Small improvement to MemoryFileSystem.
Improve documentation comments a little.
* Added PathKind
* * Make MemoryFileSystem not have implicit directories
* Make RelativeFileSystem only allow access to files in file system (kind of like chroot)
* Added Path::simplifyAbsolute
* Special handling for root of MemoryFileSystem
* Improvements around paths for different impls
* More improvements around RelativeFileSystem.
Special case root handling.
* Test archive serialization.
Move testinf from compression.
Remove the implicit directory test -> doesn't work on all file systems.
* Small optimization that removes need for check for a parent unless an item is being *created*.
* Add implicit path testing.
* Add support for saveFileBlob
Add testing for saveFileBlob
* Removed TemporaryFileSet
Added PlatformUtil::outputDebugMessage
* Some small improvements around RelativeFileSystem.
* Split out ImplicitDirectoryCollector so can use without requiring compression systems.
* Split out StringSliceIndexMap into own files.
Diffstat (limited to 'source/core/slang-implicit-directory-collector.h')
| -rw-r--r-- | source/core/slang-implicit-directory-collector.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/source/core/slang-implicit-directory-collector.h b/source/core/slang-implicit-directory-collector.h new file mode 100644 index 000000000..280ba33e6 --- /dev/null +++ b/source/core/slang-implicit-directory-collector.h @@ -0,0 +1,68 @@ +#ifndef SLANG_CORE_IMPLICIT_DIRECTORY_COLLECTOR_H +#define SLANG_CORE_IMPLICIT_DIRECTORY_COLLECTOR_H + +#include "slang-basic.h" + +#include "slang-string-slice-index-map.h" + +namespace Slang +{ + +/* This class helps to find the contents and/or existence of an implicit directory.This finds the contents of a directory. + +This is achieved by using a path prefix that any contained path must at least match. If the remainder of the path contains a folder + - detectable because it's not a leaf and so contains a delimiter - that directory is added. As a sub folder may contain many + files, and the directory itself may also be defined, it is necessary to dedup. The deduping is handled by the StringSliceIndexMap. */ +class ImplicitDirectoryCollector +{ +public: + + enum class State + { + None, ///< Neither the directory or content have been found + DirectoryExists, ///< The directory exists + HasContent, ///< If it has content, the directory must exist + }; + + /// Get the current state + State getState() const { return (m_map.getCount() > 0) ? State::HasContent : (m_directoryExists ? State::DirectoryExists : State::None); } + /// True if collector at least has the specified state + bool hasState(State state) { return Index(getState()) >= Index(state); } + + /// Set that it exists + void setDirectoryExists(bool directoryExists) { m_directoryExists = directoryExists; } + /// Get if it exists (implicitly or explicitly) + bool getDirectoryExists() const { return m_directoryExists || m_map.getCount() > 0; } + + /// True if the path matches the prefix + bool hasPrefix(const UnownedStringSlice& path) const { return path.startsWith(m_prefix.getUnownedSlice()); } + + /// True if the directory has content + bool hasContent() const { return m_map.getCount() > 0; } + + /// Gets the remainder or path after the prefix + UnownedStringSlice getRemainder(const UnownedStringSlice& path) const + { + SLANG_ASSERT(hasPrefix(path)); + return UnownedStringSlice(path.begin() + m_prefix.getLength(), path.end()); + } + + /// Add a remaining path + void addRemainingPath(SlangPathType pathType, const UnownedStringSlice& inPathRemainder); + /// Add a path + void addPath(SlangPathType pathType, const UnownedStringSlice& canonicalPath); + /// Enumerate the contents + SlangResult enumerate(FileSystemContentsCallBack callback, void* userData); + + /// Ctor + ImplicitDirectoryCollector(const String& canonicalPath, bool directoryExists = false); + + protected: + StringSliceIndexMap m_map; + String m_prefix; + bool m_directoryExists; +}; + +} + +#endif |
