Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > ffa1e6f5ad04360808fe8840fe3ba036 > files > 242

vrq-devel-1.0.88-1.fc14.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>vrq: /net/fileserver/nas/home/mdh/vrq/src/cobstack.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
  <table border="0" cellspacing="0" cellpadding="0" width="100%">
   <tr>
    <td width="180"><a href="index.html"><img src="vrq.png" width="150" height="100" border="0" alt="vrq"></a></td>
    <td background="top_bg.png" align="right" width="100%">
      <img src="glyth.png" width="500" height="100" border="0" alt="">
    </td>
   </tr>
   <tr>
    <td background="#FFFFFF" align="right" width="50" height="4"></td>
   </tr>
  </table>
</head><body>
<!-- Generated by Doxygen 1.7.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>/net/fileserver/nas/home/mdh/vrq/src/cobstack.h</h1>  </div>
</div>
<div class="contents">
<a href="cobstack_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*****************************************************************************</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 1997-2007, Mark Hummel</span>
<a name="l00003"></a>00003 <span class="comment"> * This file is part of Vrq.</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Vrq is free software; you can redistribute it and/or</span>
<a name="l00006"></a>00006 <span class="comment"> * modify it under the terms of the GNU General Public</span>
<a name="l00007"></a>00007 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l00008"></a>00008 <span class="comment"> * version 2 of the License, or (at your option) any later version.</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * Vrq is distributed in the hope that it will be useful,</span>
<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<a name="l00013"></a>00013 <span class="comment"> * General Public License for more details.</span>
<a name="l00014"></a>00014 <span class="comment"> *</span>
<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public</span>
<a name="l00016"></a>00016 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l00017"></a>00017 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, </span>
<a name="l00018"></a>00018 <span class="comment"> * Boston, MA  02110-1301  USA</span>
<a name="l00019"></a>00019 <span class="comment"> *****************************************************************************</span>
<a name="l00020"></a>00020 <span class="comment"> */</span>
<a name="l00021"></a>00021 <span class="comment">/******************************************************************************</span>
<a name="l00022"></a>00022 <span class="comment"> *</span>
<a name="l00023"></a>00023 <span class="comment"> *</span>
<a name="l00024"></a>00024 <span class="comment"> *         cobstack.hpp</span>
<a name="l00025"></a>00025 <span class="comment"> *                      - class definition for stack like bulk allocation</span>
<a name="l00026"></a>00026 <span class="comment"> *</span>
<a name="l00027"></a>00027 <span class="comment"> *</span>
<a name="l00028"></a>00028 <span class="comment"> ******************************************************************************</span>
<a name="l00029"></a>00029 <span class="comment"> */</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="preprocessor">#ifndef COBSTACK_HPP</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define COBSTACK_HPP</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;<a class="code" href="glue_8h.html">glue.h</a>&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;list&gt;</span>
<a name="l00038"></a>00038 <span class="keyword">using namespace </span>std;
<a name="l00039"></a>00039 
<a name="l00046"></a><a class="code" href="classCObstack.html">00046</a> <span class="keyword">class </span><a class="code" href="classCObstack.html" title="Bulk object allocation object.">CObstack</a>
<a name="l00047"></a>00047 {
<a name="l00048"></a>00048 <span class="keyword">private</span>:
<a name="l00049"></a>00049         <span class="keyword">static</span>  list&lt;CObstack*&gt;* obstackList;   
<a name="l00050"></a>00050 
<a name="l00054"></a>00054         <span class="keyword">typedef</span> <span class="keyword">struct  </span>obstackChunk_tag {
<a name="l00055"></a>00055                 <span class="keyword">struct  </span>obstackChunk_tag *next; 
<a name="l00056"></a>00056                 <span class="keywordtype">long</span>    size;                   
<a name="l00057"></a>00057                 <span class="keywordtype">long</span>    objectOffset;           
<a name="l00058"></a>00058                 <span class="keywordtype">long</span>    freeOffset;             
<a name="l00059"></a>00059                 <span class="keywordtype">char</span>    data[4];                
<a name="l00060"></a>00060         } Chunk_t;
<a name="l00061"></a>00061 
<a name="l00062"></a>00062         <span class="keyword">static</span> <span class="keyword">const</span>    <span class="keywordtype">int</span> OBSTACK_DEFAULT_BLOCK_SIZE = 
<a name="l00063"></a>00063                                                 1024*64; 
<a name="l00064"></a>00064 
<a name="l00065"></a>00065         <span class="keywordtype">string</span>          name;           
<a name="l00066"></a>00066         Chunk_t*        currentChunk;   
<a name="l00067"></a>00067         <span class="keywordtype">long</span>            alignment;      
<a name="l00068"></a>00068         <span class="keywordtype">long</span>            defaultSize;    
<a name="l00069"></a>00069 
<a name="l00070"></a>00070         <span class="keywordtype">int</span>             chunkCount;     
<a name="l00071"></a>00071         <span class="keywordtype">int</span>             maxChunkCount;  
<a name="l00072"></a>00072 <span class="keyword">public</span>:
<a name="l00077"></a>00077         <span class="keyword">static</span> <span class="keywordtype">void</span> OnExitDumpStats();
<a name="l00084"></a>00084         <a class="code" href="classCObstack.html" title="Bulk object allocation object.">CObstack</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* name, <span class="keywordtype">int</span> chunkSize = OBSTACK_DEFAULT_BLOCK_SIZE );
<a name="l00088"></a>00088         ~<a class="code" href="classCObstack.html" title="Bulk object allocation object.">CObstack</a>( <span class="keywordtype">void</span> );      
<a name="l00094"></a>00094         <span class="keywordtype">void</span>*   Alloc( <a class="code" href="glue_8h.html#a0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size );
<a name="l00099"></a>00099         <span class="keywordtype">void</span>    Free( <span class="keywordtype">void</span>* <span class="keywordtype">object</span> );
<a name="l00106"></a>00106         <span class="keywordtype">void</span>*   GetBase( <span class="keywordtype">void</span> );
<a name="l00113"></a>00113         <span class="keywordtype">void</span>*   NextFree( <span class="keywordtype">void</span> );
<a name="l00120"></a>00120         <span class="keywordtype">void</span>*   Finish( <span class="keywordtype">void</span> );
<a name="l00127"></a>00127         <span class="keywordtype">void</span>*   Copy( <span class="keyword">const</span> <span class="keywordtype">void</span>* ptr, <a class="code" href="glue_8h.html#a0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size );
<a name="l00135"></a>00135         <span class="keywordtype">void</span>*   Copy0( <span class="keyword">const</span> <span class="keywordtype">void</span>* ptr, <a class="code" href="glue_8h.html#a0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size );
<a name="l00140"></a>00140         <a class="code" href="glue_8h.html#a0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a>   GetObjectSize( <span class="keywordtype">void</span> );
<a name="l00147"></a>00147         <span class="keywordtype">void</span>    Grow( <span class="keyword">const</span> <span class="keywordtype">void</span>* ptr, <a class="code" href="glue_8h.html#a0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size );
<a name="l00153"></a>00153         <span class="keywordtype">void</span>    Grow( <a class="code" href="glue_8h.html#a0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size );
<a name="l00159"></a>00159         <span class="keywordtype">void</span>    PtrGrow( <span class="keywordtype">void</span>* ptr );
<a name="l00165"></a>00165         <span class="keywordtype">int</span>     IsOwner( <span class="keywordtype">void</span>* ptr );
<a name="l00166"></a>00166 <span class="keyword">private</span>:
<a name="l00170"></a>00170         <span class="keyword">static</span> <span class="keywordtype">void</span> _OnExitDumpStats();
<a name="l00171"></a>00171         <span class="keywordtype">void</span> DumpStats();
<a name="l00172"></a>00172         <span class="keywordtype">void</span>*   GrowChunk( <a class="code" href="glue_8h.html#a0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> );
<a name="l00176"></a>00176 };
<a name="l00177"></a>00177 
<a name="l00185"></a>00185 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00186"></a><a class="code" href="cobstack_8h.html#a71671edf0b388b3c4d44ffe2bfbacf82">00186</a> <span class="keyword">inline</span> T** <a class="code" href="cobstack_8h.html#a71671edf0b388b3c4d44ffe2bfbacf82" title="Transfer vector of pointers to a linear array allocated on the given obstack.">Finalize</a>( <a class="code" href="classCObstack.html" title="Bulk object allocation object.">CObstack</a>* heap, vector&lt;T*&gt;&amp; v )
<a name="l00187"></a>00187 {
<a name="l00188"></a>00188         <span class="keyword">typename</span> vector&lt;T*&gt;::iterator ptr;
<a name="l00189"></a>00189 
<a name="l00190"></a>00190         <span class="keywordflow">for</span>( ptr = v.begin(); ptr != v.end(); ++ptr ) {
<a name="l00191"></a>00191                 heap-&gt;<a class="code" href="classCObstack.html#af27ba7b48343fbcd84f5420801738f63" title="Grow current object and copy block of data to heap.">Grow</a>( &amp;*ptr, <span class="keyword">sizeof</span>(T*) );
<a name="l00192"></a>00192         }
<a name="l00193"></a>00193         heap-&gt;<a class="code" href="classCObstack.html#a170649ea35a6b88632d4441323641860" title="Grow current object and copy pointer to heap.">PtrGrow</a>(NULL);
<a name="l00194"></a>00194         v.erase( v.begin(), v.end() );
<a name="l00195"></a>00195         <span class="keywordflow">return</span> (T**)heap-&gt;<a class="code" href="classCObstack.html#ad216d2d013e463d652a79c5e2a709fe9" title="Finialized the object.">Finish</a>();
<a name="l00196"></a>00196 }
<a name="l00197"></a>00197 
<a name="l00198"></a>00198 
<a name="l00199"></a>00199 <span class="preprocessor">#endif // COBSTACK_HPP</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>