-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray2d.h
111 lines (94 loc) · 2.38 KB
/
array2d.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright (C) 2007 Simon Perreault
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARRAY2D_H
#define ARRAY2D_H
#include "array.h"
template< typename T >
class Array2D : public Array<T,2>
{
public:
Array2D();
Array2D( int m, int n );
Array2D( const Array<T,2>& array );
int M() const;
int N() const;
const T& at( int i, int j ) const;
const T& operator() ( int i, int j ) const;
T& operator() ( int i, int j );
Array2D<T> subarray( int iBegin, int jBegin, int iEnd, int jEnd );
};
template< typename T >
Array2D<T>::Array2D()
: Array<T,2>()
{
}
template< typename T >
Array2D<T>::Array2D( int m, int n )
: Array<T,2>()
{
TinyVector<int,2> sizes;
sizes(1) = m;
sizes(0) = n;
Array<T,2>::operator= ( Array<T,2>(sizes) );
}
template< typename T >
Array2D<T>::Array2D( const Array<T,2>& array )
: Array<T,2>(array)
{
}
template< typename T >
int Array2D<T>::M() const
{
return this->sizes()(1);
}
template< typename T >
int Array2D<T>::N() const
{
return this->sizes()(0);
}
template< typename T >
const T& Array2D<T>::at( int i, int j ) const
{
TinyVector<int,2> indices;
indices(1) = i;
indices(0) = j;
return Array<T,2>::at(indices);
}
template< typename T >
const T& Array2D<T>::operator() ( int i, int j ) const
{
return at(i,j);
}
template< typename T >
T& Array2D<T>::operator() ( int i, int j )
{
TinyVector<int,2> indices;
indices(1) = i;
indices(0) = j;
return Array<T,2>::operator()(indices);
}
template< typename T >
Array2D<T> Array2D<T>::subarray( int iBegin, int jBegin, int iEnd, int jEnd )
{
TinyVector<int,2> begin, end;
begin(1) = iBegin;
begin(0) = jBegin;
end(1) = iEnd;
end(0) = jEnd;
return Array<T,2>::subarray( begin, end );
}
#endif