Mana
StringPool.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "../runner/common/Platform.h"
10 #include <memory>
11 #include <string_view>
12 #include <vector>
13 
14 namespace mana
15 {
20  class StringPool final
21  {
22  public:
23  StringPool();
24  StringPool(const StringPool& other) = delete;
25  StringPool(StringPool&& other) noexcept = delete;
26  StringPool& operator=(const StringPool& other) = delete;
27  StringPool& operator=(StringPool&& other) noexcept = delete;
28  ~StringPool() = default;
29 
35  [[nodiscard]] std::string_view Get(const std::string_view& text) const;
36 
42  std::string_view Set(const std::string_view& text);
43 
44  private:
45  [[nodiscard]] address_t Find(const std::string_view& text) const noexcept;
46  [[nodiscard]] std::string_view Text(const address_t address) const;
47 
48  private:
49  std::vector<address_t> mAddress;
50  std::unique_ptr<char, decltype(&std::free)> mBuffer;
51  address_t mUsedSize = 0;
52  address_t mAllocatedSize = 0;
53  };
54 }
Definition: StringPool.h:21
StringPool()
Definition: StringPool.cpp:15
std::string_view Get(const std::string_view &text) const
Definition: StringPool.cpp:54
StringPool(const StringPool &other)=delete
std::string_view Set(const std::string_view &text)
Definition: StringPool.cpp:59
StringPool & operator=(const StringPool &other)=delete
StringPool & operator=(StringPool &&other) noexcept=delete
StringPool(StringPool &&other) noexcept=delete
~StringPool()=default
Definition: CodeBuffer.cpp:12
std::uint32_t address_t
Definition: Type.h:31