OpenBarnyard
 
Loading...
Searching...
No Matches
TPString8.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TPString8.h"
3
4//-----------------------------------------------------------------------------
5// Enables memory debugging.
6// Note: Should be the last include!
7//-----------------------------------------------------------------------------
9
10TDEFINE_FREELIST_ALLOCATOR1( Toshi::TPooledString8, 64 );
11
13
14void TPString8Pool::Get( TPooledString8*& a_pOutString, const TCHAR* a_szString, bool* a_pWasInPool )
15{
16 a_pOutString = TNULL;
17
18 if ( a_szString != TNULL )
19 {
20 auto iStrLen = TStringManager::String8Length( a_szString );
21
22 if ( iStrLen != 0 )
23 {
24 auto it = m_oMap.Find( a_szString );
25
26 if ( m_oMap.IsValid( it ) )
27 {
28 if ( a_pWasInPool )
29 *a_pWasInPool = TTRUE;
30
31 a_pOutString = it->GetSecond();
32 a_pOutString->IncRefCount();
33 }
34 else
35 {
36 TPooledString8* pString = m_pAllocator->New<TPooledString8>( a_szString, this, m_pAllocator );
37 m_oMap.Insert( pString->GetString8().GetString(), pString );
38
39 a_pOutString = pString;
40 pString->IncRefCount();
41 }
42 }
43 }
44}
45
47 : m_pAllocator( a_pAllocator ), m_oMap( a_pAllocator )
48{
49 // TODO: Initialise some unknown values
50}
51
52TPString8Pool::TPString8Pool( TINT a_iUnknown1, TINT a_iUnknown2, T2Allocator* a_pAllocator, void* m_pUnknown3 )
53 : m_pAllocator( a_pAllocator ), m_oMap( a_pAllocator )
54{
55 // TODO: Initialise some unknown values
56
57 for ( auto it = TPString8Initialiser::Head(); it != TNULL; it = it->Next() )
58 {
59 it->Initialise( this );
60 }
61}
62
63TPString8Initialiser::TPString8Initialiser( StringMap* a_pStrings, TUINT a_iStringCount, TBOOL a_bCanReinitialise )
64{
65 m_iCount = a_iStringCount;
66 m_pStrings = a_pStrings;
67 m_pNextInitialiser = ms_pHeadInitialiser;
68 m_bCanReinitialise = a_bCanReinitialise;
69 ms_pHeadInitialiser = this;
70}
71
73{
74 if ( m_bCanReinitialise )
75 {
76 for ( TSIZE i = 0; i < m_iCount; i++ )
77 {
78 if ( m_pStrings[ i ].m_pString8 )
79 {
80 m_pStrings[ i ].m_pString8->SetPooledString( TNULL );
81 }
82 }
83 }
84
85 for ( TSIZE i = 0; i < m_iCount; i++ )
86 {
87 TPString8 string( a_pStringPool, m_pStrings[ i ].m_szCString );
88
89 if ( string.GetPooledString() &&
90 string.GetPooledString() != m_pStrings[ i ].m_pString8->GetPooledString() )
91 {
92 *m_pStrings[ i ].m_pString8 = string;
93 }
94 }
95}
96
98{
99 if ( IsPooled() )
100 {
101 m_pPool->Remove( this );
102 m_pPool->GetAllocator()->Delete( this );
103 }
104 else
105 {
106 delete this;
107 }
108}
109
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TDEFINE_FREELIST_ALLOCATOR1(CLASS_NAME, GROW_SIZE)
Definition TFreeList.h:22
unsigned int TUINT
Definition Typedefs.h:8
size_t TSIZE
Definition Typedefs.h:9
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
const TString8 & GetString8() const
Definition TPString8.h:39
TBOOL IsPooled() const
Definition TPString8.h:41
TPString8Pool(T2Allocator *a_pAllocator)
Definition TPString8.cpp:46
void Get(TPooledString8 *&a_pOutString, const TCHAR *a_szString, bool *a_pWasInPool=nullptr)
Definition TPString8.cpp:14
void Initialise(TPString8Pool *a_pStringPool)
Definition TPString8.cpp:72
TPString8Initialiser(StringMap *a_pStrings, TUINT a_iStringCount, TBOOL a_bFlag)
Definition TPString8.cpp:63
static TPString8Initialiser * Head()
Definition TPString8.h:324
TINT IncRefCount()
Definition TRefCounted.h:13
const TCHAR * GetString(TINT a_iIndex=0) const
Definition TString8.cpp:286
static TSIZE String8Length(const TCHAR *str)