1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "dt_utlvector_common.h"
#include "utldict.h"
#include "tier0/memdbgon.h"
static CUtlDict<int,int> *g_STDict = 0;
static CUtlDict<int,int> *g_RTDict = 0;
char* AllocateStringHelper2( const char *pFormat, va_list marker )
{
char str[512];
_vsnprintf( str, sizeof( str ), pFormat, marker );
str[ ARRAYSIZE(str) - 1 ] = 0;
int len = strlen( str ) + 1;
char *pRet = new char[len];
memcpy( pRet, str, len );
return pRet;
}
char* AllocateStringHelper( const char *pFormat, ... )
{
va_list marker;
va_start( marker, pFormat );
char *pRet = AllocateStringHelper2( pFormat, marker );
va_end( marker );
return pRet;
}
char* AllocateUniqueDataTableName( bool bSendTable, const char *pFormat, ... )
{
// Setup the string.
va_list marker;
va_start( marker, pFormat );
char *pRet = AllocateStringHelper2( pFormat, marker );
va_end( marker );
// Make sure it's unique.
#ifdef _DEBUG
// Have to allocate them here because if they're declared as straight global variables,
// their constructors won't have been called yet by the time we get in here.
if ( !g_STDict )
{
g_STDict = new CUtlDict<int,int>;
g_RTDict = new CUtlDict<int,int>;
}
CUtlDict<int,int> *pDict = bSendTable ? g_STDict : g_RTDict;
if ( pDict->Find( pRet ) != pDict->InvalidIndex() )
{
// If it hits this, then they have 2 utlvectors in different data tables with the same name and the
// same size limit. The names of
Assert( false );
}
pDict->Insert( pRet, 0 );
#endif
return pRet;
}
|