Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef EIGEN_COMMAINITIALIZER_H
00012 #define EIGEN_COMMAINITIALIZER_H
00013
00014 namespace Eigen {
00015
00027 template<typename XprType>
00028 struct CommaInitializer
00029 {
00030 typedef typename XprType::Scalar Scalar;
00031 typedef typename XprType::Index Index;
00032
00033 inline CommaInitializer(XprType& xpr, const Scalar& s)
00034 : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1)
00035 {
00036 m_xpr.coeffRef(0,0) = s;
00037 }
00038
00039 template<typename OtherDerived>
00040 inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other)
00041 : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
00042 {
00043 m_xpr.block(0, 0, other.rows(), other.cols()) = other;
00044 }
00045
00046
00047 CommaInitializer& operator,(const Scalar& s)
00048 {
00049 if (m_col==m_xpr.cols())
00050 {
00051 m_row+=m_currentBlockRows;
00052 m_col = 0;
00053 m_currentBlockRows = 1;
00054 eigen_assert(m_row<m_xpr.rows()
00055 && "Too many rows passed to comma initializer (operator<<)");
00056 }
00057 eigen_assert(m_col<m_xpr.cols()
00058 && "Too many coefficients passed to comma initializer (operator<<)");
00059 eigen_assert(m_currentBlockRows==1);
00060 m_xpr.coeffRef(m_row, m_col++) = s;
00061 return *this;
00062 }
00063
00064
00065 template<typename OtherDerived>
00066 CommaInitializer& operator,(const DenseBase<OtherDerived>& other)
00067 {
00068 if(other.cols()==0 || other.rows()==0)
00069 return *this;
00070 if (m_col==m_xpr.cols())
00071 {
00072 m_row+=m_currentBlockRows;
00073 m_col = 0;
00074 m_currentBlockRows = other.rows();
00075 eigen_assert(m_row+m_currentBlockRows<=m_xpr.rows()
00076 && "Too many rows passed to comma initializer (operator<<)");
00077 }
00078 eigen_assert(m_col<m_xpr.cols()
00079 && "Too many coefficients passed to comma initializer (operator<<)");
00080 eigen_assert(m_currentBlockRows==other.rows());
00081 if (OtherDerived::SizeAtCompileTime != Dynamic)
00082 m_xpr.template block<OtherDerived::RowsAtCompileTime != Dynamic ? OtherDerived::RowsAtCompileTime : 1,
00083 OtherDerived::ColsAtCompileTime != Dynamic ? OtherDerived::ColsAtCompileTime : 1>
00084 (m_row, m_col) = other;
00085 else
00086 m_xpr.block(m_row, m_col, other.rows(), other.cols()) = other;
00087 m_col += other.cols();
00088 return *this;
00089 }
00090
00091 inline ~CommaInitializer()
00092 {
00093 eigen_assert((m_row+m_currentBlockRows) == m_xpr.rows()
00094 && m_col == m_xpr.cols()
00095 && "Too few coefficients passed to comma initializer (operator<<)");
00096 }
00097
00105 inline XprType& finished() { return m_xpr; }
00106
00107 XprType& m_xpr;
00108 Index m_row;
00109 Index m_col;
00110 Index m_currentBlockRows;
00111 };
00112
00126 template<typename Derived>
00127 inline CommaInitializer<Derived> DenseBase<Derived>::operator<< (const Scalar& s)
00128 {
00129 return CommaInitializer<Derived>(*static_cast<Derived*>(this), s);
00130 }
00131
00133 template<typename Derived>
00134 template<typename OtherDerived>
00135 inline CommaInitializer<Derived>
00136 DenseBase<Derived>::operator<<(const DenseBase<OtherDerived>& other)
00137 {
00138 return CommaInitializer<Derived>(*static_cast<Derived *>(this), other);
00139 }
00140
00141 }
00142
00143 #endif // EIGEN_COMMAINITIALIZER_H