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 IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime,
32 HasDirectAccess = internal::has_direct_access<Derived>::ret,
33 StorageOrderMatch = IsVectorAtCompileTime || ((PlainObjectType::Flags&
RowMajorBit)==(Derived::Flags&
RowMajorBit)),
34 InnerStrideMatch =
int(StrideType::InnerStrideAtCompileTime)==int(
Dynamic)
35 || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
36 || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
37 OuterStrideMatch = IsVectorAtCompileTime
38 ||
int(StrideType::OuterStrideAtCompileTime)==int(
Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
44 DerivedAlignment = int(evaluator<Derived>::Alignment),
45 AlignmentMatch = (int(traits<PlainObjectType>::Alignment)==int(
Unaligned)) || (DerivedAlignment >=
int(Alignment)),
46 ScalarTypeMatch = internal::is_same<typename PlainObjectType::Scalar, typename Derived::Scalar>::value,
47 MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch && ScalarTypeMatch
49 typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
54 template<
typename Derived>
55 struct traits<RefBase<Derived> > :
public traits<Derived> {};
59 template<
typename Derived>
class RefBase
60 :
public MapBase<Derived>
62 typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType;
63 typedef typename internal::traits<Derived>::StrideType StrideType;
67 typedef MapBase<Derived> Base;
68 EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
70 EIGEN_DEVICE_FUNC
inline Index innerStride()
const
72 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
75 EIGEN_DEVICE_FUNC
inline Index outerStride()
const
77 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
78 : IsVectorAtCompileTime ? this->size()
83 EIGEN_DEVICE_FUNC RefBase()
84 : Base(0,RowsAtCompileTime==
Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==
Dynamic?0:ColsAtCompileTime),
86 m_stride(StrideType::OuterStrideAtCompileTime==
Dynamic?0:StrideType::OuterStrideAtCompileTime,
87 StrideType::InnerStrideAtCompileTime==
Dynamic?0:StrideType::InnerStrideAtCompileTime)
90 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase)
94 typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase;
96 template<
typename Expression>
97 EIGEN_DEVICE_FUNC
void construct(Expression& expr)
99 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(PlainObjectType,Expression);
101 if(PlainObjectType::RowsAtCompileTime==1)
103 eigen_assert(expr.rows()==1 || expr.cols()==1);
104 ::new (
static_cast<Base*
>(
this)) Base(expr.data(), 1, expr.size());
106 else if(PlainObjectType::ColsAtCompileTime==1)
108 eigen_assert(expr.rows()==1 || expr.cols()==1);
109 ::new (
static_cast<Base*
>(
this)) Base(expr.data(), expr.size(), 1);
112 ::new (static_cast<Base*>(this)) Base(expr.data(), expr.rows(), expr.cols());
114 if(Expression::IsVectorAtCompileTime && (!PlainObjectType::IsVectorAtCompileTime) && ((Expression::Flags&
RowMajorBit)!=(PlainObjectType::Flags&
RowMajorBit)))
115 ::new (&m_stride) StrideBase(expr.innerStride(), StrideType::InnerStrideAtCompileTime==0?0:1);
117 ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(),
118 StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride());
193 template<typename PlainObjectType,
int Options, typename StrideType> class
Ref
194 : public RefBase<
Ref<PlainObjectType, Options, StrideType> >
197 typedef internal::traits<Ref> Traits;
198 template<
typename Derived>
200 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0);
203 typedef RefBase<Ref> Base;
204 EIGEN_DENSE_PUBLIC_INTERFACE(
Ref)
207 #ifndef EIGEN_PARSED_BY_DOXYGEN
208 template<
typename Derived>
210 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
212 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
213 Base::construct(expr.derived());
215 template<
typename Derived>
217 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
220 template<
typename Derived>
224 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
225 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
226 EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
227 Base::construct(expr.const_cast_derived());
230 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Ref)
235 template<
typename TPlainObjectType,
int Options,
typename Str
ideType>
class Ref<const TPlainObjectType, Options, StrideType>
236 :
public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
238 typedef internal::traits<Ref> Traits;
241 typedef RefBase<Ref> Base;
242 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
244 template<
typename Derived>
245 EIGEN_DEVICE_FUNC
inline Ref(
const DenseBase<Derived>& expr,
246 typename internal::enable_if<
bool(Traits::template match<Derived>::ScalarTypeMatch),Derived>::type* = 0)
251 construct(expr.derived(),
typename Traits::template match<Derived>::type());
254 EIGEN_DEVICE_FUNC
inline Ref(
const Ref& other) : Base(other) {
258 template<
typename OtherRef>
259 EIGEN_DEVICE_FUNC
inline Ref(
const RefBase<OtherRef>& other) {
260 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
265 template<
typename Expression>
266 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr,internal::true_type)
268 Base::construct(expr);
271 template<
typename Expression>
272 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr, internal::false_type)
274 internal::call_assignment_no_alias(m_object,expr,internal::assign_op<Scalar,Scalar>());
275 Base::construct(m_object);
279 TPlainObjectType m_object;
284 #endif // EIGEN_REF_H