Skip to content

Commit f550ec1

Browse files
committed
inline functions of intarray
1 parent 3b71fc5 commit f550ec1

File tree

2 files changed

+91
-130
lines changed

2 files changed

+91
-130
lines changed

source/module_base/intarray.cpp

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -150,124 +150,6 @@ void IntArray::create(const int d1, const int d2)
150150
assert(ptr !=0 );zero_out();
151151
}
152152

153-
const IntArray &IntArray::operator=(const IntArray &right)
154-
{
155-
assert( this->size == right.size );
156-
for (int i = 0;i < size;i++) ptr[i] = right.ptr[i];
157-
return *this;// enables x = y = z;
158-
}
159-
160-
const IntArray &IntArray::operator=(const int &value)
161-
{
162-
for (int i = 0;i < size;i++) ptr[i] = value;
163-
return *this;// enables x = y = z;
164-
}
165-
166-
//********************************************************
167-
// overloaded subscript operator for const Int Array
168-
// const reference return create an cvakue
169-
//********************************************************
170-
const int &IntArray::operator()
171-
(const int ind1,const int ind2)const
172-
{
173-
assert( ind1 < bound1 );
174-
assert( ind2 < bound2 );
175-
return ptr[ ind1 * bound2 + ind2 ];
176-
}
177-
178-
const int &IntArray::operator()
179-
(const int ind1,const int ind2,const int ind3)const
180-
{
181-
assert( ind1 < bound1 );
182-
assert( ind2 < bound2 );
183-
assert( ind3 < bound3 );
184-
return ptr[ (ind1 * bound2 + ind2) * bound3 + ind3 ];
185-
}
186-
187-
const int &IntArray::operator()
188-
(const int ind1,const int ind2,const int ind3,const int ind4)const
189-
{
190-
assert( ind1 < bound1 );
191-
assert( ind2 < bound2 );
192-
assert( ind3 < bound3 );
193-
assert( ind4 < bound4 );
194-
return ptr[ ((ind1 * bound2 + ind2) * bound3 + ind3) * bound4 + ind4 ];
195-
}
196-
197-
const int &IntArray::operator()
198-
(const int ind1,const int ind2,const int ind3,const int ind4,const int ind5)const
199-
{
200-
assert( ind1 < bound1 );
201-
assert( ind2 < bound2 );
202-
assert( ind3 < bound3 );
203-
assert( ind4 < bound4 );
204-
assert( ind5 < bound5 );
205-
return ptr[ (((ind1 * bound2 + ind2) * bound3 + ind3) * bound4 + ind4) * bound5 + ind5 ];
206-
}
207-
208-
const int &IntArray::operator()
209-
(const int ind1,const int ind2,const int ind3,const int ind4,const int ind5,const int ind6)const
210-
{
211-
assert( ind1 < bound1 );
212-
assert( ind2 < bound2 );
213-
assert( ind3 < bound3 );
214-
assert( ind4 < bound4 );
215-
assert( ind5 < bound5 );
216-
assert( ind6 < bound6 );
217-
return ptr[ ((((ind1 * bound2 + ind2) * bound3 + ind3) * bound4 + ind4) * bound5 + ind5) * bound6 + ind6 ];
218-
}
219-
220-
//********************************************************
221-
// overloaded subscript operator for non-const Int Array
222-
// const reference return creates an lvakue
223-
//********************************************************
224-
int &IntArray::operator()(const int ind1,const int ind2)
225-
{
226-
assert( ind1 < bound1 );
227-
assert( ind2 < bound2 );
228-
return ptr[ind1 * bound2 + ind2];
229-
}
230-
231-
int &IntArray::operator()(const int ind1,const int ind2,const int ind3)
232-
{
233-
assert( ind1 < bound1 );
234-
assert( ind2 < bound2 );
235-
assert( ind3 < bound3 );
236-
return ptr[ (ind1 * bound2 + ind2) * bound3 + ind3 ];
237-
}
238-
239-
int &IntArray::operator()(const int ind1,const int ind2,const int ind3,const int ind4)
240-
{
241-
assert( ind1 < bound1 );
242-
assert( ind2 < bound2 );
243-
assert( ind3 < bound3 );
244-
assert( ind4 < bound4 );
245-
return ptr[ ((ind1 * bound2 + ind2) * bound3 + ind3) * bound4 + ind4 ];
246-
}
247-
248-
int &IntArray::operator()
249-
(const int ind1,const int ind2,const int ind3,const int ind4,const int ind5)
250-
{
251-
assert( ind1 < bound1 );
252-
assert( ind2 < bound2 );
253-
assert( ind3 < bound3 );
254-
assert( ind4 < bound4 );
255-
assert( ind5 < bound5 );
256-
return ptr[ (((ind1 * bound2 + ind2) * bound3 + ind3) * bound4 + ind4) * bound5 + ind5 ];
257-
}
258-
259-
int &IntArray::operator()
260-
(const int ind1,const int ind2,const int ind3,const int ind4,const int ind5,const int ind6)
261-
{
262-
assert( ind1 < bound1 );
263-
assert( ind2 < bound2 );
264-
assert( ind3 < bound3 );
265-
assert( ind4 < bound4 );
266-
assert( ind5 < bound5 );
267-
assert( ind6 < bound6 );
268-
return ptr[ ((((ind1 * bound2 + ind2) * bound3 + ind3) * bound4 + ind4) * bound5 + ind5) * bound6 + ind6 ];
269-
}
270-
271153
//****************************
272154
// zeroes out the whole array
273155
//****************************

source/module_base/intarray.h

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ class IntArray
5353
* @param right
5454
* @return const IntArray&
5555
*/
56-
const IntArray &operator=(const IntArray &right);
56+
const IntArray &operator=(const IntArray &right)
57+
{
58+
assert( this->size == right.size );
59+
for (int i = 0;i < size;i++) ptr[i] = right.ptr[i];
60+
return *this;// enables x = y = z;
61+
};
5762

5863
/**
5964
* @brief Equal all elements of an IntArray to an
@@ -62,7 +67,11 @@ class IntArray
6267
* @param right
6368
* @return const IntArray&
6469
*/
65-
const IntArray &operator=(const int &right);
70+
const IntArray &operator=(const int &right)
71+
{
72+
for (int i = 0;i < size;i++) ptr[i] = right;
73+
return *this;// enables x = y = z;
74+
};
6675

6776
/**
6877
* @brief Access elements by using operator "()"
@@ -71,11 +80,46 @@ class IntArray
7180
* @param d2
7281
* @return int&
7382
*/
74-
int &operator()(const int d1, const int d2);
75-
int &operator()(const int d1, const int d2, const int d3);
76-
int &operator()(const int d1, const int d2, const int d3, const int d4);
77-
int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5);
78-
int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6);
83+
int &operator()(const int d1, const int d2)
84+
{
85+
assert( d1 < bound1 );
86+
assert( d2 < bound2 );
87+
return ptr[ d1 * bound2 + d2 ];
88+
};
89+
int &operator()(const int d1, const int d2, const int d3)
90+
{
91+
assert( d1 < bound1 );
92+
assert( d2 < bound2 );
93+
assert( d3 < bound3 );
94+
return ptr[ (d1 * bound2 + d2) * bound3 + d3 ];
95+
};
96+
int &operator()(const int d1, const int d2, const int d3, const int d4)
97+
{
98+
assert( d1 < bound1 );
99+
assert( d2 < bound2 );
100+
assert( d3 < bound3 );
101+
assert( d4 < bound4 );
102+
return ptr[ ((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4 ];
103+
};
104+
int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5)
105+
{
106+
assert( d1 < bound1 );
107+
assert( d2 < bound2 );
108+
assert( d3 < bound3 );
109+
assert( d4 < bound4 );
110+
assert( d5 < bound5 );
111+
return ptr[ (((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4) * bound5 + d5 ];
112+
};
113+
int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6)
114+
{
115+
assert( d1 < bound1 );
116+
assert( d2 < bound2 );
117+
assert( d3 < bound3 );
118+
assert( d4 < bound4 );
119+
assert( d5 < bound5 );
120+
assert( d6 < bound6 );
121+
return ptr[ ((((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4) * bound5 + d5) * bound6 + d6 ];
122+
};
79123

80124
/**
81125
* @brief Access elements by using "()" through pointer
@@ -85,11 +129,46 @@ class IntArray
85129
* @param d2
86130
* @return const int&
87131
*/
88-
const int &operator()(const int d1, const int d2) const;
89-
const int &operator()(const int d1, const int d2, const int d3) const;
90-
const int &operator()(const int d1, const int d2, const int d3, const int d4) const;
91-
const int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5) const;
92-
const int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6) const;
132+
const int &operator()(const int d1, const int d2) const
133+
{
134+
assert( d1 < bound1 );
135+
assert( d2 < bound2 );
136+
return ptr[ d1 * bound2 + d2 ];
137+
};
138+
const int &operator()(const int d1, const int d2, const int d3) const
139+
{
140+
assert( d1 < bound1 );
141+
assert( d2 < bound2 );
142+
assert( d3 < bound3 );
143+
return ptr[ (d1 * bound2 + d2) * bound3 + d3 ];
144+
};
145+
const int &operator()(const int d1, const int d2, const int d3, const int d4) const
146+
{
147+
assert( d1 < bound1 );
148+
assert( d2 < bound2 );
149+
assert( d3 < bound3 );
150+
assert( d4 < bound4 );
151+
return ptr[ ((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4 ];
152+
};
153+
const int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5) const
154+
{
155+
assert( d1 < bound1 );
156+
assert( d2 < bound2 );
157+
assert( d3 < bound3 );
158+
assert( d4 < bound4 );
159+
assert( d5 < bound5 );
160+
return ptr[ (((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4) * bound5 + d5 ];
161+
};
162+
const int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6) const
163+
{
164+
assert( d1 < bound1 );
165+
assert( d2 < bound2 );
166+
assert( d3 < bound3 );
167+
assert( d4 < bound4 );
168+
assert( d5 < bound5 );
169+
assert( d6 < bound6 );
170+
return ptr[ ((((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4) * bound5 + d5) * bound6 + d6 ];
171+
};
93172

94173
/**
95174
* @brief Set all elements of an IntArray to zero

0 commit comments

Comments
 (0)