![]() |
TerraLib 4.1
|
00001 /************************************************************************************ 00002 TerraLib - a library for developing GIS applications. 00003 Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio. 00004 00005 This code is part of the TerraLib library. 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 You should have received a copy of the GNU Lesser General Public 00012 License along with this library. 00013 00014 The authors reassure the license terms regarding the warranties. 00015 They specifically disclaim any warranties, including, but not limited to, 00016 the implied warranties of merchantability and fitness for a particular purpose. 00017 The library provided hereunder is on an "as is" basis, and the authors have no 00018 obligation to provide maintenance, support, updates, enhancements, or modifications. 00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct, 00020 indirect, special, incidental, or consequential damages arising out of the use 00021 of this library and its documentation. 00022 *************************************************************************************/ 00027 #ifndef TERASTERMEMMANAGER_H 00028 #define TERASTERMEMMANAGER_H 00029 00030 #include "TeSharedPtr.h" 00031 00032 #include <vector> 00033 00038 class TL_DLL TeRasterMemManager { 00039 00040 public : 00041 00045 enum MemoryPolicy { 00050 AutoMemPol = 1, 00054 RAMMemPol = 2, 00058 DiskMemPol = 3 00059 }; 00060 00064 TeRasterMemManager(); 00065 00069 ~TeRasterMemManager(); 00070 00074 void clear(); 00075 00088 bool reset( unsigned int bands, unsigned int tilesPerBand, 00089 const std::vector< unsigned int >& tilesSizesVec, 00090 MemoryPolicy memoryPolicy, unsigned char maxMemPercentUsage, 00091 unsigned long int maxTempFileSize ); 00092 00100 void* getTilePointer( const unsigned int& band, 00101 const unsigned int& tile ); 00102 00103 protected : 00104 00108 class DiskTileData 00109 { 00110 public : 00111 FILE* filePtr_; 00112 unsigned long int fileOff_; 00113 unsigned int size_; 00114 00115 DiskTileData() : filePtr_( 0 ), fileOff_( 0 ), size_( 0 ) {}; 00116 00117 ~DiskTileData() {}; 00118 }; 00119 00124 typedef unsigned char TileDataT; 00125 00130 typedef TileDataT* TilePtrT; 00131 00136 typedef std::vector< TilePtrT > TilesPtrsVecT; 00137 00142 typedef std::vector< DiskTileData > 00143 DiskTileDataVecT; 00144 00149 typedef std::vector< std::pair< FILE*, std::string > > 00150 OpenDiskFilesVecT; 00151 00156 unsigned char maxMemPercentUsage_; 00157 00161 unsigned long int maxTempFileSize_; 00162 00163 // Temp variables used by the getTilePointer method. 00164 TilePtrT getTilePointer_tilePtr_; 00165 unsigned int getTilePointer_reqTileIdx_; 00166 unsigned int getTilePointer_swapTileIdx_; 00167 00171 unsigned int tilesPerBand_; 00172 00176 unsigned int bandsNmb_; 00177 00181 std::vector< unsigned int > bandsTileSizes_; 00182 00188 TilesPtrsVecT allTilesPtrsVec_; 00189 00193 OpenDiskFilesVecT openDiskFilesVec_; 00194 00198 DiskTileDataVecT diskTilesDataVec_; 00199 00203 std::vector< unsigned int > ramTilesIndexesVec_; 00204 00210 unsigned int nextSwapTileRamTilesIndexesVecIdx_; 00211 00216 TilePtrT swapTilePtr_; 00217 00227 bool allocateDiskFiles( unsigned int tileSize, 00228 unsigned int tilesNmb, OpenDiskFilesVecT& openDiskFilesVec, 00229 DiskTileDataVecT& diskTilesData ); 00230 00238 bool createNewDiskFile( unsigned long int size, 00239 std::string& filename, FILE** fileptr ); 00240 00241 private : 00242 00247 TeRasterMemManager( const TeRasterMemManager& ) {}; 00248 00253 const TeRasterMemManager& operator=( const TeRasterMemManager& ) 00254 { return *this; }; 00255 00256 }; 00257 00258 #endif 00259