Google

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

Generated at Fri Jan 10 08:14:08 2003 for MPQC 2.1.3 using the documentation package Doxygen 1.2.14.