Main Page | Compound List | File List | Compound Members

GVector< S, TYPE > Class Template Reference

N-vector template class. More...

#include <gmatrix.h>

Collaboration diagram for GVector< S, TYPE >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GVector ()
 Default constructor.

 GVector (const GVector< S, TYPE > &v)
 Copy constructor.

 operator TYPE * () const
 Cast operator.

TYPE & operator[] (int s)
 Data access operator. Provided to give an R/W access to the vector data. No check is performed on the s value (if it is aout of bound important runtime errors may arise).

TYPE operator[] (int s) const
 Data access operator (const).

GVector< S, TYPE > & operator= (const GVector< S, TYPE > &v) const
 operator=.

GVector< S, TYPE > operator+ (const GVector< S, TYPE > &v) const
 operator+.

GVector< S, TYPE > operator- (const GVector< S, TYPE > &v) const
 operator-.

GVector< S, TYPE > operator * (TYPE k) const
 operator*.

GVector< S, TYPE > operator/ (TYPE k) const
 operator*.

void operator+= (const GVector< S, TYPE > &v)
 operator+=.

void operator-= (const GVector< S, TYPE > &v)
 operator-=.

void operator *= (TYPE k)
 operator*=.

void operator/= (TYPE k)
 operator/=.

TYPE operator * (const GVector< S, TYPE > &v) const
 operator* (dot product).

TYPE max () const
 vector maximum.

TYPE min () const
 vector minimum.


Detailed Description

template<int S, typename TYPE = float>
class GVector< S, TYPE >

N-vector template class.

The GVector class implements a N-vector object. It is mainly used for mathematics purpose (and therefore, it is not a good idea to make a GVector of std::string objects :) All the classical operators are defined : arithmetics (+, -, *, /), dot product (via the * operator) and data access (via the [] operator).

Parameters:
S the size of the vector
TYPE the underlying data type (default is float)

Definition at line 53 of file gmatrix.h.


Constructor & Destructor Documentation

template<int S, typename TYPE = float>
GVector< S, TYPE >::GVector  )  [inline]
 

Default constructor.

Does nothing. The vector datas are still uninitialized after the construction of the vector. This is mainly done to avoid the multiple initialization of the vetcor datas.

Definition at line 70 of file gmatrix.h.

00070 { }

template<int S, typename TYPE = float>
GVector< S, TYPE >::GVector const GVector< S, TYPE > &  v  )  [inline]
 

Copy constructor.

Copies the data from a vector to the newly created vector.

Parameters:
v the vector to copy

Definition at line 77 of file gmatrix.h.

00078         {
00079                 for (int i=0; i<S; i++) {
00080                         _v[i] = v._v[i];
00081                 }
00082         }


Member Function Documentation

template<int S, typename TYPE = float>
TYPE GVector< S, TYPE >::max  )  const [inline]
 

vector maximum.

Return the highest value in the vector.

Returns:
max(*this)

Definition at line 262 of file gmatrix.h.

00263         {
00264                 TYPE r = _v[0];
00265                 
00266                 for (int i=1; i<S; i++) {
00267                         if (_v[i] > r) r = _v[i];
00268                 }
00269                 return r;
00270         }

template<int S, typename TYPE = float>
TYPE GVector< S, TYPE >::min  )  const [inline]
 

vector minimum.

Return the lowest value in the vector.

Returns:
min(*this)

Definition at line 277 of file gmatrix.h.

00278         {
00279                 TYPE r = _v[0];
00280                 
00281                 for (int i=1; i<S; i++) {
00282                         if (_v[i] < r) r = _v[i];
00283                 }
00284                 return r;
00285         }

template<int S, typename TYPE = float>
TYPE GVector< S, TYPE >::operator * const GVector< S, TYPE > &  v  )  const [inline]
 

operator* (dot product).

Dot product of two vectors of the same size and type.

Parameters:
v the vector on which we want to apply the dot product
Returns:
(*this) . v

Definition at line 247 of file gmatrix.h.

00248         {
00249                 TYPE r = 0;
00250                 
00251                 for (int i=0; i<S; i++) {
00252                         r = _v[i] * v._v[i];
00253                 }
00254                 return r;
00255         }

template<int S, typename TYPE = float>
GVector<S,TYPE> GVector< S, TYPE >::operator * TYPE  k  )  const [inline]
 

operator*.

Multiply a vector by a scalar (same underlying type).

Parameters:
k a scalar
Returns:
(*this) x k

Definition at line 164 of file gmatrix.h.

00165         {
00166                 GVector<S,TYPE> r;
00167                 
00168                 for (int i=0; i<S; i++) {
00169                         r._v[i] = _v[i] * k;
00170                 }
00171                 
00172                 return r;
00173         }

template<int S, typename TYPE = float>
void GVector< S, TYPE >::operator *= TYPE  k  )  [inline]
 

operator*=.

Self multiplication of this vector with a scalar (same underlying type).

Parameters:
k a scalar

Definition at line 221 of file gmatrix.h.

00222         {
00223                 for (int i=0; i<S; i++) {
00224                         _v[i] *= k;
00225                 }
00226         }

template<int S, typename TYPE = float>
GVector< S, TYPE >::operator TYPE *  )  const [inline]
 

Cast operator.

Casts the GVector<> object to const TYPE*. The purpose of this function is to mimic the behavior of a classical C array when it is passed as a function parameter.

Returns:
pointer to the first vector element

Definition at line 91 of file gmatrix.h.

00091 { return &_v[0]; }

template<int S, typename TYPE = float>
GVector<S,TYPE> GVector< S, TYPE >::operator+ const GVector< S, TYPE > &  v  )  const [inline]
 

operator+.

Addition of two vectors. The current vector is not modified.

Parameters:
v the vector which is added to the current vector
Returns:
((*this) + v)

Definition at line 130 of file gmatrix.h.

00131         {
00132                 GVector<S,TYPE> r;
00133                 
00134                 for (int i=0; i<S; i++) {
00135                         r._v[i] = _v[i] + v._v[i];
00136                 }
00137                 
00138                 return r;
00139         }

template<int S, typename TYPE = float>
void GVector< S, TYPE >::operator+= const GVector< S, TYPE > &  v  )  [inline]
 

operator+=.

Self addition of two vectors.

Parameters:
v the vector to add

Definition at line 197 of file gmatrix.h.

00198         {
00199                 for (int i=0; i<S; i++) {
00200                         _v[i] += v._v[i];
00201                 }
00202         }

template<int S, typename TYPE = float>
GVector<S,TYPE> GVector< S, TYPE >::operator- const GVector< S, TYPE > &  v  )  const [inline]
 

operator-.

Substraction of two vectors. The current vector is not modified.

Parameters:
v the vector which is substracted to the current vector
Returns:
((*this) - v)

Definition at line 147 of file gmatrix.h.

00148         {
00149                 GVector<S,TYPE> r;
00150                 
00151                 for (int i=0; i<S; i++) {
00152                         r._v[i] = _v[i] - v._v[i];
00153                 }
00154                 
00155                 return r;
00156         }

template<int S, typename TYPE = float>
void GVector< S, TYPE >::operator-= const GVector< S, TYPE > &  v  )  [inline]
 

operator-=.

Self substratcion of two vectors.

Parameters:
v the vector to substract

Definition at line 209 of file gmatrix.h.

00210         {
00211                 for (int i=0; i<S; i++) {
00212                         _v[i] -= v._v[i];
00213                 }
00214         }

template<int S, typename TYPE = float>
GVector<S,TYPE> GVector< S, TYPE >::operator/ TYPE  k  )  const [inline]
 

operator*.

Divide a vector by a scalar (same underlying type).

Parameters:
k a scalar
Returns:
(*this) / k. If k is 0 the result is undefined.

Definition at line 181 of file gmatrix.h.

00182         {
00183                 GVector<S,TYPE> r;
00184                 
00185                 for (int i=0; i<S; i++) {
00186                         r._v[i] = _v[i] / k;
00187                 }
00188                 
00189                 return r;
00190         }

template<int S, typename TYPE = float>
void GVector< S, TYPE >::operator/= TYPE  k  )  [inline]
 

operator/=.

Self divide of this vector with a scalar (same underlying type). If k is 0 then the result of the divide operation is undefined.

Parameters:
k a scalar

Definition at line 234 of file gmatrix.h.

00235         {
00236                 for (int i=0; i<S; i++) {
00237                         _v[i] /= k;
00238                 }
00239         }

template<int S, typename TYPE = float>
GVector<S,TYPE>& GVector< S, TYPE >::operator= const GVector< S, TYPE > &  v  )  const [inline]
 

operator=.

Copie the content of an existing vector to this one.

Parameters:
v the vector to copy
Returns:
reference to this vector

Definition at line 116 of file gmatrix.h.

00117         {
00118                 for (int i=0; i<S; i++) {
00119                         _v[i] = v._v[i];
00120                 }
00121                 return *this;
00122         }

template<int S, typename TYPE = float>
TYPE GVector< S, TYPE >::operator[] int  s  )  const [inline]
 

Data access operator (const).

Provided to give an RO access to the vector data. No check is performed on the s value (if it is aout of bound important runtime errors may arise)

Parameters:
s position of the element to retrieve
Returns:
the element s

Definition at line 108 of file gmatrix.h.

00108 { return _v[s]; }

template<int S, typename TYPE = float>
TYPE& GVector< S, TYPE >::operator[] int  s  )  [inline]
 

Data access operator. Provided to give an R/W access to the vector data. No check is performed on the s value (if it is aout of bound important runtime errors may arise).

Parameters:
s position of the element to retrieve
Returns:
the element s

Definition at line 99 of file gmatrix.h.

00099 { return _v[s]; }


The documentation for this class was generated from the following file:
Generated on Tue Aug 3 12:08:15 2004 for GMATRIX by doxygen 1.3.3