summaryrefslogtreecommitdiff
path: root/external/vpc/public/tier1/stringpool.h
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /external/vpc/public/tier1/stringpool.h
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'external/vpc/public/tier1/stringpool.h')
-rw-r--r--external/vpc/public/tier1/stringpool.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/external/vpc/public/tier1/stringpool.h b/external/vpc/public/tier1/stringpool.h
new file mode 100644
index 0000000..67dfb51
--- /dev/null
+++ b/external/vpc/public/tier1/stringpool.h
@@ -0,0 +1,106 @@
+//========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef STRINGPOOL_H
+#define STRINGPOOL_H
+
+#if defined( _WIN32 )
+#pragma once
+#endif
+
+#include "utlrbtree.h"
+#include "utlvector.h"
+#include "utlbuffer.h"
+
+//-----------------------------------------------------------------------------
+// Purpose: Allocates memory for strings, checking for duplicates first,
+// reusing exising strings if duplicate found.
+//-----------------------------------------------------------------------------
+
+enum StringPoolCase_t
+{
+ StringPoolCaseInsensitive,
+ StringPoolCaseSensitive
+};
+
+class CStringPool
+{
+public:
+ CStringPool( StringPoolCase_t caseSensitivity = StringPoolCaseInsensitive );
+ ~CStringPool();
+
+ unsigned int Count() const;
+
+ const char * Allocate( const char *pszValue );
+ // This feature is deliberately not supported because it's pretty dangerous
+ // given current uses of CStringPool, which assume they can copy string pointers without
+ // any refcounts.
+ //void Free( const char *pszValue );
+ void FreeAll();
+
+ // searches for a string already in the pool
+ const char * Find( const char *pszValue );
+
+protected:
+ typedef CUtlRBTree<const char *, unsigned short> CStrSet;
+
+ CStrSet m_Strings;
+};
+
+//-----------------------------------------------------------------------------
+// Purpose: A reference counted string pool.
+//
+// Elements are stored more efficiently than in the conventional string pool,
+// quicker to look up, and storage is tracked via reference counts.
+//
+// At some point this should replace CStringPool
+//-----------------------------------------------------------------------------
+class CCountedStringPool
+{
+public: // HACK, hash_item_t structure should not be public.
+
+ struct hash_item_t
+ {
+ char* pString;
+ unsigned short nNextElement;
+ unsigned char nReferenceCount;
+ unsigned char pad;
+ };
+
+ enum
+ {
+ INVALID_ELEMENT = 0,
+ MAX_REFERENCE = 0xFF,
+ HASH_TABLE_SIZE = 1024
+ };
+
+ CUtlVector<unsigned short> m_HashTable; // Points to each element
+ CUtlVector<hash_item_t> m_Elements;
+ unsigned short m_FreeListStart;
+ StringPoolCase_t m_caseSensitivity;
+
+public:
+ CCountedStringPool( StringPoolCase_t caseSensitivity = StringPoolCaseInsensitive );
+ virtual ~CCountedStringPool();
+
+ void FreeAll();
+
+ char *FindString( const char* pIntrinsic );
+ char *ReferenceString( const char* pIntrinsic );
+ void DereferenceString( const char* pIntrinsic );
+
+ // These are only reliable if there are less than 64k strings in your string pool
+ unsigned short FindStringHandle( const char* pIntrinsic );
+ unsigned short ReferenceStringHandle( const char* pIntrinsic );
+ char *HandleToString( unsigned short handle );
+ void SpewStrings();
+ unsigned Hash( const char *pszKey );
+
+ bool SaveToBuffer( CUtlBuffer &buffer );
+ bool RestoreFromBuffer( CUtlBuffer &buffer );};
+
+#endif // STRINGPOOL_H