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 #ifndef EIGEN_COMMAINITIALIZER_H
00027 #define EIGEN_COMMAINITIALIZER_H
00028
00039 template<typename MatrixType>
00040 struct CommaInitializer
00041 {
00042 typedef typename ei_traits<MatrixType>::Scalar Scalar;
00043 inline CommaInitializer(MatrixType& mat, const Scalar& s)
00044 : m_matrix(mat), m_row(0), m_col(1), m_currentBlockRows(1)
00045 {
00046 m_matrix.coeffRef(0,0) = s;
00047 }
00048
00049 template<typename OtherDerived>
00050 inline CommaInitializer(MatrixType& mat, const MatrixBase<OtherDerived>& other)
00051 : m_matrix(mat), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
00052 {
00053 m_matrix.block(0, 0, other.rows(), other.cols()) = other;
00054 }
00055
00056
00057 CommaInitializer& operator,(const Scalar& s)
00058 {
00059 if (m_col==m_matrix.cols())
00060 {
00061 m_row+=m_currentBlockRows;
00062 m_col = 0;
00063 m_currentBlockRows = 1;
00064 ei_assert(m_row<m_matrix.rows()
00065 && "Too many rows passed to comma initializer (operator<<)");
00066 }
00067 ei_assert(m_col<m_matrix.cols()
00068 && "Too many coefficients passed to comma initializer (operator<<)");
00069 ei_assert(m_currentBlockRows==1);
00070 m_matrix.coeffRef(m_row, m_col++) = s;
00071 return *this;
00072 }
00073
00074
00075 template<typename OtherDerived>
00076 CommaInitializer& operator,(const MatrixBase<OtherDerived>& other)
00077 {
00078 if (m_col==m_matrix.cols())
00079 {
00080 m_row+=m_currentBlockRows;
00081 m_col = 0;
00082 m_currentBlockRows = other.rows();
00083 ei_assert(m_row+m_currentBlockRows<=m_matrix.rows()
00084 && "Too many rows passed to comma initializer (operator<<)");
00085 }
00086 ei_assert(m_col<m_matrix.cols()
00087 && "Too many coefficients passed to comma initializer (operator<<)");
00088 ei_assert(m_currentBlockRows==other.rows());
00089 if (OtherDerived::SizeAtCompileTime != Dynamic)
00090 m_matrix.template block<OtherDerived::RowsAtCompileTime != Dynamic ? OtherDerived::RowsAtCompileTime : 1,
00091 OtherDerived::ColsAtCompileTime != Dynamic ? OtherDerived::ColsAtCompileTime : 1>
00092 (m_row, m_col) = other;
00093 else
00094 m_matrix.block(m_row, m_col, other.rows(), other.cols()) = other;
00095 m_col += other.cols();
00096 return *this;
00097 }
00098
00099 inline ~CommaInitializer()
00100 {
00101 ei_assert((m_row+m_currentBlockRows) == m_matrix.rows()
00102 && m_col == m_matrix.cols()
00103 && "Too few coefficients passed to comma initializer (operator<<)");
00104 }
00105
00113 inline MatrixType& finished() { return m_matrix; }
00114
00115 MatrixType& m_matrix;
00116 int m_row;
00117 int m_col;
00118 int m_currentBlockRows;
00119
00120 private:
00121 CommaInitializer& operator=(const CommaInitializer&);
00122 };
00123
00137 template<typename Derived>
00138 inline CommaInitializer<Derived> MatrixBase<Derived>::operator<< (const Scalar& s)
00139 {
00140 return CommaInitializer<Derived>(*static_cast<Derived*>(this), s);
00141 }
00142
00144 template<typename Derived>
00145 template<typename OtherDerived>
00146 inline CommaInitializer<Derived>
00147 MatrixBase<Derived>::operator<<(const MatrixBase<OtherDerived>& other)
00148 {
00149 return CommaInitializer<Derived>(*static_cast<Derived *>(this), other);
00150 }
00151
00152 #endif // EIGEN_COMMAINITIALIZER_H