Overture
Version 25
Main Page
Namespaces
Classes
Files
File List
File Members
Overture.v25.d
include
ArraySimpleFixed.h
Go to the documentation of this file.
1
#ifndef __ARRAY_SIMPLE_FIXED_H__
2
#define __ARRAY_SIMPLE_FIXED_H__
3
4
#include "
ArraySimpleCommon.h
"
5
6
// // //
8
12
#ifndef OV_NO_DEFAULT_TEMPL_ARGS
13
template
<
class
T,
int
d1,
int
d2=1,
int
d3=1,
int
d4=1,
int
d5=1>
14
#else
15
template
<
class
T,
int
d1,
int
d2,
int
d3,
int
d4,
int
d5>
16
#endif
17
class
ArraySimpleFixed
18
{
19
public
:
21
inline
ArraySimpleFixed
() { }
22
24
inline
ArraySimpleFixed
(
const
ArraySimpleFixed<T,d1,d2,d3,d4,d5>
&a)
25
{
for
(
int
i=0; i<
size
(); i++ ) data[i] = a.data[i]; }
26
28
inline
~ArraySimpleFixed
() { }
29
31
33
inline
int
size
()
const
{
return
d1*d2*d3*d4*d5; }
34
36
39
inline
int
size
(
const
int
&i)
const
40
{
41
assert
(i>=0 && i<5);
42
return
i==0 ? d1 : (i==1 ? d2 : (i==2 ? d3 : ( i==3 ? d4 : d5) ) );
43
}
44
46
inline
int
rank
()
const
{
return
5; }
47
49
inline
T *
ptr
() {
return
&data[0]; }
50
52
55
inline
ArraySimpleFixed<T,d1,d2,d3,d4,d5>
&
operator=
(
const
ArraySimpleFixed<T,d1,d2,d3,d4,d5>
&a )
56
{
57
for
(
int
i=0; i<
size
(); i++ ) data[i] = a.data[i];
58
return
*
this
;
59
}
60
61
inline
ArraySimpleFixed<T,d1,d2,d3,d4,d5>
&
operator=
(
const
T &a )
62
{
63
// /Description : set all array values equal to a const value
64
for
(
int
i=0; i<
size
(); i++ ) data[i] = a;
65
return
*
this
;
66
}
67
69
73
inline
T &
operator[]
(
const
int
&i )
74
{
75
assert
(
RANGE_CHK
(i>=0 && i<
size
()) );
76
return
data[i];
77
}
78
80
84
inline
const
T &
operator[]
(
const
int
&i )
const
85
{
86
assert
(
RANGE_CHK
(i>=0 && i<
size
()) );
87
return
data[i];
88
}
89
91
99
inline
T &
operator()
(
const
int
& i1,
const
int
&
i2
=0,
const
int
& i3=0,
const
int
& i4=0,
const
int
&i5=0 )
100
{
101
assert
(
RANGE_CHK
(i1>=0 && i1<d1 &&
102
i2
>=0 &&
i2
<d2 &&
103
i3>=0 && i3<d3 &&
104
i4>=0 && i4<d4 &&
105
i5>=0 && i5<d5 ) );
106
return
data[i1 + d1*(
i2
+ d2*(i3 + d3*(i4+d4*i5)))];
107
}
108
110
117
inline
const
T &
operator()
(
const
int
& i1,
const
int
&
i2
=0,
118
const
int
& i3=0,
const
int
& i4=0,
119
const
int
& i5=0)
const
120
{
121
assert
(
RANGE_CHK
(i1>=0 && i1<d1 &&
122
i2
>=0 &&
i2
<d2 &&
123
i3>=0 && i3<d3 &&
124
i4>=0 && i4<d4 &&
125
i5>=0 && i5<d5 ) );
126
return
data[i1 + d1*(
i2
+ d2*(i3 + d3*(i4+d4*i5)))];
127
// return data[i1 + d1*(i2 + d2*(i3 + i4*d3))];
128
}
129
130
private
:
131
T data[d1*d2*d3*d4*d5];
132
};
133
134
//
135
// End of ArraySimpleFixed
136
// // //
137
138
139
140
#ifndef OV_NO_DEFAULT_TEMPL_ARGS
141
template
<
class
T,
int
d1,
int
d2,
int
d3,
int
d4,
int
d5>
142
ostream & operator<< (ostream &os, ArraySimpleFixed<T,d1,d2,d3,d4,d5> &a)
143
{
144
// /Description : overloading of ostream to make printing ArraySimpleFixeds easier
145
os<<
"********** ArraySimpleFixed( "
<<d1<<
", "
<<d2<<
", "
<<d3<<
", "
<<d4<<
" ) **********\n"
;
146
147
for
(
int
i1=0; i1<d1; i1++ )
148
for
(
int
i2
=0;
i2
<d2;
i2
++ )
149
for
(
int
i3=0; i3<d3; i3++ )
150
for
(
int
i4=0; i4<d4; i4++ )
151
for
(
int
i5=0; i5<d5; i5++ )
152
os<<
"a( "
<<i1<<
", "
<<
i2
<<
", "
<<i3<<
", "
<<i4<<
", "
<<i5<<
" ) = "
<<a(i1,
i2
,i3,i4,i5)<<endl;
153
154
return
os;
155
}
156
#endif
157
158
#endif
Generated on Fri Jan 4 2013 10:17:48 for Overture by
1.8.3