VectorBlock.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) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
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_VECTORBLOCK_H
00027 #define EIGEN_VECTORBLOCK_H
00028 
00029 namespace Eigen { 
00030 
00062 namespace internal {
00063 template<typename VectorType, int Size>
00064 struct traits<VectorBlock<VectorType, Size> >
00065   : public traits<Block<VectorType,
00066                      traits<VectorType>::Flags & RowMajorBit ? 1 : Size,
00067                      traits<VectorType>::Flags & RowMajorBit ? Size : 1> >
00068 {
00069 };
00070 }
00071 
00072 template<typename VectorType, int Size> class VectorBlock
00073   : public Block<VectorType,
00074                      internal::traits<VectorType>::Flags & RowMajorBit ? 1 : Size,
00075                      internal::traits<VectorType>::Flags & RowMajorBit ? Size : 1>
00076 {
00077     typedef Block<VectorType,
00078                      internal::traits<VectorType>::Flags & RowMajorBit ? 1 : Size,
00079                      internal::traits<VectorType>::Flags & RowMajorBit ? Size : 1> Base;
00080     enum {
00081       IsColVector = !(internal::traits<VectorType>::Flags & RowMajorBit)
00082     };
00083   public:
00084     EIGEN_DENSE_PUBLIC_INTERFACE(VectorBlock)
00085 
00086     using Base::operator=;
00087 
00090     inline VectorBlock(VectorType& vector, Index start, Index size)
00091       : Base(vector,
00092              IsColVector ? start : 0, IsColVector ? 0 : start,
00093              IsColVector ? size  : 1, IsColVector ? 1 : size)
00094     {
00095       EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock);
00096     }
00097 
00100     inline VectorBlock(VectorType& vector, Index start)
00101       : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start)
00102     {
00103       EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock);
00104     }
00105 };
00106 
00107 
00124 template<typename Derived>
00125 inline typename DenseBase<Derived>::SegmentReturnType
00126 DenseBase<Derived>::segment(Index start, Index size)
00127 {
00128   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00129   return SegmentReturnType(derived(), start, size);
00130 }
00131 
00133 template<typename Derived>
00134 inline typename DenseBase<Derived>::ConstSegmentReturnType
00135 DenseBase<Derived>::segment(Index start, Index size) const
00136 {
00137   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00138   return ConstSegmentReturnType(derived(), start, size);
00139 }
00140 
00156 template<typename Derived>
00157 inline typename DenseBase<Derived>::SegmentReturnType
00158 DenseBase<Derived>::head(Index size)
00159 {
00160   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00161   return SegmentReturnType(derived(), 0, size);
00162 }
00163 
00165 template<typename Derived>
00166 inline typename DenseBase<Derived>::ConstSegmentReturnType
00167 DenseBase<Derived>::head(Index size) const
00168 {
00169   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00170   return ConstSegmentReturnType(derived(), 0, size);
00171 }
00172 
00188 template<typename Derived>
00189 inline typename DenseBase<Derived>::SegmentReturnType
00190 DenseBase<Derived>::tail(Index size)
00191 {
00192   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00193   return SegmentReturnType(derived(), this->size() - size, size);
00194 }
00195 
00197 template<typename Derived>
00198 inline typename DenseBase<Derived>::ConstSegmentReturnType
00199 DenseBase<Derived>::tail(Index size) const
00200 {
00201   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00202   return ConstSegmentReturnType(derived(), this->size() - size, size);
00203 }
00204 
00218 template<typename Derived>
00219 template<int Size>
00220 inline typename DenseBase<Derived>::template FixedSegmentReturnType<Size>::Type
00221 DenseBase<Derived>::segment(Index start)
00222 {
00223   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00224   return typename FixedSegmentReturnType<Size>::Type(derived(), start);
00225 }
00226 
00228 template<typename Derived>
00229 template<int Size>
00230 inline typename DenseBase<Derived>::template ConstFixedSegmentReturnType<Size>::Type
00231 DenseBase<Derived>::segment(Index start) const
00232 {
00233   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00234   return typename ConstFixedSegmentReturnType<Size>::Type(derived(), start);
00235 }
00236 
00248 template<typename Derived>
00249 template<int Size>
00250 inline typename DenseBase<Derived>::template FixedSegmentReturnType<Size>::Type
00251 DenseBase<Derived>::head()
00252 {
00253   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00254   return typename FixedSegmentReturnType<Size>::Type(derived(), 0);
00255 }
00256 
00258 template<typename Derived>
00259 template<int Size>
00260 inline typename DenseBase<Derived>::template ConstFixedSegmentReturnType<Size>::Type
00261 DenseBase<Derived>::head() const
00262 {
00263   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00264   return typename ConstFixedSegmentReturnType<Size>::Type(derived(), 0);
00265 }
00266 
00278 template<typename Derived>
00279 template<int Size>
00280 inline typename DenseBase<Derived>::template FixedSegmentReturnType<Size>::Type
00281 DenseBase<Derived>::tail()
00282 {
00283   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00284   return typename FixedSegmentReturnType<Size>::Type(derived(), size() - Size);
00285 }
00286 
00288 template<typename Derived>
00289 template<int Size>
00290 inline typename DenseBase<Derived>::template ConstFixedSegmentReturnType<Size>::Type
00291 DenseBase<Derived>::tail() const
00292 {
00293   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00294   return typename ConstFixedSegmentReturnType<Size>::Type(derived(), size() - Size);
00295 }
00296 
00297 } // end namespace Eigen
00298 
00299 #endif // EIGEN_VECTORBLOCK_H