CommonLibSSE (powerof3)
Loading...
Searching...
No Matches
GString.h
Go to the documentation of this file.
1#pragma once
2
3namespace RE
4{
5 class GStringBuffer;
6
7 class GString
8 {
9 public:
10 using value_type = char; // can also be wchar_t
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
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 & operator=(GString &&a_rhs)
GString * ctor(const char *a_str)
HeapType
Definition: GString.h:16
friend bool operator==(const GString &a_lhs, const GString &a_rhs)
Definition: GString.h:111
GString(GString &&a_rhs)
const char & front() const
char & front()
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 & 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
void set_desc(DataDesc *a_desc)
GString & operator=(const std::string_view &a_rhs)
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
HeapType heap_type() const
GString & operator=(const GString &a_rhs)
void clear() noexcept
DataDescUnion _dataDesc
Definition: GString.h:127
GString & operator=(const char *a_rhs)
DataDesc * get_desc() const
const char & back() const
size_type size() const noexcept
operator std::string_view() const noexcept
const char * c_str() const noexcept
bool empty() const noexcept
friend bool operator!=(const GString &a_lhs, const std::string_view &a_rhs)
Definition: GString.h:114
value_type & reference
Definition: GString.h:12
const char * data() const noexcept
Definition: PCH.h:217
Definition: AbsorbEffect.h:6
std::size_t UPInt
Definition: SFTypes.h:5
Definition: EffectArchetypes.h:65
Definition: GString.h:33
@ kFullFlag
Definition: GString.h:36
void SetFull(bool a_set)
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