1 /* ***** BEGIN LICENSE BLOCK *****
7 * Copyright (c) 2008 BBC Research
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * ***** END LICENSE BLOCK ***** */
36 /* introduce a new type of dynamic array, that:
37 * - performs bound checking on operator[] -- enabled through (1)
38 * - disables array convolution to reduce mishtakes -- (2)
40 template<class Target
> struct P
: MergePolicies
44 /* ,indexZeroBasedNoCheck */
45 ,IndexingChecked
/* (1) */
48 /* ,ArrayConvolution *//* (2) */
56 template<class T
> class Array1d
: public psi::DynamicArray
<T
, 1, psi::P
> {
58 const int length() const
64 Array1d(const int length
)
66 typename
Q::Params init_params
;
67 /* setup the inital parameters - ie size. */
68 init_params
.params(1, psi::Size(length
));
70 /* tell psi about the actual array size we desire. */
71 this->params(init_params
);
76 /* TODO? shaddow copy the width,height -- allows for large performance
78 typedef psi::DynamicArray
<T
, 1, psi::P
> Q
;
84 Size2d(int w
, int h
) :
91 template<class T
> class Array2d
: public psi::DynamicArray
<T
, 2, psi::P
> {
93 const int height() const
98 const int width() const
104 Array2d(const int width
, const int height
)
106 typename
Q::Params init_params
;
107 /* setup the inital parameters - ie size. */
108 init_params
.params(1, psi::Size(width
));
109 init_params
.params(2, psi::Size(height
));
111 /* tell psi about the actual array size we desire. */
112 this->params(init_params
);
116 Array2d(const Size2d
& dim
)
118 typename
Q::Params init_params
;
119 /* setup the inital parameters - ie size. */
120 init_params
.params(1, psi::Size(dim
.width
));
121 init_params
.params(2, psi::Size(dim
.height
));
123 /* tell psi about the actual array size we desire. */
124 this->params(init_params
);
129 // Array2d<T>& operator=(const Array2d<T>&);
130 // Array2d(const Array2d<T>&);
131 /* TODO? shaddow copy the width,height -- allows for large performance
133 typedef psi::DynamicArray
<T
, 2, psi::P
> Q
;
136 /* Some magic arrays to get around lack of good references in C++ */
137 template<class T
> class RArray1d
{
139 RArray1d(const int length
) :
145 /* make read access look like normal container access */
146 T
& operator[](const int i
) const
152 /* make write access a bit irritating */
153 void set(const int i
, T
& thing
)
158 void set(const int i
, T
* thing
)
166 return data
.length();
171 /* don't allow copying of this array! */
172 RArray1d(const RArray1d
<T
>&);
173 RArray1d
<T
>& operator=(const RArray1d
<T
>&);