hstring.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ////////////////////////////////////////////////////////////////////////////////////////
  2. // RAVEN STANDARD USEFUL FUNCTION LIBRARY
  3. // (c) 2002 Activision
  4. //
  5. //
  6. // Handle String
  7. // -------------
  8. // Handle strings are allocated once in a static buffer (with a hash index), and are
  9. // never cleared out. You should use these for very common string names which are
  10. // redundant or intended to last a long time.
  11. //
  12. // Handle strings are also good for comparison and storage because they compare only
  13. // the handles, which are simple unique integers.
  14. //
  15. ////////////////////////////////////////////////////////////////////////////////////////
  16. #if !defined(RUFL_HSTRING_INC)
  17. #define RUFL_HSTRING_INC
  18. #ifdef _XBOX
  19. namespace dllNamespace
  20. {
  21. #endif
  22. ////////////////////////////////////////////////////////////////////////////////////////
  23. // The Handle String Class
  24. ////////////////////////////////////////////////////////////////////////////////////////
  25. class hstring
  26. {
  27. public:
  28. ////////////////////////////////////////////////////////////////////////////////////
  29. // Constructors
  30. ////////////////////////////////////////////////////////////////////////////////////
  31. hstring();
  32. hstring(const char *str);
  33. hstring(const hstring &str);
  34. ////////////////////////////////////////////////////////////////////////////////////
  35. // Assignment
  36. ////////////////////////////////////////////////////////////////////////////////////
  37. hstring& operator= (const char *str);
  38. hstring& operator= (const hstring &str);
  39. ////////////////////////////////////////////////////////////////////////////////////
  40. // Comparison
  41. ////////////////////////////////////////////////////////////////////////////////////
  42. bool operator== (const hstring &str) const {return (mHandle==str.mHandle);}
  43. bool operator< (const hstring &str) const {return (mHandle< str.mHandle);}
  44. bool operator! () const {return (mHandle==0);}
  45. ////////////////////////////////////////////////////////////////////////////////////
  46. // Conversion
  47. ////////////////////////////////////////////////////////////////////////////////////
  48. const char* c_str(void) const;
  49. const char* operator *(void) const;
  50. ////////////////////////////////////////////////////////////////////////////////////
  51. // Access Functions
  52. ////////////////////////////////////////////////////////////////////////////////////
  53. int length(void) const;
  54. int handle(void) const;
  55. bool empty() const {return handle()==0;}
  56. ////////////////////////////////////////////////////////////////////////////////////
  57. // Debug Statistics Routines
  58. ////////////////////////////////////////////////////////////////////////////////////
  59. #ifdef _DEBUG
  60. static float ave_collisions();
  61. static int total_strings();
  62. static int total_bytes();
  63. static int total_finds();
  64. static int total_collisions();
  65. #endif
  66. private:
  67. ////////////////////////////////////////////////////////////////////////////////////
  68. // Helper Functions
  69. ////////////////////////////////////////////////////////////////////////////////////
  70. void init(const char *str);
  71. ////////////////////////////////////////////////////////////////////////////////////
  72. // Data
  73. ////////////////////////////////////////////////////////////////////////////////////
  74. int mHandle;
  75. #ifdef _DEBUG
  76. char* mStr;
  77. #endif
  78. };
  79. #ifdef _XBOX
  80. } // dllNamespace
  81. using namespace dllNamespace;
  82. #endif
  83. #endif // HSTRING_H