3 * Copyright (C) 2007 Tim Moore
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 #ifndef VECTORARRAYADAPTERHXX
23 #define VECTORARRAYADAPTERHXX 1
27 template <typename Vector>
28 class VectorArrayAdapter {
31 * Adapter that provides 2D array access to the elements of a
32 * std::vector in row major order.
34 * @param rowStride distance from an element to the corresponding
35 * element in the next row.
36 * @param baseOffset offset of the first element of the array from the
37 * beginning of the vector.
38 * @param rowOffset offset of the first element in a row from the
39 * actual beginning of the row.
41 VectorArrayAdapter(Vector& v, int rowStride, int baseOffset = 0,
43 _v(v), _rowStride(rowStride), _baseOffset(baseOffset),
48 typename Vector::value_type& operator() (int i, int j)
50 return _v[_baseOffset + i * _rowStride + _rowOffset + j];
52 const typename Vector::value_type& operator() (int i, int j) const
54 return _v[_baseOffset + i * _rowStride + _rowOffset + j];
59 const int _baseOffset;