Leaked source code of windows server 2003
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.

145 lines
4.9 KiB

  1. #ifndef _STRING_HPP_
  2. #define _STRING_HPP_
  3. // Ruler
  4. // 1 2 3 4 5 6 7 8
  5. //345678901234567890123456789012345678901234567890123456789012345678901234567890
  6. /********************************************************************/
  7. /* */
  8. /* The standard layout. */
  9. /* */
  10. /* The standard layout for 'hpp' files for this code is as */
  11. /* follows: */
  12. /* */
  13. /* 1. Include files. */
  14. /* 2. Constants exported from the class. */
  15. /* 3. Data structures exported from the class. */
  16. /* 4. Forward references to other data structures. */
  17. /* 5. Class specifications (including inline functions). */
  18. /* 6. Additional large inline functions. */
  19. /* */
  20. /* Any portion that is not required is simply omitted. */
  21. /* */
  22. /********************************************************************/
  23. #include "Global.hpp"
  24. #include "Lock.hpp"
  25. #include "Spinlock.hpp"
  26. #include "Unique.hpp"
  27. /********************************************************************/
  28. /* */
  29. /* A string class. */
  30. /* */
  31. /* A typical string class manages variable length text strings. */
  32. /* Although we support the same in this class we ensure that */
  33. /* there is only one copy of every unique string. There is a */
  34. /* cost associated with this at string creation time but a big */
  35. /* win when the strings are heavily compared, copied or */
  36. /* replicated. */
  37. /* */
  38. /********************************************************************/
  39. class STRING
  40. {
  41. //
  42. // Private data.
  43. //
  44. DETAIL *Detail;
  45. //
  46. // Static private data.
  47. //
  48. #ifdef DISABLE_STRING_LOCKS
  49. STATIC UNIQUE<NO_LOCK> *Unique;
  50. #else
  51. STATIC SPINLOCK Spinlock;
  52. STATIC UNIQUE<FULL_LOCK> *Unique;
  53. #endif
  54. public:
  55. //
  56. // Public inline functions.
  57. //
  58. STRING( VOID )
  59. { DefaultString(); }
  60. STRING( CHAR *String )
  61. { CreateString( String,strlen( String ) ); }
  62. STRING( CHAR *String,SBIT32 Size )
  63. { CreateString( String,Size ); }
  64. STRING( CONST STRING & Update )
  65. { Detail = Unique -> CopyString( DefaultString(),Update.Detail ); }
  66. INLINE VOID operator=( CONST STRING & Update )
  67. { Detail = Unique -> CopyString( Detail,Update.Detail ); }
  68. INLINE BOOLEAN operator==( CONST STRING & String )
  69. { return (Detail == String.Detail); }
  70. INLINE BOOLEAN operator!=( CONST STRING & String )
  71. { return (Detail != String.Detail); }
  72. INLINE BOOLEAN operator<( CONST STRING & String )
  73. { return (Unique -> CompareStrings( Detail,String.Detail ) < 0); }
  74. INLINE BOOLEAN operator<=( CONST STRING & String )
  75. { return (Unique -> CompareStrings( Detail,String.Detail ) <= 0); }
  76. INLINE BOOLEAN operator>( CONST STRING & String )
  77. { return (Unique -> CompareStrings( Detail,String.Detail ) > 0); }
  78. INLINE BOOLEAN operator>=( CONST STRING & String )
  79. { return (Unique -> CompareStrings( Detail,String.Detail ) >= 0); }
  80. INLINE SBIT32 Size( VOID )
  81. { return Unique -> Size( Detail ); }
  82. INLINE CHAR *Value( VOID )
  83. { return Unique -> Value( Detail ); }
  84. INLINE SBIT32 ValueID( VOID )
  85. { return ((SBIT32) Detail); }
  86. ~STRING( VOID )
  87. { DeleteString(); }
  88. private:
  89. //
  90. // Private functions.
  91. //
  92. VOID CreateStringTable( VOID );
  93. //
  94. // Private inline functions.
  95. //
  96. DETAIL *CreateString( CHAR *String,SBIT32 Size )
  97. {
  98. VerifyStringTable();
  99. return (Detail = Unique -> CreateString( String,Size ));
  100. }
  101. DETAIL *DefaultString( VOID )
  102. {
  103. VerifyStringTable();
  104. return (Detail = Unique -> DefaultString());
  105. }
  106. VOID DeleteString( VOID )
  107. {
  108. if ( Unique != NULL )
  109. { Unique -> DeleteString( Detail ); }
  110. }
  111. VOID VerifyStringTable( VOID )
  112. {
  113. if ( Unique == NULL )
  114. { CreateStringTable(); }
  115. }
  116. };
  117. #endif