00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef MATRIX_H
00026 #define MATRIX_H
00027
00028 #include "ratngs.h"
00029 #include "unicharset.h"
00030
00031 static BLOB_CHOICE_LIST* NOT_CLASSIFIED = NULL;
00032
00033
00034 template <class T>
00035 class GENERIC_MATRIX {
00036 public:
00037
00038
00039
00040 GENERIC_MATRIX(int dimension, const T& empty) : empty_(empty) {
00041 matrix_ = new T[dimension * dimension];
00042 dimension_ = dimension;
00043 for (int x = 0; x < dimension; x++)
00044 for (int y = 0; y < dimension; y++)
00045 this->put(x, y, empty_);
00046 }
00047 ~GENERIC_MATRIX() { delete[] matrix_; }
00048
00049
00050 long dimension() const { return dimension_; }
00051
00052
00053 int index(int column, int row) const {
00054 return (row * this->dimension() + column);
00055 }
00056
00057
00058 void put(int column, int row, const T& thing) {
00059 matrix_[this->index(column, row)] = thing;
00060 }
00061
00062
00063 T get(int column, int row) const {
00064 return matrix_[this->index(column, row)];
00065 }
00066
00067
00068 void delete_matrix_pointers() {
00069 for (int x = 0; x < this->dimension(); x++) {
00070 for (int y = 0; y < this->dimension(); y++) {
00071 T matrix_cell = this->get(x, y);
00072 if (matrix_cell != empty_)
00073 delete matrix_cell;
00074 }
00075 }
00076 }
00077
00078 private:
00079 T *matrix_;
00080 T empty_;
00081 int dimension_;
00082 };
00083
00084 class MATRIX : public GENERIC_MATRIX<BLOB_CHOICE_LIST *> {
00085 public:
00086 MATRIX(int dimension) : GENERIC_MATRIX<BLOB_CHOICE_LIST *>(dimension,
00087 NOT_CLASSIFIED) {}
00088
00089 void print(const UNICHARSET ¤t_unicharset);
00090 };
00091
00092 #endif