CommonLibVR
GString.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace RE
4 {
5  class GStringBuffer;
6 
7  class GString
8  {
9  public:
11  {
12  public:
13  UPInt operator()(const GString& a_data) const
14  {
15  return BernsteinHashFunction(a_data.data(), a_data.size());
16  }
17  };
18 
20  {
21  public:
22  UPInt operator()(const GString& a_data) const
23  {
24  return BernsteinHashFunctionCIS(a_data.data(), a_data.size());
25  }
26  };
27 
28  using value_type = char; // can also be wchar_t
29  using size_type = UPInt;
31  using const_reference = const value_type&;
32 
33  enum class HeapType
34  {
35  kGlobal = 0, // Global
36  kLocal = 1, // Address-based
37  kDynamic = 2, // Part of class
38  kMask = 3
39  };
40 
42  {
44  {
45  kReserveIsSizeShift = static_cast<UPInt>((sizeof(UPInt) * 8 - 1)) // indicates reserve == size
46  };
47  };
49 
50  struct DataDesc
51  {
52  enum : UPInt
53  {
54  kFullFlag = 1ull << FlagConstant::kReserveIsSizeShift
55  };
56 
59 
60  void AddRef();
61  void Release();
62  [[nodiscard]] UPInt GetCapacity() const;
63  [[nodiscard]] bool IsFull() const;
64  void SetFull(bool a_set);
65 
66  // members
67  UPInt capacity; // 00
68  volatile std::int32_t refCount; // 08
69  char data[1]; // 0C
70  };
71  static_assert(sizeof(DataDesc) == 0x10);
72 
74  {
76 
79  };
80  static_assert(sizeof(DataDescUnion) == 0x8);
81 
82  // (constructor)
84  GString(const GString& a_rhs);
85  GString(GString&& a_rhs);
86  GString(const char* a_rhs);
87  GString(const std::string_view& a_rhs);
88 
89  // (destructor)
91 
92  // operator=
93  GString& operator=(const GString& a_rhs);
95  GString& operator=(const char* a_rhs);
96  GString& operator=(const std::string_view& a_rhs);
97 
98  // element access
101 
102  char& front();
103  [[nodiscard]] const char& front() const;
104 
105  char& back();
106  [[nodiscard]] const char& back() const;
107 
108  [[nodiscard]] const char* data() const noexcept;
109  char* data() noexcept;
110 
111  [[nodiscard]] const char* c_str() const noexcept;
112 
113  operator std::string_view() const noexcept;
114 
115  // Capacity
116  [[nodiscard]] bool empty() const noexcept;
117 
118  [[nodiscard]] size_type size() const noexcept;
119 
120  [[nodiscard]] size_type length() const noexcept;
121 
122  // Operations
123  void clear() noexcept;
124 
125  inline friend bool operator==(const GString& a_lhs, const char* a_rhs) { return (a_lhs.data() == a_rhs || std::strcmp(a_lhs.data(), a_rhs) == 0); }
126  inline friend bool operator!=(const GString& a_lhs, const char* a_rhs) { return !(a_lhs == a_rhs); }
127  inline friend bool operator==(const char* a_lhs, const GString& a_rhs) { return a_rhs == a_lhs; }
128  inline friend bool operator!=(const char* a_lhs, const GString& a_rhs) { return !(a_lhs == a_rhs); }
129  inline friend bool operator==(const GString& a_lhs, const GString& a_rhs) { return a_lhs == a_rhs.c_str(); }
130  inline friend bool operator!=(const GString& a_lhs, const GString& a_rhs) { return !(a_lhs == a_rhs); }
131  inline friend bool operator==(const GString& a_lhs, const std::string_view& a_rhs) { return a_lhs == a_rhs.data(); }
132  inline friend bool operator!=(const GString& a_lhs, const std::string_view& a_rhs) { return !(a_lhs == a_rhs); }
133  inline friend bool operator==(const std::string_view& a_lhs, const GString& a_rhs) { return a_rhs == a_lhs; }
134  inline friend bool operator!=(const std::string_view& a_lhs, const GString& a_rhs) { return !(a_lhs == a_rhs); }
135 
136  static UPInt BernsteinHashFunction(const void* a_dataIn, UPInt a_size, UPInt a_seed = 5381);
137 
138  static UPInt BernsteinHashFunctionCIS(const void* a_dataIn, UPInt a_size, UPInt a_seed = 5381);
139 
140  protected:
141  GString* ctor(const char* a_str);
142  [[nodiscard]] HeapType heap_type() const;
143  [[nodiscard]] DataDesc* get_desc() const;
144  void set_desc(DataDesc* a_desc);
145 
146  // members
148  private:
149  KEEP_FOR_RE()
150  };
151  static_assert(sizeof(GString) == 0x8);
152 }
#define KEEP_FOR_RE()
Definition: PCH.h:713
Definition: GString.h:11
UPInt operator()(const GString &a_data) const
Definition: GString.h:13
Definition: GString.h:20
UPInt operator()(const GString &a_data) const
Definition: GString.h:22
Definition: GString.h:8
UPInt size_type
Definition: GString.h:29
friend bool operator==(const char *a_lhs, const GString &a_rhs)
Definition: GString.h:127
GString * ctor(const char *a_str)
const char & front() const
HeapType
Definition: GString.h:34
friend bool operator==(const GString &a_lhs, const GString &a_rhs)
Definition: GString.h:129
GString(GString &&a_rhs)
DataDesc * get_desc() const
GString & operator=(const char *a_rhs)
GString & operator=(GString &&a_rhs)
GString(const char *a_rhs)
char value_type
Definition: GString.h:28
size_type length() const noexcept
friend bool operator!=(const GString &a_lhs, const char *a_rhs)
Definition: GString.h:126
char & front()
char & back()
friend bool operator==(const std::string_view &a_lhs, const GString &a_rhs)
Definition: GString.h:133
static UPInt BernsteinHashFunctionCIS(const void *a_dataIn, UPInt a_size, UPInt a_seed=5381)
const_reference operator[](size_type a_pos) const
friend bool operator!=(const std::string_view &a_lhs, const GString &a_rhs)
Definition: GString.h:134
reference operator[](size_type a_pos)
friend bool operator!=(const char *a_lhs, const GString &a_rhs)
Definition: GString.h:128
const char * data() const noexcept
void set_desc(DataDesc *a_desc)
static UPInt BernsteinHashFunction(const void *a_dataIn, UPInt a_size, UPInt a_seed=5381)
GString(const std::string_view &a_rhs)
const value_type & const_reference
Definition: GString.h:31
friend bool operator!=(const GString &a_lhs, const GString &a_rhs)
Definition: GString.h:130
GString(const GString &a_rhs)
friend bool operator==(const GString &a_lhs, const std::string_view &a_rhs)
Definition: GString.h:131
GString & operator=(const std::string_view &a_rhs)
HeapType heap_type() const
void clear() noexcept
DataDescUnion _dataDesc
Definition: GString.h:147
GString & operator=(const GString &a_rhs)
size_type size() const noexcept
bool empty() const noexcept
const char & back() const
friend bool operator!=(const GString &a_lhs, const std::string_view &a_rhs)
Definition: GString.h:132
const char * c_str() const noexcept
value_type & reference
Definition: GString.h:30
Definition: AbsorbEffect.h:6
std::size_t UPInt
Definition: SFTypes.h:5
Definition: EffectArchetypes.h:65
Definition: GString.h:51
void SetFull(bool a_set)
char data[1]
Definition: GString.h:69
volatile std::int32_t refCount
Definition: GString.h:68
UPInt capacity
Definition: GString.h:67
UPInt GetCapacity() const
@ kFullFlag
Definition: GString.h:54
Definition: GString.h:42
FlagConstant
Definition: GString.h:44
@ kReserveIsSizeShift
Definition: GString.h:45
Definition: GString.h:74
stl::enumeration< HeapType, UPInt > heapType
Definition: GString.h:78
DataDesc * data
Definition: GString.h:77