aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/stringregistry.h
blob: 9e4ff82ce91f7ab09e58fcd1b20a79369bb7ca71 (plain) (blame)
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
//========= 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