Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBmatrix.icc

Go to the documentation of this file.
00001 
00006 /*----------------------------------------------------------------------------*/
00007 /* C Tool Box: Designed and implemented by:                                   */
00008 /*    Walter F.J. Mueller   Gesellschaft fuer Schwerionenforschung (GSI)      */
00009 /*                          Planckstrasse 1, D-64291 Darmstadt, Germany       */
00010 /*                  Email:  W.F.J.Mueller@gsi.de                              */
00011 /*                  WWW:    http://www-kp3.gsi.de/www/kp3/people/mueller.html */
00012 /*------------------------------------------+---------------------------------*/
00013 
00014 #include "CTBnum.hxx"
00015 #include "CTBexceptionIndexRange.hxx"
00016 
00017 //------------------------------------------+-----------------------------------
00019 
00020 template <class T>
00021 inline CTBmatrix<T>::CTBmatrix()
00022   : m_rbuf(),
00023     mi_nrow(0),
00024     mi_ncol(0)
00025 {}
00026 
00027 //------------------------------------------+-----------------------------------
00029 
00030 template <class T>
00031 inline CTBmatrix<T>::CTBmatrix(CTBmatrix<T>& rhs, bool )
00032   : m_rbuf(rhs.m_rbuf,true),
00033     mi_nrow(rhs.mi_nrow),
00034     mi_ncol(rhs.mi_ncol)
00035 {
00036   rhs.mi_nrow = 0;
00037   rhs.mi_ncol = 0;
00038 }
00039 
00040 //------------------------------------------+-----------------------------------
00042 
00043 template <class T>
00044 inline CTBint CTBmatrix<T>::NRow() const
00045 {
00046   return mi_nrow;
00047 }
00048 
00049 //------------------------------------------+-----------------------------------
00051 
00052 template <class T>
00053 inline CTBint CTBmatrix<T>::NColumn() const
00054 {
00055   return mi_ncol;
00056 }
00057 
00058 //------------------------------------------+-----------------------------------
00060 
00061 template <class T>
00062 inline CTBint CTBmatrix<T>::Size() const
00063 {
00064   return mi_nrow*mi_ncol;
00065 }
00066 
00067 //------------------------------------------+-----------------------------------
00069 
00070 template <class T>
00071 inline CTBint CTBmatrix<T>::Capacity() const
00072 {
00073   return m_rbuf.Capacity();
00074 }
00075 
00076 //------------------------------------------+-----------------------------------
00078 
00079 template <class T>
00080 inline CTBvectorDsc<T> CTBmatrix<T>::Row(CTBint i_row)
00081 {
00082 #ifdef CTB__IndexCheck
00083   CTBindexRangeCheck(i_row,mi_nrow,"CTBmatrix::Row()");
00084 #endif
00085   return CTBvectorDsc<T>(m_rbuf+i_row*mi_ncol, mi_ncol);
00086 }
00087 
00088 //------------------------------------------+-----------------------------------
00090 
00091 template <class T>
00092 inline CTBvectorCDsc<T> CTBmatrix<T>::Row(CTBint i_row) const
00093 {
00094 #ifdef CTB__IndexCheck
00095   CTBindexRangeCheck(i_row,mi_nrow,"CTBmatrix::Row()");
00096 #endif
00097   return CTBvectorCDsc<T>(m_rbuf+i_row*mi_ncol, mi_ncol);
00098 }
00099 
00100 //------------------------------------------+-----------------------------------
00102 
00103 template <class T>
00104 inline CTBvectorDsc<T> CTBmatrix<T>::Column(CTBint i_col)
00105 {
00106 #ifdef CTB__IndexCheck
00107   CTBindexRangeCheck(i_col,mi_ncol,"CTBmatrix::Column()");
00108 #endif
00109   return CTBvectorDsc<T>(m_rbuf+i_col, mi_nrow, mi_ncol);
00110 }
00111 
00112 //------------------------------------------+-----------------------------------
00114 
00115 template <class T>
00116 inline CTBvectorCDsc<T> CTBmatrix<T>::Column(CTBint i_col) const
00117 {
00118 #ifdef CTB__IndexCheck
00119   CTBindexRangeCheck(i_col,mi_ncol,"CTBmatrix::Column()");
00120 #endif
00121   return CTBvectorCDsc<T>(m_rbuf+i_col, mi_nrow, mi_ncol);
00122 }
00123 
00124 //------------------------------------------+-----------------------------------
00126 
00127 template <class T>
00128 inline CTBvectorDsc<T> CTBmatrix<T>::Diagonal()
00129 {
00130   return CTBvectorDsc<T>(m_rbuf,CTBmin(mi_nrow,mi_ncol),mi_ncol+1);
00131 }
00132 
00133 //------------------------------------------+-----------------------------------
00135 
00136 template <class T>
00137 inline CTBvectorCDsc<T> CTBmatrix<T>::Diagonal() const
00138 {
00139   return CTBvectorCDsc<T>(m_rbuf,CTBmin(mi_nrow,mi_ncol),mi_ncol+1);
00140 }
00141 
00142 //------------------------------------------+-----------------------------------
00144 
00145 template <class T>
00146 inline CTBmatrixDsc<T> CTBmatrix<T>::Transpose()
00147 {
00148   return CTBmatrixDsc<T>(m_rbuf,mi_ncol,mi_nrow,1,mi_ncol);
00149 }
00150 
00151 //------------------------------------------+-----------------------------------
00153 
00154 template <class T>
00155 inline CTBmatrixCDsc<T> CTBmatrix<T>::Transpose() const
00156 {
00157   return CTBmatrixCDsc<T>(m_rbuf,mi_ncol,mi_nrow,1,mi_ncol);
00158 }
00159 
00160 //------------------------------------------+-----------------------------------
00162 
00163 template <class T>
00164 inline CTBvectorCDsc<T> CTBmatrix<T>::Diagonal(CTBint i_dia) const
00165 {
00166   return ((CTBmatrix<T>*) this)->Diagonal(i_dia);
00167 }
00168 
00169 // Note: simply forward const version to non-const version ... 
00170 
00171 //------------------------------------------+-----------------------------------
00173 
00174 template <class T>
00175 inline void CTBmatrix<T>::EnsureCapacity(CTBint i_cap)
00176 {
00177   if (i_cap > Capacity()) ChangeCapacity(i_cap);
00178   return;
00179 }
00180 
00181 //------------------------------------------+-----------------------------------
00183 
00184 template <class T>
00185 inline void CTBmatrix<T>::TrimCapacity()
00186 {
00187   CTBint i_size = Size();
00188   if (i_size < Capacity()) ChangeCapacity(i_size);
00189   return;
00190 }
00191 
00192 //------------------------------------------+-----------------------------------
00194 
00199 template <class T>
00200 inline const T* CTBmatrix<T>::Data() const
00201 {
00202   return *this;
00203 }
00204 
00205 //------------------------------------------+-----------------------------------
00207 
00212 template <class T>
00213 inline CTBint CTBmatrix<T>::StrideRow() const
00214 {
00215   return NColumn();
00216 }
00217 
00218 //------------------------------------------+-----------------------------------
00220 
00225 template <class T>
00226 inline CTBint CTBmatrix<T>::StrideColumn() const
00227 {
00228   return 1;
00229 }
00230 
00231 //------------------------------------------+-----------------------------------
00233 
00234 template <class T>
00235 inline CTBvectorDsc<T> CTBmatrix<T>::operator[](CTBint i_row)
00236 {
00237 #ifdef CTB__IndexCheck
00238   CTBindexRangeCheck(i_row,mi_nrow,"CTBmatrix::operator[]");
00239 #endif
00240   return CTBvectorDsc<T>(m_rbuf+i_row*mi_ncol, mi_ncol);
00241 }
00242 
00243 //------------------------------------------+-----------------------------------
00245 
00246 template <class T>
00247 inline CTBvectorCDsc<T> CTBmatrix<T>::operator[](CTBint i_row) const
00248 {
00249 #ifdef CTB__IndexCheck
00250   CTBindexRangeCheck(i_row,mi_nrow,"CTBmatrix::operator[]");
00251 #endif
00252   return CTBvectorCDsc<T>(m_rbuf+i_row*mi_ncol, mi_ncol);
00253 }
00254 
00255 //------------------------------------------+-----------------------------------
00257 
00258 template <class T>
00259 inline T& CTBmatrix<T>::operator()(CTBint i_row, CTBint i_col)
00260 {
00261 #ifndef CTB__IndexCheck
00262   return m_rbuf[i_row*mi_ncol + i_col];
00263 #else
00264   return At(i_row,i_col);
00265 #endif
00266 }
00267 
00268 //------------------------------------------+-----------------------------------
00270 
00271 template <class T>
00272 inline const T& CTBmatrix<T>::operator()(CTBint i_row, CTBint i_col) const
00273 {
00274 #ifndef CTB__IndexCheck
00275   return m_rbuf[i_row*mi_ncol + i_col];
00276 #else
00277   return At(i_row,i_col);
00278 #endif
00279 }
00280 
00281 //------------------------------------------+-----------------------------------
00283 
00284 template <class T>
00285 inline CTBvectorDsc<T> CTBmatrix<T>::operator()(CTBint i_row,
00286                                                 const CTBrange& rcol)
00287 {
00288 #ifdef CTB__IndexCheck
00289   CTBindexRangeCheck(i_row,mi_nrow,"CTBmatrix::operator(row,)");
00290   CTBindexRangeCheck(rcol,mi_ncol,"CTBmatrix::operator(,col)");
00291 #endif
00292   return CTBvectorDsc<T>(m_rbuf+i_row*mi_ncol, rcol);  
00293 }
00294 
00295 //------------------------------------------+-----------------------------------
00297 
00298 template <class T>
00299 inline CTBvectorCDsc<T> CTBmatrix<T>::operator()(CTBint i_row,
00300                                                  const CTBrange& rcol) const
00301 {
00302 #ifdef CTB__IndexCheck
00303   CTBindexRangeCheck(i_row,mi_nrow,"CTBmatrix::operator(row,)");
00304   CTBindexRangeCheck(rcol,mi_ncol,"CTBmatrix::operator(,col)");
00305 #endif
00306   return CTBvectorCDsc<T>(m_rbuf+i_row*mi_ncol, rcol);  
00307 }
00308 
00309 //------------------------------------------+-----------------------------------
00311 
00312 template <class T>
00313 inline CTBvectorDsc<T> CTBmatrix<T>::operator()(const CTBrange& rrow, 
00314                                                 CTBint i_col)
00315 {
00316 #ifdef CTB__IndexCheck
00317   CTBindexRangeCheck(rrow,mi_nrow,"CTBmatrix::operator(row,)");
00318   CTBindexRangeCheck(i_col,mi_ncol,"CTBmatrix::operator(,col)");
00319 #endif
00320   return CTBvectorDsc<T>(m_rbuf+i_col, mi_ncol, rrow);  
00321 }
00322 
00323 //------------------------------------------+-----------------------------------
00325 
00326 template <class T>
00327 inline CTBvectorCDsc<T> CTBmatrix<T>::operator()(const CTBrange& rrow, 
00328                                                 CTBint i_col) const
00329 {
00330 #ifdef CTB__IndexCheck
00331   CTBindexRangeCheck(rrow,mi_nrow,"CTBmatrix::operator(row,)");
00332   CTBindexRangeCheck(i_col,mi_ncol,"CTBmatrix::operator(,col)");
00333 #endif
00334   return CTBvectorCDsc<T>(m_rbuf+i_col, mi_ncol, rrow);  
00335 }
00336 
00337 //------------------------------------------+-----------------------------------
00339 
00340 template <class T>
00341 inline CTBmatrixDsc<T> CTBmatrix<T>::operator()(const CTBrange& rrow, 
00342                                                 const CTBrange& rcol)
00343 {
00344 #ifdef CTB__IndexCheck
00345   CTBindexRangeCheck(rrow,mi_nrow,"CTBmatrix::operator(row,)");
00346   CTBindexRangeCheck(rcol,mi_ncol,"CTBmatrix::operator(,col)");
00347 #endif
00348   return CTBmatrixDsc<T>(m_rbuf, mi_ncol, rrow, rcol);
00349 }
00350 
00351 //------------------------------------------+-----------------------------------
00353 
00354 template <class T>
00355 inline CTBmatrixCDsc<T> CTBmatrix<T>::operator()(const CTBrange& rrow, 
00356                                                  const CTBrange& rcol) const
00357 {
00358 #ifdef CTB__IndexCheck
00359   CTBindexRangeCheck(rrow,mi_nrow,"CTBmatrix::operator(row,)");
00360   CTBindexRangeCheck(rcol,mi_ncol,"CTBmatrix::operator(,col)");
00361 #endif
00362   return CTBmatrixCDsc<T>(m_rbuf, mi_ncol, rrow, rcol);
00363 }
00364 
00365 //------------------------------------------+-----------------------------------
00367 
00368 template <class T>
00369 inline bool CTBmatrix<T>::operator !() const
00370 {
00371   return mi_nrow == 0 || mi_ncol == 0;
00372 }
00373 
00374 //------------------------------------------+-----------------------------------
00376 
00377 template <class T>
00378 inline CTBmatrix<T>::operator T*()
00379 {
00380   return (mi_nrow > 0 && mi_ncol > 0) ? (T*) m_rbuf : 0;
00381 }
00382 
00383 //------------------------------------------+-----------------------------------
00385 
00386 template <class T>
00387 inline CTBmatrix<T>::operator const T*() const
00388 {
00389   return (mi_nrow > 0 && mi_ncol > 0) ? (const T*) m_rbuf : 0;
00390 }
00391 
00392 //------------------------------------------+-----------------------------------
00394 
00395 template <class T>
00396 inline CTBmatrix<T>::operator CTBmatrixDsc<T>()
00397 {
00398   return CTBmatrixDsc<T>(m_rbuf,mi_nrow,mi_ncol);
00399 }
00400 
00401 //------------------------------------------+-----------------------------------
00403 
00404 template <class T>
00405 inline CTBmatrix<T>::operator CTBmatrixCDsc<T>() const
00406 {
00407   return CTBmatrixCDsc<T>(m_rbuf,mi_nrow,mi_ncol);
00408 }
00409 
00410 //------------------------------------------+-----------------------------------
00416 template <class T>
00417 inline ostream& operator<<(ostream& os, const CTBmatrix<T>& obj)
00418 {
00419   int i_width = os.width();
00420 
00421   os << setw(0) << "{";
00422   for (CTBint i = 0; i < obj.NRow(); i++) {
00423     if (i > 0) os << ",";
00424     os << "{";
00425     for (CTBint j = 0; j < obj.NColumn(); j++) {
00426       if (j > 0) os << ",";
00427       os << setw(i_width) << obj(i,j);
00428     }
00429     os << "}";
00430   }
00431   os << "}";
00432   return os;
00433 }

Generated at Fri Oct 24 18:11:29 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001