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