VectorBlock.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25 
26 #ifndef EIGEN_VECTORBLOCK_H
27 #define EIGEN_VECTORBLOCK_H
28 
29 namespace Eigen {
30 
62 namespace internal {
63 template<typename VectorType, int Size>
64 struct traits<VectorBlock<VectorType, Size> >
65  : public traits<Block<VectorType,
66  traits<VectorType>::Flags & RowMajorBit ? 1 : Size,
67  traits<VectorType>::Flags & RowMajorBit ? Size : 1> >
68 {
69 };
70 }
71 
72 template<typename VectorType, int Size> class VectorBlock
73  : public Block<VectorType,
74  internal::traits<VectorType>::Flags & RowMajorBit ? 1 : Size,
75  internal::traits<VectorType>::Flags & RowMajorBit ? Size : 1>
76 {
77  typedef Block<VectorType,
78  internal::traits<VectorType>::Flags & RowMajorBit ? 1 : Size,
79  internal::traits<VectorType>::Flags & RowMajorBit ? Size : 1> Base;
80  enum {
81  IsColVector = !(internal::traits<VectorType>::Flags & RowMajorBit)
82  };
83  public:
85 
86  using Base::operator=;
87 
90  inline VectorBlock(VectorType& vector, Index start, Index size)
91  : Base(vector,
92  IsColVector ? start : 0, IsColVector ? 0 : start,
93  IsColVector ? size : 1, IsColVector ? 1 : size)
94  {
96  }
97 
100  inline VectorBlock(VectorType& vector, Index start)
101  : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start)
102  {
104  }
105 };
106 
107 
124 template<typename Derived>
125 inline typename DenseBase<Derived>::SegmentReturnType
127 {
129  return SegmentReturnType(derived(), start, size);
130 }
131 
133 template<typename Derived>
136 {
138  return ConstSegmentReturnType(derived(), start, size);
139 }
140 
156 template<typename Derived>
159 {
161  return SegmentReturnType(derived(), 0, size);
162 }
163 
165 template<typename Derived>
168 {
170  return ConstSegmentReturnType(derived(), 0, size);
171 }
172 
188 template<typename Derived>
191 {
193  return SegmentReturnType(derived(), this->size() - size, size);
194 }
195 
197 template<typename Derived>
200 {
202  return ConstSegmentReturnType(derived(), this->size() - size, size);
203 }
204 
218 template<typename Derived>
219 template<int Size>
222 {
224  return typename FixedSegmentReturnType<Size>::Type(derived(), start);
225 }
226 
228 template<typename Derived>
229 template<int Size>
232 {
234  return typename ConstFixedSegmentReturnType<Size>::Type(derived(), start);
235 }
236 
248 template<typename Derived>
249 template<int Size>
252 {
254  return typename FixedSegmentReturnType<Size>::Type(derived(), 0);
255 }
256 
258 template<typename Derived>
259 template<int Size>
262 {
264  return typename ConstFixedSegmentReturnType<Size>::Type(derived(), 0);
265 }
266 
278 template<typename Derived>
279 template<int Size>
282 {
284  return typename FixedSegmentReturnType<Size>::Type(derived(), size() - Size);
285 }
286 
288 template<typename Derived>
289 template<int Size>
292 {
294  return typename ConstFixedSegmentReturnType<Size>::Type(derived(), size() - Size);
295 }
296 
297 } // end namespace Eigen
298 
299 #endif // EIGEN_VECTORBLOCK_H