aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/tier1/UtlStringMap.h
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /sp/src/public/tier1/UtlStringMap.h
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'sp/src/public/tier1/UtlStringMap.h')
-rw-r--r--sp/src/public/tier1/UtlStringMap.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/sp/src/public/tier1/UtlStringMap.h b/sp/src/public/tier1/UtlStringMap.h
new file mode 100644
index 00000000..e4b64229
--- /dev/null
+++ b/sp/src/public/tier1/UtlStringMap.h
@@ -0,0 +1,99 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//===========================================================================//
+
+#ifndef UTLSTRINGMAP_H
+#define UTLSTRINGMAP_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include "utlsymbol.h"
+
+template <class T>
+class CUtlStringMap
+{
+public:
+ CUtlStringMap( bool caseInsensitive = true ) : m_SymbolTable( 0, 32, caseInsensitive )
+ {
+ }
+
+ // Get data by the string itself:
+ T& operator[]( const char *pString )
+ {
+ CUtlSymbol symbol = m_SymbolTable.AddString( pString );
+ int index = ( int )( UtlSymId_t )symbol;
+ if( m_Vector.Count() <= index )
+ {
+ m_Vector.EnsureCount( index + 1 );
+ }
+ return m_Vector[index];
+ }
+
+ // Get data by the string's symbol table ID - only used to retrieve a pre-existing symbol, not create a new one!
+ T& operator[]( UtlSymId_t n )
+ {
+ Assert( n >=0 && n <= m_Vector.Count() );
+ return m_Vector[n];
+ }
+
+ const T& operator[]( UtlSymId_t n ) const
+ {
+ Assert( n >=0 && n <= m_Vector.Count() );
+ return m_Vector[n];
+ }
+
+ bool Defined( const char *pString ) const
+ {
+ return m_SymbolTable.Find( pString ) != UTL_INVAL_SYMBOL;
+ }
+
+ UtlSymId_t Find( const char *pString ) const
+ {
+ return m_SymbolTable.Find( pString );
+ }
+
+ static UtlSymId_t InvalidIndex()
+ {
+ return UTL_INVAL_SYMBOL;
+ }
+
+ int GetNumStrings( void ) const
+ {
+ return m_SymbolTable.GetNumStrings();
+ }
+
+ const char *String( int n ) const
+ {
+ return m_SymbolTable.String( n );
+ }
+
+ // Clear all of the data from the map
+ void Clear()
+ {
+ m_Vector.RemoveAll();
+ m_SymbolTable.RemoveAll();
+ }
+
+ void Purge()
+ {
+ m_Vector.Purge();
+ m_SymbolTable.RemoveAll();
+ }
+
+ void PurgeAndDeleteElements()
+ {
+ m_Vector.PurgeAndDeleteElements();
+ m_SymbolTable.RemoveAll();
+ }
+
+
+
+private:
+ CUtlVector<T> m_Vector;
+ CUtlSymbolTable m_SymbolTable;
+};
+
+#endif // UTLSTRINGMAP_H