CommonLibSSE (Parapets fork)
BSStringPool.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/B/BSAtomic.h"
4 
5 namespace RE
6 {
7  using GlobalStringHandle = char*;
8  using GlobalStringHandleW = wchar_t*;
9 
10  struct BSStringPool
11  {
12  public:
13  class Entry
14  {
15  public:
16  enum
17  {
18  kWide = 1 << 15,
19  kRefCountMask = 0x7FFF,
20  kLengthMask = 0xFFFFFF
21  };
22 
23  static void release(const char*& a_entry);
24  static void release(const wchar_t*& a_entry);
25 
26  static void release8(const char*& a_entry);
27 
28  static void release16(const wchar_t*& a_entry);
29 
30  void acquire();
31 
32  [[nodiscard]] constexpr std::uint16_t crc() const noexcept { return _crc; }
33 
34  template <class T>
35  [[nodiscard]] const T* data() const noexcept;
36 
37  template <>
38  [[nodiscard]] inline const char* data<char>() const noexcept
39  {
40  return u8();
41  }
42 
43  template <>
44  [[nodiscard]] inline const wchar_t* data<wchar_t>() const noexcept
45  {
46  return u16();
47  }
48 
49  [[nodiscard]] constexpr std::uint32_t length() const noexcept { return _length & kLengthMask; }
50  [[nodiscard]] constexpr std::uint32_t size() const noexcept { return length(); }
51 
52  [[nodiscard]] inline const char* u8() const noexcept
53  {
54  assert(!wide());
55  return reinterpret_cast<const char*>(this + 1);
56  }
57 
58  [[nodiscard]] inline const wchar_t* u16() const noexcept
59  {
60  assert(wide());
61  return reinterpret_cast<const wchar_t*>(this + 1);
62  }
63 
64  [[nodiscard]] constexpr bool wide() const noexcept { return static_cast<bool>(_flags & kWide); }
65 
66  // members
67  Entry* _left; // 00
68  std::uint16_t _flags; // 08
69  volatile std::uint16_t _crc; // 08
70  union
71  {
72  std::uint32_t _length;
74  }; // 10
75  };
76  static_assert(sizeof(Entry) == 0x18);
77  };
78  static_assert(std::is_empty_v<BSStringPool>);
79 
80  struct BucketTable
81  {
82  enum HashMask
83  {
84  kEntryIndexMask = 0xFFFF,
85  kLockIndexMask = 0x7F
86  };
87 
89 
90  // members
91  BSStringPool::Entry* buckets[0x10000]; // 00000 - index using hash & kEntryIndexMask
92  mutable BSSpinLock locks[0x10000 / 0x800]; // 80000 - index using hash & kLockIndexMask
93  bool initialized; // 80100
94  };
95  static_assert(sizeof(BucketTable) == 0x80108);
96 }
Definition: BSAtomic.h:49
Definition: BSStringPool.h:14
constexpr bool wide() const noexcept
Definition: BSStringPool.h:64
constexpr std::uint32_t length() const noexcept
Definition: BSStringPool.h:49
const wchar_t * u16() const noexcept
Definition: BSStringPool.h:58
std::uint32_t _length
Definition: BSStringPool.h:72
static void release16(const wchar_t *&a_entry)
Entry * _left
Definition: BSStringPool.h:67
@ kRefCountMask
Definition: BSStringPool.h:19
@ kLengthMask
Definition: BSStringPool.h:20
@ kWide
Definition: BSStringPool.h:18
constexpr std::uint16_t crc() const noexcept
Definition: BSStringPool.h:32
static void release(const char *&a_entry)
const T * data() const noexcept
constexpr std::uint32_t size() const noexcept
Definition: BSStringPool.h:50
volatile std::uint16_t _crc
Definition: BSStringPool.h:69
static void release(const wchar_t *&a_entry)
Entry * _right
Definition: BSStringPool.h:73
std::uint16_t _flags
Definition: BSStringPool.h:68
static void release8(const char *&a_entry)
const char * u8() const noexcept
Definition: BSStringPool.h:52
Definition: AbsorbEffect.h:6
char * GlobalStringHandle
Definition: BSStringPool.h:7
wchar_t * GlobalStringHandleW
Definition: BSStringPool.h:8
Definition: BSStringPool.h:11
Definition: BSStringPool.h:81
HashMask
Definition: BSStringPool.h:83
@ kEntryIndexMask
Definition: BSStringPool.h:84
@ kLockIndexMask
Definition: BSStringPool.h:85
static BucketTable * GetSingleton()
bool initialized
Definition: BSStringPool.h:93
BSStringPool::Entry * buckets[0x10000]
Definition: BSStringPool.h:91
BSSpinLock locks[0x10000/0x800]
Definition: BSStringPool.h:92