Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

carray.h

00001 //
00002 // carray.h --- C Style Arrays
00003 //
00004 
00005 #ifndef _util_container_carray_h
00006 #define _util_container_carray_h
00007 
00008 template <class T>
00009 T **
00010 new_c_array2(int l, int m, T)
00011 {
00012   T *a = 0;
00013   T **b = 0;
00014   if (l*m) a = new T[l*m];
00015   if (l) b = new T*[l];
00016   for (int i=0; i<l; i++) b[i] = &a[i*m];
00017   return b;
00018 }
00019 
00020 template <class T>
00021 T **
00022 new_zero_c_array2(int l, int m, T)
00023 {
00024   T *a = 0;
00025   T **b = 0;
00026   if (l*m) a = new T[l*m];
00027   if (l) b = new T*[l];
00028   for (int i=0; i<l; i++) {
00029       b[i] = &a[i*m];
00030       for (int j=0; j<m; j++) {
00031           b[i][j] = 0;
00032         }
00033     }
00034   return b;
00035 }
00036 
00037 template <class T>
00038 void
00039 delete_c_array2(T**b)
00040 {
00041   if (b) delete[] b[0];
00042   delete[] b;
00043 }
00044 
00045 template <class T>
00046 T ***
00047 new_c_array3(int l, int m, int n, T)
00048 {
00049   T *a = 0;
00050   T **b = 0;
00051   T ***c = 0;
00052   if (l*m*n) a = new T[l*m*n];
00053   if (l*m) b = new T*[l*m];
00054   if (l) c = new T**[l];
00055   for (int i=0,ij=0; i<l; i++) {
00056       c[i] = &b[i*m];
00057       for (int j=0; j<m; j++,ij++) {
00058           c[i][j] = &a[ij*n];
00059         }
00060     }
00061   return c;
00062 }
00063 
00064 template <class T>
00065 T ***
00066 new_zero_c_array3(int l, int m, int n, T)
00067 {
00068   T *a = 0;
00069   T **b = 0;
00070   T ***c = 0;
00071   if (l*m*n) a = new T[l*m*n];
00072   if (l*m) b = new T*[l*m];
00073   if (l) c = new T**[l];
00074   for (int i=0,ij=0; i<l; i++) {
00075       c[i] = &b[i*m];
00076       for (int j=0; j<m; j++,ij++) {
00077           c[i][j] = &a[ij*n];
00078           for (int k=0; k<n; k++) {
00079               c[i][j][k] = 0;
00080             }
00081         }
00082     }
00083   return c;
00084 }
00085 
00086 template <class T>
00087 void
00088 delete_c_array3(T***b)
00089 {
00090   if (b && b[0]) delete[] b[0][0];
00091   if (b) delete[] b[0];
00092   delete[] b;
00093 }
00094 
00095 #endif
00096 
00097 // ///////////////////////////////////////////////////////////////////////////
00098 
00099 // Local Variables:
00100 // mode: c++
00101 // c-file-style: "CLJ"
00102 // End:

Generated at Thu Oct 4 18:08:42 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.