Map.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_MAP_H
00027 #define EIGEN_MAP_H
00028 
00080 namespace internal {
00081 template<typename PlainObjectType, int MapOptions, typename StrideType>
00082 struct traits<Map<PlainObjectType, MapOptions, StrideType> >
00083   : public traits<PlainObjectType>
00084 {
00085   typedef traits<PlainObjectType> TraitsBase;
00086   typedef typename PlainObjectType::Index Index;
00087   typedef typename PlainObjectType::Scalar Scalar;
00088   enum {
00089     InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
00090                              ? int(PlainObjectType::InnerStrideAtCompileTime)
00091                              : int(StrideType::InnerStrideAtCompileTime),
00092     OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
00093                              ? int(PlainObjectType::OuterStrideAtCompileTime)
00094                              : int(StrideType::OuterStrideAtCompileTime),
00095     HasNoInnerStride = InnerStrideAtCompileTime == 1,
00096     HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
00097     HasNoStride = HasNoInnerStride && HasNoOuterStride,
00098     IsAligned = bool(EIGEN_ALIGN) && ((int(MapOptions)&Aligned)==Aligned),
00099     IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic,
00100     KeepsPacketAccess = bool(HasNoInnerStride)
00101                         && ( bool(IsDynamicSize)
00102                            || HasNoOuterStride
00103                            || ( OuterStrideAtCompileTime!=Dynamic
00104                            && ((static_cast<int>(sizeof(Scalar))*OuterStrideAtCompileTime)%16)==0 ) ),
00105     Flags0 = TraitsBase::Flags,
00106     Flags1 = IsAligned ? (int(Flags0) | AlignedBit) : (int(Flags0) & ~AlignedBit),
00107     Flags2 = (bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime))
00108            ? int(Flags1) : int(Flags1 & ~LinearAccessBit),
00109     Flags3 = is_lvalue<PlainObjectType>::value ? int(Flags2) : (int(Flags2) & ~LvalueBit),
00110     Flags = KeepsPacketAccess ? int(Flags3) : (int(Flags3) & ~PacketAccessBit)
00111   };
00112 private:
00113   enum { Options }; // Expressions don't have Options
00114 };
00115 }
00116 
00117 template<typename PlainObjectType, int MapOptions, typename StrideType> class Map
00118   : public MapBase<Map<PlainObjectType, MapOptions, StrideType> >
00119 {
00120   public:
00121 
00122     typedef MapBase<Map> Base;
00123 
00124     EIGEN_DENSE_PUBLIC_INTERFACE(Map)
00125 
00126     typedef typename Base::PointerType PointerType;
00127 #if EIGEN2_SUPPORT_STAGE <= STAGE30_FULL_EIGEN3_API
00128     typedef const Scalar* PointerArgType;
00129     inline PointerType cast_to_pointer_type(PointerArgType ptr) { return const_cast<PointerType>(ptr); }
00130 #else
00131     typedef PointerType PointerArgType;
00132     inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; }
00133 #endif
00134 
00135     inline Index innerStride() const
00136     {
00137       return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
00138     }
00139 
00140     inline Index outerStride() const
00141     {
00142       return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
00143            : IsVectorAtCompileTime ? this->size()
00144            : int(Flags)&RowMajorBit ? this->cols()
00145            : this->rows();
00146     }
00147 
00153     inline Map(PointerArgType data, const StrideType& stride = StrideType())
00154       : Base(cast_to_pointer_type(data)), m_stride(stride)
00155     {
00156       PlainObjectType::Base::_check_template_params();
00157     }
00158 
00165     inline Map(PointerArgType data, Index size, const StrideType& stride = StrideType())
00166       : Base(cast_to_pointer_type(data), size), m_stride(stride)
00167     {
00168       PlainObjectType::Base::_check_template_params();
00169     }
00170 
00178     inline Map(PointerArgType data, Index rows, Index cols, const StrideType& stride = StrideType())
00179       : Base(cast_to_pointer_type(data), rows, cols), m_stride(stride)
00180     {
00181       PlainObjectType::Base::_check_template_params();
00182     }
00183 
00184 
00185     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
00186 
00187   protected:
00188     StrideType m_stride;
00189 };
00190 
00191 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00192 inline Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
00193   ::Array(const Scalar *data)
00194 {
00195   this->_set_noalias(Eigen::Map<const Array>(data));
00196 }
00197 
00198 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00199 inline Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
00200   ::Matrix(const Scalar *data)
00201 {
00202   this->_set_noalias(Eigen::Map<const Matrix>(data));
00203 }
00204 
00205 #endif // EIGEN_MAP_H


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