Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef EIGEN_ARRAYWRAPPER_H
00011 #define EIGEN_ARRAYWRAPPER_H
00012
00013 namespace Eigen {
00014
00026 namespace internal {
00027 template<typename ExpressionType>
00028 struct traits<ArrayWrapper<ExpressionType> >
00029 : public traits<typename remove_all<typename ExpressionType::Nested>::type >
00030 {
00031 typedef ArrayXpr XprKind;
00032
00033 enum {
00034 Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
00035 Flags = Flags0 & ~NestByRefBit
00036 };
00037 };
00038 }
00039
00040 template<typename ExpressionType>
00041 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
00042 {
00043 public:
00044 typedef ArrayBase<ArrayWrapper> Base;
00045 EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
00046 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
00047
00048 typedef typename internal::conditional<
00049 internal::is_lvalue<ExpressionType>::value,
00050 Scalar,
00051 const Scalar
00052 >::type ScalarWithConstIfNotLvalue;
00053
00054 typedef typename internal::nested<ExpressionType>::type NestedExpressionType;
00055
00056 inline ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
00057
00058 inline Index rows() const { return m_expression.rows(); }
00059 inline Index cols() const { return m_expression.cols(); }
00060 inline Index outerStride() const { return m_expression.outerStride(); }
00061 inline Index innerStride() const { return m_expression.innerStride(); }
00062
00063 inline ScalarWithConstIfNotLvalue* data() { return m_expression.const_cast_derived().data(); }
00064 inline const Scalar* data() const { return m_expression.data(); }
00065
00066 inline CoeffReturnType coeff(Index rowId, Index colId) const
00067 {
00068 return m_expression.coeff(rowId, colId);
00069 }
00070
00071 inline Scalar& coeffRef(Index rowId, Index colId)
00072 {
00073 return m_expression.const_cast_derived().coeffRef(rowId, colId);
00074 }
00075
00076 inline const Scalar& coeffRef(Index rowId, Index colId) const
00077 {
00078 return m_expression.const_cast_derived().coeffRef(rowId, colId);
00079 }
00080
00081 inline CoeffReturnType coeff(Index index) const
00082 {
00083 return m_expression.coeff(index);
00084 }
00085
00086 inline Scalar& coeffRef(Index index)
00087 {
00088 return m_expression.const_cast_derived().coeffRef(index);
00089 }
00090
00091 inline const Scalar& coeffRef(Index index) const
00092 {
00093 return m_expression.const_cast_derived().coeffRef(index);
00094 }
00095
00096 template<int LoadMode>
00097 inline const PacketScalar packet(Index rowId, Index colId) const
00098 {
00099 return m_expression.template packet<LoadMode>(rowId, colId);
00100 }
00101
00102 template<int LoadMode>
00103 inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
00104 {
00105 m_expression.const_cast_derived().template writePacket<LoadMode>(rowId, colId, val);
00106 }
00107
00108 template<int LoadMode>
00109 inline const PacketScalar packet(Index index) const
00110 {
00111 return m_expression.template packet<LoadMode>(index);
00112 }
00113
00114 template<int LoadMode>
00115 inline void writePacket(Index index, const PacketScalar& val)
00116 {
00117 m_expression.const_cast_derived().template writePacket<LoadMode>(index, val);
00118 }
00119
00120 template<typename Dest>
00121 inline void evalTo(Dest& dst) const { dst = m_expression; }
00122
00123 const typename internal::remove_all<NestedExpressionType>::type&
00124 nestedExpression() const
00125 {
00126 return m_expression;
00127 }
00128
00131 void resize(Index newSize) { m_expression.const_cast_derived().resize(newSize); }
00134 void resize(Index nbRows, Index nbCols) { m_expression.const_cast_derived().resize(nbRows,nbCols); }
00135
00136 protected:
00137 NestedExpressionType m_expression;
00138 };
00139
00151 namespace internal {
00152 template<typename ExpressionType>
00153 struct traits<MatrixWrapper<ExpressionType> >
00154 : public traits<typename remove_all<typename ExpressionType::Nested>::type >
00155 {
00156 typedef MatrixXpr XprKind;
00157
00158 enum {
00159 Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
00160 Flags = Flags0 & ~NestByRefBit
00161 };
00162 };
00163 }
00164
00165 template<typename ExpressionType>
00166 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
00167 {
00168 public:
00169 typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
00170 EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
00171 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
00172
00173 typedef typename internal::conditional<
00174 internal::is_lvalue<ExpressionType>::value,
00175 Scalar,
00176 const Scalar
00177 >::type ScalarWithConstIfNotLvalue;
00178
00179 typedef typename internal::nested<ExpressionType>::type NestedExpressionType;
00180
00181 inline MatrixWrapper(ExpressionType& a_matrix) : m_expression(a_matrix) {}
00182
00183 inline Index rows() const { return m_expression.rows(); }
00184 inline Index cols() const { return m_expression.cols(); }
00185 inline Index outerStride() const { return m_expression.outerStride(); }
00186 inline Index innerStride() const { return m_expression.innerStride(); }
00187
00188 inline ScalarWithConstIfNotLvalue* data() { return m_expression.const_cast_derived().data(); }
00189 inline const Scalar* data() const { return m_expression.data(); }
00190
00191 inline CoeffReturnType coeff(Index rowId, Index colId) const
00192 {
00193 return m_expression.coeff(rowId, colId);
00194 }
00195
00196 inline Scalar& coeffRef(Index rowId, Index colId)
00197 {
00198 return m_expression.const_cast_derived().coeffRef(rowId, colId);
00199 }
00200
00201 inline const Scalar& coeffRef(Index rowId, Index colId) const
00202 {
00203 return m_expression.derived().coeffRef(rowId, colId);
00204 }
00205
00206 inline CoeffReturnType coeff(Index index) const
00207 {
00208 return m_expression.coeff(index);
00209 }
00210
00211 inline Scalar& coeffRef(Index index)
00212 {
00213 return m_expression.const_cast_derived().coeffRef(index);
00214 }
00215
00216 inline const Scalar& coeffRef(Index index) const
00217 {
00218 return m_expression.const_cast_derived().coeffRef(index);
00219 }
00220
00221 template<int LoadMode>
00222 inline const PacketScalar packet(Index rowId, Index colId) const
00223 {
00224 return m_expression.template packet<LoadMode>(rowId, colId);
00225 }
00226
00227 template<int LoadMode>
00228 inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
00229 {
00230 m_expression.const_cast_derived().template writePacket<LoadMode>(rowId, colId, val);
00231 }
00232
00233 template<int LoadMode>
00234 inline const PacketScalar packet(Index index) const
00235 {
00236 return m_expression.template packet<LoadMode>(index);
00237 }
00238
00239 template<int LoadMode>
00240 inline void writePacket(Index index, const PacketScalar& val)
00241 {
00242 m_expression.const_cast_derived().template writePacket<LoadMode>(index, val);
00243 }
00244
00245 const typename internal::remove_all<NestedExpressionType>::type&
00246 nestedExpression() const
00247 {
00248 return m_expression;
00249 }
00250
00253 void resize(Index newSize) { m_expression.const_cast_derived().resize(newSize); }
00256 void resize(Index nbRows, Index nbCols) { m_expression.const_cast_derived().resize(nbRows,nbCols); }
00257
00258 protected:
00259 NestedExpressionType m_expression;
00260 };
00261
00262 }
00263
00264 #endif // EIGEN_ARRAYWRAPPER_H