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),
38 AlignmentMatch = (int(traits<PlainObjectType>::Alignment)==int(
Unaligned)) || (
int(evaluator<Derived>::Alignment) >= int(Alignment)),
39 ScalarTypeMatch = internal::is_same<typename PlainObjectType::Scalar, typename Derived::Scalar>::value,
40 MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch && ScalarTypeMatch
42 typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
47 template<
typename Derived>
48 struct traits<RefBase<Derived> > :
public traits<Derived> {};
52 template<
typename Derived>
class RefBase
53 :
public MapBase<Derived>
55 typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType;
56 typedef typename internal::traits<Derived>::StrideType StrideType;
60 typedef MapBase<Derived> Base;
61 EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
63 EIGEN_DEVICE_FUNC inline
Index innerStride()
const 65 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
68 EIGEN_DEVICE_FUNC
inline Index outerStride()
const 70 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
71 : IsVectorAtCompileTime ? this->size()
72 : int(Flags)&RowMajorBit ? this->cols()
76 EIGEN_DEVICE_FUNC RefBase()
77 : Base(0,RowsAtCompileTime==
Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==
Dynamic?0:ColsAtCompileTime),
79 m_stride(StrideType::OuterStrideAtCompileTime==
Dynamic?0:StrideType::OuterStrideAtCompileTime,
80 StrideType::InnerStrideAtCompileTime==
Dynamic?0:StrideType::InnerStrideAtCompileTime)
83 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase)
87 typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase;
89 template<typename Expression>
90 EIGEN_DEVICE_FUNC
void construct(Expression& expr)
92 if(PlainObjectType::RowsAtCompileTime==1)
94 eigen_assert(expr.rows()==1 || expr.cols()==1);
95 ::new (static_cast<Base*>(
this)) Base(expr.data(), 1, expr.size());
97 else if(PlainObjectType::ColsAtCompileTime==1)
99 eigen_assert(expr.rows()==1 || expr.cols()==1);
100 ::new (static_cast<Base*>(
this)) Base(expr.data(), expr.size(), 1);
103 ::new (static_cast<Base*>(this)) Base(expr.data(), expr.rows(), expr.cols());
105 if(Expression::IsVectorAtCompileTime && (!PlainObjectType::IsVectorAtCompileTime) && ((Expression::Flags&RowMajorBit)!=(PlainObjectType::Flags&RowMajorBit)))
106 ::new (&m_stride) StrideBase(expr.innerStride(), StrideType::InnerStrideAtCompileTime==0?0:1);
108 ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(),
109 StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride());
184 template<typename PlainObjectType,
int Options, typename StrideType> class
Ref 185 : public RefBase<
Ref<PlainObjectType, Options, StrideType> >
188 typedef internal::traits<Ref> Traits;
189 template<
typename Derived>
191 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0);
194 typedef RefBase<Ref> Base;
195 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
198 #ifndef EIGEN_PARSED_BY_DOXYGEN 199 template<
typename Derived>
201 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
203 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
204 Base::construct(expr.derived());
206 template<
typename Derived>
208 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
211 template<
typename Derived>
215 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
216 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
217 EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
218 Base::construct(expr.const_cast_derived());
221 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref)
226 template<
typename TPlainObjectType,
int Options,
typename Str
ideType>
class Ref<const TPlainObjectType, Options, StrideType>
227 :
public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
229 typedef internal::traits<Ref> Traits;
232 typedef RefBase<Ref> Base;
233 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
235 template<
typename Derived>
237 typename internal::enable_if<
bool(Traits::template match<Derived>::ScalarTypeMatch),Derived>::type* = 0)
242 construct(expr.
derived(),
typename Traits::template match<Derived>::type());
245 EIGEN_DEVICE_FUNC
inline Ref(
const Ref& other) : Base(other) {
249 template<
typename OtherRef>
250 EIGEN_DEVICE_FUNC
inline Ref(
const RefBase<OtherRef>& other) {
251 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
256 template<
typename Expression>
257 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr,internal::true_type)
259 Base::construct(expr);
262 template<
typename Expression>
263 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr, internal::false_type)
265 internal::call_assignment_no_alias(m_object,expr,internal::assign_op<Scalar,Scalar>());
266 Base::construct(m_object);
270 TPlainObjectType m_object;
275 #endif // EIGEN_REF_H Namespace containing all symbols from the Eigen library.
Definition: Core:271
Derived & derived()
Definition: EigenBase.h:44
Definition: Constants.h:228
const unsigned int RowMajorBit
Definition: Constants.h:61
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: XprHelper.h:35
Dense storage base class for matrices and arrays.
Definition: PlainObjectBase.h:89
Ref(DenseBase< Derived > &expr)
Definition: Ref.h:212
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:184
Definition: Eigen_Colamd.h:50
const int Dynamic
Definition: Constants.h:21