Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > dabb57319acb4393549d883bdd5bc220 > files > 124

libgdal0-devel-1.1.8-2mdk.ppc.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>gdalrasterblock.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.3-20001105 on Sat Dec 21 14:01:59 2002 -->
<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="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; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center>
<hr><h1>gdalrasterblock.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> * Copyright (c) 1998, Frank Warmerdam</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</font>
00005 <font class="comment"> * copy of this software and associated documentation files (the "Software"),</font>
00006 <font class="comment"> * to deal in the Software without restriction, including without limitation</font>
00007 <font class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</font>
00008 <font class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</font>
00009 <font class="comment"> * Software is furnished to do so, subject to the following conditions:</font>
00010 <font class="comment"> *</font>
00011 <font class="comment"> * The above copyright notice and this permission notice shall be included</font>
00012 <font class="comment"> * in all copies or substantial portions of the Software.</font>
00013 <font class="comment"> *</font>
00014 <font class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</font>
00015 <font class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</font>
00016 <font class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</font>
00017 <font class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</font>
00018 <font class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</font>
00019 <font class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</font>
00020 <font class="comment"> * DEALINGS IN THE SOFTWARE.</font>
00021 <font class="comment"> ******************************************************************************</font>
00022 <font class="comment"> *</font>
00023 <font class="comment"> * gdalrasterblock.cpp</font>
00024 <font class="comment"> *</font>
00025 <font class="comment"> * The GDALRasterBlock class.</font>
00026 <font class="comment"> *</font>
00027 <font class="comment"> * </font>
00028 <font class="comment"> * $Log: gdalrasterblock_cpp-source.html,v $
00028 <font class="comment"> * Revision 1.13  2002/12/21 19:13:13  warmerda
00028 <font class="comment"> * updated
00028 <font class="comment"> *</font>
00029 <font class="comment"> * Revision 1.8  2002/07/09 20:33:12  warmerda</font>
00030 <font class="comment"> * expand tabs</font>
00031 <font class="comment"> *</font>
00032 <font class="comment"> * Revision 1.7  2001/09/27 16:33:41  warmerda</font>
00033 <font class="comment"> * fixed problems with blocks larger than 2GB/8</font>
00034 <font class="comment"> *</font>
00035 <font class="comment"> * Revision 1.6  2001/07/18 04:04:30  warmerda</font>
00036 <font class="comment"> * added CPL_CVSID</font>
00037 <font class="comment"> *</font>
00038 <font class="comment"> * Revision 1.5  2001/06/22 21:00:06  warmerda</font>
00039 <font class="comment"> * fixed support for caching override by environment variable</font>
00040 <font class="comment"> *</font>
00041 <font class="comment"> * Revision 1.4  2001/06/22 20:09:13  warmerda</font>
00042 <font class="comment"> * added GDAL_CACHEMAX environment variable support</font>
00043 <font class="comment"> *</font>
00044 <font class="comment"> * Revision 1.3  2000/03/31 13:42:49  warmerda</font>
00045 <font class="comment"> * added debugging code</font>
00046 <font class="comment"> *</font>
00047 <font class="comment"> * Revision 1.2  2000/03/24 00:09:05  warmerda</font>
00048 <font class="comment"> * rewrote cache management</font>
00049 <font class="comment"> *</font>
00050 <font class="comment"> * Revision 1.1  1998/12/31 18:52:58  warmerda</font>
00051 <font class="comment"> * New</font>
00052 <font class="comment"> *</font>
00053 <font class="comment"> */</font>
00054 
00055 <font class="preprocessor">#include "gdal_priv.h"</font>
00056 
00057 CPL_CVSID(<font class="stringliteral">"$Id: gdalrasterblock_cpp-source.html,v 1.13 2002/12/21 19:13:13 warmerda Exp $"</font>);
00058 
00059 <font class="keyword">static</font> <font class="keywordtype">int</font> nTileAgeTicker = 0; 
00060 <font class="keyword">static</font> <font class="keywordtype">int</font> bCacheMaxInitialized = FALSE;
00061 <font class="keyword">static</font> <font class="keywordtype">int</font> nCacheMax = 5 * 1024*1024;
00062 <font class="keyword">static</font> <font class="keywordtype">int</font> nCacheUsed = 0;
00063 
00064 <font class="keyword">static</font> <a class="code" href="class_GDALRasterBlock.html">GDALRasterBlock</a>   *poOldest = NULL;    <font class="comment">/* tail */</font>
00065 <font class="keyword">static</font> <a class="code" href="class_GDALRasterBlock.html">GDALRasterBlock</a>   *poNewest = NULL;    <font class="comment">/* head */</font>
00066 
00067 
00068 <font class="comment">/************************************************************************/</font>
00069 <font class="comment">/*                          GDALSetCacheMax()                           */</font>
00070 <font class="comment">/************************************************************************/</font>
00071 
00072 <font class="keywordtype">void</font> GDALSetCacheMax( <font class="keywordtype">int</font> nNewSize )<font class="keyword"></font>
00073 <font class="keyword"></font>
00074 <font class="keyword"></font>{
00075     nCacheMax = nNewSize;
00076     <font class="keywordflow">if</font>( nCacheUsed &gt; nCacheMax )
00077         GDALFlushCacheBlock();
00078 }
00079 
00080 <font class="comment">/************************************************************************/</font>
00081 <font class="comment">/*                          GDALGetCacheMax()                           */</font>
00082 <font class="comment">/************************************************************************/</font>
00083 
00084 <font class="keywordtype">int</font> GDALGetCacheMax()<font class="keyword"></font>
00085 <font class="keyword"></font>{
00086     <font class="keywordflow">if</font>( !bCacheMaxInitialized )
00087     {
00088         <font class="keywordflow">if</font>( getenv(<font class="stringliteral">"GDAL_CACHEMAX"</font>) != NULL )
00089         {
00090             nCacheMax = atoi(getenv(<font class="stringliteral">"GDAL_CACHEMAX"</font>));
00091             <font class="keywordflow">if</font>( nCacheMax &lt; 1000 )
00092                 nCacheMax *= 1024 * 1024;
00093         }
00094         bCacheMaxInitialized = TRUE;
00095     }
00096     
00097     <font class="keywordflow">return</font> nCacheMax;
00098 }
00099 
00100 <font class="comment">/************************************************************************/</font>
00101 <font class="comment">/*                          GDALGetCacheUsed()                          */</font>
00102 <font class="comment">/************************************************************************/</font>
00103 
00104 <font class="keywordtype">int</font> GDALGetCacheUsed()<font class="keyword"></font>
00105 <font class="keyword"></font>{
00106     <font class="keywordflow">return</font> nCacheUsed;
00107 }
00108 
00109 <font class="comment">/************************************************************************/</font>
00110 <font class="comment">/*                        GDALFlushCacheBlock()                         */</font>
00111 <font class="comment">/*                                                                      */</font>
00112 <font class="comment">/*      The workhorse of cache management!                              */</font>
00113 <font class="comment">/************************************************************************/</font>
00114 
00115 <font class="keywordtype">int</font> GDALFlushCacheBlock()<font class="keyword"></font>
00116 <font class="keyword"></font>
00117 <font class="keyword"></font>{
00118     <font class="keywordflow">if</font>( poOldest == NULL )
00119         <font class="keywordflow">return</font> FALSE;
00120     poOldest-&gt;GetBand()-&gt;FlushBlock( poOldest-&gt;GetXOff(), 
00121                                      poOldest-&gt;GetYOff() );
00122 
00123     <font class="keywordflow">return</font> TRUE;
00124 }
00125 
00126 <font class="comment">/************************************************************************/</font>
00127 <font class="comment">/*                           GDALRasterBand()                           */</font>
00128 <font class="comment">/************************************************************************/</font>
00129 
00130 GDALRasterBlock::GDALRasterBlock( <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *poBandIn, 
00131                                   <font class="keywordtype">int</font> nXOffIn, <font class="keywordtype">int</font> nYOffIn )<font class="keyword"></font>
00132 <font class="keyword"></font>
00133 <font class="keyword"></font>{
00134     poBand = poBandIn;
00135 
00136     poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a7">GetBlockSize</a>( &amp;nXSize, &amp;nYSize );
00137     eType = poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a6">GetRasterDataType</a>();
00138     pData = NULL;
00139     bDirty = FALSE;
00140 
00141     poNext = poPrevious = NULL;
00142 
00143     nXOff = nXOffIn;
00144     nYOff = nYOffIn;
00145 }
00146 
00147 <font class="comment">/************************************************************************/</font>
00148 <font class="comment">/*                          ~GDALRasterBlock()                          */</font>
00149 <font class="comment">/************************************************************************/</font>
00150 
00151 GDALRasterBlock::~GDALRasterBlock()<font class="keyword"></font>
00152 <font class="keyword"></font>
00153 <font class="keyword"></font>{
00154     <font class="keywordflow">if</font>( pData != NULL )
00155     {
00156         <font class="keywordtype">int</font> nSizeInBytes;
00157 
00158         VSIFree( pData );
00159 
00160         nSizeInBytes = (nXSize * nYSize * GDALGetDataTypeSize(eType)+7)/8;
00161         nCacheUsed -= nSizeInBytes;
00162     }
00163 
00164     <font class="keywordflow">if</font>( poOldest == <font class="keyword">this</font> )
00165         poOldest = poPrevious;
00166 
00167     <font class="keywordflow">if</font>( poNewest == <font class="keyword">this</font> )
00168     {
00169         poNewest = poNext;
00170     }
00171 
00172     <font class="keywordflow">if</font>( poPrevious != NULL )
00173         poPrevious-&gt;poNext = poNext;
00174 
00175     <font class="keywordflow">if</font>( poNext != NULL )
00176         poNext-&gt;poPrevious = poPrevious;
00177 
00178 <font class="preprocessor">#ifdef ENABLE_DEBUG</font>
00179 <font class="preprocessor"></font>    Verify();
00180 <font class="preprocessor">#endif</font>
00181 <font class="preprocessor"></font>
00182     nAge = -1;
00183 }
00184 
00185 <font class="comment">/************************************************************************/</font>
00186 <font class="comment">/*                               Verify()                               */</font>
00187 <font class="comment">/************************************************************************/</font>
00188 
00189 <font class="keywordtype">void</font> GDALRasterBlock::Verify()<font class="keyword"></font>
00190 <font class="keyword"></font>
00191 <font class="keyword"></font>{
00192     CPLAssert( (poNewest == NULL &amp;&amp; poOldest == NULL)
00193                || (poNewest != NULL &amp;&amp; poOldest != NULL) );
00194 
00195     <font class="keywordflow">if</font>( poNewest != NULL )
00196     {
00197         CPLAssert( poNewest-&gt;poPrevious == NULL );
00198         CPLAssert( poOldest-&gt;poNext == NULL );
00199         
00200 
00201         <font class="keywordflow">for</font>( <a class="code" href="class_GDALRasterBlock.html">GDALRasterBlock</a> *poBlock = poNewest; 
00202              poBlock != NULL;
00203              poBlock = poBlock-&gt;poNext )
00204         {
00205             <font class="keywordflow">if</font>( poBlock-&gt;poPrevious )
00206             {
00207                 CPLAssert( poBlock-&gt;poPrevious-&gt;poNext == poBlock );
00208             }
00209 
00210             <font class="keywordflow">if</font>( poBlock-&gt;poNext )
00211             {
00212                 CPLAssert( poBlock-&gt;poNext-&gt;poPrevious == poBlock );
00213             }
00214         }
00215     }
00216 }
00217 
00218 <font class="comment">/************************************************************************/</font>
00219 <font class="comment">/*                               Write()                                */</font>
00220 <font class="comment">/************************************************************************/</font>
00221 
00222 CPLErr GDALRasterBlock::Write()<font class="keyword"></font>
00223 <font class="keyword"></font>
00224 <font class="keyword"></font>{
00225     <font class="keywordflow">if</font>( !GetDirty() )
00226         <font class="keywordflow">return</font> CE_None;
00227 
00228     <font class="keywordflow">if</font>( poBand == NULL )
00229         <font class="keywordflow">return</font> CE_Failure;
00230 
00231     MarkClean();
00232 
00233     <font class="keywordflow">return</font> poBand-&gt;<a class="code" href="class_GDALRasterBand.html#b1">IWriteBlock</a>( nXOff, nYOff, pData );
00234 }
00235 
00236 <font class="comment">/************************************************************************/</font>
00237 <font class="comment">/*                               Touch()                                */</font>
00238 <font class="comment">/************************************************************************/</font>
00239 
00240 <font class="keywordtype">void</font> GDALRasterBlock::Touch()<font class="keyword"></font>
00241 <font class="keyword"></font>
00242 <font class="keyword"></font>{
00243     nAge = nTileAgeTicker++;
00244 
00245     <font class="keywordflow">if</font>( poNewest == <font class="keyword">this</font> )
00246         <font class="keywordflow">return</font>;
00247 
00248     <font class="keywordflow">if</font>( poOldest == <font class="keyword">this</font> )
00249         poOldest = this-&gt;poPrevious;
00250     
00251     <font class="keywordflow">if</font>( poPrevious != NULL )
00252         poPrevious-&gt;poNext = poNext;
00253 
00254     <font class="keywordflow">if</font>( poNext != NULL )
00255         poNext-&gt;poPrevious = poPrevious;
00256 
00257     poPrevious = NULL;
00258     poNext = poNewest;
00259 
00260     <font class="keywordflow">if</font>( poNewest != NULL )
00261     {
00262         CPLAssert( poNewest-&gt;poPrevious == NULL );
00263         poNewest-&gt;poPrevious = <font class="keyword">this</font>;
00264     }
00265     poNewest = <font class="keyword">this</font>;
00266     
00267     <font class="keywordflow">if</font>( poOldest == NULL )
00268     {
00269         CPLAssert( poPrevious == NULL &amp;&amp; poNext == NULL );
00270         poOldest = <font class="keyword">this</font>;
00271     }
00272 <font class="preprocessor">#ifdef ENABLE_DEBUG</font>
00273 <font class="preprocessor"></font>    Verify();
00274 <font class="preprocessor">#endif</font>
00275 <font class="preprocessor"></font>}
00276 
00277 <font class="comment">/************************************************************************/</font>
00278 <font class="comment">/*                            Internalize()                             */</font>
00279 <font class="comment">/************************************************************************/</font>
00280 
00281 CPLErr GDALRasterBlock::Internalize()<font class="keyword"></font>
00282 <font class="keyword"></font>
00283 <font class="keyword"></font>{
00284     <font class="keywordtype">void</font>        *pNewData;
00285     <font class="keywordtype">int</font>         nSizeInBytes;
00286     <font class="keywordtype">int</font>         nCurCacheMax = GDALGetCacheMax();
00287 
00288     nSizeInBytes = nXSize * nYSize * (GDALGetDataTypeSize(eType) / 8);
00289 
00290     pNewData = VSIMalloc( nSizeInBytes );
00291     <font class="keywordflow">if</font>( pNewData == NULL )
00292         <font class="keywordflow">return</font>( CE_Failure );
00293 
00294     <font class="keywordflow">if</font>( pData != NULL )
00295         memcpy( pNewData, pData, nSizeInBytes );
00296     
00297     pData = pNewData;
00298 
00299 <font class="comment">/* -------------------------------------------------------------------- */</font>
00300 <font class="comment">/*      Flush old blocks if we are nearing our memory limit.            */</font>
00301 <font class="comment">/* -------------------------------------------------------------------- */</font>
00302     nCacheUsed += nSizeInBytes;
00303     <font class="keywordflow">while</font>( nCacheUsed &gt; nCurCacheMax )
00304     {
00305         <font class="keywordtype">int</font> nOldCacheUsed = nCacheUsed;
00306 
00307         GDALFlushCacheBlock();
00308 
00309         <font class="keywordflow">if</font>( nCacheUsed == nOldCacheUsed )
00310         {
00311             <font class="keyword">static</font> <font class="keywordtype">int</font> bReported = FALSE;
00312 
00313             <font class="keywordflow">if</font>( !bReported )
00314             {
00315                 bReported = TRUE;
00316             }
00317             <font class="keywordflow">break</font>;
00318         }
00319     }
00320 
00321 <font class="comment">/* -------------------------------------------------------------------- */</font>
00322 <font class="comment">/*      Add this block to the list.                                     */</font>
00323 <font class="comment">/* -------------------------------------------------------------------- */</font>
00324     Touch();
00325     <font class="keywordflow">return</font>( CE_None );
00326 }
00327 
00328 <font class="comment">/************************************************************************/</font>
00329 <font class="comment">/*                             MarkDirty()                              */</font>
00330 <font class="comment">/************************************************************************/</font>
00331 
00332 <font class="keywordtype">void</font> GDALRasterBlock::MarkDirty()<font class="keyword"></font>
00333 <font class="keyword"></font>
00334 <font class="keyword"></font>{
00335     bDirty = TRUE;
00336 }
00337 
00338 
00339 <font class="comment">/************************************************************************/</font>
00340 <font class="comment">/*                             MarkClean()                              */</font>
00341 <font class="comment">/************************************************************************/</font>
00342 
00343 <font class="keywordtype">void</font> GDALRasterBlock::MarkClean()<font class="keyword"></font>
00344 <font class="keyword"></font>
00345 <font class="keyword"></font>{
00346     bDirty = FALSE;
00347 }
00348 
00349 
</div></pre><hr><address><small>Generated at Sat Dec 21 14:01:59 2002 for GDAL by
<a href="http://www.stack.nl/~dimitri/doxygen/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.3-20001105 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2000</small></address>
</body>
</html>