87 template<
typename _PlainObjectType,
int _Options,
typename _Str
ideType>
88 struct traits<Ref<_PlainObjectType, _Options, _StrideType> >
89 :
public traits<Map<_PlainObjectType, _Options, _StrideType> >
91 typedef _PlainObjectType PlainObjectType;
92 typedef _StrideType StrideType;
95 Flags = traits<Map<_PlainObjectType, _Options, _StrideType> >::Flags | NestByRefBit,
96 Alignment = traits<Map<_PlainObjectType, _Options, _StrideType> >::Alignment
99 template<
typename Derived>
struct match {
101 HasDirectAccess = internal::has_direct_access<Derived>::ret,
102 StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime || ((PlainObjectType::Flags&
RowMajorBit)==(Derived::Flags&
RowMajorBit)),
103 InnerStrideMatch =
int(StrideType::InnerStrideAtCompileTime)==int(Dynamic)
104 || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
105 || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
106 OuterStrideMatch = Derived::IsVectorAtCompileTime
107 ||
int(StrideType::OuterStrideAtCompileTime)==int(Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
108 AlignmentMatch = (int(traits<PlainObjectType>::Alignment)==int(
Unaligned)) || (
int(evaluator<Derived>::Alignment) >= int(Alignment)),
109 ScalarTypeMatch = internal::is_same<typename PlainObjectType::Scalar, typename Derived::Scalar>::value,
110 MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch && ScalarTypeMatch
112 typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
117 template<
typename Derived>
118 struct traits<RefBase<Derived> > :
public traits<Derived> {};
122 template<
typename Derived>
class RefBase
123 :
public MapBase<Derived>
125 typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType;
126 typedef typename internal::traits<Derived>::StrideType StrideType;
130 typedef MapBase<Derived> Base;
131 EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
133 EIGEN_DEVICE_FUNC inline Index innerStride()
const
135 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
138 EIGEN_DEVICE_FUNC
inline Index outerStride()
const
140 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
141 : IsVectorAtCompileTime ? this->size()
142 : int(Flags)&RowMajorBit ? this->cols()
146 EIGEN_DEVICE_FUNC RefBase()
147 : Base(0,RowsAtCompileTime==Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==Dynamic?0:ColsAtCompileTime),
149 m_stride(StrideType::OuterStrideAtCompileTime==Dynamic?0:StrideType::OuterStrideAtCompileTime,
150 StrideType::InnerStrideAtCompileTime==Dynamic?0:StrideType::InnerStrideAtCompileTime)
153 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase)
157 typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase;
159 template<typename Expression>
160 EIGEN_DEVICE_FUNC
void construct(Expression& expr)
162 if(PlainObjectType::RowsAtCompileTime==1)
164 eigen_assert(expr.rows()==1 || expr.cols()==1);
165 ::new (static_cast<Base*>(
this)) Base(expr.data(), 1, expr.size());
167 else if(PlainObjectType::ColsAtCompileTime==1)
169 eigen_assert(expr.rows()==1 || expr.cols()==1);
170 ::new (static_cast<Base*>(
this)) Base(expr.data(), expr.size(), 1);
173 ::new (static_cast<Base*>(this)) Base(expr.data(), expr.rows(), expr.cols());
175 if(Expression::IsVectorAtCompileTime && (!PlainObjectType::IsVectorAtCompileTime) && ((Expression::Flags&RowMajorBit)!=(PlainObjectType::Flags&RowMajorBit)))
176 ::new (&m_stride) StrideBase(expr.innerStride(), StrideType::InnerStrideAtCompileTime==0?0:1);
178 ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(),
179 StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride());
186 template<typename PlainObjectType,
int Options, typename StrideType> class
Ref
187 : public RefBase<
Ref<PlainObjectType, Options, StrideType> >
190 typedef internal::traits<Ref> Traits;
191 template<
typename Derived>
193 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0);
196 typedef RefBase<Ref> Base;
197 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
200 #ifndef EIGEN_PARSED_BY_DOXYGEN
201 template<
typename Derived>
203 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
205 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
206 Base::construct(expr.derived());
208 template<
typename Derived>
210 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
212 template<
typename Derived>
216 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
217 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
218 EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
219 Base::construct(expr.const_cast_derived());
222 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref)
227 template<
typename TPlainObjectType,
int Options,
typename Str
ideType>
class Ref<const TPlainObjectType, Options, StrideType>
228 :
public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
230 typedef internal::traits<Ref> Traits;
233 typedef RefBase<Ref> Base;
234 EIGEN_DENSE_PUBLIC_INTERFACE(
Ref)
236 template<typename Derived>
237 EIGEN_DEVICE_FUNC inline
Ref(const
DenseBase<Derived>& expr,
238 typename
internal::enable_if<
bool(Traits::template match<Derived>::ScalarTypeMatch),Derived>::type* = 0)
243 construct(expr.derived(),
typename Traits::template match<Derived>::type());
246 EIGEN_DEVICE_FUNC
inline Ref(
const Ref& other) : Base(other) {
250 template<
typename OtherRef>
251 EIGEN_DEVICE_FUNC
inline Ref(
const RefBase<OtherRef>& other) {
252 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
257 template<
typename Expression>
258 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr,internal::true_type)
260 Base::construct(expr);
263 template<
typename Expression>
264 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr, internal::false_type)
266 internal::call_assignment_no_alias(m_object,expr,internal::assign_op<Scalar>());
267 Base::construct(m_object);
271 TPlainObjectType m_object;
276 #endif // EIGEN_REF_H
Definition: Constants.h:220
const unsigned int RowMajorBit
Definition: Constants.h:53
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
Dense storage base class for matrices and arrays.
Definition: PlainObjectBase.h:88
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:186
Definition: Eigen_Colamd.h:54