//****************************************************************** // // License: MIT // // See LICENSE.txt file in the top level directory for more details. // // Author: Garrett Potts // // Description: This file contains the Application cache algorithm // //*********************************** // $Id: ossimAppFixedTileCache.h 23664 2015-12-14 14:17:27Z dburken $ #ifndef ossimAppFixedTileCache_HEADER #define ossimAppFixedTileCache_HEADER #include #include #include #include #include #include #include class ossimFixedTileCache; class ossimImageData; class OSSIM_DLL ossimAppFixedTileCache { public: friend std::ostream& operator <<(std::ostream& out, const ossimAppFixedTileCache& rhs); static const ossim_uint32 DEFAULT_SIZE; typedef ossim_int32 ossimAppFixedCacheId; static ossimAppFixedTileCache *instance(ossim_uint32 maxSize = 0); virtual ~ossimAppFixedTileCache(); /*! * Will flush all cache registered */ virtual void flush(); virtual void flush(ossimAppFixedCacheId cacheId); virtual void deleteCache(ossimAppFixedCacheId cacheId); /*! * Will create a new Tile cache for this application if the tile size is 0,0 it will * use the default tile size. Will * return 0 if not successful. */ ossimAppFixedCacheId newTileCache(const ossimIrect& tileBoundaryRect, const ossimIpt& tileSize=ossimIpt(0,0)); ossimAppFixedCacheId newTileCache(); virtual void setRect(ossimAppFixedCacheId cacheId, const ossimIrect& boundaryTileRect); virtual void setTileSize(ossimAppFixedCacheId cacheId, const ossimIpt& tileSize); ossimRefPtr getTile(ossimAppFixedCacheId cacheId, const ossimIpt& origin); ossimRefPtr addTile(ossimAppFixedCacheId cacheId, ossimRefPtr data, bool duplicateData=true); ossimRefPtr removeTile(ossimAppFixedCacheId cacheId, const ossimIpt& origin); void deleteTile(ossimAppFixedCacheId cacheId, const ossimIpt& origin); const ossimIpt& getTileSize(ossimAppFixedCacheId cacheId); virtual void setMaxCacheSize(ossim_uint32 cacheSize); protected: // struct ossimAppFixedCacheTileInfo // { // public: // ossimAppFixedCacheTileInfo(ossimAppFixedCacheId appId, // const ossimIpt& origin) // :theAppCacheId(appId), // theOrigin(origin) // {} // ossimAppFixedCacheId theAppCacheId; // ossimIpt theOrigin; // bool operator ==(const ossimAppFixedCacheTileInfo &rhs)const // { // return (theAppCacheId == rhs.theAppCacheId && // theOrigin == rhs.theOrigin); // } // }; ossimAppFixedTileCache(); ossimFixedTileCache* getCache(ossimAppFixedCacheId cacheId); void shrinkGlobalCacheSize(ossim_int32 byteCount); void shrinkCacheSize(ossimAppFixedCacheId id, ossim_int32 byteCount); void shrinkCacheSize(ossimFixedTileCache* cache, ossim_int32 byteCount); void deleteAll(); static ossimAppFixedTileCache *theInstance; /*! * Will hold the current unique Application id. */ static ossimAppFixedCacheId theUniqueAppIdCounter; ossimIpt theTileSize; ossim_uint32 theMaxCacheSize; ossim_uint32 theMaxGlobalCacheSize; ossim_uint32 theCurrentCacheSize; std::map theAppCacheMap; OpenThreads::Mutex theMutex; }; #endif