Added function to get Array size.

Added new operators to Vector.
This commit is contained in:
David Williams 2011-01-10 21:29:18 +00:00
parent b607653e9f
commit 359c9ec343
4 changed files with 119 additions and 39 deletions

View File

@ -97,6 +97,8 @@ namespace PolyVox
void resize(const uint32_t (&pDimensions)[noOfDims]);
///Swaps the contents of this array with the one specified
void swap(Array<noOfDims, ElementType>& rhs);
///Get the size of the Array along the specified dimension
uint32_t getDimension(uint32_t uDimension);
private:
Array<noOfDims, ElementType>(const Array<noOfDims, ElementType>& rhs);

View File

@ -155,7 +155,7 @@ namespace PolyVox
////////////////////////////////////////////////////////////////////////////////
/// Because this class does not have a public assignment operator or copy constructor
/// it cnnot be used with the STL swap() function. This function provides an efficient
/// it cannot be used with the STL swap() function. This function provides an efficient
/// implementation of that feature.
/// \param rhs The array to swap this object with.
////////////////////////////////////////////////////////////////////////////////
@ -180,6 +180,16 @@ namespace PolyVox
rhs.m_pElements = m_pTempElements;
}
////////////////////////////////////////////////////////////////////////////////
/// \param uDimension The dimension to get the size of.
////////////////////////////////////////////////////////////////////////////////
template <uint32_t noOfDims, typename ElementType>
uint32_t Array<noOfDims, ElementType>::getDimension(uint32_t uDimension)
{
assert(uDimension < noOfDims);
return m_pDimensions[uDimension];
}
template <uint32_t noOfDims, typename ElementType>
Array<noOfDims, ElementType>::Array(const Array<noOfDims, ElementType>& rhs)
:m_pElements(0)

View File

@ -84,6 +84,10 @@ namespace PolyVox
Vector<Size,Type>& operator+=(const Vector<Size,Type> &rhs) throw();
///Subtraction and Assignment Operator.
Vector<Size,Type>& operator-=(const Vector<Size,Type> &rhs) throw();
///Multiplication and Assignment Operator.
Vector<Size,Type>& operator*=(const Vector<Size,Type> &rhs) throw();
///Division and Assignment Operator.
Vector<Size,Type>& operator/=(const Vector<Size,Type> &rhs) throw();
///Multiplication and Assignment Operator.
Vector<Size,Type>& operator*=(const Type& rhs) throw();
///Division and Assignment Operator.
@ -143,6 +147,12 @@ namespace PolyVox
template <uint32_t Size,typename Type>
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Multiplication operator.
template <uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Division operator.
template <uint32_t Size,typename Type>
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Multiplication operator.
template <uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw();
///Division operator.

View File

@ -190,20 +190,6 @@ namespace PolyVox
return *this;
}
/**
Addition operator adds corresponding elements of the two Vectors.
\param lhs Vector to add to.
\param rhs Vector to add.
\return The resulting Vector.
*/
template <uint32_t Size,typename Type>
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result += rhs;
return result;
}
/**
Subtraction operator subtracts corresponding elements of one Vector from the other.
\param rhs Vector to subtract
@ -220,18 +206,34 @@ namespace PolyVox
}
/**
Subtraction operator subtracts corresponding elements of one Vector from the other.
\param lhs Vector to subtract from.
\param rhs Vector to subtract.
Multiplication operator multiplies corresponding elements of the two Vectors.
\param rhs Vector to multiply by
\return The resulting Vector.
*/
template <uint32_t Size,typename Type>
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result -= rhs;
return result;
}
template <uint32_t Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator*=(const Vector<Size, Type>& rhs) throw()
{
for(uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] *= rhs.m_tElements[ct];
}
return *this;
}
/**
Division operator divides corresponding elements of one Vector by the other.
\param rhs Vector to divide by
\return The resulting Vector.
*/
template <uint32_t Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator/=(const Vector<Size, Type>& rhs) throw()
{
for(uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] /= rhs.m_tElements[ct];
}
return *this;
}
/**
Multiplication operator multiplies each element of the Vector by a number.
@ -248,20 +250,6 @@ namespace PolyVox
return *this;
}
/**
Multiplication operator multiplies each element of the Vector by a number.
\param lhs the Vector to multiply.
\param rhs the number the Vector is multiplied by.
\return The resulting Vector.
*/
template <uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw()
{
Vector<Size,Type> result = lhs;
result *= rhs;
return result;
}
/**
Division operator divides each element of the Vector by a number.
\param rhs the number the Vector is divided by.
@ -277,6 +265,76 @@ namespace PolyVox
return *this;
}
/**
Addition operator adds corresponding elements of the two Vectors.
\param lhs Vector to add to.
\param rhs Vector to add.
\return The resulting Vector.
*/
template <uint32_t Size,typename Type>
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result += rhs;
return result;
}
/**
Subtraction operator subtracts corresponding elements of one Vector from the other.
\param lhs Vector to subtract from.
\param rhs Vector to subtract.
\return The resulting Vector.
*/
template <uint32_t Size,typename Type>
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result -= rhs;
return result;
}
/**
Multiplication operator mulitplies corresponding elements of the two Vectors.
\param lhs Vector to multiply.
\param rhs Vector to multiply by.
\return The resulting Vector.
*/
template <uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result *= rhs;
return result;
}
/**
Division operator divides corresponding elements of one Vector by the other.
\param lhs Vector to divide.
\param rhs Vector to divide by.
\return The resulting Vector.
*/
template <uint32_t Size,typename Type>
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result /= rhs;
return result;
}
/**
Multiplication operator multiplies each element of the Vector by a number.
\param lhs the Vector to multiply.
\param rhs the number the Vector is multiplied by.
\return The resulting Vector.
*/
template <uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw()
{
Vector<Size,Type> result = lhs;
result *= rhs;
return result;
}
/**
Division operator divides each element of the Vector by a number.
\param lhs the Vector to divide.