<!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.5.5 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related 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> <h1>/net/fileserver/nas/home/mdh/vrq/src/cobstack.h</h1><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 "<a class="code" href="glue_8h.html">glue.h</a>"</span> <a name="l00035"></a>00035 <span class="preprocessor">#include <vector></span> <a name="l00036"></a>00036 <span class="keyword">using namespace </span>std; <a name="l00037"></a>00037 <a name="l00044"></a><a class="code" href="classCObstack.html">00044</a> <span class="keyword">class </span><a class="code" href="classCObstack.html" title="Bulk object allocation object.">CObstack</a> <a name="l00045"></a>00045 { <a name="l00046"></a>00046 <span class="keyword">private</span>: <a name="l00047"></a>00047 <a name="l00051"></a>00051 <span class="keyword">typedef</span> <span class="keyword">struct </span>obstackChunk_tag { <a name="l00052"></a>00052 <span class="keyword">struct </span>obstackChunk_tag *next; <a name="l00053"></a>00053 <span class="keywordtype">long</span> size; <a name="l00054"></a>00054 <span class="keywordtype">long</span> objectOffset; <a name="l00055"></a>00055 <span class="keywordtype">long</span> freeOffset; <a name="l00056"></a>00056 <span class="keywordtype">char</span> data[4]; <a name="l00057"></a>00057 } Chunk_t; <a name="l00058"></a>00058 <a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> OBSTACK_DEFAULT_BLOCK_SIZE = <a name="l00060"></a>00060 1024*64; <a name="l00061"></a>00061 <a name="l00062"></a>00062 Chunk_t* currentChunk; <a name="l00063"></a>00063 <span class="keywordtype">long</span> alignment; <a name="l00064"></a>00064 <span class="keywordtype">long</span> defaultSize; <a name="l00065"></a>00065 <a name="l00066"></a>00066 <span class="keyword">public</span>: <a name="l00070"></a>00070 <a class="code" href="classCObstack.html#bcdbf843928aa5d8094871bc16eda915" title="Create object stack.">CObstack</a>(); <a name="l00075"></a>00075 <a class="code" href="classCObstack.html#bcdbf843928aa5d8094871bc16eda915" title="Create object stack.">CObstack</a>( <span class="keywordtype">int</span> chunkSize ); <a name="l00079"></a>00079 <a class="code" href="classCObstack.html#cd532e9dad49a7f0fb9078662776a798" title="Destroy and free object stack storage.">~CObstack</a>( <span class="keywordtype">void</span> ); <a name="l00085"></a>00085 <span class="keywordtype">void</span>* <a class="code" href="classCObstack.html#5a34d5a2800a901ed15366c11bf269ef" title="Allocate block of storage with given size.">Alloc</a>( <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size ); <a name="l00090"></a>00090 <span class="keywordtype">void</span> <a class="code" href="classCObstack.html#7763a15e24a5bd82bc0fd382a1addb06" title="Free all storage including and after object.">Free</a>( <span class="keywordtype">void</span>* <span class="keywordtype">object</span> ); <a name="l00097"></a>00097 <span class="keywordtype">void</span>* <a class="code" href="classCObstack.html#a6d480d625bc9e614d9db94feff56148" title="Get base of current object.">GetBase</a>( <span class="keywordtype">void</span> ); <a name="l00104"></a>00104 <span class="keywordtype">void</span>* <a class="code" href="classCObstack.html#1fadce1a7dfba37fb5a11e3c5fd2b5a9" title="Get next free byte of current object.">NextFree</a>( <span class="keywordtype">void</span> ); <a name="l00111"></a>00111 <span class="keywordtype">void</span>* <a class="code" href="classCObstack.html#d216d2d013e463d652a79c5e2a709fe9" title="Finialized the object.">Finish</a>( <span class="keywordtype">void</span> ); <a name="l00118"></a>00118 <span class="keywordtype">void</span>* <a class="code" href="classCObstack.html#5eda9721eff6e83fc70b1eecc12037be" title="Allocate storage and copy block of memory to heap.">Copy</a>( <span class="keyword">const</span> <span class="keywordtype">void</span>* ptr, <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size ); <a name="l00126"></a>00126 <span class="keywordtype">void</span>* <a class="code" href="classCObstack.html#8853005f4398d98c243c203a8bd20a07" title="Allocate storage and copy block of memory with a byte of 0 to heap.">Copy0</a>( <span class="keyword">const</span> <span class="keywordtype">void</span>* ptr, <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size ); <a name="l00131"></a>00131 <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> <a class="code" href="classCObstack.html#d782078a85dc95960411e09afd268ca2" title="Get size of current open object.">GetObjectSize</a>( <span class="keywordtype">void</span> ); <a name="l00138"></a>00138 <span class="keywordtype">void</span> <a class="code" href="classCObstack.html#f27ba7b48343fbcd84f5420801738f63" title="Grow current object and copy block of data to heap.">Grow</a>( <span class="keyword">const</span> <span class="keywordtype">void</span>* ptr, <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size ); <a name="l00144"></a>00144 <span class="keywordtype">void</span> <a class="code" href="classCObstack.html#f27ba7b48343fbcd84f5420801738f63" title="Grow current object and copy block of data to heap.">Grow</a>( <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> size ); <a name="l00150"></a>00150 <span class="keywordtype">void</span> <a class="code" href="classCObstack.html#170649ea35a6b88632d4441323641860" title="Grow current object and copy pointer to heap.">PtrGrow</a>( <span class="keywordtype">void</span>* ptr ); <a name="l00156"></a>00156 <span class="keywordtype">int</span> <a class="code" href="classCObstack.html#9a1007c7a26a765ed8e007a677f93485" title="Determine if pointer was allocated from this obstack.">IsOwner</a>( <span class="keywordtype">void</span>* ptr ); <a name="l00157"></a>00157 <span class="keyword">private</span>: <a name="l00161"></a>00161 <span class="keywordtype">void</span>* GrowChunk( <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> ); <a name="l00165"></a>00165 }; <a name="l00166"></a>00166 <a name="l00174"></a><a class="code" href="cobstack_8h.html#71671edf0b388b3c4d44ffe2bfbacf82">00174</a> <span class="keyword">template</span><<span class="keyword">class</span> T> <a name="l00175"></a>00175 <span class="keyword">inline</span> T** <a class="code" href="cobstack_8h.html#71671edf0b388b3c4d44ffe2bfbacf82" 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<T*>& v ) <a name="l00176"></a>00176 { <a name="l00177"></a>00177 <span class="keyword">typename</span> vector<T*>::iterator ptr; <a name="l00178"></a>00178 <a name="l00179"></a>00179 <span class="keywordflow">for</span>( ptr = v.begin(); ptr != v.end(); ++ptr ) { <a name="l00180"></a>00180 heap-><a class="code" href="classCObstack.html#f27ba7b48343fbcd84f5420801738f63" title="Grow current object and copy block of data to heap.">Grow</a>( &*ptr, <span class="keyword">sizeof</span>(T*) ); <a name="l00181"></a>00181 } <a name="l00182"></a>00182 heap-><a class="code" href="classCObstack.html#170649ea35a6b88632d4441323641860" title="Grow current object and copy pointer to heap.">PtrGrow</a>(NULL); <a name="l00183"></a>00183 v.erase( v.begin(), v.end() ); <a name="l00184"></a>00184 <span class="keywordflow">return</span> (T**)heap-><a class="code" href="classCObstack.html#d216d2d013e463d652a79c5e2a709fe9" title="Finialized the object.">Finish</a>(); <a name="l00185"></a>00185 } <a name="l00186"></a>00186 <a name="l00187"></a>00187 <a name="l00188"></a>00188 <span class="preprocessor">#endif // COBSTACK_HPP</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Wed Oct 21 18:05:35 2009 for vrq by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address> </body> </html>