Public Types | Public Member Functions | Protected Attributes | List of all members
Seldon::Vector< T, VectFull, Allocator > Class Template Reference

Full vector class. More...

#include <Vector.hxx>

Inheritance diagram for Seldon::Vector< T, VectFull, Allocator >:
Seldon::Vector_Base< T, Allocator > Seldon::Vector< T, VectSparse, Allocator >

Public Types

typedef Allocator::value_type value_type
 
typedef Allocator::pointer pointer
 
typedef Allocator::const_pointer const_pointer
 
typedef Allocator::reference reference
 
typedef Allocator::const_reference const_reference
 
typedef VectFull storage
 
typedef Allocator allocator
 

Public Member Functions

 Vector ()
 Default constructor. More...
 
 Vector (size_t i)
 Main constructor. More...
 
 Vector (size_t i, pointer data)
 
 Vector (const Vector< T, VectFull, Allocator > &A)
 Copy constructor. More...
 
 ~Vector ()
 Destructor.
 
void Clear ()
 Clears the vector. More...
 
void Reallocate (size_t i)
 Vector reallocation. More...
 
void ReallocateVector (size_t i)
 Vector reallocation. More...
 
void Resize (size_t i)
 Changes the length of the vector, and keeps previous values. More...
 
void ResizeVector (size_t i)
 Changes the length of the vector, and keeps previous values. More...
 
void SetData (size_t i, pointer data)
 
template<class Allocator0 >
void SetData (const Vector< T, VectFull, Allocator0 > &V)
 Lets the current vector point to the data of another vector. More...
 
void Nullify ()
 Clears the vector without releasing memory. More...
 
reference operator() (long i)
 Access operator. More...
 
reference Get (long i)
 Access to element i. More...
 
const_reference operator() (long i) const
 Access operator. More...
 
const_reference Get (long i) const
 Access to element i. More...
 
Vector< T, VectFull, Allocator > & operator= (const Vector< T, VectFull, Allocator > &X)
 Duplicates a vector (assignment operator). More...
 
void Copy (const Vector< T, VectFull, Allocator > &X)
 Duplicates a vector. More...
 
Vector< T, VectFull, Allocator > Copy () const
 Duplicates a vector. More...
 
void Append (const T &x)
 Appends an element to the vector. More...
 
template<class T0 >
void PushBack (const T0 &x)
 Appends an element at the end of the vector. More...
 
template<class Allocator0 >
void PushBack (const Vector< T, VectFull, Allocator0 > &X)
 Appends a vector X at the end of the vector. More...
 
size_t GetDataSize ()
 Returns the number of elements stored. More...
 
void Zero ()
 Sets all elements to zero. More...
 
void Fill ()
 Fills the vector with 0, 1, 2, ...
 
template<class T0 >
void Fill (const T0 &x)
 Fills the vector with a given value. More...
 
Vector< T, VectFull, Allocator > & operator= (const T &X)
 Fills the vector with a given value. More...
 
template<class T0 >
Vector< T, VectFull, Allocator > & operator*= (const T0 &X)
 Multiplies a vector by a scalar. More...
 
template<class E >
Vector< T, VectFull, Allocator > & operator= (const VectorExpression< T, E > &)
 Operator =, *this = X where X is an expression.
 
template<class E >
Vector< T, VectFull, Allocator > & operator+= (const VectorExpression< T, E > &)
 Operator +=, *this = *this + X where X is an expression.
 
template<class E >
Vector< T, VectFull, Allocator > & operator-= (const VectorExpression< T, E > &)
 Operator -=, *this = *this - X where X is an expression.
 
void FillRand ()
 Fills the vector randomly. More...
 
void Print () const
 Displays the vector.
 
ClassComplexType< T >::Treal GetNormInf () const
 Returns the infinite norm. More...
 
long GetNormInfIndex () const
 Returns the index of the highest absolute value. More...
 
void Write (string FileName, bool with_size=true) const
 Writes the vector in a file. More...
 
void Write (ostream &FileStream, bool with_size=true) const
 Writes the vector in a file stream. More...
 
void WriteText (string FileName) const
 Writes the vector in a file. More...
 
void WriteText (ostream &FileStream) const
 Writes the vector in a file stream. More...
 
void Read (string FileName, bool with_size=true)
 Sets the vector from a file. More...
 
void Read (istream &FileStream, bool with_size=true)
 Sets the vector from a file stream. More...
 
void ReadText (string FileName)
 Sets the vector from a file. More...
 
void ReadText (istream &FileStream)
 Sets the vector from a file stream. More...
 
long GetM () const
 Returns the number of elements. More...
 
size_t GetLength () const
 Returns the number of elements. More...
 
size_t GetSize () const
 Returns the number of elements stored. More...
 
size_t GetMemorySize () const
 Returns the memory used by the object in bytes. More...
 
pointer GetData () const
 Returns a pointer to data_ (stored data). More...
 
const_pointer GetDataConst () const
 Returns a const pointer to data_ (stored data). More...
 
void * GetDataVoid () const
 Returns a pointer of type "void*" to the data array (data_). More...
 
const void * GetDataConstVoid () const
 Returns a pointer of type "const void*" to the data array (data_). More...
 

Protected Attributes

size_t m_
 
pointer data_
 

Detailed Description

template<class T, class Allocator>
class Seldon::Vector< T, VectFull, Allocator >

Full vector class.

Basic vector class (i.e. not sparse).

Definition at line 88 of file Vector.hxx.

Constructor & Destructor Documentation

◆ Vector() [1/3]

template<class T , class Allocator >
Seldon::Vector< T, VectFull, Allocator >::Vector
inlineexplicit

Default constructor.

On exit, the vector is empty.

Definition at line 233 of file VectorInline.cxx.

◆ Vector() [2/3]

template<class T , class Allocator >
Seldon::Vector< T, VectFull, Allocator >::Vector ( size_t  i)
inlineexplicit

Main constructor.

Builds a vector of a given size.

Parameters
ilength of the vector.

Definition at line 244 of file VectorInline.cxx.

◆ Vector() [3/3]

template<class T , class Allocator >
Seldon::Vector< T, VectFull, Allocator >::Vector ( const Vector< T, VectFull, Allocator > &  V)
inline

Copy constructor.

Builds a copy of a vector.

Parameters
Vvector to be copied.

Definition at line 300 of file VectorInline.cxx.

Member Function Documentation

◆ Append()

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Append ( const T &  x)
inline

Appends an element to the vector.

Parameters
xelement to be appended.
Warning
This method will only work if the allocator preserves the elements while reallocating.

Definition at line 665 of file VectorInline.cxx.

◆ Clear()

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Clear
inline

Clears the vector.

Destructs the vector.

Warning
On exit, the vector is an empty vector.

Definition at line 355 of file VectorInline.cxx.

◆ Copy() [1/2]

template<class T , class Allocator >
Vector< T, VectFull, Allocator > Seldon::Vector< T, VectFull, Allocator >::Copy
inline

Duplicates a vector.

Returns
A copy of the vector.
Note
Memory is duplicated: the returned vector is therefore independent from the current instance after the copy.

Definition at line 600 of file VectorInline.cxx.

◆ Copy() [2/2]

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Copy ( const Vector< T, VectFull, Allocator > &  X)
inline

Duplicates a vector.

Parameters
Xvector to be copied.
Note
Memory is duplicated: 'X' is therefore independent from the current instance after the copy.

Definition at line 584 of file VectorInline.cxx.

◆ Fill()

template<class T , class Allocator >
template<class T0 >
void Seldon::Vector< T, VectFull, Allocator >::Fill ( const T0 &  x)
inline

Fills the vector with a given value.

Parameters
xvalue to fill the vector with.

Definition at line 749 of file VectorInline.cxx.

◆ FillRand()

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::FillRand
inline

Fills the vector randomly.

Note
The random generator is very basic.

Definition at line 777 of file VectorInline.cxx.

◆ Get() [1/2]

template<class T , class Allocator >
Vector< T, VectFull, Allocator >::reference Seldon::Vector< T, VectFull, Allocator >::Get ( long  i)
inline

Access to element i.

Parameters
iindex.
Returns
The value of the vector at i.

Definition at line 513 of file VectorInline.cxx.

◆ Get() [2/2]

template<class T , class Allocator >
Vector< T, VectFull, Allocator >::const_reference Seldon::Vector< T, VectFull, Allocator >::Get ( long  i) const
inline

Access to element i.

Parameters
iindex.
Returns
The value of the vector at i.

Definition at line 549 of file VectorInline.cxx.

◆ GetData()

template<class T , class Allocator >
Vector_Base< T, Allocator >::pointer Seldon::Vector_Base< T, Allocator >::GetData
inlineinherited

Returns a pointer to data_ (stored data).

Returns
A pointer to the data_, i.e. the data array.

Definition at line 177 of file VectorInline.cxx.

◆ GetDataConst()

template<class T , class Allocator >
Vector_Base< T, Allocator >::const_pointer Seldon::Vector_Base< T, Allocator >::GetDataConst
inlineinherited

Returns a const pointer to data_ (stored data).

Returns
A const pointer to the data_, i.e. the data array.

Definition at line 189 of file VectorInline.cxx.

◆ GetDataConstVoid()

template<class T , class Allocator >
const void * Seldon::Vector_Base< T, Allocator >::GetDataConstVoid
inlineinherited

Returns a pointer of type "const void*" to the data array (data_).

Returns
A pointer of type "const void*" to the data array.

Definition at line 212 of file VectorInline.cxx.

◆ GetDataSize()

template<class T , class Allocator >
size_t Seldon::Vector< T, VectFull, Allocator >::GetDataSize
inline

Returns the number of elements stored.

Returns
The number of elements stored in memory.

Definition at line 710 of file VectorInline.cxx.

◆ GetDataVoid()

template<class T , class Allocator >
void * Seldon::Vector_Base< T, Allocator >::GetDataVoid
inlineinherited

Returns a pointer of type "void*" to the data array (data_).

Returns
A pointer of type "void*" to the data array.

Definition at line 201 of file VectorInline.cxx.

◆ GetLength()

template<class T , class Allocator >
size_t Seldon::Vector_Base< T, Allocator >::GetLength
inlineinherited

Returns the number of elements.

Returns
The length of the vector.

Definition at line 142 of file VectorInline.cxx.

◆ GetM()

template<class T , class Allocator >
long Seldon::Vector_Base< T, Allocator >::GetM
inlineinherited

Returns the number of elements.

Returns
The length of the vector.

Definition at line 131 of file VectorInline.cxx.

◆ GetMemorySize()

template<class T , class Allocator >
size_t Seldon::Vector_Base< T, Allocator >::GetMemorySize
inlineinherited

Returns the memory used by the object in bytes.

In this method, the type T is assumed to be "static" such that sizeof(T) provides the correct size

Definition at line 165 of file VectorInline.cxx.

◆ GetNormInf()

template<class T , class Allocator >
ClassComplexType< T >::Treal Seldon::Vector< T, VectFull, Allocator >::GetNormInf

Returns the infinite norm.

Returns
The infinite norm.

Definition at line 73 of file Vector.cxx.

◆ GetNormInfIndex()

template<class T , class Allocator >
long Seldon::Vector< T, VectFull, Allocator >::GetNormInfIndex

Returns the index of the highest absolute value.

Returns
The index of the element that has the highest absolute value.

Definition at line 88 of file Vector.cxx.

◆ GetSize()

template<class T , class Allocator >
size_t Seldon::Vector_Base< T, Allocator >::GetSize
inlineinherited

Returns the number of elements stored.

Returns
The length of the vector stored.

Definition at line 153 of file VectorInline.cxx.

◆ Nullify()

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Nullify
inline

Clears the vector without releasing memory.

On exit, the vector is empty and the memory has not been released. It is useful for low level manipulations on a Vector instance.

Warning
Memory is not released.

Definition at line 476 of file VectorInline.cxx.

◆ operator()() [1/2]

template<class T , class Allocator >
Vector< T, VectFull, Allocator >::reference Seldon::Vector< T, VectFull, Allocator >::operator() ( long  i)
inline

Access operator.

Parameters
iindex.
Returns
The value of the vector at 'i'.

Definition at line 495 of file VectorInline.cxx.

◆ operator()() [2/2]

template<class T , class Allocator >
Vector< T, VectFull, Allocator >::const_reference Seldon::Vector< T, VectFull, Allocator >::operator() ( long  i) const
inline

Access operator.

Parameters
iindex.
Returns
The value of the vector at 'i'.

Definition at line 531 of file VectorInline.cxx.

◆ operator*=()

template<class T , class Allocator >
template<class T0 >
Vector< T, VectFull, Allocator > & Seldon::Vector< T, VectFull, Allocator >::operator*= ( const T0 &  alpha)
inline

Multiplies a vector by a scalar.

Parameters
alphascalar.

Definition at line 612 of file VectorInline.cxx.

◆ operator=() [1/2]

template<class T , class Allocator >
Vector< T, VectFull, Allocator > & Seldon::Vector< T, VectFull, Allocator >::operator= ( const T &  x)
inline

Fills the vector with a given value.

Parameters
xvalue to fill the vector with.

Definition at line 764 of file VectorInline.cxx.

◆ operator=() [2/2]

template<class T , class Allocator >
Vector< T, VectFull, Allocator > & Seldon::Vector< T, VectFull, Allocator >::operator= ( const Vector< T, VectFull, Allocator > &  X)
inline

Duplicates a vector (assignment operator).

Parameters
Xvector to be copied.
Note
Memory is duplicated: 'X' is therefore independent from the current instance after the copy.

Definition at line 568 of file VectorInline.cxx.

◆ PushBack() [1/2]

template<class T , class Allocator >
template<class T0 >
void Seldon::Vector< T, VectFull, Allocator >::PushBack ( const T0 &  x)
inline

Appends an element at the end of the vector.

Parameters
xelement to be appended.

Definition at line 678 of file VectorInline.cxx.

◆ PushBack() [2/2]

template<class T , class Allocator >
template<class Allocator0 >
void Seldon::Vector< T, VectFull, Allocator >::PushBack ( const Vector< T, VectFull, Allocator0 > &  X)
inline

Appends a vector X at the end of the vector.

Parameters
Xvector to be appended.

Definition at line 691 of file VectorInline.cxx.

◆ Read() [1/2]

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Read ( istream &  FileStream,
bool  with_size = true 
)

Sets the vector from a file stream.

Sets the vector according to a binary file stream that stores the length of the vector (integer) and all elements.

Parameters
FileStreamfile stream.
with_sizeif set to 'false', the length of the vector is not available in the stream. In this case, the current size N of the vector is unchanged, and N elements are read in the stream.

Definition at line 370 of file Vector.cxx.

◆ Read() [2/2]

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Read ( string  FileName,
bool  with_size = true 
)

Sets the vector from a file.

Sets the vector according to a binary file that stores the length of the vector (integer) and all elements.

Parameters
FileNamefile name.
with_sizeif set to 'false', the length of the vector is not available in the file. In this case, the current size N of the vector is unchanged, and N elements are read in the file.

Definition at line 341 of file Vector.cxx.

◆ ReadText() [1/2]

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::ReadText ( istream &  FileStream)

Sets the vector from a file stream.

Sets all elements of the vector according to a text format. The length is not stored.

Parameters
FileStreamfile stream.

Definition at line 434 of file Vector.cxx.

◆ ReadText() [2/2]

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::ReadText ( string  FileName)

Sets the vector from a file.

Sets all elements of the vector according to a text format. The length is not stored.

Parameters
FileNamefile name.

Definition at line 409 of file Vector.cxx.

◆ Reallocate()

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Reallocate ( size_t  i)
inline

Vector reallocation.

The vector is resized.

Parameters
inew length of the vector.
Warning
Depending on your allocator, initial elements of the vector may be lost.

Definition at line 369 of file VectorInline.cxx.

◆ ReallocateVector()

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::ReallocateVector ( size_t  i)
inline

Vector reallocation.

The vector is resized.

Parameters
inew length of the vector.
Warning
Depending on your allocator, initial elements of the vector may be lost.

Definition at line 383 of file VectorInline.cxx.

◆ Resize()

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Resize ( size_t  n)

Changes the length of the vector, and keeps previous values.

Reallocates the vector to size i. Previous values are kept.

Parameters
nnew length of the vector.

Definition at line 34 of file Vector.cxx.

◆ ResizeVector()

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::ResizeVector ( size_t  n)

Changes the length of the vector, and keeps previous values.

Reallocates the vector to size i. Previous values are kept.

Parameters
nnew length of the vector.

Definition at line 46 of file Vector.cxx.

◆ SetData()

template<class T , class Allocator >
template<class Allocator0 >
void Seldon::Vector< T, VectFull, Allocator >::SetData ( const Vector< T, VectFull, Allocator0 > &  V)
inline

Lets the current vector point to the data of another vector.

Deallocates memory allocated for the current data array. Then sets the length and the data of the current vector to that of V. On exit, the current vector shares it data array with V.

Parameters
Vvector whose data should be shared with current instance.
Warning
On exit, V and the current instance share the same data array, and they are likely to free it. As a consequence, before the vectors are destructed, it is necessary to call 'Nullify' on either V or the current instance. In addition, if the current instance is to deallocate the data array, its allocator should be compatible with the allocator that allocated the data array (probably the allocator of V).
Note
This method should only be used by advanced users.

Definition at line 463 of file VectorInline.cxx.

◆ Write() [1/2]

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Write ( ostream &  FileStream,
bool  with_size = true 
) const

Writes the vector in a file stream.

The length of the vector (integer) and all elements of the vector are stored in binary format.

Parameters
FileStreamfile stream.
with_sizeif set to 'false', the length of the vector is not saved.

Definition at line 152 of file Vector.cxx.

◆ Write() [2/2]

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Write ( string  FileName,
bool  with_size = true 
) const

Writes the vector in a file.

The length of the vector (integer) and all elements of the vector are stored in binary format.

Parameters
FileNamefile name.
with_sizeif set to 'false', the length of the vector is not saved.

Definition at line 124 of file Vector.cxx.

◆ WriteText() [1/2]

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::WriteText ( ostream &  FileStream) const

Writes the vector in a file stream.

All elements of the vector are stored in text format. The length is not stored.

Parameters
FileStreamfile stream.

Definition at line 218 of file Vector.cxx.

◆ WriteText() [2/2]

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::WriteText ( string  FileName) const

Writes the vector in a file.

All elements of the vector are stored in text format. The length is not stored.

Parameters
FileNamefile name.

Definition at line 188 of file Vector.cxx.

◆ Zero()

template<class T , class Allocator >
void Seldon::Vector< T, VectFull, Allocator >::Zero
inline

Sets all elements to zero.

Warning
It fills the memory with zeros. If the vector stores complex structures, use 'Fill' instead.

Definition at line 727 of file VectorInline.cxx.


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