From 0b51ea6bb54b1d8a12695ccc2c259fd591069791 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 3 Oct 2022 21:09:16 -0400 Subject: 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. --- source/core/slang-string-slice-index-map.h | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 source/core/slang-string-slice-index-map.h (limited to 'source/core/slang-string-slice-index-map.h') diff --git a/source/core/slang-string-slice-index-map.h b/source/core/slang-string-slice-index-map.h new file mode 100644 index 000000000..5aef62253 --- /dev/null +++ b/source/core/slang-string-slice-index-map.h @@ -0,0 +1,78 @@ +#ifndef SLANG_CORE_STRING_SLICE_INDEX_MAP_H +#define SLANG_CORE_STRING_SLICE_INDEX_MAP_H + +#include "slang-basic.h" + +#include "slang-string-slice-pool.h" + +namespace Slang +{ + +/* Maps an UnownedStringSlice to an index. All substrings are held internally in a StringSlicePool, and so +owned by the type. +*/ +class StringSliceIndexMap +{ +public: + /// An index that identifies a key value pair. + typedef Index CountIndex; + + /// Adds a key, value pair. Returns the CountIndex of the pair. + /// If there is already a value stored for the key it is replaced. + CountIndex add(const UnownedStringSlice& key, Index valueIndex); + + /// Finds or adds the slice. If the slice is added the defaultValueIndex is set. + /// If not the index associated with the slice remains the same. + /// Returns the CountIndex where the key,value pair are stored + CountIndex findOrAdd(const UnownedStringSlice& key, Index defaultValueIndex); + + /// Gets the index associated with the key. Returns -1 if there is no associated index. + SLANG_FORCE_INLINE Index getValue(const UnownedStringSlice& key); + + /// Get the amount of pairs in the map + Index getCount() const { return m_indexMap.getCount(); } + + /// Get the slice and the index at the specified index + SLANG_INLINE KeyValuePair getAt(CountIndex countIndex) const; + + /// Clear the contents of the map + void clear(); + + /// Get the key at the specified index + UnownedStringSlice getKeyAt(CountIndex index) const { return m_pool.getSlice(StringSlicePool::Handle(index)); } + /// Get the value at the specified index + Index& getValueAt(CountIndex index) { return m_indexMap[index]; } + + /// Get the amount of key,value pairs + Index getCount() { return m_indexMap.getCount(); } + + /// Ctor + StringSliceIndexMap() : + m_pool(StringSlicePool::Style::Empty) + { + } + +protected: + StringSlicePool m_pool; ///< Pool holds the substrings + List m_indexMap; ///< Maps a pool index to the output index +}; + +// --------------------------------------------------------------------------- +Index StringSliceIndexMap::getValue(const UnownedStringSlice& key) +{ + const Index poolIndex = m_pool.findIndex(key); + return (poolIndex >= 0) ? m_indexMap[poolIndex] : -1; +} + +// --------------------------------------------------------------------------- +KeyValuePair StringSliceIndexMap::getAt(CountIndex countIndex) const +{ + KeyValuePair pair; + pair.Key = m_pool.getSlice(StringSlicePool::Handle(countIndex)); + pair.Value = m_indexMap[countIndex]; + return pair; +} + +} + +#endif -- cgit v1.2.3