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
3.7 KiB

  1. /******************************************************************************
  2. Header File: String Array.H
  3. This provides a relatively simple C++ class for manipulating an array of
  4. character strings. In this project, we use it for lists of associated
  5. devices, or potential associated devices, etc. I'm not currently sorting
  6. this list.
  7. The class declaration may look a bit bizarre. Since most of the arrays
  8. will in fact be rather small, I picked a decent size. When they get bigger,
  9. I'll chain them internally and use recursion to perform any needed function.
  10. Copyright (c) 1996 by Microsoft Corporation
  11. A Pretty Penny Enterprises Production
  12. Change History:
  13. 11-01-96 a-robkj@microsoft.com- original version
  14. 12-04-96 a-robkj@microsoft.com Added LoadString and IsEmpty to CString
  15. ******************************************************************************/
  16. #if !defined(STRING_ARRAY)
  17. #if defined(UNICODE)
  18. #define LPCOSTR LPCSTR
  19. #define LPOSTR LPSTR
  20. #define OCHAR CHAR
  21. #if !defined(_UNICODE)
  22. #define _UNICODE
  23. #endif
  24. #else
  25. #define LPCOSTR LPCWSTR
  26. #define LPOSTR LPWSTR
  27. #define OCHAR WCHAR
  28. #endif
  29. #include <tchar.h>
  30. #define STRING_ARRAY
  31. class CString {
  32. LPTSTR m_acContents;
  33. LPOSTR m_acConverted;
  34. BOOL m_bConverted;
  35. void Flip(LPCWSTR lpstrIn, LPSTR& lpstrOut);
  36. void Flip(LPCSTR lpstrIn, LPWSTR& lpstrOut);
  37. public:
  38. CString();
  39. CString(const CString& csRef);
  40. CString(LPCTSTR lpstrRef);
  41. CString(LPCOSTR lpstrRef);
  42. ~CString();
  43. BOOL IsEmpty() const { return !m_acContents || !m_acContents[0]; }
  44. void Empty();
  45. operator LPCTSTR() const { return m_acContents; }
  46. operator LPTSTR() const { return m_acContents; }
  47. operator LPARAM() const { return (LPARAM) m_acContents; }
  48. operator LPCOSTR();
  49. const CString& operator = (const CString& csSrc);
  50. const CString& operator = (LPCTSTR lpstrSrc);
  51. const CString& operator = (LPCOSTR lpstrSrc);
  52. CString NameOnly() const;
  53. CString NameAndExtension() const;
  54. void Load(int id, HINSTANCE hiWhere = NULL);
  55. void Load(HWND hwnd);
  56. void LoadAndFormat(int id,
  57. HINSTANCE hiWhere,
  58. BOOL bSystemMessage,
  59. DWORD dwNumMsg,
  60. va_list *argList);
  61. BOOL IsEqualString(CString& csRef1);
  62. friend CString operator + (const CString& csRef1, LPCTSTR lpstrRef2);
  63. };
  64. class CStringArray {
  65. CString m_aStore[20];
  66. CStringArray *m_pcsaNext;
  67. unsigned m_ucUsed;
  68. const unsigned ChunkSize() const {
  69. return sizeof m_aStore / sizeof m_aStore[0];
  70. }
  71. LPCTSTR Borrow();
  72. public:
  73. CStringArray();
  74. ~CStringArray();
  75. unsigned Count() const { return m_ucUsed; }
  76. // Add an item
  77. void Add(LPCTSTR lpstrNew);
  78. CString& operator [](unsigned u) const;
  79. void Remove(unsigned u);
  80. void Empty();
  81. // Return index of string in array- array count if not present
  82. unsigned Map(LPCTSTR lpstrRef);
  83. };
  84. class CUintArray {
  85. unsigned m_aStore[20];
  86. CUintArray *m_pcuaNext;
  87. unsigned m_ucUsed;
  88. const unsigned ChunkSize() const {
  89. return sizeof m_aStore / sizeof m_aStore[0];
  90. }
  91. unsigned Borrow();
  92. public:
  93. CUintArray();
  94. ~CUintArray();
  95. unsigned Count() const { return m_ucUsed; }
  96. // Add an item
  97. void Add(unsigned u);
  98. unsigned operator [](unsigned u) const;
  99. void Remove(unsigned u);
  100. void Empty();
  101. };
  102. #endif