?? tiny.h
字號:
#ifndef SL_MATRIX_MEMORY_TINY_H#define SL_MATRIX_MEMORY_TINY_H/* ****************************** * Scientific Library (GNU Public Licence) * * Author: Laurent Deniau, Laurent.Deniau@cern.ch * * $Id: tiny.h,v 1.2 1998/11/12 16:17:36 paubert Exp $ * * Suggestions: sl@mathinsa.insa-lyon.fr * Bugs: sl-bugs@mathinsa.insa-lyon.fr * * For more information, please see the sl++ Home Page: * http://wwwinfo.cern.ch/~ldeniau/sl.html * ****************************** */#ifndef SL_MATRIX_MEMORY_H#error <sl/matrix/memory/tiny.h> must be included via <sl/matrix/memory.h>#endif#ifdef HAVE_NAMESPACEnamespace sl {#endif/* WARNING: These classes MUST use the default copy constructor*/ template <typename T_value, size_t N> class TinyMemBlock { public: typedef T_value value_t; value_t * base () { return &my_b[0]; } value_t const* const_base() const { return &my_b[0]; } protected: // WARNING: Do NOT declare the copy constructor ! protected: template <typename T2_value> void set (size_t const n, T2_value const x) { for(size_t i=0;i<N;i++) my_b[i] = x; } template <typename T2_value> void copy (size_t const n, T2_value /* const */ * t) { assert( n <= N ); for(size_t i=0;i<N;i++) my_b[i] = t[i]; } void resize (size_t const n) { assert ( !"TinyMemBlock cannot be resized" ); } private: value_t my_b[N]; };// Should disappear when egcs will support template typedef template <typename T_value =Real, size_t N =4> class TinyVector : public Matrix<T_value, TVector, TinyMemBlock<T_value, N> > { public: typedef T_value value_t; typedef TVector structure_t; typedef TinyMemBlock<T_value, N> storage_t; typedef TVector::iterator_t iterator_t; public: explicit TinyVector () : Matrix<value_t,structure_t,storage_t>() { TVector::resize(N,1); this->my_d = storage_t::base()-structure_t::offset(); } public: // TinyVector = Scalar or List Initializer ListInit<TinyVector> operator = (T_value const x) { return ListInit<TinyVector> (*this, x); } // TinyVector = Range, for TVector only TinyVector& operator = (Range const& r) { structure_t::resize(r.size()); initialize(this->my_d, r); return *this; } // TinyVector = LoopIndex has no sense... // TinyVector = TinyVector TinyVector& operator = (TinyVector const& v) { if (this == &v) return *this; structure_t::resize(v.rows(), v.cols()); storage_t::copy(structure_t::size(),v.const_base()); return *this; } // TinyVector = TinyVector, different value, same structure template <typename T2_value> TinyVector& operator = (TinyVector<T2_value> const& v) { resize(v.rows(), v.col()); storage_t::copy(structure_t::size(), v.const_base()); return *this; } // TinyVector = Matrix template <typename T2_value, typename T2_structure, typename T2_storage> TinyVector& operator = (Matrix<T2_value, T2_structure, T2_storage> const& m) { typedef Matrix<T2_value, T2_structure, T2_storage> expr_t1; typedef MatrixExpr<expr_t1> expr_t; resize(m.rows(), m.cols()); iterator_t iter(this); while(iter) { this->my_d[iter.pos()] = m.get(iter.row(), iter.col()); ++iter; } return *this; } // Matrix = Matrix Expression, NO check for aliasing ! template <typename T_expr> TinyVector& operator = (MatrixExpr<T_expr> e) { e.preEval(); resize(e.rows(), e.cols()); iterator_t iter(this); while(iter) { this->my_d[iter.pos()] = e.get(iter.row(), iter.col()); ++iter; } e.postEval(); return *this; } }; template <typename T_value =Real, size_t N =4, size_t P =4, typename T_structure =RowMajor> class TinyMatrix : public Matrix<T_value, T_structure, TinyMemBlock<T_value, N*P> > { public: typedef T_value value_t; typedef T_structure structure_t; typedef TinyMemBlock<T_value, N*P> storage_t; typedef typename T_structure::iterator_t iterator_t; public: explicit TinyMatrix () : Matrix<value_t,structure_t,storage_t>() { T_structure::resize(N,P); this->my_d = storage_t::base()-structure_t::offset(); } public: // TinyMatrix = Scalar or List Initializer ListInit<TinyMatrix> operator = (T_value const x) { return ListInit<TinyMatrix> (*this, x); } // TinyMatrix = LoopIndex has no sense... // TinyMatrix = TinyMatrix TinyMatrix& operator = (TinyMatrix const& m) { if (this == &m) return *this; resize(m.rows(), m.cols()); storage_t::copy(structure_t::size(),m.const_base()); return *this; } // TinyMatrix = TinyMatrix, different value, same structure template <typename T2_value> TinyMatrix& operator = (TinyMatrix<T2_value> const& m) { resize(m.rows(), m.col()); storage_t::copy(structure_t::size(), m.const_base()); return *this; } // TinyMatrix = Matrix template <typename T2_value, typename T2_structure, typename T2_storage> TinyMatrix& operator = (Matrix<T2_value, T2_structure, T2_storage> const& m) { typedef Matrix<T2_value, T2_structure, T2_storage> expr_t1; typedef MatrixExpr<expr_t1> expr_t; resize(m.rows(), m.cols()); iterator_t iter(this); while(iter) { this->my_d[iter.pos()] = m.get(iter.row(), iter.col()); ++iter; } return *this; } // Matrix = Matrix Expression, NO check for aliasing ! template <typename T_expr> TinyMatrix& operator = (MatrixExpr<T_expr> e) { e.preEval(); resize(e.rows(), e.cols()); iterator_t iter(this); while(iter) { this->my_d[iter.pos()] = e.get(iter.row(), iter.col()); ++iter; } e.postEval(); return *this; } };#ifdef HAVE_NAMESPACE}#endif #endif// SL_MATRIX_MEMORY_TINY_H
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -