Source code of Windows XP (NT5)
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.

125 lines
2.8 KiB

  1. /********************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. PFArray.cpp
  5. Abstract:
  6. dynamic array table definition.
  7. Revision History:
  8. DerekM created 03/14/00
  9. ********************************************************************/
  10. #ifndef PFARRAY_H
  11. #define PFARRAY_H
  12. #include "util.h"
  13. typedef void (*pfnPFArrayDelete)(LPVOID pv);
  14. typedef LPVOID (*pfnPFArrayAllocCopy)(LPVOID pv);
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CPFArray definition
  17. class CPFArrayBase : public CPFPrivHeapGenericClassBase
  18. {
  19. protected:
  20. // member data
  21. pfnPFArrayAllocCopy m_pfnAlloc;
  22. pfnPFArrayDelete m_pfnDelete;
  23. LPVOID *m_rgpv;
  24. DWORD m_cSlots;
  25. DWORD m_iHighest;
  26. // internal methods
  27. virtual void DeleteItem(LPVOID pv)
  28. {
  29. if (m_pfnDelete != NULL && pv != NULL)
  30. (*m_pfnDelete)(pv);
  31. }
  32. virtual LPVOID AllocItemCopy(LPVOID pv)
  33. {
  34. return (m_pfnAlloc != NULL && pv != NULL) ? ((*m_pfnAlloc)(pv)) : NULL;
  35. }
  36. HRESULT CompressArray(DWORD iStart, DWORD iEnd);
  37. HRESULT Grow(DWORD iMinLast);
  38. HRESULT internalCopyFrom(CPFArrayBase *rg);
  39. public:
  40. // construction
  41. CPFArrayBase(void);
  42. virtual ~CPFArrayBase(void);
  43. // exposed methods
  44. void SetDeleteMethod(pfnPFArrayDelete pfnDelete) { m_pfnDelete = pfnDelete; }
  45. void SetAllocMethod(pfnPFArrayAllocCopy pfnAlloc) { m_pfnAlloc = pfnAlloc; }
  46. LPVOID &operator [](DWORD index);
  47. HRESULT Init(DWORD cSlots);
  48. DWORD get_Highest(void) { return m_iHighest; }
  49. HRESULT Append(LPVOID pv);
  50. HRESULT Remove(DWORD iItem, LPVOID *ppvOld = NULL);
  51. HRESULT RemoveAll(void);
  52. HRESULT get_Item(DWORD iItem, LPVOID *ppv);
  53. HRESULT put_Item(DWORD iItem, LPVOID pv, LPVOID *ppvOld = NULL);
  54. };
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CPFArrayBSTR definition
  57. class CPFArrayBSTR : public CPFArrayBase
  58. {
  59. private:
  60. void DeleteItem(LPVOID pv)
  61. {
  62. SysFreeString((BSTR)pv);
  63. }
  64. LPVOID AllocItemCopy(LPVOID pv)
  65. {
  66. return (pv != NULL) ? ((LPVOID)SysAllocString((BSTR)pv)) : NULL;
  67. }
  68. public:
  69. HRESULT CopyFrom(CPFArrayBSTR *prg)
  70. {
  71. return internalCopyFrom(prg);
  72. }
  73. };
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CPFArrayUnk definition
  76. class CPFArrayUnknown : public CPFArrayBase
  77. {
  78. private:
  79. void DeleteItem(LPVOID pv)
  80. {
  81. if (pv != NULL)
  82. ((LPUNKNOWN)pv)->Release();
  83. }
  84. LPVOID AllocItemCopy(LPVOID pv)
  85. {
  86. if (pv != NULL)
  87. ((LPUNKNOWN)pv)->AddRef();
  88. return pv;
  89. }
  90. public:
  91. HRESULT CopyFrom(CPFArrayUnknown *prg)
  92. {
  93. return internalCopyFrom(prg);
  94. }
  95. };
  96. #endif