MapBase.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_MAPBASE_H
00012 #define EIGEN_MAPBASE_H
00013 
00014 #define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \
00015       EIGEN_STATIC_ASSERT((int(internal::traits<Derived>::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \
00016                           YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT)
00017 
00018 namespace Eigen { 
00019 
00027 template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
00028   : public internal::dense_xpr_base<Derived>::type
00029 {
00030   public:
00031 
00032     typedef typename internal::dense_xpr_base<Derived>::type Base;
00033     enum {
00034       RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
00035       ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
00036       SizeAtCompileTime = Base::SizeAtCompileTime
00037     };
00038 
00039     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00040     typedef typename internal::traits<Derived>::Index Index;
00041     typedef typename internal::traits<Derived>::Scalar Scalar;
00042     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00043     typedef typename NumTraits<Scalar>::Real RealScalar;
00044     typedef typename internal::conditional<
00045                          bool(internal::is_lvalue<Derived>::value),
00046                          Scalar *,
00047                          const Scalar *>::type
00048                      PointerType;
00049 
00050     using Base::derived;
00051 //    using Base::RowsAtCompileTime;
00052 //    using Base::ColsAtCompileTime;
00053 //    using Base::SizeAtCompileTime;
00054     using Base::MaxRowsAtCompileTime;
00055     using Base::MaxColsAtCompileTime;
00056     using Base::MaxSizeAtCompileTime;
00057     using Base::IsVectorAtCompileTime;
00058     using Base::Flags;
00059     using Base::IsRowMajor;
00060 
00061     using Base::rows;
00062     using Base::cols;
00063     using Base::size;
00064     using Base::coeff;
00065     using Base::coeffRef;
00066     using Base::lazyAssign;
00067     using Base::eval;
00068 
00069     using Base::innerStride;
00070     using Base::outerStride;
00071     using Base::rowStride;
00072     using Base::colStride;
00073 
00074     // bug 217 - compile error on ICC 11.1
00075     using Base::operator=;
00076 
00077     typedef typename Base::CoeffReturnType CoeffReturnType;
00078 
00079     inline Index rows() const { return m_rows.value(); }
00080     inline Index cols() const { return m_cols.value(); }
00081 
00088     inline const Scalar* data() const { return m_data; }
00089 
00090     inline const Scalar& coeff(Index row, Index col) const
00091     {
00092       return m_data[col * colStride() + row * rowStride()];
00093     }
00094 
00095     inline const Scalar& coeff(Index index) const
00096     {
00097       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00098       return m_data[index * innerStride()];
00099     }
00100 
00101     inline const Scalar& coeffRef(Index row, Index col) const
00102     {
00103       return this->m_data[col * colStride() + row * rowStride()];
00104     }
00105 
00106     inline const Scalar& coeffRef(Index index) const
00107     {
00108       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00109       return this->m_data[index * innerStride()];
00110     }
00111 
00112     template<int LoadMode>
00113     inline PacketScalar packet(Index row, Index col) const
00114     {
00115       return internal::ploadt<PacketScalar, LoadMode>
00116                (m_data + (col * colStride() + row * rowStride()));
00117     }
00118 
00119     template<int LoadMode>
00120     inline PacketScalar packet(Index index) const
00121     {
00122       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00123       return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
00124     }
00125 
00126     inline MapBase(PointerType data) : m_data(data), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
00127     {
00128       EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
00129       checkSanity();
00130     }
00131 
00132     inline MapBase(PointerType data, Index size)
00133             : m_data(data),
00134               m_rows(RowsAtCompileTime == Dynamic ? size : Index(RowsAtCompileTime)),
00135               m_cols(ColsAtCompileTime == Dynamic ? size : Index(ColsAtCompileTime))
00136     {
00137       EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00138       eigen_assert(size >= 0);
00139       eigen_assert(data == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == size);
00140       checkSanity();
00141     }
00142 
00143     inline MapBase(PointerType data, Index rows, Index cols)
00144             : m_data(data), m_rows(rows), m_cols(cols)
00145     {
00146       eigen_assert( (data == 0)
00147               || (   rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
00148                   && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
00149       checkSanity();
00150     }
00151 
00152   protected:
00153 
00154     void checkSanity() const
00155     {
00156       EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(internal::traits<Derived>::Flags&PacketAccessBit,
00157                                         internal::inner_stride_at_compile_time<Derived>::ret==1),
00158                           PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
00159       eigen_assert(EIGEN_IMPLIES(internal::traits<Derived>::Flags&AlignedBit, (size_t(m_data) % 16) == 0)
00160                    && "data is not aligned");
00161     }
00162 
00163     PointerType m_data;
00164     const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
00165     const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
00166 };
00167 
00168 template<typename Derived> class MapBase<Derived, WriteAccessors>
00169   : public MapBase<Derived, ReadOnlyAccessors>
00170 {
00171   public:
00172 
00173     typedef MapBase<Derived, ReadOnlyAccessors> Base;
00174 
00175     typedef typename Base::Scalar Scalar;
00176     typedef typename Base::PacketScalar PacketScalar;
00177     typedef typename Base::Index Index;
00178     typedef typename Base::PointerType PointerType;
00179 
00180     using Base::derived;
00181     using Base::rows;
00182     using Base::cols;
00183     using Base::size;
00184     using Base::coeff;
00185     using Base::coeffRef;
00186 
00187     using Base::innerStride;
00188     using Base::outerStride;
00189     using Base::rowStride;
00190     using Base::colStride;
00191 
00192     typedef typename internal::conditional<
00193                     internal::is_lvalue<Derived>::value,
00194                     Scalar,
00195                     const Scalar
00196                   >::type ScalarWithConstIfNotLvalue;
00197 
00198     inline const Scalar* data() const { return this->m_data; }
00199     inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
00200 
00201     inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
00202     {
00203       return this->m_data[col * colStride() + row * rowStride()];
00204     }
00205 
00206     inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
00207     {
00208       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00209       return this->m_data[index * innerStride()];
00210     }
00211 
00212     template<int StoreMode>
00213     inline void writePacket(Index row, Index col, const PacketScalar& x)
00214     {
00215       internal::pstoret<Scalar, PacketScalar, StoreMode>
00216                (this->m_data + (col * colStride() + row * rowStride()), x);
00217     }
00218 
00219     template<int StoreMode>
00220     inline void writePacket(Index index, const PacketScalar& x)
00221     {
00222       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00223       internal::pstoret<Scalar, PacketScalar, StoreMode>
00224                 (this->m_data + index * innerStride(), x);
00225     }
00226 
00227     explicit inline MapBase(PointerType data) : Base(data) {}
00228     inline MapBase(PointerType data, Index size) : Base(data, size) {}
00229     inline MapBase(PointerType data, Index rows, Index cols) : Base(data, rows, cols) {}
00230 
00231     Derived& operator=(const MapBase& other)
00232     {
00233       Base::Base::operator=(other);
00234       return derived();
00235     }
00236 
00237     using Base::Base::operator=;
00238 };
00239 
00240 } // end namespace Eigen
00241 
00242 #endif // EIGEN_MAPBASE_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:25:15