Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > contrib > by-pkgid > 263386785cefb9ae5d63b926d214d809 > files > 34

mpqc-2.1.2-4mdk.ppc.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>carray.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.5 on Mon Oct 14 14:16:36 2002 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center>
<hr><h1>carray.h</h1><div class="fragment"><pre>00001 <font class="comment">//</font>
00002 <font class="comment">// carray.h --- C Style Arrays</font>
00003 <font class="comment">//</font>
00004 
00005 <font class="preprocessor">#ifndef _util_container_carray_h</font>
00006 <font class="preprocessor"></font><font class="preprocessor">#define _util_container_carray_h</font>
00007 <font class="preprocessor"></font>
00008 <font class="keyword">namespace </font>sc {
00009     
00010 template &lt;class T&gt;
00011 T **
00012 new_c_array2(<font class="keywordtype">int</font> l, <font class="keywordtype">int</font> m, T)<font class="keyword"></font>
00013 <font class="keyword"></font>{
00014   T *a = 0;
00015   T **b = 0;
00016   <font class="keywordflow">if</font> (l*m) a = <font class="keyword">new</font> T[l*m];
00017   <font class="keywordflow">if</font> (l) b = <font class="keyword">new</font> T*[l];
00018   <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=0; i&lt;l; i++) b[i] = &amp;a[i*m];
00019   <font class="keywordflow">return</font> b;
00020 }
00021 
00022 template &lt;class T&gt;
00023 T **
00024 new_zero_c_array2(<font class="keywordtype">int</font> l, <font class="keywordtype">int</font> m, T)<font class="keyword"></font>
00025 <font class="keyword"></font>{
00026   T *a = 0;
00027   T **b = 0;
00028   <font class="keywordflow">if</font> (l*m) a = <font class="keyword">new</font> T[l*m];
00029   <font class="keywordflow">if</font> (l) b = <font class="keyword">new</font> T*[l];
00030   <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=0; i&lt;l; i++) {
00031       b[i] = &amp;a[i*m];
00032       <font class="keywordflow">for</font> (<font class="keywordtype">int</font> j=0; j&lt;m; j++) {
00033           b[i][j] = 0;
00034         }
00035     }
00036   <font class="keywordflow">return</font> b;
00037 }
00038 
00039 template &lt;class T&gt;
00040 <font class="keywordtype">void</font>
00041 delete_c_array2(T**b)<font class="keyword"></font>
00042 <font class="keyword"></font>{
00043   <font class="keywordflow">if</font> (b) <font class="keyword">delete</font>[] b[0];
00044   <font class="keyword">delete</font>[] b;
00045 }
00046 
00047 template &lt;class T&gt;
00048 T ***
00049 new_c_array3(<font class="keywordtype">int</font> l, <font class="keywordtype">int</font> m, <font class="keywordtype">int</font> n, T)<font class="keyword"></font>
00050 <font class="keyword"></font>{
00051   T *a = 0;
00052   T **b = 0;
00053   T ***c = 0;
00054   <font class="keywordflow">if</font> (l*m*n) a = <font class="keyword">new</font> T[l*m*n];
00055   <font class="keywordflow">if</font> (l*m) b = <font class="keyword">new</font> T*[l*m];
00056   <font class="keywordflow">if</font> (l) c = <font class="keyword">new</font> T**[l];
00057   <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=0,ij=0; i&lt;l; i++) {
00058       c[i] = &amp;b[i*m];
00059       <font class="keywordflow">for</font> (<font class="keywordtype">int</font> j=0; j&lt;m; j++,ij++) {
00060           c[i][j] = &amp;a[ij*n];
00061         }
00062     }
00063   <font class="keywordflow">return</font> c;
00064 }
00065 
00066 template &lt;class T&gt;
00067 T ***
00068 new_zero_c_array3(<font class="keywordtype">int</font> l, <font class="keywordtype">int</font> m, <font class="keywordtype">int</font> n, T)<font class="keyword"></font>
00069 <font class="keyword"></font>{
00070   T *a = 0;
00071   T **b = 0;
00072   T ***c = 0;
00073   <font class="keywordflow">if</font> (l*m*n) a = <font class="keyword">new</font> T[l*m*n];
00074   <font class="keywordflow">if</font> (l*m) b = <font class="keyword">new</font> T*[l*m];
00075   <font class="keywordflow">if</font> (l) c = <font class="keyword">new</font> T**[l];
00076   <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=0,ij=0; i&lt;l; i++) {
00077       c[i] = &amp;b[i*m];
00078       <font class="keywordflow">for</font> (<font class="keywordtype">int</font> j=0; j&lt;m; j++,ij++) {
00079           c[i][j] = &amp;a[ij*n];
00080           <font class="keywordflow">for</font> (<font class="keywordtype">int</font> k=0; k&lt;n; k++) {
00081               c[i][j][k] = 0;
00082             }
00083         }
00084     }
00085   <font class="keywordflow">return</font> c;
00086 }
00087 
00088 template &lt;class T&gt;
00089 <font class="keywordtype">void</font>
00090 delete_c_array3(T***b)<font class="keyword"></font>
00091 <font class="keyword"></font>{
00092   <font class="keywordflow">if</font> (b &amp;&amp; b[0]) <font class="keyword">delete</font>[] b[0][0];
00093   <font class="keywordflow">if</font> (b) <font class="keyword">delete</font>[] b[0];
00094   <font class="keyword">delete</font>[] b;
00095 }
00096 
00097 }
00098 
00099 <font class="preprocessor">#endif</font>
00100 <font class="preprocessor"></font>
00101 <font class="comment">// ///////////////////////////////////////////////////////////////////////////</font>
00102 
00103 <font class="comment">// Local Variables:</font>
00104 <font class="comment">// mode: c++</font>
00105 <font class="comment">// c-file-style: "CLJ"</font>
00106 <font class="comment">// End:</font>
</div></pre><hr>
<address>
<small>

Generated at Mon Oct 14 14:16:36 2002 for <a
href="http://aros.ca.sandia.gov/~cljanss/mpqc">MPQC</a>
2.1.2 using the documentation package <a
href="http://www.stack.nl/~dimitri/doxygen/index.html">Doxygen</a>
1.2.5.

</small>
</address>
</body>
</html>