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
00026
00027
00028
00029
00030
00031
00032 #ifndef __UT_RefMatrix_h__
00033 #define __UT_RefMatrix_h__
00034
00035 #include "UT_RefArray.h"
00036 #include "UT_PtrArray.h"
00037
00038
00039 template <class utRef>
00040 class UT_RefMatrix {
00041 public:
00042
00043 explicit UT_RefMatrix(unsigned int mSz = 0, unsigned int nSz = 0)
00044 : rowArr(mSz) { nbrCols = nSz; }
00045 virtual ~UT_RefMatrix(void);
00046
00047
00048
00049 UT_RefMatrix(const UT_RefMatrix<utRef> &m);
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 unsigned int insertRow(unsigned int index);
00060 unsigned int insertRow(const UT_RefArray<utRef> &r,
00061 unsigned int index,
00062 unsigned short dupliCheck = 0);
00063 unsigned int insertRow(const UT_RefArray<utRef> &r,
00064 unsigned int index,
00065 int (*cmpare)(const void *t1,const void *t2));
00066 unsigned int appendRow(const UT_RefArray<utRef> &r,
00067 unsigned short dupliCheck = 0);
00068 unsigned int appendRow(const UT_RefArray<utRef> &r,
00069 int (*cmpare)(const void *t1,const void *t2));
00070
00071
00072
00073
00074 unsigned int insertRowFast(const UT_RefArray<utRef> &r,
00075 unsigned int index,
00076 unsigned short dupliCheck = 0);
00077 unsigned int insertRowFast(const UT_RefArray<utRef> &r,
00078 unsigned int index, int (*compare)
00079 (const void *t1,const void *t2));
00080 unsigned int appendRowFast(const UT_RefArray<utRef> &r,
00081 unsigned short dupliCheck = 0);
00082 unsigned int appendRowFast(const UT_RefArray<utRef> &r,int (*compare)
00083 (const void *t1,const void *t2));
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 int insertCol(unsigned int index);
00094 int insertCol(const UT_RefArray<utRef> &c,
00095 unsigned int index,
00096 unsigned short dupliCheck = 0);
00097 int insertCol(const UT_RefArray<utRef> &c,
00098 unsigned int index,
00099 int (*compare)(const void *t1,const void *t2));
00100 int appendCol(const UT_RefArray<utRef> &c,
00101 unsigned short dupliCheck = 0);
00102 int appendCol(const UT_RefArray<utRef> &c,
00103 int (*compare)(const void *t1,const void *t2));
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 int removeRow(const UT_RefArray<utRef> &r,
00116 unsigned short dupliCheck = 0);
00117 int removeRow(unsigned int index,
00118 unsigned short dupliCheck = 0);
00119 int removeRow(const UT_RefArray<utRef> &r,
00120 int (*compare)(const void *t1,const void *t2),
00121 unsigned short dupliCheck = 0);
00122 int removeRow(unsigned int index,
00123 int (*compare)(const void *t1,const void *t2),
00124 unsigned short dupliCheck = 0);
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 int removeCol(const UT_RefArray<utRef> &c,
00135 unsigned short dupliCheck = 0);
00136 int removeCol(unsigned int index,
00137 unsigned short dupliCheck = 0);
00138 int removeCol(const UT_RefArray<utRef> &c,
00139 int (*compare)(const void *t1,const void *t2),
00140 unsigned short dupliCheck = 0);
00141 int removeCol(unsigned int index,
00142 int (*compare)(const void *t1,const void *t2),
00143 unsigned short dupliCheck = 0);
00144
00145
00146 void cycle(int rowshift, int colshift);
00147
00148
00149
00150
00151
00152 int operator==(const UT_RefMatrix<utRef> &m) const;
00153 int isEqual(const UT_RefMatrix<utRef> &m,
00154 int (*compare)(const void *t1,const void *t2)
00155 ) const;
00156
00157
00158
00159
00160
00161 UT_RefMatrix<utRef> &operator=(const UT_RefMatrix<utRef> &m);
00162
00163
00164
00165
00166 UT_RefArray<utRef> &operator()(unsigned int i)
00167 {
00168 return *rowArr(i);
00169 }
00170 UT_RefArray<utRef> &operator[](unsigned int i);
00171 const UT_RefArray<utRef> &operator()(unsigned int i) const
00172 {
00173 return *rowArr(i);
00174 }
00175 const UT_RefArray<utRef> &operator[](unsigned int i) const
00176 {
00177 return *rowArr[i];
00178 }
00179
00180
00181
00182 const utRef &operator()(unsigned i, unsigned j) const
00183 {
00184 return rowArr(i)->operator()(j);
00185 }
00186 utRef &operator()(unsigned i, unsigned j)
00187 {
00188 return rowArr(i)->operator()(j);
00189 }
00190
00191
00192
00193 const utRef &safeGet(unsigned i, unsigned j) const
00194 {
00195 return ((*this)[i])[j];
00196 }
00197 utRef &safeGet(unsigned i, unsigned j)
00198 {
00199 if (rowArr.entries() <= i) insertRow(i);
00200 if (j >= rowArr(0)->entries()) insertCol(j);
00201 return ((*this)[i])(j);
00202 }
00203
00204
00205
00206
00207
00208
00209
00210 const UT_RefArray<utRef> &row(unsigned int i) const {return (*this)(i);}
00211 UT_RefArray<utRef> &row(unsigned int i) {return (*this)(i);}
00212 UT_RefArray<utRef> &col(unsigned int j) const;
00213
00214
00215
00216
00217
00218 int find(const utRef &t, unsigned int *m, unsigned int *n) const;
00219 int find(const utRef &t, unsigned int *m, unsigned int *n,
00220 int (*compare)(const void *t1, const void *t2)) const;
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 int findRow(const UT_RefArray<utRef> &r, unsigned int s = 0) const;
00231 int findRow(const UT_RefArray<utRef> &r,
00232 int (*compare)(const void *t1, const void *t2),
00233 unsigned int s = 0) const;
00234 int findCol(const UT_RefArray<utRef> &c, unsigned int s = 0) const;
00235 int findCol(const UT_RefArray<utRef> &c,
00236 int (*compare)(const void *t1, const void *t2),
00237 unsigned int s = 0) const;
00238
00239
00240
00241 unsigned int rows(void) const { return rowArr.capacity(); }
00242 unsigned int cols(void) const { return nbrCols; }
00243 unsigned int usedRows(void) const { return rowArr.entries();}
00244 unsigned int usedCols(void) const
00245 {
00246
00247 return (rowArr.entries()) ? rowArr(0)->entries():0;
00248 }
00249 unsigned short isEmpty(void) const
00250 {
00251 return rowArr.entries() == 0 ||
00252 (rowArr.entries() == 1 &&
00253 rowArr(0)->entries() == 0 );
00254 }
00255
00256
00257
00258 void resize(unsigned int mSz, unsigned int nSz,
00259 unsigned short copyFlag=1);
00260
00261
00262
00263
00264
00265 int apply(int (*applyFct)(utRef &t, void *d), void *d);
00266
00267
00268 protected:
00269
00270 const UT_PtrArray< UT_RefArray<utRef>*> &data(void) const { return rowArr; }
00271
00272 private:
00273
00274 UT_PtrArray<UT_RefArray<utRef>*> rowArr;
00275
00276
00277 unsigned int nbrCols;
00278
00279
00280 unsigned int assignRow(const UT_RefArray<utRef> &r,
00281 unsigned int index)
00282 {
00283 rowArr(index) = new UT_RefArray<utRef>(nbrCols);
00284 *rowArr(index) = r;
00285 return index;
00286 }
00287 unsigned int insertFastFill(const UT_RefArray<utRef> &r,
00288 unsigned int index);
00289 unsigned int insertSlowFill(unsigned int index,
00290 unsigned int uRows, unsigned int uCols);
00291
00292
00293 void removeOneCol(unsigned int index);
00294
00295
00296 void removeOneRow(unsigned int index)
00297 {
00298 UT_RefArray<utRef> *rdel = rowArr(index);
00299 rowArr.remove(index);
00300 delete rdel;
00301 }
00302 };
00303
00304 #if defined(WIN32) || defined(LINUX) || defined(MBSD) || defined(GAMEOS)
00305 #include "UT_RefMatrix.C"
00306 #endif
00307
00308
00309 #endif