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.

115 lines
2.8 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: d3dtempl.hpp
  6. * Content: Direct3D templates include file
  7. *
  8. *
  9. ***************************************************************************/
  10. #ifndef __D3DTEMPL_HPP
  11. #define __D3DTEMPL_HPP
  12. #include <d3dutil.h>
  13. #include "d3dmem.h"
  14. //--------------------------------------------------------------------------
  15. //
  16. // Template for growable arrays
  17. //
  18. //--------------------------------------------------------------------------
  19. template <class ARRAY_ELEMENT>
  20. class GArrayT
  21. {
  22. public:
  23. GArrayT()
  24. {
  25. m_pArray = NULL;
  26. m_dwArraySize = 0;
  27. m_dwGrowSize = 8;
  28. }
  29. ~GArrayT()
  30. {
  31. if( m_pArray )
  32. {
  33. DDASSERT( (m_dwArraySize != 0) && (m_pArray != NULL) );
  34. delete[] m_pArray;
  35. }
  36. else
  37. {
  38. DDASSERT( (m_dwArraySize == 0) && (m_pArray == NULL) );
  39. }
  40. }
  41. LPVOID GetArrayPointer() const {return m_pArray;}
  42. virtual void SetGrowSize( DWORD dwGrowSize)
  43. {
  44. m_dwGrowSize = dwGrowSize;
  45. }
  46. #if 0
  47. virtual HRESULT Init( DWORD dwInitialSize, DWORD dwGrowSize)
  48. {
  49. m_pArray = AllocArray( dwInitialSize );
  50. if( m_pArray == NULL ) return E_OUTOFMEMORY;
  51. m_dwArraySize = dwInitialSize;
  52. m_dwGrowSize = dwGrowSize;
  53. return S_OK;
  54. }
  55. #endif
  56. virtual HRESULT Grow( DWORD dwIndex )
  57. {
  58. if( dwIndex < m_dwArraySize ) return S_OK;
  59. DWORD dwNewArraySize = m_dwArraySize;
  60. while( dwNewArraySize <= dwIndex ) dwNewArraySize += m_dwGrowSize;
  61. ARRAY_ELEMENT *pNewArray = AllocArray( dwNewArraySize );
  62. if( pNewArray == NULL ) return E_OUTOFMEMORY;
  63. for( DWORD i = 0; i<m_dwArraySize; i++ )
  64. {
  65. pNewArray[i] = m_pArray[i];
  66. m_pArray[i].m_pObj = NULL; // To prevent deleting the object
  67. }
  68. delete[] m_pArray;
  69. m_pArray = pNewArray;
  70. m_dwArraySize = dwNewArraySize;
  71. return S_OK;
  72. }
  73. virtual ARRAY_ELEMENT *AllocArray( DWORD dwSize ) const
  74. {
  75. return new ARRAY_ELEMENT[dwSize];
  76. }
  77. virtual ARRAY_ELEMENT& operator []( DWORD dwIndex ) const
  78. {
  79. DDASSERT(dwIndex < m_dwArraySize);
  80. return m_pArray[dwIndex];
  81. }
  82. virtual BOOL Check( DWORD dwIndex ) const
  83. {
  84. return (dwIndex < m_dwArraySize);
  85. }
  86. virtual DWORD GetSize() const
  87. {
  88. return m_dwArraySize;
  89. }
  90. virtual DWORD GetGrowSize() const
  91. {
  92. return m_dwGrowSize;
  93. }
  94. protected:
  95. ARRAY_ELEMENT *m_pArray;
  96. DWORD m_dwArraySize;
  97. DWORD m_dwGrowSize;
  98. };
  99. #endif //__D3DTEMPL_HPP