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 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_MAPBASE_H
00027 #define EIGEN_MAPBASE_H
00028 
00029 #define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \
00030       EIGEN_STATIC_ASSERT((int(internal::traits<Derived>::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \
00031                           YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT)
00032 
00033 
00041 template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
00042   : public internal::dense_xpr_base<Derived>::type
00043 {
00044   public:
00045 
00046     typedef typename internal::dense_xpr_base<Derived>::type Base;
00047     enum {
00048       RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
00049       ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
00050       SizeAtCompileTime = Base::SizeAtCompileTime
00051     };
00052 
00053     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00054     typedef typename internal::traits<Derived>::Index Index;
00055     typedef typename internal::traits<Derived>::Scalar Scalar;
00056     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00057     typedef typename NumTraits<Scalar>::Real RealScalar;
00058     typedef typename internal::conditional<
00059                          bool(internal::is_lvalue<Derived>::value),
00060                          Scalar *,
00061                          const Scalar *>::type
00062                      PointerType;
00063 
00064     using Base::derived;
00065 //    using Base::RowsAtCompileTime;
00066 //    using Base::ColsAtCompileTime;
00067 //    using Base::SizeAtCompileTime;
00068     using Base::MaxRowsAtCompileTime;
00069     using Base::MaxColsAtCompileTime;
00070     using Base::MaxSizeAtCompileTime;
00071     using Base::IsVectorAtCompileTime;
00072     using Base::Flags;
00073     using Base::IsRowMajor;
00074 
00075     using Base::rows;
00076     using Base::cols;
00077     using Base::size;
00078     using Base::coeff;
00079     using Base::coeffRef;
00080     using Base::lazyAssign;
00081     using Base::eval;
00082 
00083     using Base::innerStride;
00084     using Base::outerStride;
00085     using Base::rowStride;
00086     using Base::colStride;
00087 
00088     // bug 217 - compile error on ICC 11.1
00089     using Base::operator=;
00090 
00091     typedef typename Base::CoeffReturnType CoeffReturnType;
00092 
00093     inline Index rows() const { return m_rows.value(); }
00094     inline Index cols() const { return m_cols.value(); }
00095 
00102     inline const Scalar* data() const { return m_data; }
00103 
00104     inline const Scalar& coeff(Index row, Index col) const
00105     {
00106       return m_data[col * colStride() + row * rowStride()];
00107     }
00108 
00109     inline const Scalar& coeff(Index index) const
00110     {
00111       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00112       return m_data[index * innerStride()];
00113     }
00114 
00115     inline const Scalar& coeffRef(Index row, Index col) const
00116     {
00117       return this->m_data[col * colStride() + row * rowStride()];
00118     }
00119 
00120     inline const Scalar& coeffRef(Index index) const
00121     {
00122       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00123       return this->m_data[index * innerStride()];
00124     }
00125 
00126     template<int LoadMode>
00127     inline PacketScalar packet(Index row, Index col) const
00128     {
00129       return internal::ploadt<PacketScalar, LoadMode>
00130                (m_data + (col * colStride() + row * rowStride()));
00131     }
00132 
00133     template<int LoadMode>
00134     inline PacketScalar packet(Index index) const
00135     {
00136       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00137       return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
00138     }
00139 
00140     inline MapBase(PointerType data) : m_data(data), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
00141     {
00142       EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
00143       checkSanity();
00144     }
00145 
00146     inline MapBase(PointerType data, Index size)
00147             : m_data(data),
00148               m_rows(RowsAtCompileTime == Dynamic ? size : Index(RowsAtCompileTime)),
00149               m_cols(ColsAtCompileTime == Dynamic ? size : Index(ColsAtCompileTime))
00150     {
00151       EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00152       eigen_assert(size >= 0);
00153       eigen_assert(data == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == size);
00154       checkSanity();
00155     }
00156 
00157     inline MapBase(PointerType data, Index rows, Index cols)
00158             : m_data(data), m_rows(rows), m_cols(cols)
00159     {
00160       eigen_assert( (data == 0)
00161               || (   rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
00162                   && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
00163       checkSanity();
00164     }
00165 
00166   protected:
00167 
00168     void checkSanity() const
00169     {
00170       EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(internal::traits<Derived>::Flags&PacketAccessBit,
00171                                         internal::inner_stride_at_compile_time<Derived>::ret==1),
00172                           PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
00173       eigen_assert(EIGEN_IMPLIES(internal::traits<Derived>::Flags&AlignedBit, (size_t(m_data) % (sizeof(Scalar)*internal::packet_traits<Scalar>::size)) == 0)
00174         && "data is not aligned");
00175     }
00176 
00177     PointerType m_data;
00178     const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
00179     const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
00180 };
00181 
00182 template<typename Derived> class MapBase<Derived, WriteAccessors>
00183   : public MapBase<Derived, ReadOnlyAccessors>
00184 {
00185   public:
00186 
00187     typedef MapBase<Derived, ReadOnlyAccessors> Base;
00188 
00189     typedef typename Base::Scalar Scalar;
00190     typedef typename Base::PacketScalar PacketScalar;
00191     typedef typename Base::Index Index;
00192     typedef typename Base::PointerType PointerType;
00193 
00194     using Base::derived;
00195     using Base::rows;
00196     using Base::cols;
00197     using Base::size;
00198     using Base::coeff;
00199     using Base::coeffRef;
00200 
00201     using Base::innerStride;
00202     using Base::outerStride;
00203     using Base::rowStride;
00204     using Base::colStride;
00205 
00206     typedef typename internal::conditional<
00207                     internal::is_lvalue<Derived>::value,
00208                     Scalar,
00209                     const Scalar
00210                   >::type ScalarWithConstIfNotLvalue;
00211 
00212     inline const Scalar* data() const { return this->m_data; }
00213     inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
00214 
00215     inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
00216     {
00217       return this->m_data[col * colStride() + row * rowStride()];
00218     }
00219 
00220     inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
00221     {
00222       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00223       return this->m_data[index * innerStride()];
00224     }
00225 
00226     template<int StoreMode>
00227     inline void writePacket(Index row, Index col, const PacketScalar& x)
00228     {
00229       internal::pstoret<Scalar, PacketScalar, StoreMode>
00230                (this->m_data + (col * colStride() + row * rowStride()), x);
00231     }
00232 
00233     template<int StoreMode>
00234     inline void writePacket(Index index, const PacketScalar& x)
00235     {
00236       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00237       internal::pstoret<Scalar, PacketScalar, StoreMode>
00238                 (this->m_data + index * innerStride(), x);
00239     }
00240 
00241     explicit inline MapBase(PointerType data) : Base(data) {}
00242     inline MapBase(PointerType data, Index size) : Base(data, size) {}
00243     inline MapBase(PointerType data, Index rows, Index cols) : Base(data, rows, cols) {}
00244 
00245     Derived& operator=(const MapBase& other)
00246     {
00247       Base::Base::operator=(other);
00248       return derived();
00249     }
00250 
00251     using Base::Base::operator=;
00252 };
00253 
00254 
00255 #endif // EIGEN_MAPBASE_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:51