|
|
@ -9,33 +9,58 @@ template<class T, unsigned SIZE> class Vec; |
|
|
|
template <class T, unsigned SIZE> class Mat; |
|
|
|
|
|
|
|
|
|
|
|
// Vector class for SIMPLE data types |
|
|
|
/** |
|
|
|
* Vector class for class and simple data types |
|
|
|
* template with type and size of the vector |
|
|
|
* |
|
|
|
* @author Philipp Schoenberger <ph.schoenberger@googlemail.com> |
|
|
|
* @copyright 2012 philipp schoenberger All rights reserved. |
|
|
|
* @license This project is released under the GNU Public License. |
|
|
|
*/ |
|
|
|
template <class T, unsigned SIZE> class Vec |
|
|
|
{ |
|
|
|
public: |
|
|
|
|
|
|
|
// standard constructor |
|
|
|
/** |
|
|
|
* standard constructor |
|
|
|
*/ |
|
|
|
Vec<T,SIZE> () |
|
|
|
{ // initialize all elements with zero |
|
|
|
{ |
|
|
|
// initialize all elements with zero |
|
|
|
for (unsigned int i=0; i<SIZE; i++) |
|
|
|
m_atData[i] = T(0); |
|
|
|
} |
|
|
|
|
|
|
|
// construction with data array |
|
|
|
/** |
|
|
|
* construction with data value |
|
|
|
* Initialize the Vector completely to the given value |
|
|
|
* |
|
|
|
* @param tData initial value for the vector |
|
|
|
*/ |
|
|
|
Vec<T, SIZE> (const T tData) |
|
|
|
{ |
|
|
|
for (unsigned int i=0; i<SIZE; i++) |
|
|
|
m_atData[i] = tData; |
|
|
|
} |
|
|
|
|
|
|
|
// construction with data array |
|
|
|
/** |
|
|
|
* construction with data array |
|
|
|
* Initialize the Vector completely for each field with array values |
|
|
|
* |
|
|
|
* @param tData array of initial values for the vector |
|
|
|
*/ |
|
|
|
Vec<T, SIZE> (const T atData[SIZE]) |
|
|
|
{ |
|
|
|
for (unsigned int i=0; i<SIZE; i++) |
|
|
|
m_atData[i] = atData[i]; |
|
|
|
} |
|
|
|
|
|
|
|
// copy constructor |
|
|
|
/** |
|
|
|
* copy construction from an other vector |
|
|
|
* Initialize the Vector completely for each field like the given vector |
|
|
|
* |
|
|
|
* @param vec of initial values for the new vector |
|
|
|
*/ |
|
|
|
Vec<T, SIZE> (const Vec<T, SIZE> &vec) |
|
|
|
{ |
|
|
|
if (this==&vec) |
|
|
@ -44,17 +69,30 @@ public: |
|
|
|
m_atData[i] = vec.m_atData[i]; |
|
|
|
} |
|
|
|
|
|
|
|
// destructor |
|
|
|
/** |
|
|
|
* destructor which has nothing |
|
|
|
*/ |
|
|
|
~Vec () |
|
|
|
{ // nothing to do here ... |
|
|
|
{ |
|
|
|
// nothing to do here ... |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* copy the values from the array to the Vector |
|
|
|
* |
|
|
|
* @param atData source array for the copy process |
|
|
|
*/ |
|
|
|
void setData (const T atData[SIZE]) |
|
|
|
{ |
|
|
|
for (unsigned int i=0; i<SIZE; i++) |
|
|
|
m_atData[i] = atData[i]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* copy the values from the vector to the array |
|
|
|
* |
|
|
|
* @param atData destination array for the copy process |
|
|
|
*/ |
|
|
|
void getData (T atData[SIZE]) |
|
|
|
{ |
|
|
|
for (unsigned int i=0; i<SIZE; i++) |
|
|
@ -62,22 +100,43 @@ public: |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* returns the dimension of the vector |
|
|
|
* |
|
|
|
* @retval dimension size |
|
|
|
*/ |
|
|
|
unsigned getDimension () |
|
|
|
{ |
|
|
|
return SIZE; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* assignment operator between vectors |
|
|
|
* also capabile of muilti asignments |
|
|
|
* e.g: |
|
|
|
* |
|
|
|
* vec1 = vec2 = vec3; |
|
|
|
* L-Value = R-Value/L-Value = R-Value |
|
|
|
* |
|
|
|
* @param vec source vector which should be copied |
|
|
|
* @retval returns the current |
|
|
|
*/ |
|
|
|
Vec<T, SIZE> &operator = (const Vec<T, SIZE> &vec) |
|
|
|
{ |
|
|
|
/// check if the L and R values are the same |
|
|
|
/// do nothing in this case |
|
|
|
if (this==&vec) |
|
|
|
return (*this); // ok, it's me, so no L-value action |
|
|
|
for (unsigned int i=0; i<SIZE; i++) // not me, so L-Value action: copy data |
|
|
|
return (*this); |
|
|
|
|
|
|
|
/// not the same values so copy content data |
|
|
|
for (unsigned int i=0; i<SIZE; i++) |
|
|
|
m_atData[i] = vec.m_atData[i]; |
|
|
|
|
|
|
|
return (*this); // also an R-value in e.g |
|
|
|
// also an R-value in e.g |
|
|
|
// vec1 = vec2 = vec3; |
|
|
|
// L-Value = R-Value/L-Value = R-Value |
|
|
|
return (*this); |
|
|
|
} |
|
|
|
|
|
|
|
Vec<T, SIZE> &operator = (const T atData[SIZE]) |
|
|
|