Main Page | Compound List | File List | Compound Members

gmatrix::GVector< S, TYPE > Class Template Reference

N-vector template class. More...

#include <gmatrix.h>

Collaboration diagram for gmatrix::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)
 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 gmatrix::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 61 of file gmatrix.h.


Constructor & Destructor Documentation

template<int S, typename TYPE = float>
gmatrix::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 78 of file gmatrix.h.

00078 { }

template<int S, typename TYPE = float>
gmatrix::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 85 of file gmatrix.h.

00086                 {
00087                         for (int i=0; i<S; i++) {
00088                                 _v[i] = v._v[i];
00089                         }
00090                 }


Member Function Documentation

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

vector maximum.

Return the highest value in the vector.

Returns:
max(*this)

Definition at line 270 of file gmatrix.h.

00271                 {
00272                         TYPE r = _v[0];
00273                         
00274                         for (int i=1; i<S; i++) {
00275                                 if (_v[i] > r) r = _v[i];
00276                         }
00277                         return r;
00278                 }

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

vector minimum.

Return the lowest value in the vector.

Returns:
min(*this)

Definition at line 285 of file gmatrix.h.

00286                 {
00287                         TYPE r = _v[0];
00288                         
00289                         for (int i=1; i<S; i++) {
00290                                 if (_v[i] < r) r = _v[i];
00291                         }
00292                         return r;
00293                 }

template<int S, typename TYPE = float>
TYPE gmatrix::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 255 of file gmatrix.h.

00256                 {
00257                         TYPE r = 0;
00258                         
00259                         for (int i=0; i<S; i++) {
00260                                 r = _v[i] * v._v[i];
00261                         }
00262                         return r;
00263                 }

template<int S, typename TYPE = float>
GVector<S,TYPE> gmatrix::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 172 of file gmatrix.h.

00173                 {
00174                         GVector<S,TYPE> r;
00175                         
00176                         for (int i=0; i<S; i++) {
00177                                 r._v[i] = _v[i] * k;
00178                         }
00179                         
00180                         return r;
00181                 }

template<int S, typename TYPE = float>
void gmatrix::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 229 of file gmatrix.h.

00230                 {
00231                         for (int i=0; i<S; i++) {
00232                                 _v[i] *= k;
00233                         }
00234                 }

template<int S, typename TYPE = float>
gmatrix::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 99 of file gmatrix.h.

00099 { return &_v[0]; }

template<int S, typename TYPE = float>
GVector<S,TYPE> gmatrix::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 138 of file gmatrix.h.

00139                 {
00140                         GVector<S,TYPE> r;
00141                         
00142                         for (int i=0; i<S; i++) {
00143                                 r._v[i] = _v[i] + v._v[i];
00144                         }
00145                         
00146                         return r;
00147                 }

template<int S, typename TYPE = float>
void gmatrix::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 205 of file gmatrix.h.

00206                 {
00207                         for (int i=0; i<S; i++) {
00208                                 _v[i] += v._v[i];
00209                         }
00210                 }

template<int S, typename TYPE = float>
GVector<S,TYPE> gmatrix::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 155 of file gmatrix.h.

00156                 {
00157                         GVector<S,TYPE> r;
00158                         
00159                         for (int i=0; i<S; i++) {
00160                                 r._v[i] = _v[i] - v._v[i];
00161                         }
00162                         
00163                         return r;
00164                 }

template<int S, typename TYPE = float>
void gmatrix::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 217 of file gmatrix.h.

00218                 {
00219                         for (int i=0; i<S; i++) {
00220                                 _v[i] -= v._v[i];
00221                         }
00222                 }

template<int S, typename TYPE = float>
GVector<S,TYPE> gmatrix::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 189 of file gmatrix.h.

00190                 {
00191                         GVector<S,TYPE> r;
00192                         
00193                         for (int i=0; i<S; i++) {
00194                                 r._v[i] = _v[i] / k;
00195                         }
00196                         
00197                         return r;
00198                 }

template<int S, typename TYPE = float>
void gmatrix::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 242 of file gmatrix.h.

00243                 {
00244                         for (int i=0; i<S; i++) {
00245                                 _v[i] /= k;
00246                         }
00247                 }

template<int S, typename TYPE = float>
GVector<S,TYPE>& gmatrix::GVector< S, TYPE >::operator= const GVector< S, TYPE > &  v  )  [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 124 of file gmatrix.h.

00125                 {
00126                         for (int i=0; i<S; i++) {
00127                                 _v[i] = v._v[i];
00128                         }
00129                         return *this;
00130                 }

template<int S, typename TYPE = float>
TYPE gmatrix::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 116 of file gmatrix.h.

00116 { return _v[s]; }

template<int S, typename TYPE = float>
TYPE& gmatrix::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 107 of file gmatrix.h.

00107 { return _v[s]; }


The documentation for this class was generated from the following file:
Generated on Thu Aug 12 16:22:29 2004 for GMATRIX by doxygen 1.3.3