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.

122 lines
4.3 KiB

  1. /*******************************************************************************
  2. * DXVector.h *
  3. *------------*
  4. * Description:
  5. * This is the header file for the vector helper classes.
  6. *
  7. *******************************************************************************/
  8. #ifndef DXVector_h
  9. #define DXVector_h
  10. //=== Constants ====================================================
  11. //=== Class, Struct and Union Definitions ==========================
  12. /*** CDXVec ************
  13. * This template implements basic vector operations for each of the
  14. * union types
  15. */
  16. #define CDXV_C CDXVec<TYPE, eBndType>
  17. #define CDXV_T ((TYPE*)u.D)
  18. #define CDXV_O( OtherVec ) ((TYPE*)OtherVec.u.D)
  19. template<class TYPE, DXBNDTYPE eBndType>
  20. class CDXVec : public DXVEC
  21. {
  22. /*=== Methods =======*/
  23. public:
  24. /*--- Constructors ---*/
  25. CDXVec() { eType = eBndType; ZeroVector(); }
  26. CDXVec(BOOL bInit) { eType = eBndType; if (bInit) ZeroVector(); }
  27. CDXVec( TYPE x, TYPE y, TYPE z, TYPE t )
  28. { eType = eBndType; CDXV_T[DXB_X] = x; CDXV_T[DXB_Y] = y;
  29. CDXV_T[DXB_Z] = z; CDXV_T[DXB_T] = t; }
  30. CDXVec( const CDXVec& Other ) { memcpy( this, (void *)&Other, sizeof(DXVEC) ); }
  31. CDXVec( const DXVEC Other ) { memcpy( this, &Other, sizeof(DXVEC) ); }
  32. operator TYPE *() { return CDXV_T; }
  33. operator const TYPE *() { return CDXV_T; }
  34. /*--- operations ---*/
  35. void ZeroVector( void ) { memset( u.D, 0, sizeof(TYPE) * 4); }
  36. /*--- operators ---*/
  37. TYPE& operator[]( int index ) const { return CDXV_T[index]; }
  38. TYPE& operator[]( long index ) const { return CDXV_T[index]; }
  39. TYPE& operator[]( USHORT index ) const { return CDXV_T[index]; }
  40. TYPE& operator[]( DWORD index ) const { return CDXV_T[index]; }
  41. CDXV_C operator+(const CDXV_C& v);
  42. CDXV_C operator-(const CDXV_C& v);
  43. void operator=(const CDXV_C& srcVector);
  44. void operator+=(const CDXV_C& vOther);
  45. void operator-=(const CDXV_C& vOther);
  46. BOOL operator==(const CDXV_C& otherVector) const;
  47. BOOL operator!=(const CDXV_C& otherVector) const;
  48. };
  49. template<class TYPE, DXBNDTYPE eBndType>
  50. CDXV_C CDXV_C::operator+( const CDXV_C& srcVector )
  51. {
  52. CDXV_C Result( this );
  53. CDXV_O( Result )[DXB_X] += CDXV_O( srcVector )[DXB_X];
  54. CDXV_O( Result )[DXB_Y] += CDXV_O( srcVector )[DXB_Y];
  55. CDXV_O( Result )[DXB_Z] += CDXV_O( srcVector )[DXB_Z];
  56. CDXV_O( Result )[DXB_T] += CDXV_O( srcVector )[DXB_T];
  57. return Result;
  58. } /* CDXVec::operator+ */
  59. template<class TYPE, DXBNDTYPE eBndType>
  60. CDXV_C CDXV_C::operator-( const CDXV_C& srcVector )
  61. {
  62. CDXV_C Result( this );
  63. CDXV_O( Result )[DXB_X] -= CDXV_O( srcVector )[DXB_X];
  64. CDXV_O( Result )[DXB_Y] -= CDXV_O( srcVector )[DXB_Y];
  65. CDXV_O( Result )[DXB_Z] -= CDXV_O( srcVector )[DXB_Z];
  66. CDXV_O( Result )[DXB_T] -= CDXV_O( srcVector )[DXB_T];
  67. return Result;
  68. } /* CDXVec::operator- */
  69. template<class TYPE, DXBNDTYPE eBndType>
  70. void CDXV_C::operator=( const CDXV_C& srcVector )
  71. {
  72. memcpy( this, &srcVector, sizeof(CDXVec) );
  73. } /* CDXVec::operator= */
  74. template<class TYPE, DXBNDTYPE eBndType>
  75. BOOL CDXV_C::operator==(const CDXV_C& otherVector) const
  76. {
  77. return !memcmp( this, &otherVector, sizeof(otherVector) );
  78. } /* CDXVec::operator== */
  79. template<class TYPE, DXBNDTYPE eBndType>
  80. BOOL CDXV_C::operator!=(const CDXV_C& otherVector) const
  81. {
  82. return memcmp( this, &otherVector, sizeof(otherVector) );
  83. } /* CDXVec::operator!= */
  84. template<class TYPE, DXBNDTYPE eBndType>
  85. void CDXV_C::operator+=(const CDXV_C& vOther)
  86. {
  87. CDXV_T[DXB_X] += CDXV_O( vOther )[DXB_X];
  88. CDXV_T[DXB_Y] += CDXV_O( vOther )[DXB_Y];
  89. CDXV_T[DXB_Z] += CDXV_O( vOther )[DXB_Z];
  90. CDXV_T[DXB_T] += CDXV_O( vOther )[DXB_T];
  91. } /* CDXVec::operator+= */
  92. template<class TYPE, DXBNDTYPE eBndType>
  93. void CDXV_C::operator-=(const CDXVec& vOther)
  94. {
  95. CDXV_T[DXB_X] -= CDXV_O( vOther )[DXB_X];
  96. CDXV_T[DXB_Y] -= CDXV_O( vOther )[DXB_Y];
  97. CDXV_T[DXB_Z] -= CDXV_O( vOther )[DXB_Z];
  98. CDXV_T[DXB_T] -= CDXV_O( vOther )[DXB_T];
  99. } /* CDXVec::operator-= */
  100. typedef CDXVec<long, DXBT_DISCRETE> CDXDVec;
  101. typedef CDXVec<LONGLONG, DXBT_DISCRETE64> CDXDVec64;
  102. typedef CDXVec<float, DXBT_CONTINUOUS> CDXCVec;
  103. typedef CDXVec<double, DXBT_CONTINUOUS64> CDXCVec64;
  104. #endif // DXVector_h