The Original CHomP Software
Classes | Public Member Functions | Protected Attributes | List of all members
chomp::homology::flatMatrix< element > Class Template Reference

This class defines a simple data structure for a flat 2-dim square matrix whose entries are stored in a single array. More...

#include <flatmatr.h>

Classes

class  const_row
 The class that represents a constant single row of the matrix. More...
 
class  row
 The class that represents a single row of the matrix. More...
 

Public Member Functions

 flatMatrix (int size)
 The main constructor. More...
 
 flatMatrix (const flatMatrix< element > &M)
 The copy constructor which copies all the entries of the matrix. More...
 
flatMatrixoperator= (const flatMatrix< element > &M)
 The assignment operator. More...
 
 ~flatMatrix ()
 The destructor which deallocates the memory. More...
 
row operator[] (int i)
 Returns a row of the matrix. More...
 
const_row operator[] (int i) const
 Returns a constant row of the matrix. More...
 
void clear (const element &elem)
 Clears all the entries of the matrix with the provided value. More...
 
void swap (flatMatrix< element > &M)
 Swaps the memory of two flat matrices. More...
 
const element * memory () const
 Returns the address of the memory buffer with the elements of the matrix for reading only. More...
 
element * memory ()
 Returns the address of the memory buffer with the elements of the matrix for reading and writing. More...
 

Protected Attributes

int n
 The size of the matrix. More...
 
element * tab
 The array of elements. More...
 

Detailed Description

template<class element>
class chomp::homology::flatMatrix< element >

This class defines a simple data structure for a flat 2-dim square matrix whose entries are stored in a single array.

Additional classes for a row and a constant row are defined within this class which allow to use the usual double indexing to get to the entries of the matrix, both for reading only and for modifying the entries, e.g., M[0][1].

Definition at line 54 of file flatmatr.h.

Constructor & Destructor Documentation

◆ flatMatrix() [1/2]

template<class element >
chomp::homology::flatMatrix< element >::flatMatrix ( int  size)
inline

The main constructor.

The size of the matrix (the number of rows and collumns) must be given at initialization.

Definition at line 60 of file flatmatr.h.

60: n (size), tab (new element [n * n]) {return;}
int n
The size of the matrix.
Definition: flatmatr.h:168
element * tab
The array of elements.
Definition: flatmatr.h:171

◆ flatMatrix() [2/2]

template<class element >
chomp::homology::flatMatrix< element >::flatMatrix ( const flatMatrix< element > &  M)
inline

The copy constructor which copies all the entries of the matrix.

Definition at line 63 of file flatmatr.h.

63 :
64 n (M. n), tab (new element [n * n])
65 {
66 int memSize = n * n;
67 for (int i = 0; i < memSize; ++ i)
68 tab [i] = M. tab [i];
69 return;
70 }

References chomp::homology::flatMatrix< element >::n, and chomp::homology::flatMatrix< element >::tab.

◆ ~flatMatrix()

template<class element >
chomp::homology::flatMatrix< element >::~flatMatrix ( )
inline

The destructor which deallocates the memory.

Definition at line 85 of file flatmatr.h.

85{delete [] tab;}

References chomp::homology::flatMatrix< element >::tab.

Member Function Documentation

◆ clear()

template<class element >
void chomp::homology::flatMatrix< element >::clear ( const element &  elem)
inline

Clears all the entries of the matrix with the provided value.

Definition at line 138 of file flatmatr.h.

139 {
140 int size = n * n;
141 for (int i = 0; i < size; ++ i)
142 tab [i] = elem;
143 return;
144 }

References chomp::homology::flatMatrix< element >::n, and chomp::homology::flatMatrix< element >::tab.

◆ memory() [1/2]

template<class element >
element * chomp::homology::flatMatrix< element >::memory ( )
inline

Returns the address of the memory buffer with the elements of the matrix for reading and writing.

Definition at line 164 of file flatmatr.h.

164{return tab;}

References chomp::homology::flatMatrix< element >::tab.

◆ memory() [2/2]

template<class element >
const element * chomp::homology::flatMatrix< element >::memory ( ) const
inline

Returns the address of the memory buffer with the elements of the matrix for reading only.

Definition at line 160 of file flatmatr.h.

160{return tab;}

References chomp::homology::flatMatrix< element >::tab.

◆ operator=()

template<class element >
flatMatrix & chomp::homology::flatMatrix< element >::operator= ( const flatMatrix< element > &  M)
inline

The assignment operator.

It is permitted only for matrices of the same size. It copies all the entries of the matrix.

Definition at line 74 of file flatmatr.h.

75 {
76 if (n != M. n)
77 throw "Different matrix sizes in operator =.";
78 int memSize = n * n;
79 for (int i = 0; i < memSize; ++ i)
80 tab [i] = M. tab [i];
81 return *this;
82 }

References chomp::homology::flatMatrix< element >::n, and chomp::homology::flatMatrix< element >::tab.

◆ operator[]() [1/2]

template<class element >
row chomp::homology::flatMatrix< element >::operator[] ( int  i)
inline

Returns a row of the matrix.

Definition at line 109 of file flatmatr.h.

110 {return row (n * i, tab);}

References chomp::homology::flatMatrix< element >::n, and chomp::homology::flatMatrix< element >::tab.

◆ operator[]() [2/2]

template<class element >
const_row chomp::homology::flatMatrix< element >::operator[] ( int  i) const
inline

Returns a constant row of the matrix.

Definition at line 134 of file flatmatr.h.

135 {return const_row (n * i, tab);}

References chomp::homology::flatMatrix< element >::n, and chomp::homology::flatMatrix< element >::tab.

◆ swap()

template<class element >
void chomp::homology::flatMatrix< element >::swap ( flatMatrix< element > &  M)
inline

Swaps the memory of two flat matrices.

Definition at line 147 of file flatmatr.h.

148 {
149 int this_n = n;
150 element *this_tab = tab;
151 n = M. n;
152 tab = M. tab;
153 M. n = this_n;
154 M. tab = this_tab;
155 return;
156 }

References chomp::homology::flatMatrix< element >::n, and chomp::homology::flatMatrix< element >::tab.

Member Data Documentation

◆ n

template<class element >
int chomp::homology::flatMatrix< element >::n
protected

◆ tab

template<class element >
element* chomp::homology::flatMatrix< element >::tab
protected

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