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.

113 lines
2.6 KiB

  1. // tstring.h string helpers
  2. // Copyright (c) Microsoft Corporation 1998.
  3. #pragma once
  4. #ifndef TSTRING_H
  5. #define TSTRING_H
  6. #include <tchar.h>
  7. #include <string>
  8. #include <atlconv.h>
  9. #ifndef USE_TSTRING_CSTRING
  10. #include <atltmp.h>
  11. #endif
  12. #ifdef DEBUG
  13. typedef std::basic_string<TCHAR> base_tstring;
  14. class Tstring : public base_tstring {
  15. public:
  16. inline Tstring() {}
  17. virtual ~Tstring() {}
  18. inline Tstring(const base_tstring &ts) : base_tstring(ts) {}
  19. inline Tstring(const Tstring &ts) : base_tstring(ts) {}
  20. inline Tstring &operator=(const Tstring &rhs) {
  21. if (this != rhs.const_address()) {
  22. base_tstring::operator=(rhs);
  23. }
  24. return *this;
  25. }
  26. inline Tstring &operator=(const TCHAR *rhs) {
  27. if (this != reinterpret_cast<const Tstring *>(rhs)) {
  28. base_tstring::operator=(rhs);
  29. }
  30. return *this;
  31. }
  32. inline LPCTSTR operator&() const {
  33. // NOTE: this is based on c++ std basic_string. all caveats about
  34. // c_str method apply: ptr is read-only and invalid after another
  35. // non-const member is called
  36. return c_str();
  37. }
  38. #ifndef _UNICODE
  39. inline Tstring &operator=(const LPCOLESTR rhs) {
  40. if (this != reinterpret_cast<const Tstring *>(rhs)) {
  41. USES_CONVERSION;
  42. base_tstring::operator=(OLE2T(rhs));
  43. }
  44. return *this;
  45. }
  46. #else
  47. inline Tstring &operator=(const LPCSTR rhs) {
  48. if (this != reinterpret_cast<const Tstring *>(rhs)) {
  49. USES_CONVERSION;
  50. base_tstring::operator=(A2T(rhs));
  51. }
  52. return *this;
  53. }
  54. #endif
  55. inline const Tstring *const_address() const {
  56. return this;
  57. }
  58. inline Tstring *address() {
  59. return this;
  60. }
  61. };
  62. #endif
  63. #ifdef USE_TSTRING_CSTRING
  64. class CString : public Tstring {
  65. public:
  66. inline CString() : Tstring() {}
  67. inline CString(const Tstring &ts) : Tstring(ts) {}
  68. inline CString(const CString &cs) : Tstring(cs) {}
  69. virtual ~CString() {}
  70. inline LPCTSTR operator&() const {
  71. // NOTE: this is based on c++ std basic_string. all caveats about
  72. // c_str method apply: ptr is read-only and invalid after another
  73. // non-const member is called
  74. return c_str();
  75. }
  76. inline CString &operator=(const CString &rhs) {
  77. if (this != rhs.const_address()) {
  78. Tstring::operator=(rhs);
  79. }
  80. return *this;
  81. }
  82. inline CString &operator=(const TCHAR *rhs) {
  83. if (this != reinterpret_cast<const CString *>(rhs)) {
  84. Tstring::operator=(rhs);
  85. }
  86. return *this;
  87. }
  88. inline const CString *const_address() const {
  89. return this;
  90. }
  91. inline CString *address() {
  92. return this;
  93. }
  94. bool IsEmpty(void) const {
  95. return size() == 0;
  96. };
  97. };
  98. #endif
  99. #endif
  100. // end of file tstring.h