From 4a44fd852450d9e97032633524f92d1fad5f7187 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 8 Apr 2019 08:34:52 +1000 Subject: Backport: Rename FontNames to UniqueStringSet and move into UniqueString. It may be useful in more situations than just font names. Backport of changeset 7409:a70a4ee51448. --- src/UniqueString.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/UniqueString.h') diff --git a/src/UniqueString.h b/src/UniqueString.h index 44ba26652..f7f7ebbdc 100644 --- a/src/UniqueString.h +++ b/src/UniqueString.h @@ -2,6 +2,8 @@ /** @file UniqueString.h ** Define UniqueString, a unique_ptr based string type for storage in containers ** and an allocator for UniqueString. + ** Define UniqueStringSet which holds a set of strings, used to avoid holding many copies + ** of font names. **/ // Copyright 2017 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. @@ -21,6 +23,24 @@ using UniqueString = std::unique_ptr; /// into collections. UniqueString UniqueStringCopy(const char *text); +// A set of strings that always returns the same pointer for each string. + +class UniqueStringSet { +private: + std::vector strings; +public: + UniqueStringSet() noexcept; + // UniqueStringSet objects can not be copied. + UniqueStringSet(const UniqueStringSet &) = delete; + UniqueStringSet &operator=(const UniqueStringSet &) = delete; + // UniqueStringSet objects can be moved. + UniqueStringSet(UniqueStringSet &&) = default; + UniqueStringSet &operator=(UniqueStringSet &&) = default; + ~UniqueStringSet(); + void Clear() noexcept; + const char *Save(const char *text); +}; + } #endif -- cgit v1.2.3