Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GENERIC_2D_ARRAY< T > Class Template Reference

#include <matrix.h>

Inheritance diagram for GENERIC_2D_ARRAY< T >:
GENERIC_MATRIX< T >

Public Member Functions

 GENERIC_2D_ARRAY (int dim1, int dim2, const T &empty)
 
 ~GENERIC_2D_ARRAY ()
 
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
 
int index (int column, int row) const
 
void put (int column, int row, const T &thing)
 
get (int column, int row) const
 
const T & operator() (int column, int row) const
 
T & operator() (int column, int row)
 
T * operator[] (int column)
 
void delete_matrix_pointers ()
 

Detailed Description

template<class T>
class GENERIC_2D_ARRAY< T >

Definition at line 35 of file matrix.h.

Constructor & Destructor Documentation

template<class T>
GENERIC_2D_ARRAY< T >::GENERIC_2D_ARRAY ( int  dim1,
int  dim2,
const T &  empty 
)
inline

Definition at line 40 of file matrix.h.

41  : empty_(empty), dim1_(dim1), dim2_(dim2) {
42  array_ = new T[dim1_ * dim2_];
43  for (int x = 0; x < dim1_; x++)
44  for (int y = 0; y < dim2_; y++)
45  this->put(x, y, empty_);
46  }
int dim2() const
Definition: matrix.h:102
int dim1() const
Definition: matrix.h:101
void put(int column, int row, const T &thing)
Definition: matrix.h:112
template<class T>
GENERIC_2D_ARRAY< T >::~GENERIC_2D_ARRAY ( )
inline

Definition at line 47 of file matrix.h.

47 { delete[] array_; }

Member Function Documentation

template<class T>
void GENERIC_2D_ARRAY< T >::delete_matrix_pointers ( )
inline

Definition at line 134 of file matrix.h.

134  {
135  for (int x = 0; x < dim1_; x++) {
136  for (int y = 0; y < dim2_; y++) {
137  T matrix_cell = this->get(x, y);
138  if (matrix_cell != empty_)
139  delete matrix_cell;
140  }
141  }
142  }
template<class T>
bool GENERIC_2D_ARRAY< T >::DeSerialize ( bool  swap,
FILE *  fp 
)
inline

Definition at line 62 of file matrix.h.

62  {
63  if (!DeSerializeSize(swap, fp)) return false;
64  if (fread(&empty_, sizeof(empty_), 1, fp) != 1) return false;
65  if (swap) ReverseN(&empty_, sizeof(empty_));
66  int size = dim1_ * dim2_;
67  if (fread(array_, sizeof(*array_), size, fp) != size) return false;
68  if (swap) {
69  for (int i = 0; i < size; ++i)
70  ReverseN(&array_[i], sizeof(array_[i]));
71  }
72  return true;
73  }
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:126
template<class T>
bool GENERIC_2D_ARRAY< T >::DeSerializeClasses ( bool  swap,
FILE *  fp 
)
inline

Definition at line 90 of file matrix.h.

90  {
91  if (!DeSerializeSize(swap, fp)) return false;
92  if (!empty_.DeSerialize(swap, fp)) return false;
93  int size = dim1_ * dim2_;
94  for (int i = 0; i < size; ++i) {
95  if (!array_[i].DeSerialize(swap, fp)) return false;
96  }
97  return true;
98  }
bool DeSerialize(bool swap, FILE *fp)
Definition: matrix.h:62
template<class T>
int GENERIC_2D_ARRAY< T >::dim1 ( ) const
inline

Definition at line 101 of file matrix.h.

101 { return dim1_; }
template<class T>
int GENERIC_2D_ARRAY< T >::dim2 ( ) const
inline

Definition at line 102 of file matrix.h.

102 { return dim2_; }
template<class T>
T GENERIC_2D_ARRAY< T >::get ( int  column,
int  row 
) const
inline

Definition at line 117 of file matrix.h.

117  {
118  return array_[this->index(column, row)];
119  }
int index(int column, int row) const
Definition: matrix.h:107
template<class T>
int GENERIC_2D_ARRAY< T >::index ( int  column,
int  row 
) const
inline

Definition at line 107 of file matrix.h.

107  {
108  return (column * dim2_ + row);
109  }
template<class T>
const T& GENERIC_2D_ARRAY< T >::operator() ( int  column,
int  row 
) const
inline

Definition at line 121 of file matrix.h.

121  {
122  return array_[this->index(column, row)];
123  }
int index(int column, int row) const
Definition: matrix.h:107
template<class T>
T& GENERIC_2D_ARRAY< T >::operator() ( int  column,
int  row 
)
inline

Definition at line 124 of file matrix.h.

124  {
125  return array_[this->index(column, row)];
126  }
int index(int column, int row) const
Definition: matrix.h:107
template<class T>
T* GENERIC_2D_ARRAY< T >::operator[] ( int  column)
inline

Definition at line 129 of file matrix.h.

129  {
130  return &array_[this->index(column, 0)];
131  }
int index(int column, int row) const
Definition: matrix.h:107
template<class T>
void GENERIC_2D_ARRAY< T >::put ( int  column,
int  row,
const T &  thing 
)
inline

Definition at line 112 of file matrix.h.

112  {
113  array_[this->index(column, row)] = thing;
114  }
int index(int column, int row) const
Definition: matrix.h:107
template<class T>
bool GENERIC_2D_ARRAY< T >::Serialize ( FILE *  fp) const
inline

Definition at line 51 of file matrix.h.

51  {
52  if (!SerializeSize(fp)) return false;
53  if (fwrite(&empty_, sizeof(empty_), 1, fp) != 1) return false;
54  int size = dim1_ * dim2_;
55  if (fwrite(array_, sizeof(*array_), size, fp) != size) return false;
56  return true;
57  }
template<class T>
bool GENERIC_2D_ARRAY< T >::SerializeClasses ( FILE *  fp) const
inline

Definition at line 77 of file matrix.h.

77  {
78  if (!SerializeSize(fp)) return false;
79  if (!empty_.Serialize(fp)) return false;
80  int size = dim1_ * dim2_;
81  for (int i = 0; i < size; ++i) {
82  if (!array_[i].Serialize(fp)) return false;
83  }
84  return true;
85  }
bool Serialize(FILE *fp) const
Definition: matrix.h:51

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