tesseract
3.03
|
#include <matrix.h>
Public Member Functions | |
GENERIC_2D_ARRAY (int dim1, int dim2, const T &empty, T *array) | |
GENERIC_2D_ARRAY (int dim1, int dim2, const T &empty) | |
virtual | ~GENERIC_2D_ARRAY () |
void | Resize (int size1, int size2, const T &empty) |
void | ResizeWithCopy (int size1, int size2) |
void | Clear () |
bool | Serialize (FILE *fp) const |
bool | DeSerialize (bool swap, FILE *fp) |
bool | SerializeClasses (FILE *fp) const |
bool | DeSerializeClasses (bool swap, FILE *fp) |
int | dim1 () const |
int | dim2 () const |
virtual int | num_elements () const |
virtual int | index (int column, int row) const |
void | put (int column, int row, const T &thing) |
T | get (int column, int row) const |
const T & | operator() (int column, int row) const |
T & | operator() (int column, int row) |
T * | operator[] (int column) |
const T * | operator[] (int column) const |
void | delete_matrix_pointers () |
Protected Member Functions | |
bool | SerializeSize (FILE *fp) const |
bool | DeSerializeSize (bool swap, FILE *fp) |
Protected Attributes | |
T * | array_ |
T | empty_ |
int | dim1_ |
int | dim2_ |
GENERIC_2D_ARRAY< T >::GENERIC_2D_ARRAY | ( | int | dim1, |
int | dim2, | ||
const T & | empty, | ||
T * | array | ||
) | [inline] |
GENERIC_2D_ARRAY< T >::GENERIC_2D_ARRAY | ( | int | dim1, |
int | dim2, | ||
const T & | empty | ||
) | [inline] |
virtual GENERIC_2D_ARRAY< T >::~GENERIC_2D_ARRAY | ( | ) | [inline, virtual] |
void GENERIC_2D_ARRAY< T >::Clear | ( | ) | [inline] |
Definition at line 94 of file matrix.h.
{ int total_size = num_elements(); for (int i = 0; i < total_size; ++i) array_[i] = empty_; }
void GENERIC_2D_ARRAY< T >::delete_matrix_pointers | ( | ) | [inline] |
Definition at line 191 of file matrix.h.
{ int size = num_elements(); for (int i = 0; i < size; ++i) { T matrix_cell = array_[i]; if (matrix_cell != empty_) delete matrix_cell; } }
bool GENERIC_2D_ARRAY< T >::DeSerialize | ( | bool | swap, |
FILE * | fp | ||
) | [inline] |
Definition at line 113 of file matrix.h.
{ if (!DeSerializeSize(swap, fp)) return false; if (fread(&empty_, sizeof(empty_), 1, fp) != 1) return false; if (swap) ReverseN(&empty_, sizeof(empty_)); int size = num_elements(); if (fread(array_, sizeof(*array_), size, fp) != size) return false; if (swap) { for (int i = 0; i < size; ++i) ReverseN(&array_[i], sizeof(array_[i])); } return true; }
bool GENERIC_2D_ARRAY< T >::DeSerializeClasses | ( | bool | swap, |
FILE * | fp | ||
) | [inline] |
Definition at line 141 of file matrix.h.
{ if (!DeSerializeSize(swap, fp)) return false; if (!empty_.DeSerialize(swap, fp)) return false; int size = num_elements(); for (int i = 0; i < size; ++i) { if (!array_[i].DeSerialize(swap, fp)) return false; } return true; }
bool GENERIC_2D_ARRAY< T >::DeSerializeSize | ( | bool | swap, |
FILE * | fp | ||
) | [inline, protected] |
int GENERIC_2D_ARRAY< T >::dim1 | ( | ) | const [inline] |
int GENERIC_2D_ARRAY< T >::dim2 | ( | ) | const [inline] |
T GENERIC_2D_ARRAY< T >::get | ( | int | column, |
int | row | ||
) | const [inline] |
virtual int GENERIC_2D_ARRAY< T >::index | ( | int | column, |
int | row | ||
) | const [inline, virtual] |
Reimplemented in BandTriMatrix< T >, and BandTriMatrix< BLOB_CHOICE_LIST * >.
Definition at line 161 of file matrix.h.
{ return (column * dim2_ + row); }
virtual int GENERIC_2D_ARRAY< T >::num_elements | ( | ) | const [inline, virtual] |
const T& GENERIC_2D_ARRAY< T >::operator() | ( | int | column, |
int | row | ||
) | const [inline] |
T& GENERIC_2D_ARRAY< T >::operator() | ( | int | column, |
int | row | ||
) | [inline] |
T* GENERIC_2D_ARRAY< T >::operator[] | ( | int | column | ) | [inline] |
const T* GENERIC_2D_ARRAY< T >::operator[] | ( | int | column | ) | const [inline] |
void GENERIC_2D_ARRAY< T >::put | ( | int | column, |
int | row, | ||
const T & | thing | ||
) | [inline] |
void GENERIC_2D_ARRAY< T >::Resize | ( | int | size1, |
int | size2, | ||
const T & | empty | ||
) | [inline] |
void GENERIC_2D_ARRAY< T >::ResizeWithCopy | ( | int | size1, |
int | size2 | ||
) | [inline] |
Definition at line 72 of file matrix.h.
{ if (size1 != dim1_ || size2 != dim2_) { T* new_array = new T[size1 * size2]; for (int col = 0; col < size1; ++col) { for (int row = 0; row < size2; ++row) { int old_index = col * dim2() + row; int new_index = col * size2 + row; if (col < dim1_ && row < dim2_) { new_array[new_index] = array_[old_index]; } else { new_array[new_index] = empty_; } } } delete[] array_; array_ = new_array; dim1_ = size1; dim2_ = size2; } }
bool GENERIC_2D_ARRAY< T >::Serialize | ( | FILE * | fp | ) | const [inline] |
Definition at line 102 of file matrix.h.
{ if (!SerializeSize(fp)) return false; if (fwrite(&empty_, sizeof(empty_), 1, fp) != 1) return false; int size = num_elements(); if (fwrite(array_, sizeof(*array_), size, fp) != size) return false; return true; }
bool GENERIC_2D_ARRAY< T >::SerializeClasses | ( | FILE * | fp | ) | const [inline] |
Definition at line 128 of file matrix.h.
{ if (!SerializeSize(fp)) return false; if (!empty_.Serialize(fp)) return false; int size = num_elements(); for (int i = 0; i < size; ++i) { if (!array_[i].Serialize(fp)) return false; } return true; }
bool GENERIC_2D_ARRAY< T >::SerializeSize | ( | FILE * | fp | ) | const [inline, protected] |
T* GENERIC_2D_ARRAY< T >::array_ [protected] |
int GENERIC_2D_ARRAY< T >::dim1_ [protected] |
int GENERIC_2D_ARRAY< T >::dim2_ [protected] |
T GENERIC_2D_ARRAY< T >::empty_ [protected] |