blob: b0063b8f3241764e487e68beb914a1638b659d74 [file] [log] [blame]
<HTML><HEAD><TITLE>Xalan-C++ API Documentation</TITLE></HEAD>
<BODY>
<h2 align="center">Xalan-C++ API Documentation</h2>
<h3 align="center">The Xalan C++ XSLT Processor Version 1.10</h3>
</BODY>
<!-- Generated by Doxygen 1.2.8.1 -->
<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="classes.html">Alphabetical List</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="globals.html">File Members</a> &nbsp; </center>
<hr><h1>ReusableArenaBlock.hpp</h1><a href="ReusableArenaBlock_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/*</font>
00002 <font class="comment"> * Copyright 1999-2004 The Apache Software Foundation.</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</font>
00005 <font class="comment"> * you may not use this file except in compliance with the License.</font>
00006 <font class="comment"> * You may obtain a copy of the License at</font>
00007 <font class="comment"> *</font>
00008 <font class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</font>
00009 <font class="comment"> *</font>
00010 <font class="comment"> * Unless required by applicable law or agreed to in writing, software</font>
00011 <font class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</font>
00012 <font class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</font>
00013 <font class="comment"> * See the License for the specific language governing permissions and</font>
00014 <font class="comment"> * limitations under the License.</font>
00015 <font class="comment"> */</font>
00016
00017 <font class="preprocessor">#if !defined(REUSABLEARENABLOCK_INCLUDE_GUARD_1357924680)</font>
<a name="l00018"></a><a class="code" href="ReusableArenaBlock_8hpp.html#a0">00018</a> <font class="preprocessor"></font><font class="preprocessor">#define REUSABLEARENABLOCK_INCLUDE_GUARD_1357924680</font>
00019 <font class="preprocessor"></font>
00020
00021 <font class="preprocessor">#include &lt;<a class="code" href="ArenaBlockBase_8hpp.html">xalanc/PlatformSupport/ArenaBlockBase.hpp</a>&gt;</font>
00022
00023
00024
00025 <font class="preprocessor">#include &lt;<a class="code" href="XalanMemMgrAutoPtr_8hpp.html">xalanc/Include/XalanMemMgrAutoPtr.hpp</a>&gt;</font>
00026
00027
00028
00029 XALAN_CPP_NAMESPACE_BEGIN
00030
00031
00032
00033 <font class="keyword">template</font> &lt;<font class="keyword">class </font><a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>,
00034 <font class="preprocessor">#if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)</font>
00035 <font class="preprocessor"></font> <font class="keyword">class </font>SizeType&gt;
00036 <font class="preprocessor">#else</font>
00037 <font class="preprocessor"></font> <font class="keyword">class </font>SizeType = unsigned short&gt;
00038 #endif
<a name="l00039"></a><a class="code" href="classReusableArenaBlock.html">00039</a> class <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlock</a> : <font class="keyword">public</font> <a class="code" href="classArenaBlockBase.html">ArenaBlockBase</a>&lt;ObjectType, SizeType&gt;
00040 {
00041
00042 <font class="keyword">public</font>:
00043
<a name="l00044"></a><a class="code" href="classReusableArenaBlock.html#s0">00044</a> <font class="keyword">typedef</font> <a class="code" href="classArenaBlockBase.html">ArenaBlockBase&lt;ObjectType, SizeType&gt;</a> <a class="code" href="classstd_1_1unary__function.html">BaseClassType</a>;
00045
<a name="l00046"></a><a class="code" href="classReusableArenaBlock.html#s1">00046</a> <font class="keyword">typedef</font> <font class="keyword">typename</font> BaseClassType::size_type size_type;
00047
<a name="l00048"></a><a class="code" href="classReusableArenaBlock.html#s2">00048</a> <font class="keyword">typedef</font> <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlock&lt;ObjectType, SizeType&gt;</a> <a class="code" href="classXalanDeque.html">ThisType</a>;
00049
<a name="l00050"></a><a class="code" href="structReusableArenaBlock_1_1NextBlock.html">00050</a> <font class="keyword">struct </font>NextBlock
00051 {
00052 <font class="keyword">enum</font> { VALID_OBJECT_STAMP = 0xffddffdd };
00053
<a name="l00054"></a><a class="code" href="structReusableArenaBlock_1_1NextBlock.html#m0">00054</a> size_type next;
<a name="l00055"></a><a class="code" href="structReusableArenaBlock_1_1NextBlock.html#m1">00055</a> <font class="keyword">const</font> <font class="keywordtype">int</font> verificationStamp;
00056
<a name="l00057"></a><a class="code" href="structReusableArenaBlock_1_1NextBlock.html#a0">00057</a> <a class="code" href="structReusableArenaBlock_1_1NextBlock.html#a0">NextBlock</a>( size_type _next):
00058 next(_next),
00059 verificationStamp(VALID_OBJECT_STAMP)
00060 {
00061 }
00062
00063 <font class="keywordtype">bool</font>
<a name="l00064"></a><a class="code" href="structReusableArenaBlock_1_1NextBlock.html#a1">00064</a> <a class="code" href="structReusableArenaBlock_1_1NextBlock.html#a1">isValidFor</a>( size_type rightBorder )<font class="keyword"> const</font>
00065 <font class="keyword"> </font>{
00066 <font class="keywordflow">return</font> ( ( verificationStamp == int(VALID_OBJECT_STAMP)) &amp;&amp;
00067 ( next &lt;= rightBorder ) ) ? <font class="keyword">true</font> : <font class="keyword">false</font> ;
00068 }
00069
00070 <font class="keyword">static</font> NextBlock*
<a name="l00071"></a><a class="code" href="structReusableArenaBlock_1_1NextBlock.html#d0">00071</a> <a class="code" href="structReusableArenaBlock_1_1NextBlock.html#d0">cast</a>(<font class="keywordtype">void</font>* thePointer)<font class="keyword"></font>
00072 <font class="keyword"> </font>{
00073 <font class="keywordflow">return</font> reinterpret_cast&lt;NextBlock*&gt;(thePointer);
00074 }
00075
00076 <font class="keyword">static</font> <font class="keyword">const</font> NextBlock*
<a name="l00077"></a><a class="code" href="structReusableArenaBlock_1_1NextBlock.html#d1">00077</a> <a class="code" href="structReusableArenaBlock_1_1NextBlock.html#d0">cast</a>(<font class="keyword">const</font> <font class="keywordtype">void</font>* thePointer)<font class="keyword"></font>
00078 <font class="keyword"> </font>{
00079 <font class="keywordflow">return</font> reinterpret_cast&lt;const NextBlock*&gt;(thePointer);
00080 }
00081 };
00082
00083 <font class="comment">/*</font>
00084 <font class="comment"> * Construct an ArenaBlock of the specified size</font>
00085 <font class="comment"> * of objects.</font>
00086 <font class="comment"> *</font>
00087 <font class="comment"> * @param theBlockSize The size of the block (the</font>
00088 <font class="comment"> * number of objects it can contain).</font>
00089 <font class="comment"> */</font>
<a name="l00090"></a><a class="code" href="classReusableArenaBlock.html#a0">00090</a> <a class="code" href="classReusableArenaBlock.html#a0">ReusableArenaBlock</a>(
00091 MemoryManagerType&amp; theManager,
00092 size_type theBlockSize) :
00093 <a class="code" href="classstd_1_1unary__function.html">BaseClassType</a>(theManager, theBlockSize),
00094 m_firstFreeBlock(0),
00095 m_nextFreeBlock(0)
00096
00097 {
00098 XALAN_STATIC_ASSERT(<font class="keyword">sizeof</font>(<a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>) &gt;= <font class="keyword">sizeof</font>(NextBlock));
00099
00100 <font class="keywordflow">for</font>( size_type i = 0; i &lt; this-&gt;m_blockSize; ++i )
00101 {
00102 <font class="keyword">new</font> (&amp;this-&gt;m_objectBlock[i]) NextBlock(<a class="code" href="classArenaBlockBase.html#s2">size_type</a>(i + 1));
00103 }
00104 }
00105
<a name="l00106"></a><a class="code" href="classReusableArenaBlock.html#a1">00106</a> <a class="code" href="classReusableArenaBlock.html#a1">~ReusableArenaBlock</a>()<font class="keyword"></font>
00107 <font class="keyword"> </font>{
00108 size_type removedObjects = 0;
00109
00110 <font class="keywordflow">for</font> (size_type i = 0;
00111 i &lt; this-&gt;m_blockSize &amp;&amp;
00112 removedObjects &lt; this-&gt;m_objectCount;
00113 ++i)
00114 {
00115 NextBlock* <font class="keyword">const</font> pStruct =
00116 NextBlock::cast(&amp;this-&gt;m_objectBlock[i]);
00117
00118 <font class="keywordflow">if</font> ( <a class="code" href="classReusableArenaBlock.html#b1">isOccupiedBlock</a>(pStruct) )
00119 {
00120 this-&gt;m_objectBlock[i].~ObjectType();
00121
00122 ++removedObjects;
00123 }
00124 }
00125 }
00126
00127 <font class="keyword">static</font> <a class="code" href="classXalanDeque.html">ThisType</a>*
<a name="l00128"></a><a class="code" href="classReusableArenaBlock.html#d0">00128</a> <a class="code" href="classReusableArenaBlock.html#d0">create</a>(
00129 MemoryManagerType&amp; theManager,
00130 size_type theBlockSize)<font class="keyword"></font>
00131 <font class="keyword"> </font>{
00132 <a class="code" href="classXalanDeque.html">ThisType</a>* theInstance;
00133
00134 <font class="keywordflow">return</font> <a class="code" href="XalanMemoryManagement_8hpp.html#a17">XalanConstruct</a>(
00135 theManager,
00136 theInstance,
00137 theManager,
00138 theBlockSize);
00139 }
00140
00141 <font class="comment">/*</font>
00142 <font class="comment"> * Allocate a block. Once the object is constructed, you must call</font>
00143 <font class="comment"> * commitAllocation().</font>
00144 <font class="comment"> *</font>
00145 <font class="comment"> * @return a pointer to the new block.</font>
00146 <font class="comment"> */</font>
00147 <a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>*
<a name="l00148"></a><a class="code" href="classReusableArenaBlock.html#a2">00148</a> <a class="code" href="classReusableArenaBlock.html#a2">allocateBlock</a>()<font class="keyword"></font>
00149 <font class="keyword"> </font>{
00150 <font class="keywordflow">if</font> ( this-&gt;m_objectCount == this-&gt;m_blockSize )
00151 {
00152 assert ( this-&gt;m_firstFreeBlock == (this-&gt;m_blockSize + 1) );
00153
00154 <font class="keywordflow">return</font> 0;
00155 }
00156 <font class="keywordflow">else</font>
00157 {
00158 assert( this-&gt;m_objectCount &lt; this-&gt;m_blockSize );
00159
00160 <a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* theResult = 0;
00161
00162 assert ( this-&gt;m_firstFreeBlock &lt;= this-&gt;m_blockSize );
00163 assert ( this-&gt;m_nextFreeBlock &lt;= this-&gt;m_blockSize );
00164
00165 <font class="comment">// check if any part was allocated but not commited</font>
00166 <font class="keywordflow">if</font>(this-&gt;m_firstFreeBlock != this-&gt;m_nextFreeBlock)
00167 {
00168 <font class="comment">// return the previously allocated block and wait for a commit</font>
00169 theResult = this-&gt;m_objectBlock + this-&gt;m_firstFreeBlock;
00170 }
00171 <font class="keywordflow">else</font>
00172 {
00173 theResult = this-&gt;m_objectBlock + this-&gt;m_firstFreeBlock;
00174
00175 assert(<a class="code" href="classArenaBlockBase.html#s2">size_type</a>(theResult - this-&gt;m_objectBlock) &lt; this-&gt;m_blockSize);
00176
00177 this-&gt;m_nextFreeBlock = NextBlock::cast(theResult)-&gt;next;
00178
00179 assert(NextBlock::cast(theResult)-&gt;isValidFor(this-&gt;m_blockSize));
00180 assert(this-&gt;m_nextFreeBlock &lt;= this-&gt;m_blockSize);
00181
00182 ++this-&gt;m_objectCount;
00183 }
00184
00185 <font class="keywordflow">return</font> theResult;
00186 }
00187 }
00188
00189 <font class="comment">/*</font>
00190 <font class="comment"> * Commit the previous allocation.</font>
00191 <font class="comment"> *</font>
00192 <font class="comment"> * @param theBlock the address that was returned by allocateBlock()</font>
00193 <font class="comment"> */</font>
00194 <font class="keywordtype">void</font>
<a name="l00195"></a><a class="code" href="classReusableArenaBlock.html#a3">00195</a> <a class="code" href="classReusableArenaBlock.html#a3">commitAllocation</a>(<a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* <font class="comment">/* theBlock */</font>)<font class="keyword"></font>
00196 <font class="keyword"> </font>{
00197 assert ( this-&gt;m_objectCount &lt;= this-&gt;m_blockSize );
00198
00199 this-&gt;m_firstFreeBlock = this-&gt;m_nextFreeBlock;
00200 }
00201
00202 <font class="comment">/*</font>
00203 <font class="comment"> * Destroy the object, and return the block to the free list.</font>
00204 <font class="comment"> * The behavior is undefined if the object pointed to is not</font>
00205 <font class="comment"> * owned by the block.</font>
00206 <font class="comment"> *</font>
00207 <font class="comment"> * @param theObject the address of the object.</font>
00208 <font class="comment"> */</font>
00209 <font class="keywordtype">void</font>
<a name="l00210"></a><a class="code" href="classReusableArenaBlock.html#a4">00210</a> <a class="code" href="classReusableArenaBlock.html#a4">destroyObject</a>(<a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* theObject)<font class="keyword"></font>
00211 <font class="keyword"> </font>{
00212 assert(theObject != 0);
00213
00214 <font class="comment">// check if any uncommited block is there, add it to the list</font>
00215 <font class="keywordflow">if</font> ( this-&gt;m_firstFreeBlock != this-&gt;m_nextFreeBlock )
00216 {
00217 <font class="comment">// Return it to the pool of free blocks</font>
00218 <font class="keywordtype">void</font>* <font class="keyword">const</font> p = this-&gt;m_objectBlock + this-&gt;m_firstFreeBlock;
00219
00220 <font class="keyword">new</font> (p) NextBlock(this-&gt;m_nextFreeBlock);
00221
00222 this-&gt;m_nextFreeBlock = this-&gt;m_firstFreeBlock;
00223 }
00224
00225 assert(<a class="code" href="classReusableArenaBlock.html#a5">ownsObject</a>(theObject) == <font class="keyword">true</font>);
00226 assert(<a class="code" href="classReusableArenaBlock.html#b0">shouldDestroyBlock</a>(theObject));
00227
00228 <a class="code" href="XalanMemoryManagement_8hpp.html#a10">XalanDestroy</a>(*theObject);
00229
00230 <font class="keyword">new</font> (theObject) NextBlock(this-&gt;m_firstFreeBlock);
00231
00232 m_firstFreeBlock =
00233 this-&gt;m_nextFreeBlock =
00234 <a class="code" href="classArenaBlockBase.html#s2">size_type</a>(theObject - this-&gt;m_objectBlock);
00235
00236 assert (this-&gt;m_firstFreeBlock &lt;= this-&gt;m_blockSize);
00237
00238 --this-&gt;m_objectCount;
00239 }
00240
00241 <font class="comment">/*</font>
00242 <font class="comment"> * Determine if this block owns the specified object. Note</font>
00243 <font class="comment"> * that even if the object address is within our block, this</font>
00244 <font class="comment"> * call will return false if no object currently occupies the</font>
00245 <font class="comment"> * block. See also ownsBlock().</font>
00246 <font class="comment"> *</font>
00247 <font class="comment"> * @param theObject the address of the object.</font>
00248 <font class="comment"> * @return true if we own the object, false if not.</font>
00249 <font class="comment"> */</font>
00250 <font class="keywordtype">bool</font>
<a name="l00251"></a><a class="code" href="classReusableArenaBlock.html#a5">00251</a> <a class="code" href="classReusableArenaBlock.html#a5">ownsObject</a>(<font class="keyword">const</font> <a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* theObject)<font class="keyword"> const</font>
00252 <font class="keyword"> </font>{
00253 assert ( theObject != 0 );
00254
00255 <font class="keywordflow">return</font> <a class="code" href="classReusableArenaBlock.html#b1">isOccupiedBlock</a>(NextBlock::cast(theObject));
00256 }
00257
00258 <font class="keyword">protected</font>:
00259
00260 <font class="comment">/*</font>
00261 <font class="comment"> * Determine if the block should be destroyed. Returns true,</font>
00262 <font class="comment"> * unless the object is on the free list. The behavior is</font>
00263 <font class="comment"> * undefined if the object pointed to is not owned by the</font>
00264 <font class="comment"> * block.</font>
00265 <font class="comment"> *</font>
00266 <font class="comment"> * @param theObject the address of the object</font>
00267 <font class="comment"> * @return true if block should be destroyed, false if not.</font>
00268 <font class="comment"> */</font>
00269 <font class="keywordtype">bool</font>
<a name="l00270"></a><a class="code" href="classReusableArenaBlock.html#b0">00270</a> <a class="code" href="classReusableArenaBlock.html#b0">shouldDestroyBlock</a>(<font class="keyword">const</font> <a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* theObject)<font class="keyword"> const</font>
00271 <font class="keyword"> </font>{
00272 assert(<a class="code" href="classArenaBlockBase.html#s2">size_type</a>(theObject - this-&gt;m_objectBlock) &lt; this-&gt;m_blockSize);
00273
00274 <font class="keywordflow">return</font> !isOnFreeList(theObject);
00275 }
00276
00277 <font class="keywordtype">bool</font>
<a name="l00278"></a><a class="code" href="classReusableArenaBlock.html#b1">00278</a> <a class="code" href="classReusableArenaBlock.html#b1">isOccupiedBlock</a>(<font class="keyword">const</font> NextBlock* block)<font class="keyword"> const</font>
00279 <font class="keyword"> </font>{
00280 assert( block !=0 );
00281
00282 <font class="keywordflow">return</font> !(this-&gt;<a class="code" href="classArenaBlockBase.html#a5">ownsBlock</a>(reinterpret_cast&lt;const ObjectType*&gt;(block)) &amp;&amp;
00283 block-&gt;isValidFor(this-&gt;m_blockSize));
00284 }
00285
00286 <font class="keyword">private</font>:
00287
00288 <font class="comment">// Not implemented...</font>
00289 <a class="code" href="classReusableArenaBlock.html#a0">ReusableArenaBlock</a>(<font class="keyword">const</font> <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlock&lt;ObjectType, SizeType&gt;</a>&amp;);
00290
00291 <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlock&lt;ObjectType, SizeType&gt;</a>&amp;
00292 operator=(<font class="keyword">const</font> <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlock&lt;ObjectType, SizeType&gt;</a>&amp;);
00293
00294 <font class="keywordtype">bool</font>
00295 <a class="code" href="ElemAttributeSet_8hpp.html#a1">operator==</a>(<font class="keyword">const</font> <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlock&lt;ObjectType, SizeType&gt;</a>&amp;) <font class="keyword">const</font>;
00296
00297
00298 <font class="comment">/*</font>
00299 <font class="comment"> * Determine if the block is on the free list. The behavior is</font>
00300 <font class="comment"> * undefined if the object pointed to is not owned by the</font>
00301 <font class="comment"> * block.</font>
00302 <font class="comment"> *</font>
00303 <font class="comment"> * @param theObject the address of the object</font>
00304 <font class="comment"> * @return true if block is on the free list, false if not.</font>
00305 <font class="comment"> */</font>
00306 <font class="keywordtype">bool</font>
00307 isOnFreeList(<font class="keyword">const</font> <a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* theObject)<font class="keyword"> const</font>
00308 <font class="keyword"> </font>{
00309 <font class="keywordflow">if</font> ( this-&gt;m_objectCount == 0 )
00310 {
00311 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00312 }
00313 <font class="keywordflow">else</font>
00314 {
00315 <a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* pRunPtr = this-&gt;m_objectBlock + this-&gt;m_firstFreeBlock;
00316
00317 <font class="keywordflow">for</font> (size_type i = 0;
00318 i &lt; this-&gt;m_blockSize - this-&gt;m_objectCount;
00319 ++i)
00320 {
00321 assert(this-&gt;ownsBlock(pRunPtr));
00322
00323 <font class="keywordflow">if</font> (pRunPtr == theObject)
00324 {
00325 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00326 }
00327 <font class="keywordflow">else</font>
00328 {
00329 NextBlock* <font class="keyword">const</font> p = reinterpret_cast&lt;NextBlock*&gt;(pRunPtr);
00330
00331 assert(p-&gt;isValidFor(this-&gt;m_blockSize));
00332
00333 pRunPtr = this-&gt;m_objectBlock + p-&gt;next;
00334 }
00335 }
00336
00337 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00338 }
00339 }
00340
00341 <font class="comment">// Data members...</font>
00342 size_type m_firstFreeBlock;
00343
00344 size_type m_nextFreeBlock;
00345 };
00346
00347
00348
00349 XALAN_CPP_NAMESPACE_END
00350
00351
00352
00353 <font class="preprocessor">#endif // !defined(REUSABLEARENABLOCK_INCLUDE_GUARD_1357924680)</font>
</font></pre></div><p align="center"><a href="diagramnotes.html">Interpreting class diagrams</a></p>
<p><FONT color="#000000" face="arial,helvetica,sanserif" size="-1">
<i><A href="http://www.stack.nl/~dimitri/doxygen/">Doxygen</A> and
<A href="http://www.research.att.com/sw/tools/graphviz/">GraphViz</A> are used to generate this API documentation from the Xalan-C header files.</I></FONT></p>
<TABLE border="0" cellpadding="0" cellspacing="0" width="820"><TR><TD bgcolor="#0086b2"><IMG height="1" src="../resources/dot.gif" width="1" alt="dot"></TD></TR></TABLE>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="80%">
<TR>
<TD WIDTH="80%" VALIGN="TOP">
<P ALIGN="CENTER"><B>Xalan-C++ XSLT Processor Version 1.10</B><BR>
Copyright &copy; 1999-2004 The Apache Software Foundation. All Rights Reserved.</i></p>
</TD>
</TR>
<TR>
<TD WIDTH="100%">
<P ALIGN="CENTER"><IMG SRC="ApacheLogo.jpg" WIDTH="387" HEIGHT="100" ALIGN="BOTTOM" BORDER="0" ALT="Apache Logo">
</TD>
</TR>
</TABLE>