Vector< T > Class Template Reference

#include <Vector.hpp>

Inheritance diagram for Vector< T >:

Inheritance graph
[legend]
Collaboration diagram for Vector< T >:

Collaboration graph
[legend]

List of all members.

Public Types

typedef T ValueType
 T ValueType Used to be able to access to T using typename.

Public Member Functions

const size_t & size () const
 Read-only access to the size of the vector.
size_t number (T const &e) const
 Finds the number of an element of the vector.
const T & operator[] (const size_t &i) const
 Read-only access to the ith __values of the vector.
T & operator[] (const size_t &i)
 Access to the ith element of the vector.
const T & operator() (const size_t &i) const
T & operator() (const size_t &i)
void resize (const size_t &newSize)
const Vector< T > & operator= (const T &t)
 operator= overloading. Initializes every element to the value t.
const Vector< T > & operator= (const Vector< T > &V)
 operator= overloading. Copies the vector V.
Vector< T > operator* (const T &t) const
template<class T2>
const Vector< T > & operator*= (const T2 &t)
 operator*= overloading. The vector is multiplied by t.
Vector< T > operator+ (const Vector< T > &V) const
Vector< T > operator- (const Vector< T > &V) const
const Vector< T > & operator+= (const Vector< T > &V)
 operator+= overloading. Addes V to the vector.
const Vector< T > & operator+= (const T &t)
 operator+= overloading. Addes V to the vector.
const Vector< T > & operator-= (const Vector< T > &V)
 operator-= overloading. Substractes V to the vector.
real_t operator* (const Vector< T > &V) const
 operator* overloading. Scalar product.
 Vector ()
 Default constructor initializes a dimension 0 vector.
 Vector (size_t size)
 Vector (const Vector< T > &V)
 Copy constructor.
 ~Vector ()
 Destructor.

Protected Attributes

size_t __size
 The number of elements of the vector.
T *__restrict __values
 The elements of the vector.

Friends

std::ostream & operator<< (std::ostream &os, const Vector< T > &V)
 writes a vector in a stream.
Vector< T > operator* (const T &t, const Vector< T > &V)
real_t Norm (const Vector< T > &v)


Detailed Description

template<typename T>
class Vector< T >

class Vector This class defines a template Vector class to store huge quantity of datas. The stored elements type is the template argument.

Todo:
Use expression template to provide a more efficient code.
Author:
Stéphane Del Pino.

Definition at line 46 of file Vector.hpp.


Member Typedef Documentation

template<typename T>
typedef T Vector< T >::ValueType

T ValueType Used to be able to access to T using typename.

Definition at line 51 of file Vector.hpp.


Constructor & Destructor Documentation

template<typename T>
Vector< T >::Vector (  )  [inline]

Default constructor initializes a dimension 0 vector.

Definition at line 279 of file Vector.hpp.

00280     : __size(0)
00281   {
00282     ;
00283   }

template<typename T>
Vector< T >::Vector ( size_t  size  )  [inline]

Constructs a vector which size is givenSize. __values values are garbage.

Definition at line 289 of file Vector.hpp.

00290     : __size(size)
00291   {
00292     if (__size>0)
00293       __values = new T[__size];
00294   }

template<typename T>
Vector< T >::Vector ( const Vector< T > &  V  )  [inline]

Copy constructor.

Definition at line 297 of file Vector.hpp.

00298     : __size(V.__size)
00299   {
00300     if (__size>0)
00301       __values = new T[__size];
00302     ZoneCopy(__values,V.__values,__size);
00303   }

template<typename T>
Vector< T >::~Vector (  )  [inline]

Destructor.

Definition at line 306 of file Vector.hpp.

00307   {
00308     if (__size > 0)
00309       delete[] __values;
00310   }


Member Function Documentation

template<typename T>
const size_t& Vector< T >::size (  )  const [inline]

Read-only access to the size of the vector.

Definition at line 61 of file Vector.hpp.

Referenced by DegreeOfFreedomSetBuilder::__buildCorrespondance(), SurfaceMesh::__computesFictitiousCells(), SurfaceMeshGenerator::Internals::__constructionFinalMesh(), SurfaceMeshGenerator::Internals::__constructionVerticesList(), WriterVTK::__fillCrossedComponent(), WriterMedit::__fillCrossedComponent(), ScalarFunctionBuilder::Simplifier::__getOperatorF1F2SimplifiedFunction(), SpectralFEMPreconditioner::Internal::__legendreToLagrange(), SpectralFEMPreconditioner::Internal::__legendreToLagrangeTransposed(), WriterMedit::__proceedData(), MeshFormatReader::__readHexahedra(), MeshFormatReader::__readQuadrilaterals(), MeshFormatReader::__readTetrahedra(), MeshReaderAM_FMTFormat::__readTriangles(), MeshFormatReader::__readTriangles(), MeshReaderAM_FMTFormat::__readTrianglesReferences(), OctreeMeshBuilder::buildMesh(), SpectralFEMPreconditioner::Internal::computes(), MultiGrid::computes(), IncompleteCholeskiFactorization::computes(), DiagPrecond::computes(), SpectralFEMPreconditioner::Internal::computesTransposed(), MultiGrid::copyDirichlet(), LagrangeBasis::degree(), DGFunction< MeshType, FiniteElementTraits >::DGFunction(), LagrangeBasis::dimension(), FEMFunction< MeshType, FiniteElementTraits >::FEMFunction(), FGMRES::FGMRES(), LegendreBasis::getDerivativeValues(), ScalarFunctionReaderVTK::getFunction(), LegendreBasis::getSecondDerivativeValues(), LegendreBasis::getValues(), LagrangeBasis::getValues(), GMRES::GMRES(), invertEndianess(), LagrangeBasis::LagrangeBasis(), ScalarDegreeOfFreedomPositionsSet::number(), Structured3DMesh::numberOfCells(), SpectralMesh::numberOfCells(), EdgesSet::numberOfEdges(), FacesSet< Triangle >::numberOfFaces(), GaussLobatto::numberOfPoints(), VerticesSet::numberOfVertices(), MultiGrid::DirichletPositions::operator()(), Structured3DVector< bool >::operator=(), FEMFunctionBase::operator=(), FEMFunction< MeshType, FiniteElementTraits >::operator=(), DGFunctionBase::operator=(), DGFunction< MeshType, FiniteElementTraits >::operator=(), MultiGrid::residuDirichlet(), ScalarFunctionBuilder::setUnaryMinus(), MultiGrid::DirichletPositions::size(), SpectralFunction::SpectralFunction(), SparseMatrix::transposedTimesX(), and MultiGrid::weightJacobi().

00062   {
00063     return __size;
00064   }

template<typename T>
size_t Vector< T >::number ( T const &  e  )  const [inline]

Finds the number of an element of the vector.

Definition at line 67 of file Vector.hpp.

Referenced by DegreeOfFreedomSetBuilder::__buildFEMFictitious(), Structured3DMesh::cellNumber(), SpectralMesh::cellNumber(), DegreeOfFreedomSet::DegreeOfFreedomSet(), VerticesSet::number(), FacesSet< Triangle >::number(), and EdgesSet::number().

00068   {
00069     ASSERT ((&e >= __values)&&(static_cast<size_t>(&e-__values) < __size));
00070     return (&e-__values);
00071   }

template<typename T>
const T& Vector< T >::operator[] ( const size_t &  i  )  const [inline]

Read-only access to the ith __values of the vector.

Definition at line 83 of file Vector.hpp.

00084   {
00085     ASSERT (i<__size);
00086     return __values[i];
00087   }

template<typename T>
T& Vector< T >::operator[] ( const size_t &  i  )  [inline]

Access to the ith element of the vector.

Definition at line 90 of file Vector.hpp.

00091   {
00092     ASSERT (i<__size);
00093     return __values[i];
00094   }

template<typename T>
const T& Vector< T >::operator() ( const size_t &  i  )  const [inline]

Read-only access to the ith element of the vector. Used to provide a Blitz-like interface.

Definition at line 100 of file Vector.hpp.

00101   {
00102     ASSERT (i<__size);
00103     return __values[i];
00104   }

template<typename T>
T& Vector< T >::operator() ( const size_t &  i  )  [inline]

Access to the ith element of the vector. Used to provide a Blitz-like interface.

Definition at line 110 of file Vector.hpp.

00111   {
00112     ASSERT (i<__size);
00113     return __values[i];
00114   }

template<typename T>
void Vector< T >::resize ( const size_t &  newSize  )  [inline]

template<typename T>
const Vector<T>& Vector< T >::operator= ( const T &  t  )  [inline]

operator= overloading. Initializes every element to the value t.

Reimplemented in Structured3DVector< T >, and Structured3DVector< bool >.

Definition at line 137 of file Vector.hpp.

Referenced by Structured3DVector< bool >::operator=().

00138   {
00139     for (size_t i=0; i<__size; ++i)
00140       __values[i] = t;
00141     return (*this);
00142   }

template<typename T>
const Vector<T>& Vector< T >::operator= ( const Vector< T > &  V  )  [inline]

operator= overloading. Copies the vector V.

Reimplemented in Structured3DVector< T >, and Structured3DVector< bool >.

Definition at line 145 of file Vector.hpp.

00146   {
00147     ASSERT (__size == V.__size);
00148     ZoneCopy(__values, V.__values, __size);
00149 
00150     return (*this);
00151   }

template<typename T>
Vector<T> Vector< T >::operator* ( const T &  t  )  const [inline]

operator* overloading. Returns t * this.

Warning:
a temporary is created!

Definition at line 158 of file Vector.hpp.

00159   {
00160     Vector<T> prod(*this);
00161     TermToTermProduct<T> tttp;
00162     for (size_t i=0; i<__size; ++i)
00163       prod.__values[i] = tttp(__values[i],t);
00164     return prod;
00165   }

template<typename T>
template<class T2>
const Vector<T>& Vector< T >::operator*= ( const T2 &  t  )  [inline]

operator*= overloading. The vector is multiplied by t.

Definition at line 185 of file Vector.hpp.

00186   {
00187     TermToTermProduct<T> tttp;
00188     for (size_t i=0; i<__size; ++i)
00189       __values[i] = tttp(__values[i],t);
00190     return *this;
00191   }

template<typename T>
Vector<T> Vector< T >::operator+ ( const Vector< T > &  V  )  const [inline]

operator+ overloading. Computes sum with V.

Warning:
a temporary is created!

Definition at line 197 of file Vector.hpp.

00198   {
00199     ASSERT(__size==V.__size);
00200     Vector<T> W(__size);
00201     for (size_t i=0; i<__size; ++i)
00202       W.__values[i] = __values[i] + V.__values[i];
00203     return W;
00204   }

template<typename T>
Vector<T> Vector< T >::operator- ( const Vector< T > &  V  )  const [inline]

operator- overloading. Computes difference with V.

Warning:
a temporary is created!

Definition at line 210 of file Vector.hpp.

00211   {
00212     ASSERT(__size==V.__size);
00213 
00214     Vector<T> W(__size);
00215     for (size_t i=0; i<__size; ++i) {
00216       W.__values[i] = __values[i] - V.__values[i];
00217     }
00218 
00219     return W;
00220   }

template<typename T>
const Vector<T>& Vector< T >::operator+= ( const Vector< T > &  V  )  [inline]

operator+= overloading. Addes V to the vector.

Definition at line 224 of file Vector.hpp.

00225   {
00226     ASSERT(__size==V.__size);
00227 
00228     for (size_t i=0; i<__size; ++i)
00229       __values[i] += V.__values[i];
00230 
00231     return *this;
00232   }

template<typename T>
const Vector<T>& Vector< T >::operator+= ( const T &  t  )  [inline]

operator+= overloading. Addes V to the vector.

Definition at line 235 of file Vector.hpp.

00236   {
00237     for (size_t i=0; i<__size; ++i)
00238       __values[i] += t;
00239 
00240     return *this;
00241   }

template<typename T>
const Vector<T>& Vector< T >::operator-= ( const Vector< T > &  V  )  [inline]

operator-= overloading. Substractes V to the vector.

Definition at line 244 of file Vector.hpp.

00245   {
00246     ASSERT(__size==V.__size);
00247 
00248     for (size_t i=0; i<__size; ++i)
00249       __values[i] -= V.__values[i];
00250 
00251     return (*this);
00252   }

template<typename T>
real_t Vector< T >::operator* ( const Vector< T > &  V  )  const [inline]

operator* overloading. Scalar product.

Definition at line 255 of file Vector.hpp.

00256   {
00257     ASSERT(__size==V.__size);
00258 
00259     real_t t = 0;
00260     for (size_t i=0; i<__size; ++i)
00261       t += __values[i] * V.__values[i];
00262 
00263     return t;
00264   }


Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
const Vector< T > &  V 
) [friend]

writes a vector in a stream.

Definition at line 74 of file Vector.hpp.

00075   {
00076     for (size_t i=0; i<V.size(); ++i) {
00077       os << V[i] << '\n';
00078     }
00079     return os;
00080   }

template<typename T>
Vector<T> operator* ( const T &  t,
const Vector< T > &  V 
) [friend]

operator* overloading (friend version). Returns t * this.

Warning:
a temporary is created!

Definition at line 172 of file Vector.hpp.

00173   {
00174     Vector<T> sum(V.__size);
00175     TermToTermProduct<T> tttp;
00176     for (size_t i=0; i<V.__size; ++i)
00177       sum.__values[i] = tttp(V.__values[i],t);
00178 
00179     return sum;
00180   }

template<typename T>
real_t Norm ( const Vector< T > &  v  )  [friend]

Computes the « norm » of a given vector v. The result is a T! If T is of scalar type it returns the usual norm.

Warning:
only works if the template type T allows scalar product.
Todo:
Name might be change?

Definition at line 272 of file Vector.hpp.

00273   {
00274     return sqrt(v*v);
00275   }


Member Data Documentation

template<typename T>
size_t Vector< T >::__size [protected]

template<typename T>
T* __restrict Vector< T >::__values [protected]


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

Generated on Wed Nov 19 00:17:50 2008 for FreeFEM3D (aka ff3d) by  doxygen 1.5.6