aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/stringregistry.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/stringregistry.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/stringregistry.h')
-rw-r--r--sp/src/public/stringregistry.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/sp/src/public/stringregistry.h b/sp/src/public/stringregistry.h
new file mode 100644
index 00000000..7c88b2b4
--- /dev/null
+++ b/sp/src/public/stringregistry.h
@@ -0,0 +1,57 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: A registry of strings and associated ints
+//
+// $Workfile: $
+// $Date: $
+//
+//-----------------------------------------------------------------------------
+// $Log: $
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef STRINGREGISTRY_H
+#define STRINGREGISTRY_H
+#pragma once
+
+struct StringTable_t;
+
+//-----------------------------------------------------------------------------
+// Purpose: Just a convenience/legacy wrapper for CUtlDict<> .
+//-----------------------------------------------------------------------------
+class CStringRegistry
+{
+private:
+ StringTable_t *m_pStringList;
+
+public:
+ // returns a key for a given string
+ unsigned short AddString(const char *stringText, int stringID);
+
+ // This is optimized. It will do 2 O(logN) searches
+ // Only one of the searches needs to compare strings, the other compares symbols (ints)
+ // returns -1 if the string is not present in the registry.
+ int GetStringID(const char *stringText);
+
+ // This is unoptimized. It will linearly search (but only compares ints, not strings)
+ const char *GetStringText(int stringID);
+
+ // This is O(1). It will not search. key MUST be a value that was returned by AddString
+ const char *GetStringForKey(unsigned short key);
+ // This is O(1). It will not search. key MUST be a value that was returned by AddString
+ int GetIDForKey(unsigned short key);
+
+ void ClearStrings(void);
+
+
+ // Iterate all the keys.
+ unsigned short First() const;
+ unsigned short Next( unsigned short key ) const;
+ unsigned short InvalidIndex() const;
+
+ ~CStringRegistry(void); // Need to free allocated memory
+ CStringRegistry(void);
+};
+
+#endif // STRINGREGISTRY_H