blob: 6fee4c63a2994ff60aa312e889e8c9b0713b202b [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>XalanArrayAllocator.hpp</h1><a href="XalanArrayAllocator_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 <font class="preprocessor">#if !defined(XALANARRAYALLOCATOR_HEADER_GUARD_1357924680)</font>
<a name="l00017"></a><a class="code" href="XalanArrayAllocator_8hpp.html#a0">00017</a> <font class="preprocessor"></font><font class="preprocessor">#define XALANARRAYALLOCATOR_HEADER_GUARD_1357924680</font>
00018 <font class="preprocessor"></font>
00019
00020
00021 <font class="preprocessor">#include &lt;<a class="code" href="PlatformSupportDefinitions_8hpp.html">xalanc/PlatformSupport/PlatformSupportDefinitions.hpp</a>&gt;</font>
00022
00023
00024
00025 <font class="preprocessor">#include &lt;cassert&gt;</font>
00026 <font class="preprocessor">#include &lt;utility&gt;</font>
00027
00028
00029 <font class="preprocessor">#include &lt;<a class="code" href="XalanMemMgrHelper_8hpp.html">xalanc/Include/XalanMemMgrHelper.hpp</a>&gt;</font>
00030 <font class="preprocessor">#include &lt;<a class="code" href="XalanVector_8hpp.html">xalanc/Include/XalanVector.hpp</a>&gt;</font>
00031 <font class="preprocessor">#include &lt;<a class="code" href="XalanList_8hpp.html">xalanc/Include/XalanList.hpp</a>&gt;</font>
00032
00033
00034
00035 XALAN_CPP_NAMESPACE_BEGIN
00036
00037
00038
00039 template&lt;class Type&gt;
<a name="l00040"></a><a class="code" href="classXalanArrayAllocator.html">00040</a> <font class="keyword">class </font>XALAN_PLATFORMSUPPORT_EXPORT <a class="code" href="classXalanArrayAllocator.html">XalanArrayAllocator</a>
00041 {
00042 <font class="keyword">public</font>:
00043
<a name="l00044"></a><a class="code" href="classXalanArrayAllocator.html#s0">00044</a> <font class="keyword">typedef</font> XalanVector&lt;Type&gt; VectorType;
<a name="l00045"></a><a class="code" href="classXalanArrayAllocator.html#s1">00045</a> <font class="keyword">typedef</font> <font class="keyword">typename</font> VectorType::size_type size_type;
00046
<a name="l00047"></a><a class="code" href="classXalanArrayAllocator.html#s2">00047</a> <font class="keyword">typedef</font> XALAN_STD_QUALIFIER pair&lt;size_type, VectorType * &gt; ListEntryType;
<a name="l00048"></a><a class="code" href="classXalanArrayAllocator.html#s3">00048</a> <font class="keyword">typedef</font> <a class="code" href="classXalanList.html">XalanList&lt;ListEntryType&gt;</a> <a class="code" href="classXalanList.html">ListType</a>;
00049
<a name="l00050"></a><a class="code" href="classXalanArrayAllocator.html#s4">00050</a> <font class="keyword">typedef</font> Type value_type;
00051
<a name="l00052"></a><a class="code" href="classXalanArrayAllocator.html#s5">00052</a> <font class="keyword">typedef</font> <font class="keyword">typename</font> ListType::iterator ListIteratorType;
00053
00054 <font class="comment">// Default size for vector allocation.</font>
00055 <font class="keyword">enum</font> { eDefaultBlockSize = 500 };
00056
<a name="l00062"></a><a class="code" href="classXalanArrayAllocator.html#a0">00062</a> <a class="code" href="classXalanArrayAllocator.html#a0">XalanArrayAllocator</a>(MemoryManagerType&amp; theManager,
00063 size_type theBlockSize = eDefaultBlockSize) :
00064 m_list(theManager),
00065 m_blockSize(theBlockSize),
00066 m_lastEntryFound(0)
00067 {
00068 }
00069
<a name="l00070"></a><a class="code" href="classXalanArrayAllocator.html#a1">00070</a> <a class="code" href="classXalanArrayAllocator.html#a1">~XalanArrayAllocator</a>()<font class="keyword"></font>
00071 <font class="keyword"> </font>{
00072 <font class="keyword">typename</font> ListType::iterator iter = m_list.<a class="code" href="classXalanList.html#a4">begin</a>();
00073
00074 MemoryManagerType&amp; theManager = m_list.<a class="code" href="classXalanList.html#a2">getMemoryManager</a>();
00075
00076 <font class="keywordflow">for</font>( iter = m_list.<a class="code" href="classXalanList.html#a4">begin</a>(); iter != m_list.<a class="code" href="classXalanList.html#a6">end</a>(); ++iter)
00077 {
00078 <font class="keywordflow">if</font>( (*iter).second != 0)
00079 {
00080 <font class="preprocessor">#if defined(XALAN_REQUIRES_QUALIFIED_DESTRUCTOR)</font>
00081 <font class="preprocessor"></font> (*iter).second-&gt;VectorType::~VectorType();
00082 <font class="preprocessor">#else</font>
00083 <font class="preprocessor"></font> (*iter).second-&gt;~VectorType();
00084 <font class="preprocessor">#endif </font>
00085 <font class="preprocessor"></font> theManager.deallocate((<font class="keywordtype">void</font>*)(*iter).second);
00086 }
00087 }
00088 }
00089
00093 <font class="keywordtype">void</font>
<a name="l00094"></a><a class="code" href="classXalanArrayAllocator.html#a2">00094</a> <a class="code" href="classXalanArrayAllocator.html#a2">clear</a>()<font class="keyword"></font>
00095 <font class="keyword"> </font>{
00096 m_list.<a class="code" href="classXalanList.html#a24">clear</a>();
00097
00098 m_lastEntryFound = 0;
00099 }
00100
00106 <font class="keywordtype">void</font>
<a name="l00107"></a><a class="code" href="classXalanArrayAllocator.html#a3">00107</a> <a class="code" href="classXalanArrayAllocator.html#a3">reset</a>()<font class="keyword"></font>
00108 <font class="keyword"> </font>{
00109 <font class="keywordflow">if</font> (m_list.<a class="code" href="classXalanList.html#a15">empty</a>() == <font class="keyword">true</font>)
00110 {
00111 m_lastEntryFound = 0;
00112 }
00113 <font class="keywordflow">else</font>
00114 {
00115 <font class="keyword">const</font> ListIteratorType theEnd = m_list.<a class="code" href="classXalanList.html#a6">end</a>();
00116 ListIteratorType theCurrent = m_list.<a class="code" href="classXalanList.html#a4">begin</a>();
00117
00118 <font class="keywordflow">do</font>
00119 {
00120 (*theCurrent).first = (*theCurrent).second-&gt;size();
00121
00122 ++theCurrent;
00123 } <font class="keywordflow">while</font>(theCurrent != theEnd);
00124
00125 m_lastEntryFound = &amp;*m_list.<a class="code" href="classXalanList.html#a4">begin</a>();
00126 }
00127 }
00128
00135 Type*
<a name="l00136"></a><a class="code" href="classXalanArrayAllocator.html#a4">00136</a> <a class="code" href="classXalanArrayAllocator.html#a4">allocate</a>(size_type theCount)<font class="keyword"></font>
00137 <font class="keyword"> </font>{
00138 <font class="comment">// Handle the case of theCount being greater than the block size first...</font>
00139 <font class="keywordflow">if</font> (theCount &gt;= m_blockSize)
00140 {
00141 <font class="keywordflow">return</font> createEntry(theCount, theCount);
00142 }
00143 <font class="keywordflow">else</font>
00144 {
00145 ListEntryType* theEntry =
00146 findEntry(theCount);
00147
00148 <font class="comment">// Did we find a slot?</font>
00149 <font class="keywordflow">if</font> (theEntry == 0)
00150 {
00151 <font class="comment">// Nope, create a new one...</font>
00152 <font class="keywordflow">return</font> createEntry(m_blockSize, theCount);
00153 }
00154 <font class="keywordflow">else</font>
00155 {
00156 <font class="comment">// The address we want is that of the first free element in the</font>
00157 <font class="comment">// vector...</font>
00158 assert( theEntry-&gt;second != 0);
00159 Type* <font class="keyword">const</font> thePointer =
00160 &amp;*theEntry-&gt;second-&gt;begin() + (theEntry-&gt;second-&gt;size() - theEntry-&gt;first);
00161
00162 <font class="comment">// Resize the vector to the appropriate size...</font>
00163 theEntry-&gt;first -= theCount;
00164
00165 <font class="keywordflow">return</font> thePointer;
00166 }
00167 }
00168 }
00169
00170 <font class="keyword">private</font>:
00171
00172 <font class="comment">// Utility functions...</font>
00173 Type*
00174 createEntry(
00175 size_type theBlockSize,
00176 size_type theCount)<font class="keyword"></font>
00177 <font class="keyword"> </font>{
00178 assert(theBlockSize &gt;= theCount);
00179
00180 <font class="comment">// Push on a new entry. The entry has no open space,</font>
00181 <font class="comment">// since it's greater than our block size...</font>
00182 m_list.<a class="code" href="classXalanList.html#a16">push_back</a>(<a class="code" href="classXalanArrayAllocator.html#s2">ListEntryType</a>(0, VectorType::create(m_list.<a class="code" href="classXalanList.html#a2">getMemoryManager</a>())));
00183
00184 <font class="comment">// Get the new entry...</font>
00185 ListEntryType&amp; theNewEntry = m_list.<a class="code" href="classXalanList.html#a13">back</a>();
00186
00187 <font class="comment">// Resize the vector to the appropriate size...</font>
00188 assert(theNewEntry.second);
00189
00190 theNewEntry.second-&gt;resize(theBlockSize, <a class="code" href="classXalanArrayAllocator.html#s4">value_type</a>());
00191
00192 <font class="comment">// Set the number of free spaces accordingly...</font>
00193 theNewEntry.first = theBlockSize - theCount;
00194
00195 <font class="keywordflow">if</font> (theNewEntry.first != 0)
00196 {
00197 m_lastEntryFound = &amp;theNewEntry;
00198 }
00199
00200 <font class="comment">// Return a pointer to the beginning of the allocated memory...</font>
00201 <font class="keywordflow">return</font> &amp;*theNewEntry.second-&gt;begin();
00202 }
00203
00204 ListEntryType*
00205 findEntry(size_type theCount)<font class="keyword"></font>
00206 <font class="keyword"> </font>{
00207 <font class="comment">// Search for an entry that has some free space.</font>
00208
00209 <font class="keywordflow">if</font> (m_lastEntryFound != 0 &amp;&amp; m_lastEntryFound-&gt;first &gt;= theCount)
00210 {
00211 <font class="keywordflow">return</font> m_lastEntryFound;
00212 }
00213 <font class="keywordflow">else</font>
00214 {
00215 <font class="keyword">const</font> ListIteratorType theEnd = m_list.<a class="code" href="classXalanList.html#a6">end</a>();
00216 ListIteratorType theCurrent = m_list.<a class="code" href="classXalanList.html#a4">begin</a>();
00217
00218 ListEntryType* theEntry = 0;
00219
00220 <font class="keywordflow">while</font>(theCurrent != theEnd)
00221 {
00222 <font class="comment">// We're looking for the best fit, so</font>
00223 <font class="comment">// if the free space and the count we're</font>
00224 <font class="comment">// looking for are equal, that's pretty</font>
00225 <font class="comment">// much the best we can do...</font>
00226 <font class="keywordflow">if</font> ((*theCurrent).first == theCount)
00227 {
00228 theEntry = &amp;*theCurrent;
00229
00230 <font class="keywordflow">break</font>;
00231 }
00232 <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((*theCurrent).first &gt;= theCount)
00233 {
00234 <font class="comment">// If we haven't found anything yet, the first</font>
00235 <font class="comment">// entry we find that's large enough becomes</font>
00236 <font class="comment">// our best fit.</font>
00237 <font class="comment">//</font>
00238 <font class="comment">// Otherwise, we'll assume that a smaller</font>
00239 <font class="comment">// slot is a better fit, though I may be</font>
00240 <font class="comment">// wrong about this...</font>
00241 <font class="keywordflow">if</font> (theEntry == 0 ||
00242 (*theCurrent).first &lt; theEntry-&gt;first)
00243 {
00244 <font class="comment">// Nope, so this becomes our best-fit so far.</font>
00245 theEntry = &amp;*theCurrent;
00246 }
00247
00248 ++theCurrent;
00249 }
00250 <font class="keywordflow">else</font>
00251 {
00252 <font class="comment">// Won't fit, so just continue...</font>
00253 ++theCurrent;
00254 }
00255 }
00256
00257 m_lastEntryFound = theEntry;
00258
00259 <font class="keywordflow">return</font> theEntry;
00260 }
00261 }
00262
00263 <font class="comment">// Not implemented...</font>
00264 <a class="code" href="classXalanArrayAllocator.html#a0">XalanArrayAllocator</a>(<font class="keyword">const</font> <a class="code" href="classXalanArrayAllocator.html">XalanArrayAllocator&lt;Type&gt;</a>&amp; theSource);
00265
00266 <a class="code" href="classXalanArrayAllocator.html">XalanArrayAllocator&lt;Type&gt;</a>&amp;
00267 operator=(<font class="keyword">const</font> <a class="code" href="classXalanArrayAllocator.html">XalanArrayAllocator&lt;Type&gt;</a>&amp; theSource);
00268
00269 <font class="keywordtype">bool</font>
00270 <a class="code" href="ElemAttributeSet_8hpp.html#a1">operator==</a>(<font class="keyword">const</font> <a class="code" href="classXalanArrayAllocator.html">XalanArrayAllocator&lt;Type&gt;</a>&amp; theRHS) <font class="keyword">const</font>;
00271
00272
00273 <font class="comment">// Data members...</font>
00274 <a class="code" href="classXalanList.html">ListType</a> m_list;
00275
00276 <font class="keyword">const</font> size_type m_blockSize;
00277
00278 ListEntryType* m_lastEntryFound;
00279 };
00280
00281
00282
00283 XALAN_CPP_NAMESPACE_END
00284
00285
00286
00287 <font class="preprocessor">#endif // !defined(XALANARRAYALLOCATOR_HEADER_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>