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.

58 lines
1.4 KiB

  1. //
  2. // SortString.h
  3. //
  4. #pragma once
  5. typedef int (WINAPI* SORTSTRING_COMPARE_PROC)(LPCTSTR, LPCTSTR);
  6. // A custom compare routine that will put strings like "100+" after "9"
  7. int WINAPI CompareStringsWithNumbers(LPCTSTR psz1, LPCTSTR psz2);
  8. class CSortedStringArray
  9. {
  10. public:
  11. CSortedStringArray(SORTSTRING_COMPARE_PROC pfnCustomCompare = NULL);
  12. ~CSortedStringArray();
  13. int Add(LPCTSTR psz, DWORD dwData);
  14. int GetSize() const;
  15. LPCTSTR GetAt(int iItem) const;
  16. LPCTSTR operator[](int iItem) const;
  17. DWORD GetItemData(int iItem) const;
  18. int Find(LPCTSTR pszString) const;
  19. protected:
  20. LPTSTR* m_prgStrings; // points to string data, which is preceded by 4-byte item data
  21. int m_cStrings;
  22. int m_maxStrings;
  23. SORTSTRING_COMPARE_PROC m_pfnCompare;
  24. static int __cdecl _crtCompareHelper(const void* elem1, const void* elem2);
  25. static SORTSTRING_COMPARE_PROC _pfnCompare;
  26. };
  27. inline int CSortedStringArray::GetSize() const
  28. {
  29. return m_cStrings;
  30. }
  31. inline LPCTSTR CSortedStringArray::GetAt(int iItem) const
  32. {
  33. ASSERT(iItem >= 0 && iItem < m_cStrings);
  34. return m_prgStrings[iItem];
  35. }
  36. inline LPCTSTR CSortedStringArray::operator[](int iItem) const
  37. {
  38. return GetAt(iItem);
  39. }
  40. inline DWORD CSortedStringArray::GetItemData(int iItem) const
  41. {
  42. ASSERT(iItem >= 0 && iItem < m_cStrings);
  43. return *((DWORD*)m_prgStrings[iItem] - 1);
  44. }