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;
100 template<
typename Derived>
struct match {
102 HasDirectAccess = internal::has_direct_access<Derived>::ret,
103 StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || ((PlainObjectType::Flags&
RowMajorBit)==(Derived::Flags&
RowMajorBit)),
104 InnerStrideMatch =
int(StrideType::InnerStrideAtCompileTime)==int(
Dynamic)
105 || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
106 || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
107 OuterStrideMatch = Derived::IsVectorAtCompileTime
108 ||
int(StrideType::OuterStrideAtCompileTime)==int(
Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
109 AlignmentMatch = (_Options!=
Aligned) || ((PlainObjectType::Flags&
AlignedBit)==0) || ((traits<Derived>::Flags&AlignedBit)==
AlignedBit),
110 MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch
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 inline Index innerStride()
const
135 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
138 inline Index outerStride()
const
140 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
141 : IsVectorAtCompileTime ? this->size()
142 : int(Flags)&RowMajorBit ? this->cols()
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 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());
174 ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(),
175 StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride());
182 template<typename PlainObjectType,
int Options, typename StrideType> class Ref
183 : public RefBase<Ref<PlainObjectType, Options, StrideType> >
185 typedef internal::traits<Ref> Traits;
188 typedef RefBase<Ref> Base;
189 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
192 #ifndef EIGEN_PARSED_BY_DOXYGEN
193 template<
typename Derived>
194 inline Ref(PlainObjectBase<Derived>& expr,
195 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
197 Base::construct(expr);
199 template<
typename Derived>
200 inline Ref(
const DenseBase<Derived>& expr,
201 typename internal::enable_if<
bool(internal::is_lvalue<Derived>::value&&
bool(Traits::template match<Derived>::MatchAtCompileTime)),Derived>::type* = 0,
202 int = Derived::ThisConstantIsPrivateInPlainObjectBase)
204 template<
typename Derived>
205 inline Ref(DenseBase<Derived>& expr)
208 Base::construct(expr.const_cast_derived());
211 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref)
216 template<
typename TPlainObjectType,
int Options,
typename Str
ideType>
class Ref<const TPlainObjectType, Options, StrideType>
217 :
public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
219 typedef internal::traits<Ref> Traits;
222 typedef RefBase<Ref> Base;
223 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
225 template<typename Derived>
226 inline Ref(const DenseBase<Derived>& expr)
231 construct(expr.derived(),
typename Traits::template match<Derived>::type());
236 template<
typename Expression>
237 void construct(
const Expression& expr,internal::true_type)
239 Base::construct(expr);
242 template<
typename Expression>
243 void construct(
const Expression& expr, internal::false_type)
245 m_object.lazyAssign(expr);
246 Base::construct(m_object);
250 TPlainObjectType m_object;
255 #endif // EIGEN_REF_H