15 template<
typename Derived>
class RefBase;
16 template<
typename PlainObjectType,
int Options = 0,
17 typename StrideType =
typename internal::conditional<PlainObjectType::IsVectorAtCompileTime,InnerStride<1>,
OuterStride<> >::type >
class Ref;
90 template<
typename _PlainObjectType,
int _Options,
typename _Str
ideType>
91 struct traits<
Ref<_PlainObjectType, _Options, _StrideType> >
92 :
public traits<Map<_PlainObjectType, _Options, _StrideType> >
94 typedef _PlainObjectType PlainObjectType;
95 typedef _StrideType StrideType;
98 Flags = traits<Map<_PlainObjectType, _Options, _StrideType> >::Flags | NestByRefBit
101 template<
typename Derived>
struct match {
103 HasDirectAccess = internal::has_direct_access<Derived>::ret,
104 StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime || ((PlainObjectType::Flags&
RowMajorBit)==(Derived::Flags&
RowMajorBit)),
105 InnerStrideMatch =
int(StrideType::InnerStrideAtCompileTime)==int(Dynamic)
106 || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
107 || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
108 OuterStrideMatch = Derived::IsVectorAtCompileTime
109 ||
int(StrideType::OuterStrideAtCompileTime)==int(Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
110 AlignmentMatch = (_Options!=
Aligned) || ((PlainObjectType::Flags&
AlignedBit)==0) || ((traits<Derived>::Flags&AlignedBit)==
AlignedBit),
111 MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch
113 typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
118 template<
typename Derived>
119 struct traits<RefBase<Derived> > :
public traits<Derived> {};
123 template<
typename Derived>
class RefBase
124 :
public MapBase<Derived>
126 typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType;
127 typedef typename internal::traits<Derived>::StrideType StrideType;
131 typedef MapBase<Derived> Base;
132 EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
134 inline Index innerStride()
const
136 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
139 inline Index outerStride()
const
141 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
142 : IsVectorAtCompileTime ? this->size()
143 : int(Flags)&RowMajorBit ? this->cols()
148 : Base(0,RowsAtCompileTime==Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==Dynamic?0:ColsAtCompileTime),
150 m_stride(StrideType::OuterStrideAtCompileTime==Dynamic?0:StrideType::OuterStrideAtCompileTime,
151 StrideType::InnerStrideAtCompileTime==Dynamic?0:StrideType::InnerStrideAtCompileTime)
154 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase)
158 typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase;
160 template<typename Expression>
161 void construct(Expression& expr)
163 if(PlainObjectType::RowsAtCompileTime==1)
165 eigen_assert(expr.rows()==1 || expr.cols()==1);
166 ::new (static_cast<Base*>(
this)) Base(expr.data(), 1, expr.size());
168 else if(PlainObjectType::ColsAtCompileTime==1)
170 eigen_assert(expr.rows()==1 || expr.cols()==1);
171 ::new (static_cast<Base*>(
this)) Base(expr.data(), expr.size(), 1);
174 ::new (static_cast<Base*>(this)) Base(expr.data(), expr.rows(), expr.cols());
176 if(Expression::IsVectorAtCompileTime && (!PlainObjectType::IsVectorAtCompileTime) && ((Expression::Flags&RowMajorBit)!=(PlainObjectType::Flags&RowMajorBit)))
177 ::new (&m_stride) StrideBase(expr.innerStride(), StrideType::InnerStrideAtCompileTime==0?0:1);
179 ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(),
180 StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride());
187 template<typename PlainObjectType,
int Options, typename StrideType> class Ref
188 : public RefBase<Ref<PlainObjectType, Options, StrideType> >
190 typedef internal::traits<Ref> Traits;
191 template<
typename Derived>
192 inline Ref(
const PlainObjectBase<Derived>& expr);
195 typedef RefBase<Ref> Base;
196 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
199 #ifndef EIGEN_PARSED_BY_DOXYGEN
200 template<
typename Derived>
201 inline Ref(PlainObjectBase<Derived>& expr)
203 EIGEN_STATIC_ASSERT(static_cast<bool>(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
204 Base::construct(expr.derived());
206 template<
typename Derived>
207 inline Ref(
const DenseBase<Derived>& expr)
209 template<
typename Derived>
210 inline Ref(DenseBase<Derived>& expr)
213 EIGEN_STATIC_ASSERT(static_cast<bool>(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
214 EIGEN_STATIC_ASSERT(static_cast<bool>(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
215 enum { THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY = Derived::ThisConstantIsPrivateInPlainObjectBase};
216 Base::construct(expr.const_cast_derived());
219 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref)
224 template<
typename TPlainObjectType,
int Options,
typename Str
ideType>
class Ref<const TPlainObjectType, Options, StrideType>
225 :
public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
227 typedef internal::traits<Ref> Traits;
230 typedef RefBase<Ref> Base;
231 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
233 template<typename Derived>
234 inline Ref(const DenseBase<Derived>& expr)
239 construct(expr.derived(),
typename Traits::template match<Derived>::type());
244 template<
typename Expression>
245 void construct(
const Expression& expr,internal::true_type)
247 Base::construct(expr);
250 template<
typename Expression>
251 void construct(
const Expression& expr, internal::false_type)
253 m_object.lazyAssign(expr);
254 Base::construct(m_object);
258 TPlainObjectType m_object;
263 #endif // EIGEN_REF_H
A matrix or vector expression mapping an existing expressions.
Definition: Ref.h:17
Definition: Constants.h:194
Definition: Eigen_Colamd.h:54
const unsigned int RowMajorBit
Definition: Constants.h:53
Convenience specialization of Stride to specify only an outer stride See class Map for some examples...
Definition: Stride.h:97
const unsigned int AlignedBit
Definition: Constants.h:147