00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef CACHEDPAGE_H 00011 #define CACHEDPAGE_H 00012 00013 #include "DimensionDescriptor.h" 00014 #include "RasterPage.h" 00015 00016 #include <boost/shared_ptr.hpp> 00017 00018 /** 00019 * Provides means of using page sharing with the DataAccessor class. 00020 * 00021 * Page sharing/caching allows multiple data accessors to have read-only 00022 * access to the same page. The CachedPage and RasterPage 00023 * are thread-safe classes. 00024 */ 00025 class CachedPage : public RasterPage 00026 { 00027 public: 00028 class CacheUnit 00029 { 00030 public: 00031 /** 00032 * A DimensionDescriptor signifying that the page contains all of the cube's bands. 00033 */ 00034 static const DimensionDescriptor ALL_BANDS; 00035 00036 /** 00037 * Construct a CacheUnit with the given parameters. 00038 * 00039 * @param pData 00040 * The buffer which has already been populated with the data for the 00041 * cache unit. Must be at least \p size bytes long, and must have 00042 * been allocated with new char[n]. The cache unit takes ownership 00043 * of this buffer. 00044 * @param startRow 00045 * The starting row for this unit. 00046 * @param concurrentRows 00047 * The number of concurrent rows provided. 00048 * @param size 00049 * The size of the buffer provided in \p pData. 00050 * @param band 00051 * The band provided if BSQ, or ALL_BANDS if all bands are provided. 00052 * @param interlineBytes 00053 * The number of interline bytes within the buffer. 00054 */ 00055 CacheUnit(char *pData, DimensionDescriptor startRow, int concurrentRows, size_t size, 00056 DimensionDescriptor band = ALL_BANDS, unsigned int interlineBytes = 0); 00057 00058 /** 00059 * Destroy a CacheUnit. 00060 */ 00061 ~CacheUnit(); 00062 00063 /** 00064 * Returns the band for this dataset if interleave type is BSQ; for BIP, returns ALL_BANDS. 00065 * 00066 * @return For BSQ data, the band number of the data loaded. For any other interleave type, ALL_BANDS. 00067 */ 00068 DimensionDescriptor getBand(); 00069 00070 /** 00071 * A function that determines if a specification of number of rows, concurrent rows, and a 00072 * band (for BSQ) matches (ie. is contained by) this current page. 00073 * 00074 * @param startRow 00075 * The start row of the block that may be requested. 00076 * @param concurrentRows 00077 * The number of rows needed at any given time. 00078 * @param band 00079 * For BSQ data, the band number. When called on BIP data, this is assumed to be ALL_BANDS. 00080 */ 00081 bool matches(DimensionDescriptor startRow, int concurrentRows, DimensionDescriptor band); 00082 00083 /** 00084 * Accessor function to private data. 00085 * 00086 * @return The start row of this block. 00087 */ 00088 DimensionDescriptor getStartRow() const; 00089 00090 /** 00091 * Accessor function to private data. 00092 * 00093 * @return The total size, in bytes, of the entire block. 00094 */ 00095 size_t getSize() const; 00096 00097 /** 00098 * Get the raw data contained in the cache unit. 00099 * 00100 * @return The raw data contained in the cache unit. 00101 */ 00102 char *getRawData(); 00103 00104 /** 00105 * Get the number of concurrent rows contained in the cache unit. 00106 * 00107 * @return The number of concurrent rows contained in the cache unit. 00108 */ 00109 unsigned int getConcurrentRows(); 00110 00111 /** 00112 * Get the number of interline bytes contained in the cache unit. 00113 * 00114 * @return The number of interline bytes contained in the cache unit. 00115 */ 00116 unsigned int getInterlineBytes(); 00117 00118 private: 00119 char* mpData; 00120 DimensionDescriptor mStartRow; 00121 int mConcurrentRows; 00122 DimensionDescriptor mBand; // for BSQ 00123 size_t mSize; 00124 unsigned int mInterlineBytes; 00125 }; 00126 00127 typedef boost::shared_ptr<CacheUnit> UnitPtr; 00128 00129 /** 00130 * Creates a CachedPage. 00131 * 00132 * @param pCacheUnit 00133 * The CacheUnit for this page 00134 * @param offset 00135 * The number of bytes to offset into the block. This does not account for size of the 00136 * data type. 00137 * @param startRow 00138 * The start row for this page. 00139 */ 00140 CachedPage(UnitPtr pCacheUnit, size_t offset, DimensionDescriptor startRow); 00141 00142 /** 00143 * Virtual destructor to ensure proper deletion of inherited classes. 00144 */ 00145 virtual ~CachedPage(); 00146 00147 /** 00148 * Obligation from base class; returns a pointer to the raw data. 00149 * 00150 * @return A pointer to the memory owned by the shared_array. 00151 */ 00152 void* getRawData(); 00153 00154 /** 00155 * Accessor to private data. 00156 * 00157 * @return The number of concurrent rows in this page. 00158 */ 00159 unsigned int getNumRows(); 00160 00161 00162 /** 00163 * Inherited obligations that return 0. 00164 * 00165 * @return Returns 0. 00166 */ 00167 unsigned int getNumColumns(); 00168 00169 /** 00170 * Inherited obligations that return 0. 00171 * 00172 * @return Returns 0. 00173 */ 00174 unsigned int getNumBands(); 00175 00176 /** 00177 * Access the number of interline bytes in the page. 00178 * 00179 * @return The number of interline bytes. 00180 */ 00181 unsigned int getInterlineBytes(); 00182 00183 private: 00184 UnitPtr mpCacheUnit; 00185 00186 /** 00187 * The offset into the cache unit. 00188 * 00189 * The CachedPager and PageCache use this method to provide better performance for 00190 * the following case: two data accessors request rows 0-127 and rows 128-255 and a block 00191 * exists in the PageCache that contains rows 0-255. 00192 */ 00193 size_t mOffset; 00194 00195 DimensionDescriptor mStartRow; 00196 }; 00197 00198 #endif