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.

211 lines
6.8 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, void *pData);
  12. typedef int (CALLBACK *_PFNDPACOMPARE)(T *p1, T *p2, LPARAM lParam);
  13. // Functions
  14. CDPA(HDPA hdpa = NULL) {m_hdpa = hdpa;}
  15. BOOL IsDPASet() {return m_hdpa != NULL; }
  16. void Attach(const HDPA hdpa) {m_hdpa = hdpa;}
  17. HDPA Detach() {HDPA hdpa = m_hdpa; m_hdpa = NULL; return hdpa;}
  18. operator HDPA () { return m_hdpa; }
  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. {BOOL fRet = DPA_Destroy(m_hdpa); m_hdpa = NULL; return fRet;}
  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, (void *) 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, (void *) p);}
  35. int InsertPtr(int i, T* p)
  36. {return DPA_InsertPtr(m_hdpa, i, (void *) 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, void *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<void *>(pData));}
  46. void DestroyCallback(_PFNDPAENUMCALLBACK pfnCB, void *pData)
  47. {DPA_DestroyCallback(m_hdpa, (PFNDPAENUMCALLBACK)pfnCB, pData); m_hdpa = NULL;}
  48. template<class T2>
  49. void DestroyCallbackEx(int (CALLBACK *pfnCB)(T* p, T2 pData), T2 pData)
  50. {DestroyCallback((_PFNDPAENUMCALLBACK)pfnCB, reinterpret_cast<void *>(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, (void *) pitem);}
  59. #ifdef __IStream_INTERFACE_DEFINED__
  60. HRESULT LoadStream(PFNDPASTREAM pfn, IStream * pstream, void *pvInstData)
  61. {return DPA_LoadStream(&m_hdpa, pfn, pstream, pvInstData);}
  62. HRESULT SaveStream(PFNDPASTREAM pfn, IStream * pstream, void *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, (void *) 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, (void *) pFind, iStart, (PFNDPACOMPARE)pfnCompare, lParam, options, (void *) 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, void *pData);
  96. typedef int (CALLBACK *_PFNDSACOMPARE)(T *p1, T *p2, LPARAM lParam);
  97. // Functions
  98. CDSA(HDSA hdsa = NULL) {m_hdsa = hdsa;}
  99. void Attach(const HDSA hdsa) {m_hdsa = hdsa;}
  100. HDSA Detach() { HDSA hdsa = m_hdsa; m_hdsa = NULL; return hdsa; }
  101. operator HDSA () { return m_hdsa; }
  102. BOOL Create(int cItemGrow)
  103. {return (m_hdsa = DSA_Create(sizeof(T), cItemGrow)) != NULL;}
  104. BOOL Destroy()
  105. {BOOL fRet = DSA_Destroy(m_hdsa); m_hdsa = NULL; return fRet;}
  106. BOOL GetItem(int i, T* pitem)
  107. {return DSA_GetItem(m_hdsa, i, (void *)pitem);}
  108. T* GetItemPtr(int i)
  109. {return (T*)DSA_GetItemPtr(m_hdsa, i);}
  110. BOOL SetItem(int i, T* pitem)
  111. {return DSA_SetItem(m_hdsa, i, (void *)pitem);}
  112. int InsertItem(int i, T* pitem)
  113. {return DSA_InsertItem(m_hdsa, i, (void *)pitem);}
  114. virtual BOOL DeleteItem(int i)
  115. {return DSA_DeleteItem(m_hdsa, i);}
  116. virtual BOOL DeleteAllItems()
  117. {return DSA_DeleteAllItems(m_hdsa);}
  118. void EnumCallback(_PFNDSAENUMCALLBACK pfnCB, void *pData)
  119. {DSA_EnumCallback(m_hdsa, (PFNDSAENUMCALLBACK)pfnCB, pData);}
  120. template<class T2>
  121. void EnumCallbackEx(int (CALLBACK *pfnCB)(T *p, T2 pData), T2 pData)
  122. {EnumCallback((_PFNDSAENUMCALLBACK)pfnCB, reinterpret_cast<void *>(pData));}
  123. void DestroyCallback(_PFNDSAENUMCALLBACK pfnCB, void *pData)
  124. {DSA_DestroyCallback(m_hdsa, (PFNDSAENUMCALLBACK)pfnCB, pData); m_hdsa = NULL;}
  125. template<class T2>
  126. void DestroyCallbackEx(int (CALLBACK *pfnCB)(T *p, T2 pData), T2 pData)
  127. {DestroyCallback((_PFNDSAENUMCALLBACK)pfnCB, reinterpret_cast<void *>(pData));}
  128. int GetItemCount()
  129. {return DSA_GetItemCount(m_hdsa);}
  130. int AppendItem(T* pitem)
  131. {return DSA_AppendItem(m_hdsa, (void *)pitem);}
  132. private:
  133. HDSA m_hdsa;
  134. };
  135. template <class T>
  136. CDSA<T>* CDSA_Create(int cItemGrow)
  137. {
  138. CDSA<T> *pdsa = new CDSA<T>();
  139. if (pdsa)
  140. {
  141. if (!pdsa->Create(cItemGrow))
  142. {
  143. delete pdsa;
  144. pdsa = NULL;
  145. }
  146. }
  147. return pdsa;
  148. }
  149. #endif // !GUARD_D70787804D9C11d28784F6E920524153