17 template<
typename _PlainObjectType,
int _Options,
typename _Str
ideType>
18 struct traits<Ref<_PlainObjectType, _Options, _StrideType> >
19 :
public traits<Map<_PlainObjectType, _Options, _StrideType> >
21 typedef _PlainObjectType PlainObjectType;
22 typedef _StrideType StrideType;
25 Flags = traits<Map<_PlainObjectType, _Options, _StrideType> >::Flags | NestByRefBit,
26 Alignment = traits<Map<_PlainObjectType, _Options, _StrideType> >::Alignment
29 template<
typename Derived>
struct match {
31 HasDirectAccess = internal::has_direct_access<Derived>::ret,
32 StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime || ((PlainObjectType::Flags&
RowMajorBit)==(Derived::Flags&
RowMajorBit)),
33 InnerStrideMatch =
int(StrideType::InnerStrideAtCompileTime)==int(
Dynamic)
34 || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
35 || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
36 OuterStrideMatch = Derived::IsVectorAtCompileTime
37 ||
int(StrideType::OuterStrideAtCompileTime)==int(
Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
43 DerivedAlignment = int(evaluator<Derived>::Alignment),
44 AlignmentMatch = (int(traits<PlainObjectType>::Alignment)==int(
Unaligned)) || (DerivedAlignment >=
int(Alignment)),
45 ScalarTypeMatch = internal::is_same<typename PlainObjectType::Scalar, typename Derived::Scalar>::value,
46 MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch && ScalarTypeMatch
48 typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
53 template<
typename Derived>
54 struct traits<RefBase<Derived> > :
public traits<Derived> {};
58 template<
typename Derived>
class RefBase
59 :
public MapBase<Derived>
61 typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType;
62 typedef typename internal::traits<Derived>::StrideType StrideType;
66 typedef MapBase<Derived> Base;
67 EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
69 EIGEN_DEVICE_FUNC
inline Index innerStride()
const
71 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
74 EIGEN_DEVICE_FUNC
inline Index outerStride()
const
76 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
77 : IsVectorAtCompileTime ? this->size()
82 EIGEN_DEVICE_FUNC RefBase()
83 : Base(0,RowsAtCompileTime==
Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==
Dynamic?0:ColsAtCompileTime),
85 m_stride(StrideType::OuterStrideAtCompileTime==
Dynamic?0:StrideType::OuterStrideAtCompileTime,
86 StrideType::InnerStrideAtCompileTime==
Dynamic?0:StrideType::InnerStrideAtCompileTime)
89 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase)
93 typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase;
95 template<
typename Expression>
96 EIGEN_DEVICE_FUNC
void construct(Expression& expr)
98 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(PlainObjectType,Expression);
100 if(PlainObjectType::RowsAtCompileTime==1)
102 eigen_assert(expr.rows()==1 || expr.cols()==1);
103 ::new (
static_cast<Base*
>(
this)) Base(expr.data(), 1, expr.size());
105 else if(PlainObjectType::ColsAtCompileTime==1)
107 eigen_assert(expr.rows()==1 || expr.cols()==1);
108 ::new (
static_cast<Base*
>(
this)) Base(expr.data(), expr.size(), 1);
111 ::new (static_cast<Base*>(this)) Base(expr.data(), expr.rows(), expr.cols());
113 if(Expression::IsVectorAtCompileTime && (!PlainObjectType::IsVectorAtCompileTime) && ((Expression::Flags&
RowMajorBit)!=(PlainObjectType::Flags&
RowMajorBit)))
114 ::new (&m_stride) StrideBase(expr.innerStride(), StrideType::InnerStrideAtCompileTime==0?0:1);
116 ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(),
117 StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride());
192 template<typename PlainObjectType,
int Options, typename StrideType> class
Ref
193 : public RefBase<
Ref<PlainObjectType, Options, StrideType> >
196 typedef internal::traits<Ref> Traits;
197 template<
typename Derived>
199 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0);
202 typedef RefBase<Ref> Base;
203 EIGEN_DENSE_PUBLIC_INTERFACE(
Ref)
206 #ifndef EIGEN_PARSED_BY_DOXYGEN
207 template<
typename Derived>
209 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
211 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
212 Base::construct(expr.derived());
214 template<
typename Derived>
216 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
219 template<
typename Derived>
223 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
224 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
225 EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
226 Base::construct(expr.const_cast_derived());
229 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Ref)
234 template<
typename TPlainObjectType,
int Options,
typename Str
ideType>
class Ref<const TPlainObjectType, Options, StrideType>
235 :
public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
237 typedef internal::traits<Ref> Traits;
240 typedef RefBase<Ref> Base;
241 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
243 template<
typename Derived>
244 EIGEN_DEVICE_FUNC
inline Ref(
const DenseBase<Derived>& expr,
245 typename internal::enable_if<
bool(Traits::template match<Derived>::ScalarTypeMatch),Derived>::type* = 0)
250 construct(expr.derived(),
typename Traits::template match<Derived>::type());
253 EIGEN_DEVICE_FUNC
inline Ref(
const Ref& other) : Base(other) {
257 template<
typename OtherRef>
258 EIGEN_DEVICE_FUNC
inline Ref(
const RefBase<OtherRef>& other) {
259 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
264 template<
typename Expression>
265 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr,internal::true_type)
267 Base::construct(expr);
270 template<
typename Expression>
271 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr, internal::false_type)
273 internal::call_assignment_no_alias(m_object,expr,internal::assign_op<Scalar,Scalar>());
274 Base::construct(m_object);
278 TPlainObjectType m_object;
283 #endif // EIGEN_REF_H