CommonLibSSE (powerof3)
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:
10  using value_type = char; // can also be wchar_t
11  using size_type = UPInt;
13  using const_reference = const value_type&;
14 
15  enum class HeapType
16  {
17  kGlobal = 0, // Global
18  kLocal = 1, // Address-based
19  kDynamic = 2, // Part of class
20  kMask = 3
21  };
22 
24  {
26  {
27  kReserveIsSizeShift = static_cast<UPInt>((sizeof(UPInt) * 8 - 1)) // indicates reserve == size
28  };
29  };
31 
32  struct DataDesc
33  {
34  enum : UPInt
35  {
36  kFullFlag = 1ull << FlagConstant::kReserveIsSizeShift
37  };
38 
41 
42  void AddRef();
43  void Release();
44  [[nodiscard]] UPInt GetCapacity() const;
45  [[nodiscard]] bool IsFull() const;
46  void SetFull(bool a_set);
47 
48  // members
49  UPInt capacity; // 00
50  volatile std::int32_t refCount; // 08
51  char data[1]; // 0C
52  };
53  static_assert(sizeof(DataDesc) == 0x10);
54 
56  {
58 
61  };
62  static_assert(sizeof(DataDescUnion) == 0x8);
63 
64  // (constructor)
66  GString(const GString& a_rhs);
67  GString(GString&& a_rhs);
68  GString(const char* a_rhs);
69  GString(const std::string_view& a_rhs);
70 
71  // (destructor)
73 
74  // operator=
75  GString& operator=(const GString& a_rhs);
77  GString& operator=(const char* a_rhs);
78  GString& operator=(const std::string_view& a_rhs);
79 
80  // element access
83 
84  char& front();
85  [[nodiscard]] const char& front() const;
86 
87  char& back();
88  [[nodiscard]] const char& back() const;
89 
90  [[nodiscard]] const char* data() const noexcept;
91  char* data() noexcept;
92 
93  [[nodiscard]] const char* c_str() const noexcept;
94 
95  operator std::string_view() const noexcept;
96 
97  // Capacity
98  [[nodiscard]] bool empty() const noexcept;
99 
100  [[nodiscard]] size_type size() const noexcept;
101 
102  [[nodiscard]] size_type length() const noexcept;
103 
104  // Operations
105  void clear() noexcept;
106 
107  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); }
108  inline friend bool operator!=(const GString& a_lhs, const char* a_rhs) { return !(a_lhs == a_rhs); }
109  inline friend bool operator==(const char* a_lhs, const GString& a_rhs) { return a_rhs == a_lhs; }
110  inline friend bool operator!=(const char* a_lhs, const GString& a_rhs) { return !(a_lhs == a_rhs); }
111  inline friend bool operator==(const GString& a_lhs, const GString& a_rhs) { return a_lhs == a_rhs.c_str(); }
112  inline friend bool operator!=(const GString& a_lhs, const GString& a_rhs) { return !(a_lhs == a_rhs); }
113  inline friend bool operator==(const GString& a_lhs, const std::string_view& a_rhs) { return a_lhs == a_rhs.data(); }
114  inline friend bool operator!=(const GString& a_lhs, const std::string_view& a_rhs) { return !(a_lhs == a_rhs); }
115  inline friend bool operator==(const std::string_view& a_lhs, const GString& a_rhs) { return a_rhs == a_lhs; }
116  inline friend bool operator!=(const std::string_view& a_lhs, const GString& a_rhs) { return !(a_lhs == a_rhs); }
117 
118  static UPInt BernsteinHashFunction(const void* a_dataIn, UPInt a_size, UPInt a_seed = 5381);
119 
120  protected:
121  GString* ctor(const char* a_str);
122  [[nodiscard]] HeapType heap_type() const;
123  [[nodiscard]] DataDesc* get_desc() const;
124  void set_desc(DataDesc* a_desc);
125 
126  // members
128  };
129  static_assert(sizeof(GString) == 0x8);
130 }
Definition: GString.h:8
UPInt size_type
Definition: GString.h:11
friend bool operator==(const char *a_lhs, const GString &a_rhs)
Definition: GString.h:109
GString * ctor(const char *a_str)
const char & front() const
HeapType
Definition: GString.h:16
friend bool operator==(const GString &a_lhs, const GString &a_rhs)
Definition: GString.h:111
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:10
size_type length() const noexcept
friend bool operator!=(const GString &a_lhs, const char *a_rhs)
Definition: GString.h:108
char & front()
char & back()
friend bool operator==(const std::string_view &a_lhs, const GString &a_rhs)
Definition: GString.h:115
const_reference operator[](size_type a_pos) const
friend bool operator!=(const std::string_view &a_lhs, const GString &a_rhs)
Definition: GString.h:116
reference operator[](size_type a_pos)
friend bool operator!=(const char *a_lhs, const GString &a_rhs)
Definition: GString.h:110
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:13
friend bool operator!=(const GString &a_lhs, const GString &a_rhs)
Definition: GString.h:112
GString(const GString &a_rhs)
friend bool operator==(const GString &a_lhs, const std::string_view &a_rhs)
Definition: GString.h:113
GString & operator=(const std::string_view &a_rhs)
HeapType heap_type() const
void clear() noexcept
DataDescUnion _dataDesc
Definition: GString.h:127
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:114
const char * c_str() const noexcept
value_type & reference
Definition: GString.h:12
Definition: AbsorbEffect.h:6
std::size_t UPInt
Definition: SFTypes.h:5
Definition: NiBinaryStream.h:94
Definition: GString.h:33
void SetFull(bool a_set)
@ kFullFlag
Definition: GString.h:36
char data[1]
Definition: GString.h:51
volatile std::int32_t refCount
Definition: GString.h:50
UPInt capacity
Definition: GString.h:49
UPInt GetCapacity() const
Definition: GString.h:24
FlagConstant
Definition: GString.h:26
@ kReserveIsSizeShift
Definition: GString.h:27
Definition: GString.h:56
stl::enumeration< HeapType, UPInt > heapType
Definition: GString.h:60
DataDesc * data
Definition: GString.h:59