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.

196 lines
6.4 KiB

  1. #ifndef GUARD_D70787804D9C11d28784F6E920524153
  2. #define GUARD_D70787804D9C11d28784F6E920524153
  3. #include "comctrlp.h"
  4. // The Ex versions of EnumCallback, DestroyCallback, Sort, Search, etc.
  5. // do stricter type checking to make sure that the reference data /
  6. // parameter matches both on the calling side and the callback side.
  7. template <class T> class CDPA
  8. {
  9. public:
  10. // Typedefs
  11. typedef int (CALLBACK *_PFNDPAENUMCALLBACK)(T *p, LPVOID pData);
  12. typedef int (CALLBACK *_PFNDPACOMPARE)(T *p1, T *p2, LPARAM lParam);
  13. // Functions
  14. CDPA() {}
  15. CDPA(HDPA hdpa) {m_hdpa = hdpa;}
  16. HDPA GetHDPA() {return m_hdpa;}
  17. void SetHDPA(const HDPA hdpa) {m_hdpa = hdpa;}
  18. operator bool () { return m_hdpa != NULL; }
  19. BOOL Create(int cItemGrow)
  20. {return (m_hdpa = DPA_Create(cItemGrow)) != NULL;}
  21. BOOL CreateEx(int cpGrow, HANDLE hheap)
  22. {return (m_hdpa = DPA_CreateEx(cpGrow, hheap)) != NULL;}
  23. BOOL Destroy()
  24. {return DPA_Destroy(m_hdpa);}
  25. HDPA Clone(HDPA hdpaNew)
  26. {return DPA_Clone(m_hdpa, hdpaNew);}
  27. T* GetPtr(INT_PTR i)
  28. {return (T*) DPA_GetPtr(m_hdpa, i);}
  29. int GetPtrIndex(T* p)
  30. {return DPA_GetPtrIndex(m_hdpa, (LPVOID) p);}
  31. BOOL Grow(int cp)
  32. {return DPA_Grow(m_hdpa, cp);}
  33. BOOL SetPtr(int i, T* p)
  34. {return DPA_SetPtr(m_hdpa, i, (LPVOID) p);}
  35. int InsertPtr(int i, T* p)
  36. {return DPA_InsertPtr(m_hdpa, i, (LPVOID) p);}
  37. T* DeletePtr(int i)
  38. {return (T*) DPA_DeletePtr(m_hdpa, i);}
  39. BOOL DeleteAllPtrs()
  40. {return DPA_DeleteAllPtrs(m_hdpa);}
  41. void EnumCallback(_PFNDPAENUMCALLBACK pfnCB, LPVOID pData)
  42. {DPA_EnumCallback(m_hdpa, (PFNDPAENUMCALLBACK)pfnCB, pData);}
  43. template<class T2>
  44. void EnumCallbackEx(int (CALLBACK *pfnCB)(T* p, T2 pData), T2 pData)
  45. {EnumCallback((_PFNDPAENUMCALLBACK)pfnCB, reinterpret_cast<LPVOID>(pData));}
  46. void DestroyCallback(_PFNDPAENUMCALLBACK pfnCB, LPVOID pData)
  47. {DPA_DestroyCallback(m_hdpa, (PFNDPAENUMCALLBACK)pfnCB, pData);}
  48. template<class T2>
  49. void DestroyCallbackEx(int (CALLBACK *pfnCB)(T* p, T2 pData), T2 pData)
  50. {DestroyCallback((_PFNDPAENUMCALLBACK)pfnCB, reinterpret_cast<LPVOID>(pData));}
  51. int GetPtrCount()
  52. {return DPA_GetPtrCount(m_hdpa);}
  53. T* GetPtrPtr()
  54. {return (T*)DPA_GetPtrPtr(m_hdpa);}
  55. T*& FastGetPtr(int i)
  56. {return (T*&)DPA_FastGetPtr(m_hdpa, i);}
  57. int AppendPtr(T* pitem)
  58. {return DPA_AppendPtr(m_hdpa, (LPVOID) pitem);}
  59. #ifdef __IStream_INTERFACE_DEFINED__
  60. HRESULT LoadStream(PFNDPASTREAM pfn, IStream * pstream, LPVOID pvInstData)
  61. {return DPA_LoadStream(&m_hdpa, pfn, pstream, pvInstData);}
  62. HRESULT SaveStream(PFNDPASTREAM pfn, IStream * pstream, LPVOID pvInstData)
  63. {return DPA_SaveStream(m_hdpa, pfn, pstream, pvInstData);}
  64. #endif
  65. BOOL Sort(_PFNDPACOMPARE pfnCompare, LPARAM lParam)
  66. {return DPA_Sort(m_hdpa, (PFNDPACOMPARE)pfnCompare, lParam);}
  67. template<class T2>
  68. BOOL SortEx(int (CALLBACK *pfnCompare)(T *p1, T *p2, T2 lParam), T2 lParam)
  69. {return Sort((_PFNDPACOMPARE)pfnCompare, reinterpret_cast<LPARAM>(lParam));}
  70. // Merge not supported through this object; use DPA_Merge
  71. int Search(T* pFind, int iStart, _PFNDPACOMPARE pfnCompare,
  72. LPARAM lParam, UINT options)
  73. {return DPA_Search(m_hdpa, (LPVOID) pFind, iStart, (PFNDPACOMPARE)pfnCompare, lParam, options);}
  74. template<class T2>
  75. int SearchEx(T* pFind, int iStart,
  76. int (CALLBACK *pfnCompare)(T *p1, T *p2, T2 lParam),
  77. T2 lParam, UINT options)
  78. {return Search(pFind, iStart, (_PFNDPACOMPARE)pfnCompare, reinterpret_cast<LPARAM>(lParam), options);}
  79. int SortedInsertPtr(T* pFind, int iStart, _PFNDPACOMPARE pfnCompare,
  80. LPARAM lParam, UINT options, T* pitem)
  81. {return DPA_SortedInsertPtr(m_hdpa, (LPVOID) pFind, iStart, (PFNDPACOMPARE)pfnCompare, lParam, options, (LPVOID) pitem);}
  82. template<class T2>
  83. int SortedInsertPtrEx(T* pFind, int iStart,
  84. int (CALLBACK *pfnCompare)(T *p1, T *p2, T2 lParam),
  85. T2 lParam, UINT options, T* pitem)
  86. {return SortedInsertPtr(pFind, iStart, (_PFNDPACOMPARE)pfnCompare,
  87. reinterpret_cast<LPARAM>(lParam), options, pitem);}
  88. private:
  89. HDPA m_hdpa;
  90. };
  91. template <class T> class CDSA
  92. {
  93. public:
  94. // Typedefs
  95. typedef int (CALLBACK *_PFNDSAENUMCALLBACK)(T *p, LPVOID pData);
  96. typedef int (CALLBACK *_PFNDSACOMPARE)(T *p1, T *p2, LPARAM lParam);
  97. // Functions
  98. CDSA() {}
  99. CDSA(HDSA hdsa) {m_hdsa = hdsa;}
  100. HDSA GetHDSA() {return m_hdsa;}
  101. void SetHDSA(const HDSA hdsa) {m_hdsa = hdsa;}
  102. operator bool () { return m_hdsa != NULL; }
  103. BOOL Create(int cItemGrow)
  104. {return (m_hdsa = DSA_Create(sizeof(T), cItemGrow)) != NULL;}
  105. BOOL Destroy()
  106. {BOOL fRet = DSA_Destroy(m_hdsa); m_hdsa = NULL; return fRet;}
  107. BOOL GetItem(int i, T* pitem)
  108. {return DSA_GetItem(m_hdsa, i, (LPVOID)pitem);}
  109. T* GetItemPtr(int i)
  110. {return (T*)DSA_GetItemPtr(m_hdsa, i);}
  111. BOOL SetItem(int i, T* pitem)
  112. {return DSA_SetItem(m_hdsa, i, (LPVOID)pitem);}
  113. int InsertItem(int i, T* pitem)
  114. {return DSA_InsertItem(m_hdsa, i, (LPVOID)pitem);}
  115. BOOL DeleteItem(int i)
  116. {return DSA_DeleteItem(m_hdsa, i);}
  117. BOOL DeleteAllItems()
  118. {return DSA_DeleteAllItems(m_hdsa);}
  119. void EnumCallback(_PFNDSAENUMCALLBACK pfnCB, LPVOID pData)
  120. {DSA_EnumCallback(m_hdsa, (PFNDSAENUMCALLBACK)pfnCB, pData);}
  121. template<class T2>
  122. void EnumCallbackEx(int (CALLBACK *pfnCB)(T *p, T2 pData), T2 pData)
  123. {EnumCallback((_PFNDSAENUMCALLBACK)pfnCB, reinterpret_cast<LPVOID>(pData));}
  124. void DestroyCallback(_PFNDSAENUMCALLBACK pfnCB, LPVOID pData)
  125. {DSA_DestroyCallback(m_hdsa, (PFNDSAENUMCALLBACK)pfnCB, pData); m_hdsa = NULL;}
  126. template<class T2>
  127. void DestroyCallbackEx(int (CALLBACK *pfnCB)(T *p, T2 pData), T2 pData)
  128. {DestroyCallback((_PFNDSAENUMCALLBACK)pfnCB, reinterpret_cast<LPVOID>(pData));}
  129. int GetItemCount()
  130. {return DSA_GetItemCount(m_hdsa);}
  131. int AppendItem(T* pitem)
  132. {return DSA_AppendItem(m_hdsa, (LPVOID)pitem);}
  133. private:
  134. HDSA m_hdsa;
  135. };
  136. #endif // !GUARD_D70787804D9C11d28784F6E920524153