OpenBarnyard
 
Loading...
Searching...
No Matches
TPString8.h
Go to the documentation of this file.
1#pragma once
2#ifndef __TOSHI_TPSTRING8_H__
3# define __TOSHI_TPSTRING8_H__
4#endif
5
6#include "TString8.h"
7#include "TStringManager.h"
8#include "Toshi/TRefCounted.h"
9#include "Toshi/T2Allocator.h"
10#include "Toshi/T2Map.h"
11#include "Toshi/T2String.h"
12#include "Toshi/TSystem.h"
13#include "Toshi/TFreeList.h"
14
15#define TPSTRING8_DECLARE( STR ) extern Toshi::TPString8 g_str_##STR
16#define TPS8( STR ) ( g_str_##STR )
17#define TPS8D( STR ) ( Toshi::TPString8( STR ) )
18
20
21class TPString8Pool;
22
24{
25public:
27
28 friend class TPString8;
29
30public:
31 TPooledString8( const TCHAR* a_szString, TPString8Pool* a_pPool, T2Allocator* a_pAllocator )
32 : m_oString( a_szString, a_pAllocator )
33 {
34 m_pPool = a_pPool;
35 }
36
37 void Delete();
38
39 const TString8& GetString8() const { return m_oString; }
40 TPString8Pool* GetStringPool() const { return m_pPool; }
41 TBOOL IsPooled() const { return m_pPool != TNULL; }
42
43private:
44 TString8 m_oString;
45 TPString8Pool* m_pPool;
46};
47
49{
50public:
51 // Doesn't initialise strings from TPString8Initialiser
52 TPString8Pool( T2Allocator* a_pAllocator );
53
54 // Initialises strings from TPString8Initialiser
55 TPString8Pool( TINT a_iUnknown1, TINT a_iUnknown2, T2Allocator* a_pAllocator, void* m_pUnknown3 );
56
57 void Get( TPooledString8*& a_pOutString, const TCHAR* a_szString, bool* a_pWasInPool = TNULL );
58
59 void Remove( TPooledString8* a_pString )
60 {
61 TASSERT( a_pString->GetRefCount() == 0 );
62 m_oMap.Remove( a_pString->GetString8() );
63 }
64
66 {
67 TIMPLEMENT();
68 }
69
71 {
72 return m_pAllocator;
73 }
74
79
84
85private:
86 T2Allocator* m_pAllocator;
87 TUINT m_Unk1;
89 TUINT m_Unk2;
90 TUINT m_Unk3;
91 TUINT m_Unk4;
92 TUINT m_Unk5;
93};
94
96{
97public:
99 {
100 public:
101 static TBOOL IsEqual( const TPString8& a, const TPString8& b )
102 {
103 return a.GetPooledString() == b.GetPooledString();
104 }
105
106 static TBOOL IsGreater( const TPString8& a, const TPString8& b )
107 {
108 return a.GetPooledString() > b.GetPooledString();
109 }
110
111 static TBOOL IsLess( const TPString8& a, const TPString8& b )
112 {
113 return a.GetPooledString() < b.GetPooledString();
114 }
115
116 static TBOOL IsLessOrEqual( const TPString8& a, const TPString8& b )
117 {
118 return a.GetPooledString() <= b.GetPooledString();
119 }
120
121 static TBOOL IsGreaterOrEqual( const TPString8& a, const TPString8& b )
122 {
123 return a.GetPooledString() >= b.GetPooledString();
124 }
125 };
126
127 inline static const TString8 ms_sEmpty = TString8( "" );
128
129public:
131 : m_pPtr( TNULL )
132 {}
133
134 TFORCEINLINE explicit TPString8( const TCHAR* a_szString )
135 {
136 TUtil::GetTPStringPool()->Get( m_pPtr, a_szString, TNULL );
137 }
138
139 TFORCEINLINE TPString8( TPString8Pool* a_pPool, const TCHAR* a_szString )
140 {
141 a_pPool->Get( m_pPtr, a_szString, TNULL );
142 }
143
144 TFORCEINLINE explicit TPString8( TPooledString8* a_pPooled )
145 {
146 m_pPtr = a_pPooled;
147 Increment();
148 }
149
151 {
152 m_pPtr = a_rOther.m_pPtr;
153 Increment();
154 }
155
157 {
158 m_pPtr = a_rOther.m_pPtr;
159 a_rOther.m_pPtr = TNULL;
160 }
161
163 {
164 Decrement();
165 }
166
168 {
169 return GetString8().GetString();
170 }
171
173 {
174 return m_pPtr ? m_pPtr->m_oString : ms_sEmpty;
175 }
176
178 {
179 return m_pPtr;
180 }
181
183 {
184 return m_pPtr == TNULL || m_pPtr->GetString8().Length() == 0;
185 }
186
188 {
189 if ( m_pPtr != a_pPooledString )
190 {
191 Decrement();
192 m_pPtr = a_pPooledString;
193 Increment();
194 }
195 }
196
197 TFORCEINLINE bool IsEqual( const TPString8& a_Other ) const
198 {
199 return m_pPtr == a_Other.m_pPtr;
200 }
201
202 TFORCEINLINE bool IsEqual( const TPString8* a_pOther ) const
203 {
204 return m_pPtr == a_pOther->m_pPtr;
205 }
206
207 TFORCEINLINE bool operator==( const TPString8& a_Other ) const
208 {
209 return m_pPtr == a_Other.m_pPtr;
210 }
211
212 TFORCEINLINE bool operator!=( const TPString8& a_Other ) const
213 {
214 return m_pPtr != a_Other.m_pPtr;
215 }
216
218 {
219 if ( m_pPtr != a_pString )
220 {
221 Decrement();
222 m_pPtr = a_pString;
223 Increment();
224 }
225
226 return *this;
227 }
228
230 {
231 if ( m_pPtr != other.m_pPtr )
232 {
233 Decrement();
234 m_pPtr = other.m_pPtr;
235 Increment();
236 }
237
238 return *this;
239 }
240
242 {
243 if ( m_pPtr != pOther->m_pPtr )
244 {
245 Decrement();
246 m_pPtr = pOther->m_pPtr;
247 Increment();
248 }
249
250 return *this;
251 }
252
253 TFORCEINLINE TPString8& operator=( const TCHAR* a_szString )
254 {
255 Decrement();
256 TUtil::GetTPStringPool()->Get( m_pPtr, a_szString, TNULL );
257 return *this;
258 }
259
261 {
262 Decrement();
263 m_pPtr = a_rOther.m_pPtr;
264 a_rOther.m_pPtr = TNULL;
265 return *this;
266 }
267
268 TFORCEINLINE operator const TCHAR*() const
269 {
270 return m_pPtr ? m_pPtr->m_oString.GetString() : ms_sEmpty.GetString();
271 }
272
273 TFORCEINLINE operator const TString8*() const
274 {
275 return m_pPtr ? &m_pPtr->m_oString : &ms_sEmpty;
276 }
277
278 TFORCEINLINE operator const TPooledString8*() const
279 {
280 return m_pPtr;
281 }
282
283private:
284 TFORCEINLINE void Increment()
285 {
286 if ( m_pPtr )
287 {
288 m_pPtr->IncRefCount();
289 }
290 }
291
292 TFORCEINLINE void Decrement()
293 {
294 if ( m_pPtr && m_pPtr->DecRefCount() == 0 )
295 {
296 m_pPtr->Delete();
297 }
298 }
299
300private:
301 TPooledString8* m_pPtr;
302};
303
305{
306public:
312
313public:
314 TPString8Initialiser( StringMap* a_pStrings, TUINT a_iStringCount, TBOOL a_bFlag );
316
317 void Initialise( TPString8Pool* a_pStringPool );
318
319 StringMap* GetStringMap() const { return m_pStrings; }
320 TUINT GetCount() const { return m_iCount; }
321 TPString8Initialiser* Next() const { return m_pNextInitialiser; }
322
323public:
324 static TPString8Initialiser* Head() { return ms_pHeadInitialiser; }
325
326private:
327 inline static TPString8Initialiser* ms_pHeadInitialiser;
328
329private:
330 StringMap* m_pStrings;
331 TUINT m_iCount;
332 TPString8Initialiser* m_pNextInitialiser;
333 TBOOL m_bCanReinitialise;
334};
335
#define TIMPLEMENT()
Definition Defines.h:136
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TFORCEINLINE
Definition Defines.h:74
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TDECLARE_FREELIST_ALLOCATOR(CLASS_NAME)
Definition TFreeList.h:3
Char string implementation for the Toshi engine.
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6
Definition T2Map.h:10
T2RedBlackTree< Pair >::Iterator Iterator
Definition T2Map.h:13
const TString8 & GetString8() const
Definition TPString8.h:39
TPooledString8(const TCHAR *a_szString, TPString8Pool *a_pPool, T2Allocator *a_pAllocator)
Definition TPString8.h:31
TBOOL IsPooled() const
Definition TPString8.h:41
friend class TPString8
Definition TPString8.h:28
TPString8Pool * GetStringPool() const
Definition TPString8.h:40
TPString8Pool(T2Allocator *a_pAllocator)
Definition TPString8.cpp:46
T2Allocator * GetAllocator() const
Definition TPString8.h:70
T2Map< constTCHAR *, TPooledString8 *, T2String8Comparator >::Iterator Begin()
Definition TPString8.h:75
T2Map< constTCHAR *, TPooledString8 *, T2String8Comparator >::Iterator End()
Definition TPString8.h:80
void Get(TPooledString8 *&a_pOutString, const TCHAR *a_szString, bool *a_pWasInPool=nullptr)
Definition TPString8.cpp:14
void Remove(TPooledString8 *a_pString)
Definition TPString8.h:59
void InitialiseStatic()
Definition TPString8.h:65
TFORCEINLINE bool IsEqual(const TPString8 *a_pOther) const
Definition TPString8.h:202
TFORCEINLINE const TString8 & GetString8() const
Definition TPString8.h:172
TFORCEINLINE TPString8 & operator=(const TPString8 &other)
Definition TPString8.h:229
TFORCEINLINE void SetPooledString(TPooledString8 *a_pPooledString)
Definition TPString8.h:187
TFORCEINLINE TPString8(TPooledString8 *a_pPooled)
Definition TPString8.h:144
TFORCEINLINE TPString8(const TCHAR *a_szString)
Definition TPString8.h:134
TFORCEINLINE TPString8(TPString8Pool *a_pPool, const TCHAR *a_szString)
Definition TPString8.h:139
TFORCEINLINE TPString8(TPString8 &&a_rOther)
Definition TPString8.h:156
TFORCEINLINE const TPooledString8 * GetPooledString() const
Definition TPString8.h:177
static const TString8 ms_sEmpty
Definition TPString8.h:127
TFORCEINLINE TPString8 & operator=(const TCHAR *a_szString)
Definition TPString8.h:253
TFORCEINLINE TPString8 & operator=(TPString8 &&a_rOther)
Definition TPString8.h:260
TFORCEINLINE TPString8 & operator=(TPooledString8 *a_pString)
Definition TPString8.h:217
TFORCEINLINE ~TPString8()
Definition TPString8.h:162
TFORCEINLINE TPString8(const TPString8 &a_rOther)
Definition TPString8.h:150
TFORCEINLINE bool IsEqual(const TPString8 &a_Other) const
Definition TPString8.h:197
TFORCEINLINE TBOOL IsEmpty() const
Definition TPString8.h:182
TFORCEINLINE bool operator==(const TPString8 &a_Other) const
Definition TPString8.h:207
TFORCEINLINE const TCHAR * GetString() const
Definition TPString8.h:167
TFORCEINLINE constexpr TPString8()
Definition TPString8.h:130
TFORCEINLINE bool operator!=(const TPString8 &a_Other) const
Definition TPString8.h:212
TFORCEINLINE TPString8 & operator=(const TPString8 *pOther)
Definition TPString8.h:241
static TBOOL IsGreaterOrEqual(const TPString8 &a, const TPString8 &b)
Definition TPString8.h:121
static TBOOL IsGreater(const TPString8 &a, const TPString8 &b)
Definition TPString8.h:106
static TBOOL IsLess(const TPString8 &a, const TPString8 &b)
Definition TPString8.h:111
static TBOOL IsEqual(const TPString8 &a, const TPString8 &b)
Definition TPString8.h:101
static TBOOL IsLessOrEqual(const TPString8 &a, const TPString8 &b)
Definition TPString8.h:116
void Initialise(TPString8Pool *a_pStringPool)
Definition TPString8.cpp:72
TPString8Initialiser(StringMap *a_pStrings, TUINT a_iStringCount, TBOOL a_bFlag)
Definition TPString8.cpp:63
StringMap * GetStringMap() const
Definition TPString8.h:319
TPString8Initialiser * Next() const
Definition TPString8.h:321
~TPString8Initialiser()=default
TUINT GetCount() const
Definition TPString8.h:320
static TPString8Initialiser * Head()
Definition TPString8.h:324
TINT IncRefCount()
Definition TRefCounted.h:13
TINT GetRefCount()
Definition TRefCounted.h:12
const TCHAR * GetString(TINT a_iIndex=0) const
Definition TString8.cpp:286
static TPString8Pool * GetTPStringPool()
Definition TUtil.h:123