MPQC  3.0.0-alpha
carray.h
1 //
2 // carray.h --- C Style Arrays
3 //
4 
5 #ifndef _util_container_carray_h
6 #define _util_container_carray_h
7 
8 namespace sc {
9 
10 template <class T>
11 T **
12 new_c_array2(int l, int m, T)
13 {
14  T *a = 0;
15  T **b = 0;
16  if (l*m) a = new T[l*m];
17  if (l) b = new T*[l];
18  for (int i=0; i<l; i++) b[i] = &a[i*m];
19  return b;
20 }
21 
22 template <class T>
23 T **
24 new_zero_c_array2(int l, int m, T)
25 {
26  T *a = 0;
27  T **b = 0;
28  if (l*m) a = new T[l*m];
29  if (l) b = new T*[l];
30  for (int i=0; i<l; i++) {
31  b[i] = &a[i*m];
32  for (int j=0; j<m; j++) {
33  b[i][j] = 0;
34  }
35  }
36  return b;
37 }
38 
39 template <class T>
40 void
41 delete_c_array2(T**b)
42 {
43  if (b) delete[] b[0];
44  delete[] b;
45 }
46 
47 template <class T>
48 T ***
49 new_c_array3(int l, int m, int n, T)
50 {
51  T *a = 0;
52  T **b = 0;
53  T ***c = 0;
54  if (l*m*n) a = new T[l*m*n];
55  if (l*m) b = new T*[l*m];
56  if (l) c = new T**[l];
57  for (int i=0,ij=0; i<l; i++) {
58  c[i] = &b[i*m];
59  for (int j=0; j<m; j++,ij++) {
60  c[i][j] = &a[ij*n];
61  }
62  }
63  return c;
64 }
65 
66 template <class T>
67 T ***
68 new_zero_c_array3(int l, int m, int n, T)
69 {
70  T *a = 0;
71  T **b = 0;
72  T ***c = 0;
73  if (l*m*n) a = new T[l*m*n];
74  if (l*m) b = new T*[l*m];
75  if (l) c = new T**[l];
76  for (int i=0,ij=0; i<l; i++) {
77  c[i] = &b[i*m];
78  for (int j=0; j<m; j++,ij++) {
79  c[i][j] = &a[ij*n];
80  for (int k=0; k<n; k++) {
81  c[i][j][k] = 0;
82  }
83  }
84  }
85  return c;
86 }
87 
88 template <class T>
89 void
90 delete_c_array3(T***b)
91 {
92  if (b && b[0]) delete[] b[0][0];
93  if (b) delete[] b[0];
94  delete[] b;
95 }
96 
97 }
98 
99 #endif
100 
101 // ///////////////////////////////////////////////////////////////////////////
102 
103 // Local Variables:
104 // mode: c++
105 // c-file-style: "CLJ"
106 // End:
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.