Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A registry of strings and associated ints
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef STRINGREGISTRY_H
  14. #define STRINGREGISTRY_H
  15. #pragma once
  16. struct StringTable_t;
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Just a convenience/legacy wrapper for CUtlDict<> .
  19. //-----------------------------------------------------------------------------
  20. class CStringRegistry
  21. {
  22. private:
  23. StringTable_t *m_pStringList;
  24. public:
  25. // returns a key for a given string
  26. unsigned short AddString(const char *stringText, int stringID);
  27. // This is optimized. It will do 2 O(logN) searches
  28. // Only one of the searches needs to compare strings, the other compares symbols (ints)
  29. // returns -1 if the string is not present in the registry.
  30. int GetStringID(const char *stringText);
  31. // This is unoptimized. It will linearly search (but only compares ints, not strings)
  32. const char *GetStringText(int stringID);
  33. // This is O(1). It will not search. key MUST be a value that was returned by AddString
  34. const char *GetStringForKey(unsigned short key);
  35. // This is O(1). It will not search. key MUST be a value that was returned by AddString
  36. int GetIDForKey(unsigned short key);
  37. void ClearStrings(void);
  38. // Iterate all the keys.
  39. unsigned short First() const;
  40. unsigned short Next( unsigned short key ) const;
  41. unsigned short InvalidIndex() const;
  42. ~CStringRegistry(void); // Need to free allocated memory
  43. CStringRegistry(void);
  44. };
  45. #endif // STRINGREGISTRY_H