summaryrefslogtreecommitdiff
path: root/source/core/slang-string-slice-pool.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-string-slice-pool.h')
-rw-r--r--source/core/slang-string-slice-pool.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/source/core/slang-string-slice-pool.h b/source/core/slang-string-slice-pool.h
new file mode 100644
index 000000000..e6846b3dd
--- /dev/null
+++ b/source/core/slang-string-slice-pool.h
@@ -0,0 +1,50 @@
+#ifndef SLANG_STRING_SLICE_POOL_H
+#define SLANG_STRING_SLICE_POOL_H
+
+#include "slang-string.h"
+
+#include "list.h"
+#include "slang-memory-arena.h"
+#include "dictionary.h"
+
+namespace Slang {
+
+class StringSlicePool
+{
+public:
+ /// Handle of 0 is null. If accessed will be returned as the empty string
+ enum class Handle : uint32_t;
+ typedef UnownedStringSlice Slice;
+
+ /// Returns the index of a slice, if contained, or -1 if not found
+ int findIndex(const Slice& slice) const;
+
+ /// True if has the slice
+ bool has(const Slice& slice) { return findIndex(slice) >= 0; }
+ /// Add a slice
+ Handle add(const Slice& slice);
+
+ /// Empty contents
+ void clear();
+
+ /// Get the slice from the handle
+ const UnownedStringSlice& getSlice(Handle handle) const { return m_slices[UInt(handle)]; }
+
+ /// Get all the slices
+ const List<UnownedStringSlice>& getSlices() const { return m_slices; }
+
+ /// Convert a handle to and index. (A handle is just an index!)
+ static int asIndex(Handle handle) { return int(handle); }
+
+ /// Ctor
+ StringSlicePool();
+
+protected:
+ List<UnownedStringSlice> m_slices;
+ Dictionary<UnownedStringSlice, int> m_map;
+ MemoryArena m_arena;
+};
+
+} // namespace Slang
+
+#endif // SLANG_STRING_SLICE_POOL_H