Stride.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) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_STRIDE_H
00026 #define EIGEN_STRIDE_H
00027 
00028 namespace Eigen { 
00029 
00058 template<int _OuterStrideAtCompileTime, int _InnerStrideAtCompileTime>
00059 class Stride
00060 {
00061   public:
00062     typedef DenseIndex Index;
00063     enum {
00064       InnerStrideAtCompileTime = _InnerStrideAtCompileTime,
00065       OuterStrideAtCompileTime = _OuterStrideAtCompileTime
00066     };
00067 
00069     Stride()
00070       : m_outer(OuterStrideAtCompileTime), m_inner(InnerStrideAtCompileTime)
00071     {
00072       eigen_assert(InnerStrideAtCompileTime != Dynamic && OuterStrideAtCompileTime != Dynamic);
00073     }
00074 
00076     Stride(Index outerStride, Index innerStride)
00077       : m_outer(outerStride), m_inner(innerStride)
00078     {
00079       eigen_assert(innerStride>=0 && outerStride>=0);
00080     }
00081 
00083     Stride(const Stride& other)
00084       : m_outer(other.outer()), m_inner(other.inner())
00085     {}
00086 
00088     inline Index outer() const { return m_outer.value(); }
00090     inline Index inner() const { return m_inner.value(); }
00091 
00092   protected:
00093     internal::variable_if_dynamic<Index, OuterStrideAtCompileTime> m_outer;
00094     internal::variable_if_dynamic<Index, InnerStrideAtCompileTime> m_inner;
00095 };
00096 
00099 template<int Value = Dynamic>
00100 class InnerStride : public Stride<0, Value>
00101 {
00102     typedef Stride<0, Value> Base;
00103   public:
00104     typedef DenseIndex Index;
00105     InnerStride() : Base() {}
00106     InnerStride(Index v) : Base(0, v) {}
00107 };
00108 
00111 template<int Value = Dynamic>
00112 class OuterStride : public Stride<Value, 0>
00113 {
00114     typedef Stride<Value, 0> Base;
00115   public:
00116     typedef DenseIndex Index;
00117     OuterStride() : Base() {}
00118     OuterStride(Index v) : Base(v,0) {}
00119 };
00120 
00121 } // end namespace Eigen
00122 
00123 #endif // EIGEN_STRIDE_H