-
Notifications
You must be signed in to change notification settings - Fork 188
Update hash staff & engine sync #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: cs2
Are you sure you want to change the base?
Changes from all commits
80aff5e
292e03c
d8c5f54
caa5928
bcb8069
c4e277d
a4982c5
8441bc8
c806485
c6ac506
998f037
49b6339
dfc32eb
ae85a4e
6c97622
2b2c447
1c5f015
3a6ff85
bd0c6b3
892434b
44e3ddf
eaf586e
f6ca035
37a2d4b
5f9f05b
cfcd835
c1ee083
145f2f9
111a6bf
936f277
5e3b264
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,27 +6,31 @@ | |
|
||
#ifndef UTLSTRINGMAP_H | ||
#define UTLSTRINGMAP_H | ||
|
||
#ifdef _WIN32 | ||
#pragma once | ||
#endif | ||
|
||
#include "utlsymbol.h" | ||
|
||
#define FOR_EACH_STRING_MAP( mapName, iter ) \ | ||
for ( auto iter = (mapName).Head(); iter < (mapName).GetNumStrings() && iter != (mapName).InvalidIndex(); iter = (mapName).Next( iter ) ) | ||
|
||
template <class T> | ||
class CUtlStringMap | ||
{ | ||
public: | ||
CUtlStringMap( bool caseInsensitive = true, int initsize = 32 ) : | ||
m_SymbolTable( 0, 32, caseInsensitive ), | ||
m_Vector( initsize ) | ||
m_Vector( initsize ), | ||
m_SymbolTable( 0, initsize, caseInsensitive ) | ||
{ | ||
} | ||
|
||
// Get data by the string itself: | ||
T& operator[]( const char *pString ) | ||
{ | ||
CUtlSymbol symbol = m_SymbolTable.AddString( pString ); | ||
int index = ( int )( UtlSymId_t )symbol; | ||
int index = ( int )symbol; | ||
if( m_Vector.Count() <= index ) | ||
{ | ||
m_Vector.EnsureCount( index + 1 ); | ||
|
@@ -47,32 +51,95 @@ class CUtlStringMap | |
return m_Vector[n]; | ||
} | ||
|
||
unsigned int Count() const | ||
{ | ||
Assert( m_Vector.Count() == m_SymbolTable.GetNumStrings() ); | ||
|
||
return m_Vector.Count(); | ||
} | ||
|
||
bool Defined( const char *pString ) const | ||
{ | ||
return m_SymbolTable.Find( pString ).IsValid(); | ||
} | ||
|
||
UtlSymId_t Find( const char *pString ) const | ||
CUtlSymbol Find( const char *pString ) const | ||
{ | ||
return m_SymbolTable.Find( pString ); | ||
} | ||
|
||
UtlSymId_t AddString( const char *pString, bool* created = NULL ) | ||
CUtlSymbol AddString( const char *pString, bool* created = NULL ) | ||
{ | ||
CUtlSymbol symbol = m_SymbolTable.AddString( pString, created ); | ||
int index = ( int )( UtlSymId_t )symbol; | ||
int index = ( int )symbol; | ||
if( m_Vector.Count() <= index ) | ||
{ | ||
m_Vector.EnsureCount( index + 1 ); | ||
} | ||
return symbol; | ||
} | ||
|
||
static UtlSymId_t InvalidIndex() | ||
/// Add a string to the map and also insert an item at | ||
/// its location in the same operation. Returns the | ||
/// newly created index (or the one that was just | ||
/// overwritten, if pString already existed.) | ||
CUtlSymbol Insert( const char *pString, const T &item ) | ||
{ | ||
CUtlSymbol symbol = m_SymbolTable.AddString( pString ); // implicit coercion | ||
if ( m_Vector.Count() > symbol ) | ||
{ | ||
// this string is already in the dictionary. | ||
|
||
} | ||
else if ( m_Vector.Count() == symbol ) | ||
{ | ||
// this is the expected case when we've added one more to the tail. | ||
m_Vector.AddToTail( item ); | ||
} | ||
else // ( m_Vector.Count() < symbol ) | ||
{ | ||
// this is a strange shouldn't-happen case. | ||
AssertMsg( false, "CUtlStringMap insert unexpected entries." ); | ||
m_Vector.EnsureCount( symbol + 1 ); | ||
m_Vector[symbol] = item; | ||
} | ||
return symbol; | ||
} | ||
|
||
bool FindAndRemove( const char *pString ) | ||
{ | ||
CUtlSymbol symbol = m_SymbolTable.Find( pString ); | ||
|
||
if ( !symbol.IsValid() ) | ||
{ | ||
return false; | ||
} | ||
|
||
Destruct( &m_Vector[ symbol ] ); | ||
m_Vector[ symbol ] = {}; | ||
m_SymbolTable.Remove( symbol ); | ||
|
||
return true; | ||
} | ||
Comment on lines
+109
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the comment in CUtlSymbolTable::Remove, this is also becomes invalid so please revert that one as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also for gsplugins. Are you sure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replied in the CUtlSymbolTable::Remove comment |
||
|
||
static CUtlSymbol InvalidIndex() | ||
{ | ||
return {}; | ||
} | ||
|
||
// iterators (for uniformity with other map types) | ||
inline CUtlSymbol Head() const | ||
{ | ||
return m_SymbolTable.GetNumStrings() > 0 ? CUtlSymbol( 0 ) : InvalidIndex(); | ||
} | ||
|
||
inline CUtlSymbol Next( const CUtlSymbol &i ) const | ||
{ | ||
return UTL_INVAL_SYMBOL; | ||
CUtlSymbol n = i+1; | ||
return n < m_SymbolTable.GetNumStrings() ? n : InvalidIndex(); | ||
} | ||
|
||
|
||
int GetNumStrings( void ) const | ||
{ | ||
return m_SymbolTable.GetNumStrings(); | ||
|
@@ -109,4 +176,16 @@ class CUtlStringMap | |
CUtlSymbolTable m_SymbolTable; | ||
}; | ||
|
||
|
||
template< class T > | ||
class CUtlStringMapAutoPurge : public CUtlStringMap < T > | ||
{ | ||
public: | ||
~CUtlStringMapAutoPurge( void ) | ||
{ | ||
this->PurgeAndDeleteElements(); | ||
} | ||
|
||
}; | ||
|
||
#endif // UTLSTRINGMAP_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,13 @@ | |
#pragma once | ||
#endif | ||
|
||
#include "tier0/platform.h" | ||
#define __need_size_t | ||
#include <stddef.h> | ||
#undef __need_size_t | ||
|
||
#include "strtools.h" | ||
#include "utlstring.h" | ||
#include "tier0/platform.h" | ||
#include "tier1/utlcommon.h" | ||
|
||
class CFormatStringElement; | ||
class IFormatOutputStream; | ||
|
@@ -83,7 +87,6 @@ class CBufferString | |
m_nAllocatedSize( (bAllowHeapAllocation * ALLOW_HEAP_ALLOCATION) | STACK_ALLOCATED_MARKER | (nAllocatedSize + sizeof( m_szString )) ), | ||
m_pString( nullptr ) | ||
{ | ||
Assert( nAllocatedSize > 8 ); | ||
} | ||
|
||
public: | ||
|
@@ -122,11 +125,11 @@ class CBufferString | |
bool IsAllocationEmpty() const { return AllocatedNum() == 0; } | ||
|
||
protected: | ||
char *Base() { return IsStackAllocated() ? m_szString : (!IsAllocationEmpty() ? m_pString : nullptr); } | ||
char *Base() { return IsStackAllocated() ? m_szString : m_pString; } | ||
const char *Base() const { return const_cast<CBufferString *>( this )->Base(); } | ||
|
||
public: | ||
const char *Get() const { auto base = Base(); return base ? base : StringFuncs<char>::EmptyString(); } | ||
const char *Get() const { return IsStackAllocated() ? m_szString : (IsAllocationEmpty() ? StringFuncs<char>::EmptyString() : m_pString); } | ||
|
||
void Clear() | ||
{ | ||
|
@@ -269,8 +272,8 @@ class CBufferString | |
DLL_CLASS_IMPORT const char *StripExtension(); | ||
DLL_CLASS_IMPORT const char *StripTrailingSlash(); | ||
|
||
DLL_CLASS_IMPORT void ToLowerFast(int nStart); | ||
DLL_CLASS_IMPORT void ToUpperFast(int nStart); | ||
DLL_CLASS_IMPORT void ToLowerFast(int nStart = 0); | ||
DLL_CLASS_IMPORT void ToUpperFast(int nStart = 0); | ||
|
||
DLL_CLASS_IMPORT const char *Trim(const char *pTrimChars = "\t\r\n "); | ||
DLL_CLASS_IMPORT const char *TrimHead(const char *pTrimChars = "\t\r\n "); | ||
|
@@ -292,19 +295,14 @@ class CBufferString | |
}; | ||
}; | ||
|
||
template<size_t SIZE> | ||
template< size_t SIZE > | ||
class CBufferStringN : public CBufferString | ||
{ | ||
public: | ||
static const size_t DATA_SIZE = ALIGN_VALUE( SIZE - sizeof( char[8] ), 8 ); | ||
|
||
CBufferStringN( bool bAllowHeapAllocation = true ) : CBufferString( DATA_SIZE, bAllowHeapAllocation ), m_FixedData{} {} | ||
CBufferStringN( const char *pString, bool bAllowHeapAllocation = true ) : CBufferStringN( bAllowHeapAllocation ) | ||
{ | ||
Insert( 0, pString ); | ||
} | ||
|
||
~CBufferStringN() { PurgeN(); } | ||
CBufferStringN( bool bAllowHeapAllocation = true ) : CBufferString( DATA_SIZE, bAllowHeapAllocation ) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why have you removed m_FixedData initialization? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A destructor is definitely not needed, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be updated in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why github is showing also the destructor part etc, but all I'm asking here is constructor related, you've removed m_FixedData member initialization from it, thus is why I ask why? I'm not sure what is sketches stuff you are talking about, if you can, please, elaborate more. |
||
CBufferStringN( const char *pString, int nLen = -1, bool bAllowHeapAllocation = true ) : CBufferStringN( bAllowHeapAllocation ) { Insert( 0, pString, nLen ); } | ||
|
||
// Should be preferred over CBufferString::Purge as it preserves stack space correctly | ||
void PurgeN() { Purge( DATA_SIZE ); } | ||
|
@@ -314,7 +312,7 @@ class CBufferStringN : public CBufferString | |
}; | ||
|
||
// AMNOTE: CBufferStringN name is preferred to be used, altho CBufferStringGrowable is left as a small bcompat | ||
template <size_t SIZE> | ||
template< size_t SIZE > | ||
using CBufferStringGrowable = CBufferStringN<SIZE>; | ||
|
||
#endif /* BUFFERSTRING_H */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no real need in such a method as utlstringmap expects you to do insertions directly by a key, example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to add a new string key & insert it into the expanded utlvector.
CUtlStringMap
's operators are desiged for getting/setting an existing key.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are tho, how else would you expect new entries to be added there? You can test yourself these with adding new keys. This code in particular handles that
hl2sdk/public/tier1/UtlStringMap.h
Lines 30 to 39 in c6ac506