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.

178 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. String.hxx
  6. Abstract:
  7. Short-short implementation of strings.
  8. Author:
  9. Albert Ting (AlbertT) 9-June-1994
  10. Revision History:
  11. --*/
  12. #ifndef _STRING_HXX
  13. #define _STRING_HXX
  14. class TString {
  15. SIGNATURE( 'strg' )
  16. SAFE_NEW
  17. public:
  18. //
  19. // For the default constructor, we initialize _pszString to a
  20. // global gszState[kValid] string. This allows them to work correctly,
  21. // but prevents the extra memory allocation.
  22. //
  23. // Note: if this class is extended (with reference counting
  24. // or "smart" reallocations), this strategy may break.
  25. //
  26. TString(
  27. VOID
  28. );
  29. TString(
  30. IN LPCTSTR psz
  31. );
  32. ~TString(
  33. VOID
  34. );
  35. TString(
  36. IN const TString &String
  37. );
  38. BOOL
  39. bEmpty(
  40. VOID
  41. ) const;
  42. BOOL
  43. bValid(
  44. VOID
  45. ) const;
  46. BOOL
  47. bUpdate(
  48. IN LPCTSTR pszNew
  49. );
  50. HRESULT
  51. Update(
  52. IN LPCTSTR pszNew
  53. );
  54. BOOL
  55. bLoadString(
  56. IN HINSTANCE hInst,
  57. IN UINT uID
  58. );
  59. UINT
  60. TString::
  61. uLen(
  62. VOID
  63. ) const;
  64. BOOL
  65. TString::
  66. bCat(
  67. IN LPCTSTR psz
  68. );
  69. //
  70. // Caution: See function header for usage and side effects.
  71. //
  72. BOOL
  73. TString::
  74. bFormat(
  75. IN LPCTSTR pszFmt,
  76. IN ...
  77. );
  78. //
  79. // Caution: See function header for usage and side effects.
  80. //
  81. BOOL
  82. TString::
  83. bvFormat(
  84. IN LPCTSTR pszFmt,
  85. IN va_list avlist
  86. );
  87. //
  88. // Operator overloads.
  89. //
  90. operator LPCTSTR( VOID ) const
  91. { return _pszString; }
  92. friend INT operator==(const TString& String, LPCTSTR& psz)
  93. { return !lstrcmp(String._pszString, psz); }
  94. friend INT operator==(LPCTSTR& psz, const TString& String)
  95. { return !lstrcmp(psz, String._pszString); }
  96. friend INT operator==(const TString& String1, const TString& String2)
  97. { return !lstrcmp(String1._pszString, String2._pszString); }
  98. friend INT operator!=(const TString& String, LPCTSTR& psz)
  99. { return lstrcmp(String._pszString, psz) != 0; }
  100. friend INT operator!=(LPCTSTR& psz, const TString& String)
  101. { return lstrcmp(psz, String._pszString) != 0; }
  102. friend INT operator!=(const TString& String1, const TString& String2)
  103. { return lstrcmp(String1._pszString, String2._pszString) != 0; }
  104. protected:
  105. //
  106. // Not defined; used bUpdate since this forces clients to
  107. // check whether the assignment succeeded (it may fail due
  108. // to lack of memory, etc.).
  109. //
  110. TString& operator=( LPCTSTR psz );
  111. TString& operator=(const TString& String);
  112. private:
  113. enum StringStatus {
  114. kValid = 0,
  115. kInValid = 1,
  116. };
  117. enum {
  118. kStrIncrement = 256,
  119. kStrMaxFormatSize = 1024 * 100,
  120. };
  121. LPTSTR _pszString;
  122. static TCHAR gszNullState[2];
  123. LPTSTR
  124. TString::
  125. vsntprintf(
  126. IN LPCTSTR szFmt,
  127. IN va_list pArgs
  128. );
  129. VOID
  130. TString::
  131. vFree(
  132. IN LPTSTR pszString
  133. );
  134. };
  135. #endif // ndef _STRING_HXX