Source code of Windows XP (NT5)
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.

155 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  4. //
  5. // File: custring.hxx
  6. //
  7. // Contents: This has declarations for some functions used in String class.
  8. //
  9. // Classes:
  10. //
  11. // Functions:
  12. //
  13. // History: 04-Feb-93 SudK Created
  14. //
  15. //--------------------------------------------------------------------------
  16. #ifndef __CUSTRING_CLASS_INCLUDED
  17. #define __CUSTRING_CLASS_INCLUDED
  18. void SRtlDuplicateString(PUNICODE_STRING pDest, PUNICODE_STRING pSrc);
  19. void SRtlNewString( PUNICODE_STRING pDest, PWCHAR pSrc);
  20. void SRtlFreeString( PUNICODE_STRING pString);
  21. //+-------------------------------------------------------------------------
  22. //
  23. // Name: CUnicodeString
  24. //
  25. // Synopsis: Wrapper for a UNICODE_STRING.
  26. //
  27. // Methods: ~CUnicodeString()
  28. // CUnicodeString()
  29. // CUnicodeString(WCHAR)
  30. // CUnicodeString(CHAR)
  31. // CUnicodeString(CUnicodeString&)
  32. // CUnicodeString(UNICODE_STRING&)
  33. // implicit conversions to PWCHAR, PUNICODE_STRING, UNICODE_STRING
  34. // assignment operator from PWCHAR, UNICODE_STRING&, CUnicodeString&
  35. // CUnicodeStrCat(CUnicodeString&)
  36. // CUnicodeStrCat(PWCHAR)
  37. //
  38. // Notes: This class is not cheap on memory. Each of the constructors (
  39. // including the assignment operators) allocate new storage for
  40. // the string. The destructor frees the storage.
  41. //
  42. // This class will implicity convert to either a UNICODE_STRING or
  43. // to a PUNICODE_STRING. This means if you have a function:
  44. // Foo1 ( UNICODE_STRING ss, PUNICODE_STRING pss );
  45. // and two CUnicodeStrings, cuStr1, cuStr2, you call it foo like:
  46. // Foo1 ( cuStr1, cuStr2 );
  47. // (ie. you don't use "&cuStr2" like you do for a UNICODE_STRING.)
  48. //
  49. //--------------------------------------------------------------------------
  50. class CUnicodeString {
  51. private:
  52. UNICODE_STRING _ss;
  53. public:
  54. //
  55. // Destructor
  56. //
  57. ~CUnicodeString()
  58. { SRtlFreeString( &_ss ); };
  59. //
  60. // Constructors
  61. //
  62. CUnicodeString()
  63. {
  64. _ss.Length = _ss.MaximumLength = 0;
  65. _ss.Buffer = 0;
  66. };
  67. CUnicodeString( WCHAR *pwc)
  68. { SRtlNewString( &_ss, pwc ); };
  69. CUnicodeString( CUnicodeString& css )
  70. { SRtlDuplicateString( &_ss, &css._ss ); };
  71. CUnicodeString( UNICODE_STRING& ss )
  72. { SRtlDuplicateString( &_ss, &ss ); };
  73. //
  74. // Some useful conversions
  75. //
  76. operator PWCHAR ()
  77. { return(_ss.Buffer); };
  78. operator UNICODE_STRING ()
  79. { return(_ss); }
  80. operator PUNICODE_STRING ()
  81. { return(&_ss); }
  82. VOID Transfer(PUNICODE_STRING pustr)
  83. { *pustr = _ss; _ss.Length = _ss.MaximumLength = 0; _ss.Buffer = NULL; }
  84. //
  85. // Access to elements
  86. //
  87. USHORT GetLength()
  88. { return(_ss.Length); };
  89. USHORT GetMaximumLength()
  90. { return(_ss.MaximumLength); };
  91. WCHAR * GetBuffer()
  92. { return(_ss.Buffer); };
  93. //
  94. // Finally, some operators
  95. //
  96. VOID Copy( PWCHAR r)
  97. {
  98. ASSERT((_ss.MaximumLength == 0)&&(_ss.Buffer == NULL));
  99. SRtlNewString( &_ss, r);
  100. return;
  101. };
  102. // =
  103. CUnicodeString& operator=( PWCHAR r )
  104. {
  105. ASSERT((_ss.MaximumLength == 0)&&(_ss.Buffer == NULL));
  106. SRtlNewString( &_ss, r );
  107. return(*this);
  108. };
  109. CUnicodeString& operator=( CUnicodeString& r )
  110. {
  111. ASSERT((_ss.MaximumLength == 0)&&(_ss.Buffer == NULL));
  112. SRtlDuplicateString( &_ss, &r._ss );
  113. return(*this);
  114. };
  115. CUnicodeString& operator=( UNICODE_STRING r )
  116. {
  117. ASSERT((_ss.MaximumLength == 0)&&(_ss.Buffer == NULL));
  118. SRtlDuplicateString( &_ss, &r );
  119. return(*this);
  120. };
  121. CUnicodeString& operator=( STRING r )
  122. {
  123. ASSERT((_ss.MaximumLength == 0)&&(_ss.Buffer == NULL));
  124. SRtlDuplicateString( &_ss, (PUNICODE_STRING) &r );
  125. return(*this);
  126. };
  127. };
  128. #endif // __CUSTRING_CLASS_INCLUDED