ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
intarray.h
Go to the documentation of this file.
1/*******************************************
2 * ESCP:Electro-Structure Calculate Package.
3 ********************************************/
4
5#ifndef INTARRAY_H
6#define INTARRAY_H
7
8#include <cassert>
9#include <fstream>
10#include <iomanip>
11#include <iostream>
12
13namespace ModuleBase
14{
20{
21 public:
22 int *ptr;
23
30 IntArray(const int d1 = 1, const int d2 = 1);
31 IntArray(const int d1, const int d2, const int d3);
32 IntArray(const int d1, const int d2, const int d3, const int d4);
33 IntArray(const int d1, const int d2, const int d3, const int d4, const int d5);
34 IntArray(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6);
35
36 ~IntArray();
37
44 void create(const int d1, const int d2);
45 void create(const int d1, const int d2, const int d3);
46 void create(const int d1, const int d2, const int d3, const int d4);
47 void create(const int d1, const int d2, const int d3, const int d4, const int d5);
48 void create(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6);
49
57 {
58 if(this != &other)
59 {
60 delete[] ptr;
61 size = other.size;
62 dim = other.dim;
63 bound1 = other.bound1;
64 bound2 = other.bound2;
65 bound3 = other.bound3;
66 bound4 = other.bound4;
67 bound5 = other.bound5;
68 bound6 = other.bound6;
69 ptr = new int[size];
70 for (int i = 0;i < size;i++)
71 { ptr[i] = other.ptr[i]; }
72 }
73 return *this;
74 }
75
83 const IntArray &operator=(const int &right)
84 {
85 for (int i = 0;i < size;i++) ptr[i] = right;
86 return *this;// enables x = y = z;
87 }
88
96 int &operator()(const int d1, const int d2)
97 {
98 assert( d1 < bound1 );
99 assert( d2 < bound2 );
100 return ptr[ d1 * bound2 + d2 ];
101 }
102 int &operator()(const int d1, const int d2, const int d3)
103 {
104 assert( d1 < bound1 );
105 assert( d2 < bound2 );
106 assert( d3 < bound3 );
107 return ptr[ (d1 * bound2 + d2) * bound3 + d3 ];
108 }
109 int &operator()(const int d1, const int d2, const int d3, const int d4)
110 {
111 assert( d1 < bound1 );
112 assert( d2 < bound2 );
113 assert( d3 < bound3 );
114 assert( d4 < bound4 );
115 return ptr[ ((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4 ];
116 }
117 int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5)
118 {
119 assert( d1 < bound1 );
120 assert( d2 < bound2 );
121 assert( d3 < bound3 );
122 assert( d4 < bound4 );
123 assert( d5 < bound5 );
124 return ptr[ (((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4) * bound5 + d5 ];
125 }
126 int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6)
127 {
128 assert( d1 < bound1 );
129 assert( d2 < bound2 );
130 assert( d3 < bound3 );
131 assert( d4 < bound4 );
132 assert( d5 < bound5 );
133 assert( d6 < bound6 );
134 return ptr[ ((((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4) * bound5 + d5) * bound6 + d6 ];
135 }
136
145 const int &operator()(const int d1, const int d2) const
146 {
147 assert( d1 < bound1 );
148 assert( d2 < bound2 );
149 return ptr[ d1 * bound2 + d2 ];
150 }
151 const int &operator()(const int d1, const int d2, const int d3) const
152 {
153 assert( d1 < bound1 );
154 assert( d2 < bound2 );
155 assert( d3 < bound3 );
156 return ptr[ (d1 * bound2 + d2) * bound3 + d3 ];
157 }
158 const int &operator()(const int d1, const int d2, const int d3, const int d4) const
159 {
160 assert( d1 < bound1 );
161 assert( d2 < bound2 );
162 assert( d3 < bound3 );
163 assert( d4 < bound4 );
164 return ptr[ ((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4 ];
165 }
166 const int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5) const
167 {
168 assert( d1 < bound1 );
169 assert( d2 < bound2 );
170 assert( d3 < bound3 );
171 assert( d4 < bound4 );
172 assert( d5 < bound5 );
173 return ptr[ (((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4) * bound5 + d5 ];
174 }
175 const int &operator()(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6) const
176 {
177 assert( d1 < bound1 );
178 assert( d2 < bound2 );
179 assert( d3 < bound3 );
180 assert( d4 < bound4 );
181 assert( d5 < bound5 );
182 assert( d6 < bound6 );
183 return ptr[ ((((d1 * bound2 + d2) * bound3 + d3) * bound4 + d4) * bound5 + d5) * bound6 + d6 ];
184 }
185
190 void zero_out(void);
191
192 int getSize() const
193 {
194 return size;
195 }
196 int getDim() const
197 {
198 return dim;
199 }
200 int getBound1() const
201 {
202 return bound1;
203 }
204 int getBound2() const
205 {
206 return bound2;
207 }
208 int getBound3() const
209 {
210 return bound3;
211 }
212 int getBound4() const
213 {
214 return bound4;
215 }
216 int getBound5() const
217 {
218 return bound5;
219 }
220 int getBound6() const
221 {
222 return bound6;
223 }
224
225 private:
226 int size=0;
227 int dim=0;
228 int bound1=0;
229 int bound2=0;
230 int bound3=0;
231 int bound4=0;
232 int bound5=0;
233 int bound6=0;
234 void freemem();
235};
236} // namespace ModuleBase
237
238#endif // IntArray class
Integer array.
Definition intarray.h:20
void freemem()
Definition intarray.cpp:92
int getBound5() const
Definition intarray.h:216
const IntArray & operator=(const int &right)
Equal all elements of an IntArray to an integer.
Definition intarray.h:83
int getBound6() const
Definition intarray.h:220
const int & operator()(const int d1, const int d2) const
Access elements by using "()" through pointer without changing its elements.
Definition intarray.h:145
int bound1
Definition intarray.h:228
~IntArray()
Definition intarray.cpp:87
const int & operator()(const int d1, const int d2, const int d3, const int d4) const
Definition intarray.h:158
int * ptr
Definition intarray.h:22
int dim
Definition intarray.h:227
int bound5
Definition intarray.h:232
void create(const int d1, const int d2)
Create integer arrays.
Definition intarray.cpp:137
int & operator()(const int d1, const int d2, const int d3, const int d4, const int d5)
Definition intarray.h:117
int getDim() const
Definition intarray.h:196
int getBound3() const
Definition intarray.h:208
int bound6
Definition intarray.h:233
int & operator()(const int d1, const int d2, const int d3, const int d4)
Definition intarray.h:109
int getBound4() const
Definition intarray.h:212
const int & operator()(const int d1, const int d2, const int d3) const
Definition intarray.h:151
int bound3
Definition intarray.h:230
int getSize() const
Definition intarray.h:192
const int & operator()(const int d1, const int d2, const int d3, const int d4, const int d5) const
Definition intarray.h:166
void zero_out(void)
Set all elements of an IntArray to zero.
Definition intarray.cpp:149
int getBound2() const
Definition intarray.h:204
IntArray & operator=(const IntArray &other)
copy assignment
Definition intarray.h:56
int & operator()(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6)
Definition intarray.h:126
int & operator()(const int d1, const int d2, const int d3)
Definition intarray.h:102
int getBound1() const
Definition intarray.h:200
int size
Definition intarray.h:226
int & operator()(const int d1, const int d2)
Access elements by using operator "()".
Definition intarray.h:96
int bound2
Definition intarray.h:229
int bound4
Definition intarray.h:231
const int & operator()(const int d1, const int d2, const int d3, const int d4, const int d5, const int d6) const
Definition intarray.h:175
D2< double > d2
Definition gint_move.hpp:19
Definition array_pool.h:6