GCpp general purpose C++ library  version 1.0
GVectorT< T > Class Template Reference

#include <GVectorT.hh>

Inheritance diagram for GVectorT< T >:
GVector4

Public Member Functions

 GVectorT (size_t n=1)
 
 GVectorT (size_t n, const T &x)
 
 GVectorT (size_t n, const T x[])
 
 GVectorT (const GVectorT< T > &v)
 
GVectorToperator= (const GVectorT< T > &v)
 
virtual ~GVectorT ()
 
virtual void InitElement (size_t i)
 
virtual void InitData ()
 
virtual void InitData (const T x)
 
virtual void InitData (const T x[])
 
virtual void InitData (size_t n, const T x[])
 
virtual bool CheckIndex (size_t i) const
 
virtual bool CheckDimension (const GVectorT< T > &v) const
 
virtual bool CheckProduct (const GMatrixT< T > &m) const
 
size_t SetDimension (size_t n)
 
size_t GetDimension () const
 
const T * Data () const
 
T * Data ()
 
virtual const T & operator() (size_t i) const
 
virtual T & operator() (size_t i)
 
virtual const T & operator[] (size_t i) const
 
virtual T & operator[] (size_t i)
 
virtual GVectorT< T > operator+ (const GVectorT< T > &v) const
 
virtual GVectorT< T > operator- (const GVectorT< T > &v) const
 
virtual GVectorT< T > operator* (const T k) const
 
virtual GVectorT< T > operator/ (const T k) const
 
virtual GVectorT< T > & operator+= (const GVectorT< T > &v)
 
virtual GVectorT< T > & operator-= (const GVectorT< T > &v)
 
virtual GVectorT< T > & operator*= (const T k)
 
virtual GVectorT< T > & operator/= (const T k)
 
virtual GVectorT< T > operator- () const
 
virtual T operator* (const GVectorT< T > &v) const
 
virtual GVectorT< T > operator* (const GMatrixT< T > &m) const
 
virtual double Norm2Squared () const
 
virtual double Norm2 () const
 
virtual double LengthSquared () const
 
virtual double Length () const
 
virtual string GetString () const
 
virtual string GetString (const char *fmt) const
 
template<>
void InitData ()
 
template<>
double Norm2 () const
 

Protected Member Functions

virtual T * Allocate (size_t n)
 
virtual void Reset ()
 

Protected Attributes

bool change_dim
 Indicates if dimension can be changed.
 
size_t dimension
 Vector dimension.
 
T * element
 Vector elements array.
 

Static Private Attributes

static string vect_open = "< "
 Pattern for string representation.
 
static string vect_close = " >"
 Pattern for string representation.
 
static string vect_separ = " ; "
 Pattern for string representation.
 
static string vect_format = "%8.3f"
 Pattern for string representation.
 

Detailed Description

template<typename T>
class GVectorT< T >

Template class defining a vector for numerical types.

The basic vector operations are defined, with the assumption that the standard algebaric operation of the template class are defined.

For effective instantiation of a class, the following functions should be specialised (see file GVectorD.hh):

  • Norm2: it is well defined for real numbers, but should be precised for other types
Note
  • the initialisation functions InitElement and InitData clear the elements memory with 0; if elements initialisation requires more sophisticated actions, due to class type, the template class must be specialised.

Constructor & Destructor Documentation

template<typename T >
GVectorT< T >::GVectorT ( size_t  n = 1)

Default constructor.

Parameters
nvector dimension
template<typename T >
GVectorT< T >::GVectorT ( size_t  n,
const T &  x 
)

Constructor with initialisation to a unique value (all elements).

Parameters
nvector dimension
xdata value
template<typename T >
GVectorT< T >::GVectorT ( size_t  n,
const T  x[] 
)

Constructor with array initialisation.

Parameters
nvector dimension
xdata array (at least of size n)
template<typename T >
GVectorT< T >::GVectorT ( const GVectorT< T > &  v)

Copy constructor.

Parameters
vvector to copy

References GVectorT< T >::Data(), and GVectorT< T >::GetDimension().

template<typename T >
GVectorT< T >::~GVectorT ( )
inlinevirtual

Destructor.

Member Function Documentation

template<typename T >
T * GVectorT< T >::Allocate ( size_t  n)
protectedvirtual

Allocate the memory for vector elements, and set dimension.

Parameters
nvector dimension
template<typename T >
bool GVectorT< T >::CheckDimension ( const GVectorT< T > &  v) const
inlinevirtual

Function warning when the argument vector has a different dimension.

Parameters
vchecked vector

References GVectorT< T >::GetDimension(), and GLogWarning().

Referenced by GVector4::GVector4().

template<typename T >
bool GVectorT< T >::CheckIndex ( size_t  i) const
inlinevirtual

Function warning when an index is out of bounds.

Parameters
ichecked index value

References GGetString(), and GLogWarning().

template<typename T >
bool GVectorT< T >::CheckProduct ( const GMatrixT< T > &  m) const
inlinevirtual

Function warning if the vector is not compatible with the argument for the product (*this)*m.

Parameters
mmatrix operand

References GMatrixT< T >::GetRowsNumber(), and GLogWarning().

template<typename T >
T * GVectorT< T >::Data ( )
inline

Return the data array pointer.

template<typename T >
size_t GVectorT< T >::GetDimension ( ) const
inline
template<typename T >
string GVectorT< T >::GetString ( ) const
inlinevirtual

Write the vector content in a string, using static numerical format.

template<typename T >
string GVectorT< T >::GetString ( const char *  fmt) const
virtual

Write the vector content in a string.

Parameters
fmtnumerical format (C style)

References GGetString().

template<>
void GVectorT< double >::InitData ( )
inline

Specialisation of the function to initialise the vector content.

template<typename T >
void GVectorT< T >::InitData ( )
inlinevirtual

Function to initialise the vector content.

Referenced by GVector4::GVector4().

template<typename T >
void GVectorT< T >::InitData ( const T  x)
inlinevirtual

Function to initialise all vector elements with the same value.

Parameters
xelement value
template<typename T >
void GVectorT< T >::InitData ( const T  x[])
inlinevirtual

Function to initialise the vector content with an array of data. If the array dimension must be at least the vector dimension.

Parameters
xvalues array
template<typename T >
void GVectorT< T >::InitData ( size_t  n,
const T  x[] 
)
inlinevirtual

Function to initialise the vector content with an array of data, limited to maximum
b.

Parameters
xvalues array
nmaximum number of elements to set
template<typename T >
void GVectorT< T >::InitElement ( size_t  i)
inlinevirtual

Function to initialise an element content.

template<typename T >
double GVectorT< T >::Length ( ) const
inlinevirtual

Return the vector length (euclidian).

template<typename T >
double GVectorT< T >::LengthSquared ( ) const
inlinevirtual

Return the vector length squared (euclidian).

template<>
double GVectorT< double >::Norm2 ( ) const
inline

Return the norm 2 (euclidian length).

template<typename T >
double GVectorT< T >::Norm2 ( ) const
inlinevirtual

Return the norm 2 (euclidian length).

template<typename T >
double GVectorT< T >::Norm2Squared ( ) const
inlinevirtual

Return the norm 2 squared (euclidian length).

template<typename T >
const T & GVectorT< T >::operator() ( size_t  i) const
inlinevirtual

Return a component.

Parameters
icomponent index
template<typename T >
T & GVectorT< T >::operator() ( size_t  i)
inlinevirtual

Return a component.

Parameters
icomponent index
template<typename T >
GVectorT< T > GVectorT< T >::operator* ( const T  k) const
virtual

Multiplication scaling.

Parameters
kscaling factor

References GVectorT< T >::Data().

template<typename T >
T GVectorT< T >::operator* ( const GVectorT< T > &  v) const
virtual

Scalar product.

Parameters
vvector

References GVectorT< T >::Data().

template<typename T >
GVectorT< T > GVectorT< T >::operator* ( const GMatrixT< T > &  m) const
virtual

Product of the vector with a matrix.

Parameters
msecond operand

References GVectorT< T >::Data(), GMatrixT< T >::Data(), GMatrixT< T >::GetColumnsNumber(), and GMatrixT< T >::GetIndex().

template<typename T >
GVectorT< T > & GVectorT< T >::operator*= ( const T  k)
virtual

Multiplication scaling.

Parameters
kscaling factor
template<typename T >
GVectorT< T > GVectorT< T >::operator+ ( const GVectorT< T > &  v) const
virtual

Vector addition.

Parameters
voperand

References GVectorT< T >::Data().

template<typename T >
GVectorT< T > & GVectorT< T >::operator+= ( const GVectorT< T > &  v)
virtual

Vector addition.

Parameters
voperand

References GVectorT< T >::Data().

template<typename T >
GVectorT< T > GVectorT< T >::operator- ( const GVectorT< T > &  v) const
virtual

Vector subtraction.

Parameters
voperand

References GVectorT< T >::Data().

template<typename T >
GVectorT< T > GVectorT< T >::operator- ( ) const
virtual

Unary minus.

References GVectorT< T >::Data().

template<typename T >
GVectorT< T > & GVectorT< T >::operator-= ( const GVectorT< T > &  v)
virtual

Vector subtraction.

Parameters
voperand

References GVectorT< T >::Data().

template<typename T >
GVectorT< T > GVectorT< T >::operator/ ( const T  k) const
virtual

Division scaling.

Parameters
kscaling factor

References GVectorT< T >::Data().

template<typename T >
GVectorT< T > & GVectorT< T >::operator/= ( const T  k)
virtual

Division scaling.

Parameters
kscaling factor
template<typename T >
GVectorT< T > & GVectorT< T >::operator= ( const GVectorT< T > &  v)

Affectation operator.

Parameters
vvector to copy

References GVectorT< T >::Data(), and GVectorT< T >::GetDimension().

template<typename T >
const T & GVectorT< T >::operator[] ( size_t  i) const
inlinevirtual

Return a component.

Parameters
icomponent index
template<typename T >
T & GVectorT< T >::operator[] ( size_t  i)
inlinevirtual

Return a component.

Parameters
icomponent index
template<typename T >
void GVectorT< T >::Reset ( )
inlineprotectedvirtual

Reset the vector (dimension set to 0).

template<typename T >
size_t GVectorT< T >::SetDimension ( size_t  n)

Sets a new dimension. The previous data are conserved. The function returns the dimension.

Parameters
nnew dimension

References GLogWarning().


The documentation for this class was generated from the following files: