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

3D array. More...

#include <Array3D.hxx>

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
 

Public Member Functions

 Array3D ()
 Default constructor. More...
 
 Array3D (int i, int j, int k)
 Main constructor. More...
 
 Array3D (const Array3D< T, Allocator > &A)
 Copy constructor.
 
 ~Array3D ()
 Destructor.
 
int GetLength1 () const
 Returns the length in dimension #1. More...
 
int GetLength2 () const
 Returns the length in dimension #2. More...
 
int GetLength3 () const
 Returns the length in dimension #3. More...
 
long GetSize () const
 Returns the number of elements in the 3D array. More...
 
long GetDataSize () const
 Returns the number of elements stored in memory. More...
 
pointer GetData () const
 Returns a pointer to the data array. More...
 
pointer GetDataPointer (int i, int j, int k) const
 Returns a pointer to an element of data array. More...
 
void Reallocate (int i, int j, int k)
 Reallocates memory to resize the 3D array. More...
 
void SetData (int i, int j, int k, pointer data)
 Changes the size of the array and sets its data array (low level method). More...
 
void Nullify ()
 Clears the 3D array without releasing memory. More...
 
void Clear ()
 Clears the array. More...
 
reference operator() (int i, int j, int k)
 Access operator. More...
 
const_reference operator() (int i, int j, int k) const
 Access operator. More...
 
Array3D< T, Allocator > & operator= (const Array3D< T, Allocator > &A)
 Duplicates a 3D array (assignment operator). More...
 
void Copy (const Array3D< T, Allocator > &A)
 Duplicates a 3D array. More...
 
size_t GetMemorySize () const
 Returns the memory used by the object in bytes. More...
 
void Zero ()
 Sets all elements to zero. More...
 
void Fill ()
 Fills the array. More...
 
template<class T0 >
void Fill (const T0 &x)
 Fills the 3D array with a given value. More...
 
void FillRand ()
 Fills the 3D array randomly. More...
 
void Print () const
 Displays the array on the standard output. More...
 
void Write (string FileName, bool with_size=true) const
 Writes the 3D array in a file. More...
 
void Write (ofstream &FileStream, bool with_size=true) const
 Writes the 3D array to an output stream. More...
 
void Read (string FileName, bool with_size=true)
 Reads the 3D array from a file. More...
 
void Read (ifstream &FileStream, bool with_size=true)
 Reads the 3D array from an input stream. More...
 

Protected Attributes

int length1_
 
int length2_
 
int length3_
 
long length23_
 
pointer data_
 

Detailed Description

template<class T, class Allocator>
class Seldon::Array3D< T, Allocator >

3D array.

This class implements 3D arrays.

Definition at line 38 of file Array3D.hxx.

Constructor & Destructor Documentation

◆ Array3D() [1/2]

template<class T , class Allocator >
Seldon::Array3D< T, Allocator >::Array3D

Default constructor.

On exit, the array is an empty 0x0x0 3D array.

Definition at line 38 of file Array3D.cxx.

◆ Array3D() [2/2]

template<class T , class Allocator >
Seldon::Array3D< T, Allocator >::Array3D ( int  i,
int  j,
int  k 
)

Main constructor.

Builds a i x j x k 3D array, but data is not initialized.

Parameters
ilength in dimension #1.
jlength in dimension #2.
klength in dimension #3.

Definition at line 57 of file Array3D.cxx.

Member Function Documentation

◆ Clear()

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::Clear

Clears the array.

Destructs the array.

Warning
On exit, the 3D array is empty.

Definition at line 228 of file Array3D.cxx.

◆ Copy()

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::Copy ( const Array3D< T, Allocator > &  A)
inline

Duplicates a 3D array.

Parameters
A3D array to be copied.
Note
Memory is duplicated: 'A' is therefore independent from the current instance after the copy.

Definition at line 204 of file Array3D_Inline.cxx.

◆ Fill() [1/2]

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::Fill

Fills the array.

On exit, the 3D array is filled with 1, 2, 3, 4, ... The order of those numbers depends on the storage.

Definition at line 296 of file Array3D.cxx.

◆ Fill() [2/2]

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

Fills the 3D array with a given value.

On exit, the 3D array is filled with 'x'.

Parameters
xthe value to fill the 3D array with.

Definition at line 311 of file Array3D.cxx.

◆ FillRand()

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::FillRand

Fills the 3D array randomly.

On exit, the 3D array is filled with random values.

Definition at line 326 of file Array3D.cxx.

◆ GetData()

template<class T , class Allocator >
Array3D< T, Allocator >::pointer Seldon::Array3D< T, Allocator >::GetData
inline

Returns a pointer to the data array.

Returns a pointer to data, i.e. the data array 'data_' which stores the values.

Returns
A pointer to the data array.

Definition at line 114 of file Array3D_Inline.cxx.

◆ GetDataPointer()

template<class T , class Allocator >
Array3D< T, Allocator >::pointer Seldon::Array3D< T, Allocator >::GetDataPointer ( int  i,
int  j,
int  k 
) const
inline

Returns a pointer to an element of data array.

Returns a pointer to an element of data array.

Parameters
iindex along dimension #1.
jindex along dimension #2.
kindex along dimension #3.
Returns
A pointer to the data array.

Definition at line 130 of file Array3D_Inline.cxx.

◆ GetDataSize()

template<class T , class Allocator >
long Seldon::Array3D< T, Allocator >::GetDataSize
inline

Returns the number of elements stored in memory.

Returns the number of elements stored in memory by the array, i.e. the product of lengths in the three dimensions.

Returns
The number of elements stored in the array.

Definition at line 100 of file Array3D_Inline.cxx.

◆ GetLength1()

template<class T , class Allocator >
int Seldon::Array3D< T, Allocator >::GetLength1
inline

Returns the length in dimension #1.

Returns
The length in dimension #1.

Definition at line 51 of file Array3D_Inline.cxx.

◆ GetLength2()

template<class T , class Allocator >
int Seldon::Array3D< T, Allocator >::GetLength2
inline

Returns the length in dimension #2.

Returns
The length in dimension #2.

Definition at line 62 of file Array3D_Inline.cxx.

◆ GetLength3()

template<class T , class Allocator >
int Seldon::Array3D< T, Allocator >::GetLength3
inline

Returns the length in dimension #3.

Returns
The length in dimension #3.

Definition at line 73 of file Array3D_Inline.cxx.

◆ GetMemorySize()

template<class T , class Allocator >
size_t Seldon::Array3D< T, Allocator >::GetMemorySize

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 271 of file Array3D.cxx.

◆ GetSize()

template<class T , class Allocator >
long Seldon::Array3D< T, Allocator >::GetSize
inline

Returns the number of elements in the 3D array.

Returns the number of elements stored by the 3D array, i.e. the product of the lengths in the three dimensions.

Returns
The number of elements in the 3D array.

Definition at line 86 of file Array3D_Inline.cxx.

◆ Nullify()

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::Nullify

Clears the 3D array without releasing memory.

On exit, the 3D array is empty and the memory has not been released. It is useful for low level manipulations on a 3D arrat instance.

Definition at line 212 of file Array3D.cxx.

◆ operator()() [1/2]

template<class T , class Allocator >
Array3D< T, Allocator >::reference Seldon::Array3D< T, Allocator >::operator() ( int  i,
int  j,
int  k 
)
inline

Access operator.

Returns the value of element (i, j, k).

Parameters
iindex along dimension #1.
jindex along dimension #2.
kindex along dimension #3.
Returns
Element (i, j, k) of the 3D array.

Definition at line 151 of file Array3D_Inline.cxx.

◆ operator()() [2/2]

template<class T , class Allocator >
Array3D< T, Allocator >::const_reference Seldon::Array3D< T, Allocator >::operator() ( int  i,
int  j,
int  k 
) const
inline

Access operator.

Returns the value of element (i, j, k).

Parameters
iindex along dimension #1.
jindex along dimension #2.
kindex along dimension #3.
Returns
Element (i, j, k) of the 3D array.

Definition at line 172 of file Array3D_Inline.cxx.

◆ operator=()

template<class T , class Allocator >
Array3D< T, Allocator > & Seldon::Array3D< T, Allocator >::operator= ( const Array3D< T, Allocator > &  A)
inline

Duplicates a 3D array (assignment operator).

Parameters
A3D array to be copied.
Note
Memory is duplicated: 'A' is therefore independent from the current instance after the copy.

Definition at line 190 of file Array3D_Inline.cxx.

◆ Print()

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::Print

Displays the array on the standard output.

Displays elements on the standard output, in text format.

Definition at line 342 of file Array3D.cxx.

◆ Read() [1/2]

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::Read ( ifstream &  FileStream,
bool  with_size = true 
)

Reads the 3D array from an input stream.

Reads a 3D array in binary format from an input stream. The dimensions of the array are read (i,j, k three integers), and array elements are then read in the same order as it should be in memory

Parameters
FileStreaminput stream.

Definition at line 472 of file Array3D.cxx.

◆ Read() [2/2]

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

Reads the 3D array from a file.

Reads a 3D array stored in binary format in a file. The dimensions of the array are read (i,j, k three integers), and array elements are then read in the same order as it should be in memory

Parameters
FileNameinput file name.

Definition at line 444 of file Array3D.cxx.

◆ Reallocate()

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::Reallocate ( int  i,
int  j,
int  k 
)

Reallocates memory to resize the 3D array.

On exit, the array is a i x j x k 3D array.

Parameters
ilength in dimension #1.
jlength in dimension #2.
klength in dimension #3.
Warning
Depending on your allocator, data may be lost.

Definition at line 127 of file Array3D.cxx.

◆ SetData()

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::SetData ( int  i,
int  j,
int  k,
pointer  data 
)

Changes the size of the array and sets its data array (low level method).

The 3D array is first cleared (memory is freed). The 3D array is then resized to a i x j x k, and the data array of the 3D array is set to 'data'. 'data' elements are not duplicated: the new data array of the 3D array is the 'data' array. It is useful to create a 3D array from pre-existing data.

Parameters
ilength in dimension #1.
jlength in dimension #2.
klength in dimension #3.
datanew array storing elements.
Warning
'data' has to be used carefully outside the object. Unless you use 'Nullify', 'data' will be freed by the destructor, which means that 'data' must have been allocated carefully. The matrix allocator should be compatible.
Note
This method should only be used by advanced users.

Definition at line 192 of file Array3D.cxx.

◆ Write() [1/2]

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

Writes the 3D array to an output stream.

Writes the 3D array to an output stream in binary format. The number of rows (integer) and the number of columns (integer) are written, and array elements are then written in the same order as in memory

Parameters
FileStreamoutput stream.

Definition at line 400 of file Array3D.cxx.

◆ Write() [2/2]

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

Writes the 3D array in a file.

Stores the 3D array in a file in binary format. The number of rows (integer) and the number of columns (integer) are written, and matrix elements are then written in the same order as in memory

Parameters
FileNameoutput file name.

Definition at line 373 of file Array3D.cxx.

◆ Zero()

template<class T , class Allocator >
void Seldon::Array3D< T, Allocator >::Zero

Sets all elements to zero.

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

Definition at line 283 of file Array3D.cxx.


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