blob: 8e268153decaae97d8fec6b87c66dc502d262fb5 [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>ReusableArenaAllocator.hpp</h1><a href="ReusableArenaAllocator_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(REUSABLEARENAALLOCATOR_INCLUDE_GUARD_1357924680)</font>
<a name="l00018"></a><a class="code" href="ReusableArenaAllocator_8hpp.html#a0">00018</a> <font class="preprocessor"></font><font class="preprocessor">#define REUSABLEARENAALLOCATOR_INCLUDE_GUARD_1357924680</font>
00019 <font class="preprocessor"></font>
00020
00021
00022 <font class="preprocessor">#include &lt;algorithm&gt;</font>
00023
00024
00025
00026 <font class="preprocessor">#include "<a class="code" href="ReusableArenaBlock_8hpp.html">ReusableArenaBlock.hpp</a>"</font>
00027 <font class="preprocessor">#include "<a class="code" href="ArenaAllocator_8hpp.html">ArenaAllocator.hpp</a>"</font>
00028
00029
00030
00031 XALAN_CPP_NAMESPACE_BEGIN
00032
00033
00034
00035 template&lt;class ObjectType&gt;
<a name="l00036"></a><a class="code" href="classReusableArenaAllocator.html">00036</a> <font class="keyword">class </font><a class="code" href="classReusableArenaAllocator.html">ReusableArenaAllocator</a> : <font class="keyword">public</font> <a class="code" href="classArenaAllocator.html">ArenaAllocator</a>&lt;ObjectType,
00037 ReusableArenaBlock&lt;ObjectType&gt; &gt;
00038 {
00039 <font class="keyword">public</font>:
00040
<a name="l00041"></a><a class="code" href="classReusableArenaAllocator.html#s0">00041</a> <font class="keyword">typedef</font> <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlock&lt;ObjectType&gt;</a> <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlockType</a>;
00042
<a name="l00043"></a><a class="code" href="classReusableArenaAllocator.html#s1">00043</a> <font class="keyword">typedef</font> <font class="keyword">typename</font> ReusableArenaBlockType::size_type size_type;
00044
00045 <font class="keyword">typedef</font> <a class="code" href="classArenaAllocator.html">ArenaAllocator</a>&lt;<a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>,
<a name="l00046"></a><a class="code" href="classReusableArenaAllocator.html#s2">00046</a> <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlockType</a>&gt; <a class="code" href="classstd_1_1unary__function.html">BaseClassType</a>;
00047
<a name="l00048"></a><a class="code" href="classReusableArenaAllocator.html#s3">00048</a> <font class="keyword">typedef</font> <a class="code" href="classReusableArenaAllocator.html">ReusableArenaAllocator&lt;ObjectType&gt;</a> <a class="code" href="classXalanDeque.html">ThisType</a>;
00049
<a name="l00050"></a><a class="code" href="classReusableArenaAllocator.html#s4">00050</a> <font class="keyword">typedef</font> <a class="code" href="classXalanList.html">XalanList&lt;ReusableArenaBlockType*&gt;</a> <a class="code" href="classXalanList.html">ArenaBlockListType</a>;
00051
<a name="l00052"></a><a class="code" href="classReusableArenaAllocator.html#s5">00052</a> <font class="keyword">typedef</font> <font class="keyword">typename</font> ArenaBlockListType::iterator iterator;
<a name="l00053"></a><a class="code" href="classReusableArenaAllocator.html#s6">00053</a> <font class="keyword">typedef</font> <font class="keyword">typename</font> ArenaBlockListType::const_iterator const_iterator;
<a name="l00054"></a><a class="code" href="classReusableArenaAllocator.html#s7">00054</a> <font class="keyword">typedef</font> <font class="keyword">typename</font> ArenaBlockListType::reverse_iterator reverse_iterator;
<a name="l00055"></a><a class="code" href="classReusableArenaAllocator.html#s8">00055</a> <font class="keyword">typedef</font> <font class="keyword">typename</font> ArenaBlockListType::const_reverse_iterator const_reverse_iterator;
00056
00057
00058 <font class="comment">/*</font>
00059 <font class="comment"> * Construct an instance that will allocate blocks of the specified size.</font>
00060 <font class="comment"> *</font>
00061 <font class="comment"> * @param theBlockSize The block size.</font>
00062 <font class="comment"> */</font>
<a name="l00063"></a><a class="code" href="classReusableArenaAllocator.html#a0">00063</a> <a class="code" href="classReusableArenaAllocator.html#a0">ReusableArenaAllocator</a>(
00064 MemoryManagerType&amp; theManager,
00065 size_type theBlockSize,
00066 <font class="keywordtype">bool</font> destroyBlocks = <font class="keyword">false</font>) :
00067 <a class="code" href="classstd_1_1unary__function.html">BaseClassType</a>(theManager, theBlockSize),
00068 m_destroyBlocks(destroyBlocks)
00069 {
00070 }
00071
00072 <font class="keyword">virtual</font>
<a name="l00073"></a><a class="code" href="classReusableArenaAllocator.html#a1">00073</a> <a class="code" href="classReusableArenaAllocator.html#a1">~ReusableArenaAllocator</a>()<font class="keyword"></font>
00074 <font class="keyword"> </font>{
00075 }
00076
00077 <font class="comment">/*</font>
00078 <font class="comment"> * Destroy the object, and free the block for re-use.</font>
00079 <font class="comment"> *</font>
00080 <font class="comment"> * @param theObject the address of the object.</font>
00081 <font class="comment"> * @return true if the object was deleted, false if not.</font>
00082 <font class="comment"> */</font>
00083 <font class="keywordtype">bool</font>
<a name="l00084"></a><a class="code" href="classReusableArenaAllocator.html#a2">00084</a> <a class="code" href="classReusableArenaAllocator.html#a2">destroyObject</a>(<a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* theObject)<font class="keyword"></font>
00085 <font class="keyword"> </font>{
00086 <font class="keywordtype">bool</font> bResult = <font class="keyword">false</font>;
00087
00088 assert ( theObject != 0 );
00089
00090 <font class="keywordflow">if</font> ( this-&gt;m_blocks.empty() )
00091 <font class="keywordflow">return</font> bResult;
00092
00093 iterator iTerator = this-&gt;m_blocks.begin();
00094
00095 iterator iEnd = this-&gt;m_blocks.end();
00096
00097 <font class="comment">// first , run over unfull blocks ( that consentrated from the head )</font>
00098 <font class="keywordflow">while</font>( iTerator != iEnd
00099 &amp;&amp; (*iTerator)-&gt;blockAvailable() )
00100 {
00101 <font class="keywordflow">if</font> ((*iTerator)-&gt;ownsBlock(theObject) == <font class="keyword">true</font>)
00102 {
00103 (*iTerator)-&gt;destroyObject(theObject);
00104
00105 <font class="comment">// move the block we have just deleted to the head of the list</font>
00106 <font class="keywordflow">if</font> (iTerator != this-&gt;m_blocks.begin())
00107 {
00108 <font class="comment">// move the block to the beginning</font>
00109 <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlockType</a>* block = *iTerator;
00110
00111 assert(block != 0);
00112
00113 this-&gt;m_blocks.erase(iTerator);
00114
00115 this-&gt;m_blocks.push_front(block);
00116 }
00117
00118 <font class="keywordflow">if</font> (m_destroyBlocks)
00119 {
00120 <a class="code" href="classReusableArenaAllocator.html#b0">destroyBlock</a>();
00121 }
00122
00123 bResult = <font class="keyword">true</font>;
00124
00125 <font class="keywordflow">break</font>;
00126 }
00127
00128 ++iTerator;
00129 }
00130
00131 reverse_iterator rIterator = this-&gt;m_blocks.rbegin();
00132
00133 reverse_iterator rEnd = this-&gt;m_blocks.rend();
00134
00135 <font class="comment">// if the block hasn't been found from the head , start with full blocks ( from the taile)</font>
00136 <font class="keywordflow">while</font> ( !bResult &amp;&amp; rIterator != rEnd )
00137 {
00138 <font class="keywordflow">if</font> ((*rIterator)-&gt;ownsBlock(theObject))
00139 {
00140 (*rIterator)-&gt;destroyObject(theObject);
00141
00142 <font class="keywordflow">if</font> (rIterator != this-&gt;m_blocks.rbegin())
00143 {
00144 <font class="comment">// move the block to the beginning</font>
00145 <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlockType</a>* block = *iTerator;
00146
00147 assert(block != 0);
00148
00149 this-&gt;m_blocks.erase(iTerator);
00150
00151 this-&gt;m_blocks.push_front(block);
00152
00153 }
00154
00155 <font class="keywordflow">if</font> (m_destroyBlocks)
00156 {
00157 <a class="code" href="classReusableArenaAllocator.html#b0">destroyBlock</a>();
00158 }
00159
00160 bResult = <font class="keyword">true</font>;
00161
00162 <font class="keywordflow">break</font>;
00163 }
00164
00165 <font class="keywordflow">if</font> ( *rIterator == *iTerator)
00166 {
00167 <font class="keywordflow">break</font>;
00168 }
00169 <font class="keywordflow">else</font>
00170 {
00171 ++rIterator;
00172 }
00173 }
00174
00175 <font class="keywordflow">return</font> bResult;
00176
00177 assert ( bResult );
00178 }
00179
00180 <font class="comment">/*</font>
00181 <font class="comment"> * Allocate a block of the appropriate size for an</font>
00182 <font class="comment"> * object. Call commitAllocation() when after</font>
00183 <font class="comment"> * the object is successfully constructed. You _must_</font>
00184 <font class="comment"> * commit an allocation before performing any other</font>
00185 <font class="comment"> * operation on the allocator.</font>
00186 <font class="comment"> * </font>
00187 <font class="comment"> *</font>
00188 <font class="comment"> * @return A pointer to a block of memory</font>
00189 <font class="comment"> */</font>
00190 <font class="keyword">virtual</font> <a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>*
<a name="l00191"></a><a class="code" href="classReusableArenaAllocator.html#a3">00191</a> <a class="code" href="classArenaAllocator.html#a7">allocateBlock</a>()<font class="keyword"></font>
00192 <font class="keyword"> </font>{
00193 <font class="keywordflow">if</font>( this-&gt;m_blocks.empty()
00194 || !this-&gt;m_blocks.front()-&gt;blockAvailable() )
00195 {
00196 this-&gt;m_blocks.push_front(
00197 ReusableArenaBlockType::create(
00198 this-&gt;getMemoryManager(),
00199 this-&gt;m_blockSize));
00200
00201 assert( this-&gt;m_blocks.front() != 0 );
00202 }
00203
00204 assert( this-&gt;m_blocks.front() != 0 );
00205 assert( this-&gt;m_blocks.front()-&gt;blockAvailable() );
00206
00207 <font class="keywordflow">return</font> this-&gt;m_blocks.front()-&gt;allocateBlock();
00208 }
00209
00210 <font class="comment">/*</font>
00211 <font class="comment"> * Commits the allocation of the previous</font>
00212 <font class="comment"> * allocateBlock() call.</font>
00213 <font class="comment"> *</font>
00214 <font class="comment"> * @param theObject A pointer to a block of memory</font>
00215 <font class="comment"> */</font>
00216 <font class="keyword">virtual</font> <font class="keywordtype">void</font>
<a name="l00217"></a><a class="code" href="classReusableArenaAllocator.html#a4">00217</a> <a class="code" href="classArenaAllocator.html#a8">commitAllocation</a>(<a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* theObject)<font class="keyword"></font>
00218 <font class="keyword"> </font>{
00219 <font class="comment">// Note that this-&gt; is required by template lookup rules.</font>
00220 assert( this-&gt;m_blocks.empty() == <font class="keyword">false</font> );
00221 assert( this-&gt;m_blocks.front() != 0 );
00222 assert( this-&gt;m_blocks.front()-&gt;ownsBlock(theObject) == <font class="keyword">true</font> );
00223
00224 this-&gt;m_blocks.front()-&gt;commitAllocation(theObject);
00225
00226 <font class="keywordflow">if</font>( !this-&gt;m_blocks.front()-&gt;blockAvailable() )
00227 {
00228 <a class="code" href="classReusableArenaBlock.html">ReusableArenaBlockType</a>* fullBlock = this-&gt;m_blocks.front();
00229
00230 assert ( fullBlock != 0 );
00231
00232 this-&gt;m_blocks.pop_front();
00233
00234 this-&gt;m_blocks.push_back( fullBlock );
00235 }
00236 }
00237
00238
00239 <font class="keyword">virtual</font> <font class="keywordtype">bool</font>
<a name="l00240"></a><a class="code" href="classReusableArenaAllocator.html#a5">00240</a> <a class="code" href="classArenaAllocator.html#a9">ownsObject</a>(<font class="keyword">const</font> <a class="code" href="classXalanSourceTreeAttr.html">ObjectType</a>* theObject)<font class="keyword"> const</font>
00241 <font class="keyword"> </font>{
00242 <font class="keywordflow">if</font> ( this-&gt;m_blocks.empty() )
00243 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00244
00245 const_iterator iTerator = this-&gt;m_blocks.begin();
00246
00247 const_iterator iEnd = this-&gt;m_blocks.end();
00248
00249 <font class="keywordflow">while</font>( iTerator != iEnd
00250 &amp;&amp; (*iTerator)-&gt;blockAvailable() )
00251 {
00252 <font class="keywordflow">if</font> ((*iTerator)-&gt;ownsBlock(theObject) )
00253 {
00254 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00255 }
00256
00257 ++iTerator;
00258 }
00259
00260 const_reverse_iterator rIterator = this-&gt;m_blocks.rbegin();
00261
00262 const_reverse_iterator rEnd = this-&gt;m_blocks.rend();
00263
00264 <font class="keywordflow">while</font>( rIterator != rEnd )
00265 {
00266 <font class="keywordflow">if</font> ((*rIterator)-&gt;ownsBlock(theObject) )
00267 {
00268 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00269 }
00270
00271 <font class="keywordflow">if</font> ( *iTerator == *rIterator )
00272 {
00273 <font class="keywordflow">break</font>;
00274 }
00275 <font class="keywordflow">else</font>
00276 {
00277 ++rIterator;
00278 }
00279 }
00280
00281 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00282 }
00283
00284 <font class="keyword">protected</font>:
00285
00286 <font class="comment">/*</font>
00287 <font class="comment"> * The method destroys an empty block from the head of the list.</font>
00288 <font class="comment"> * For eliminating multiple create/destroy operation, the block</font>
00289 <font class="comment"> * is destroyed only if the second one is not full.</font>
00290 <font class="comment"> */</font>
00291 <font class="keywordtype">void</font>
<a name="l00292"></a><a class="code" href="classReusableArenaAllocator.html#b0">00292</a> <a class="code" href="classReusableArenaAllocator.html#b0">destroyBlock</a>()<font class="keyword"></font>
00293 <font class="keyword"> </font>{
00294 assert(m_destroyBlocks == <font class="keyword">true</font>);
00295
00296 <font class="keywordflow">if</font> ( this-&gt;m_blocks.empty() == <font class="keyword">false</font>)
00297 {
00298 const_iterator iTerator = this-&gt;m_blocks.begin();
00299
00300 <font class="keywordflow">if</font> ( (*iTerator)-&gt;isEmpty() )
00301 {
00302 ++iTerator;
00303
00304 <font class="keywordflow">if</font> (iTerator == this-&gt;m_blocks.end() ||
00305 (*iTerator)-&gt;blockAvailable() )
00306 {
00307 this-&gt;m_blocks.pop_front();
00308 }
00309 }
00310 }
00311 }
00312
00313 <font class="comment">// data members</font>
<a name="l00314"></a><a class="code" href="classReusableArenaAllocator.html#n0">00314</a> <font class="keyword">const</font> <font class="keywordtype">bool</font> m_destroyBlocks;
00315
00316 <font class="keyword">private</font>:
00317
00318 <font class="comment">// Not defined...</font>
00319 <a class="code" href="classReusableArenaAllocator.html#a0">ReusableArenaAllocator</a>(<font class="keyword">const</font> <a class="code" href="classReusableArenaAllocator.html">ReusableArenaAllocator&lt;ObjectType&gt;</a>&amp;);
00320
00321 <a class="code" href="classReusableArenaAllocator.html">ReusableArenaAllocator&lt;ObjectType&gt;</a>&amp;
00322 operator=(<font class="keyword">const</font> <a class="code" href="classReusableArenaAllocator.html">ReusableArenaAllocator&lt;ObjectType&gt;</a>&amp;);
00323
00324 <font class="keywordtype">bool</font>
00325 <a class="code" href="ElemAttributeSet_8hpp.html#a1">operator==</a>(<font class="keyword">const</font> <a class="code" href="classReusableArenaAllocator.html">ReusableArenaAllocator&lt;ObjectType&gt;</a>&amp;) <font class="keyword">const</font>;
00326 };
00327
00328
00329
00330 XALAN_CPP_NAMESPACE_END
00331
00332
00333
00334 <font class="preprocessor">#endif // !defined(REUSABLEARENAALLOCATOR_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>