OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ossimAppTileCache Class Reference

#include <ossimAppTileCache.h>

Classes

struct  ossimAppCacheTileInfo
 

Public Types

typedef ossim_int32 ossimAppCacheId
 
typedef ossim_int32 ossimTileId
 
typedef map< ossimAppCacheId, ossimTileCache * >::iterator AppIdIterator
 

Public Member Functions

 ~ossimAppTileCache ()
 
ossimAppCacheId newTileCache (ossim_uint32 bucketSize=DEFAULT_BUCKET_SIZE)
 
ossimDataObjectget (ossimAppCacheId id, const ossimDpt3d &origin, ossim_uint32 resLevel=0)
 
ossimRefPtr< ossimDataObjectremoveTile (ossimAppCacheId id, const ossimDpt3d &origin, unsigned long resLevel)
 
ossimRefPtr< ossimDataObjectinsert (ossimAppCacheId id, const ossimDpt3d &origin, const ossimDataObject *data, ossim_uint32 resLevel=0)
 
void deleteCache (ossimAppCacheId appId)
 

Static Public Member Functions

static ossimAppTileCacheinstance (ossim_uint32 maxSize=0)
 

Static Public Attributes

static const ossim_uint32 DEFAULT_SIZE = 80*1024*1024
 
static const ossim_uint32 DEFAULT_BUCKET_SIZE = 293
 

Protected Member Functions

 ossimAppTileCache (ossim_uint32 maxSize=DEFAULT_SIZE)
 
void deleteAll ()
 
ossimTileCacheget (ossimAppCacheId id)
 
void deleteAppCacheFromQueue (ossimAppCacheId appId)
 
void removeTileFromQueue (ossimAppCacheId appId, const ossimDpt3d &origin, ossim_uint32 resLevel)
 
void adjustQueue (ossimAppCacheId id, const ossimDpt3d &origin, ossim_uint32 resLevel)
 
ossimRefPtr< ossimDataObjectremoveTile ()
 

Protected Attributes

map< ossimAppCacheId, ossimTileCache * > theAppCache
 
ossim_uint32 theMaxGlobalCacheSize
 
ossim_uint32 theMaxCacheSize
 
ossim_uint32 theCurrentCacheSize
 
list< ossimAppCacheTileInfotheUsedQueue
 

Static Protected Attributes

static ossimAppTileCachetheInstance = 0
 
static ossimAppCacheId theUniqueAppIdCounter = 1
 

Detailed Description

Definition at line 27 of file ossimAppTileCache.h.

Member Typedef Documentation

◆ AppIdIterator

Definition at line 36 of file ossimAppTileCache.h.

◆ ossimAppCacheId

Definition at line 34 of file ossimAppTileCache.h.

◆ ossimTileId

Definition at line 35 of file ossimAppTileCache.h.

Constructor & Destructor Documentation

◆ ~ossimAppTileCache()

ossimAppTileCache::~ossimAppTileCache ( )

Definition at line 52 of file ossimAppTileCache.cpp.

References deleteAll().

53 {
54  deleteAll();
55 }

◆ ossimAppTileCache()

ossimAppTileCache::ossimAppTileCache ( ossim_uint32  maxSize = DEFAULT_SIZE)
inlineprotected

Definition at line 104 of file ossimAppTileCache.h.

Referenced by instance().

105  :
106  theMaxCacheSize(maxSize),
108  {}
ossim_uint32 theCurrentCacheSize
ossim_uint32 theMaxCacheSize

Member Function Documentation

◆ adjustQueue()

void ossimAppTileCache::adjustQueue ( ossimAppCacheId  id,
const ossimDpt3d origin,
ossim_uint32  resLevel 
)
protected

Definition at line 284 of file ossimAppTileCache.cpp.

References theUsedQueue.

Referenced by get().

287 {
288  list<ossimAppCacheTileInfo>::iterator anIterator = theUsedQueue.begin();
289  ossimAppCacheTileInfo info(id, origin, resLevel);
290 
291  while(anIterator != theUsedQueue.end())
292  {
293 
294  if((*anIterator) == info)
295  {
296  theUsedQueue.erase(anIterator);
297  theUsedQueue.push_back(info);
298  return;
299  }
300  ++anIterator;
301  }
302 }
list< ossimAppCacheTileInfo > theUsedQueue

◆ deleteAll()

void ossimAppTileCache::deleteAll ( )
protected

Definition at line 210 of file ossimAppTileCache.cpp.

References theAppCache.

Referenced by ~ossimAppTileCache().

211 {
212  AppIdIterator iter = theAppCache.begin();
213 
214  while(iter != theAppCache.end())
215  {
216  delete (*iter).second;
217  ++iter;
218  }
219 
220  theAppCache.clear();
221 }
map< ossimAppCacheId, ossimTileCache * > theAppCache
map< ossimAppCacheId, ossimTileCache * >::iterator AppIdIterator

◆ deleteAppCacheFromQueue()

void ossimAppTileCache::deleteAppCacheFromQueue ( ossimAppCacheId  appId)
protected

will remove all occurances of the appId from the queue

Definition at line 246 of file ossimAppTileCache.cpp.

References theUsedQueue.

Referenced by deleteCache().

247 {
248  list<ossimAppCacheTileInfo>::iterator anIterator;
249 
250  anIterator = theUsedQueue.begin();
251  while(anIterator != theUsedQueue.end())
252  {
253  if( (*anIterator).theAppCacheId == appId)
254  {
255  anIterator = theUsedQueue.erase(anIterator);
256  }
257  else
258  {
259  ++anIterator;
260  }
261  }
262 }
list< ossimAppCacheTileInfo > theUsedQueue

◆ deleteCache()

void ossimAppTileCache::deleteCache ( ossimAppCacheId  appId)

This will delete the specified cache. The LRU queue will be updated accordingly

Definition at line 192 of file ossimAppTileCache.cpp.

References deleteAppCacheFromQueue(), ossimTileCache::sizeInBytes(), theAppCache, and theCurrentCacheSize.

193 {
194  // first delete the cache
195  AppIdIterator anIterator = theAppCache.find(appId);
196  if(anIterator != theAppCache.end())
197  {
198  ossimTileCache *aCache = (*anIterator).second;
199  theCurrentCacheSize -= aCache->sizeInBytes();
200 
201  delete aCache;
202 
203  theAppCache.erase(anIterator);
204  }
205  // now delete all occurences of the appCacheId in the queue
206  // used for LRU algorithm.
208 }
virtual ossim_uint32 sizeInBytes()
ossim_uint32 theCurrentCacheSize
map< ossimAppCacheId, ossimTileCache * > theAppCache
void deleteAppCacheFromQueue(ossimAppCacheId appId)
map< ossimAppCacheId, ossimTileCache * >::iterator AppIdIterator

◆ get() [1/2]

ossimDataObject * ossimAppTileCache::get ( ossimAppCacheId  id,
const ossimDpt3d origin,
ossim_uint32  resLevel = 0 
)

Will retrieve a tile from the cache. Will return NULL if not found.

Will retrieve a tile from the cache.

Definition at line 77 of file ossimAppTileCache.cpp.

References adjustQueue(), and ossimTileCache::get().

80 {
81  ossimDataObject* result = 0;
82  if(id>0)
83  {
84  ossimTileCache *aCache = this->get(id);
85  if(aCache)
86  {
87  result = aCache->get(origin,
88  resLevel);
89  if(result)
90  {
91  adjustQueue(id, origin, resLevel);
92  }
93  }
94  }
95 
96  return result;
97 }
virtual ossimDataObject * get(const ossimDpt3d &origin, unsigned long resLevel=0)
void adjustQueue(ossimAppCacheId id, const ossimDpt3d &origin, ossim_uint32 resLevel)

◆ get() [2/2]

ossimTileCache * ossimAppTileCache::get ( ossimAppCacheId  id)
protected

Used to get access to the App cache.

Definition at line 178 of file ossimAppTileCache.cpp.

References theAppCache.

179 {
180  ossimTileCache *result=0;
181 
182  AppIdIterator anIterator = theAppCache.find(id);
183 
184  if(anIterator != theAppCache.end())
185  {
186  result = (*anIterator).second;
187  }
188 
189  return result;
190 }
map< ossimAppCacheId, ossimTileCache * > theAppCache
map< ossimAppCacheId, ossimTileCache * >::iterator AppIdIterator

◆ insert()

ossimRefPtr< ossimDataObject > ossimAppTileCache::insert ( ossimAppCacheId  id,
const ossimDpt3d origin,
const ossimDataObject data,
ossim_uint32  resLevel = 0 
)

Will insert a tile into the cache.

Definition at line 124 of file ossimAppTileCache.cpp.

References ossimObject::dup(), ossimRefPtr< T >::get(), ossimDataObject::getDataSizeInBytes(), ossimTileCache::insert(), ossimNotify(), ossimNotifyLevel_WARN, removeTile(), theCurrentCacheSize, theMaxCacheSize, and theUsedQueue.

128 {
129  static const char MODULE[] = "ossimAppTileCache::insert";
130  ossimDataObject *result = 0;
131 
132  // find the cache and if it's not there then return NULL
133  ossimTileCache *aCache = this->get(appId);
134  if(!aCache)
135  {
136  return result;
137  }
138 
139  ossimRefPtr<ossimDataObject> tileToInsert = 0;
140  long dataSize = data->getDataSizeInBytes();
141 
142  if( (theCurrentCacheSize+dataSize) > theMaxCacheSize)
143  {
144  do
145  {
147  }while((theCurrentCacheSize+dataSize) > theMaxCacheSize);
148  }
149 
150  if(data)
151  {
152  tileToInsert = (ossimDataObject*)data->dup();
153 
154  result = aCache->insert(origin,
155  tileToInsert.get(),
156  resLevel);
157  if(!result)
158  {
160  << MODULE << " ERROR: can't insert and should not happen"
161  << endl;
162 
163  tileToInsert = 0;
164  }
165  else
166  {
167  theCurrentCacheSize += dataSize;
168  theUsedQueue.push_back(ossimAppCacheTileInfo(appId,
169  origin,
170  resLevel));
171  }
172  }
173 
174  return result;
175 }
ossim_uint32 theCurrentCacheSize
list< ossimAppCacheTileInfo > theUsedQueue
ossimRefPtr< ossimDataObject > removeTile()
virtual ossimDataObject * insert(const ossimDpt3d &origin, ossimDataObject *data, unsigned long resLevel=0)
virtual ossimObject * dup() const
Definition: ossimObject.cpp:29
ossim_uint32 theMaxCacheSize
virtual ossim_uint32 getDataSizeInBytes() const =0
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ instance()

ossimAppTileCache * ossimAppTileCache::instance ( ossim_uint32  maxSize = 0)
static

We will force a singleton on this class.

Definition at line 28 of file ossimAppTileCache.cpp.

References DEFAULT_SIZE, ossimPreferences::findPreference(), ossimPreferences::instance(), ossimAppTileCache(), ossimNotify(), ossimNotifyLevel_NOTICE, theInstance, and ossimString::toUInt32().

29 {
30  if(!theInstance)
31  {
32  if(maxSize < 1)
33  {
34  ossimString cacheSize = ossimPreferences::instance()->findPreference("cache_size");
35  if(cacheSize!="")
36  {
37  maxSize = cacheSize.toUInt32()*1024*1024;
38  }
39  else
40  {
41  maxSize = DEFAULT_SIZE;
42  }
44  << "Setting SIZE----------------------- " << maxSize << std::endl;
45  }
46  theInstance = new ossimAppTileCache(maxSize);
47  }
48 
49  return theInstance;
50 }
static ossimAppTileCache * theInstance
static const ossim_uint32 DEFAULT_SIZE
ossim_uint32 toUInt32() const
ossimAppTileCache(ossim_uint32 maxSize=DEFAULT_SIZE)
const char * findPreference(const char *key) const
static ossimPreferences * instance()
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ newTileCache()

ossimAppTileCache::ossimAppCacheId ossimAppTileCache::newTileCache ( ossim_uint32  bucketSize = DEFAULT_BUCKET_SIZE)

Will create a new Tile cache for this application. Will return 0 if not successful.

Definition at line 57 of file ossimAppTileCache.cpp.

References theAppCache, and theUniqueAppIdCounter.

58 {
59  ossimTileCache *aCache = 0;
60  ossimAppCacheId result = 0;
61 
62  aCache = new ossimTileCache(bucketSize);
63 
64  if(aCache)
65  {
66  theAppCache.insert(make_pair(theUniqueAppIdCounter, aCache));
67  result = theUniqueAppIdCounter;
69  }
70 
71  return result;
72 }
map< ossimAppCacheId, ossimTileCache * > theAppCache
static ossimAppCacheId theUniqueAppIdCounter
ossim_int32 ossimAppCacheId

◆ removeTile() [1/2]

ossimRefPtr< ossimDataObject > ossimAppTileCache::removeTile ( ossimAppCacheId  id,
const ossimDpt3d origin,
unsigned long  resLevel 
)

Will remove a tile completly from the cache. The returned tile is no longer owned by the cache.

Definition at line 99 of file ossimAppTileCache.cpp.

References ossimDataObject::getDataSizeInBytes(), ossimTileCache::remove(), removeTileFromQueue(), theCurrentCacheSize, and ossimRefPtr< T >::valid().

102 {
103  ossimRefPtr<ossimDataObject> result = 0;
104  if(id>0)
105  {
106  ossimTileCache *aCache = this->get(id);
107  if(aCache)
108  {
109  // remove from cache
110  result = aCache->remove(origin,
111  resLevel);
112  // adjust the byte count
113  if(result.valid())
114  {
116  }
117  removeTileFromQueue(id, origin, resLevel);
118  }
119  }
120 
121  return result;
122 }
virtual ossimDataObject * remove(const ossimDpt3d &origin, unsigned long resLevel=0)
bool valid() const
Definition: ossimRefPtr.h:75
ossim_uint32 theCurrentCacheSize
void removeTileFromQueue(ossimAppCacheId appId, const ossimDpt3d &origin, ossim_uint32 resLevel)
virtual ossim_uint32 getDataSizeInBytes() const =0

◆ removeTile() [2/2]

ossimRefPtr< ossimDataObject > ossimAppTileCache::removeTile ( )
protected

will pop the queue and remove that tile from its cache and return it to the caller. This is used by the insert when the max cache size is exceeded.

Definition at line 264 of file ossimAppTileCache.cpp.

References ossimDataObject::getDataSizeInBytes(), ossimTileCache::remove(), ossimAppTileCache::ossimAppCacheTileInfo::theAppCacheId, theCurrentCacheSize, ossimAppTileCache::ossimAppCacheTileInfo::theOrigin, ossimAppTileCache::ossimAppCacheTileInfo::theResLevel, and theUsedQueue.

Referenced by insert().

265 {
267  if(!theUsedQueue.empty())
268  {
269  ossimAppCacheTileInfo &info = *(theUsedQueue.begin());
270 
271  ossimTileCache *aCache = get(info.theAppCacheId);
272  if(aCache)
273  {
274  result = aCache->remove(info.theOrigin,
275  info.theResLevel);
277  }
278  theUsedQueue.erase(theUsedQueue.begin());
279  }
280 
281  return result;
282 }
virtual ossimDataObject * remove(const ossimDpt3d &origin, unsigned long resLevel=0)
ossim_uint32 theCurrentCacheSize
list< ossimAppCacheTileInfo > theUsedQueue
virtual ossim_uint32 getDataSizeInBytes() const =0

◆ removeTileFromQueue()

void ossimAppTileCache::removeTileFromQueue ( ossimAppCacheId  appId,
const ossimDpt3d origin,
ossim_uint32  resLevel 
)
protected

Will remove a single instance of a tile from the queue.

Definition at line 223 of file ossimAppTileCache.cpp.

References theUsedQueue.

Referenced by removeTile().

226 {
227  list<ossimAppCacheTileInfo>::iterator anIterator;
228 
229  anIterator = theUsedQueue.begin();
230  while(anIterator != theUsedQueue.end())
231  {
232  if( ((*anIterator).theAppCacheId == appId) &&
233  ((*anIterator).theOrigin == origin)&&
234  ((*anIterator).theResLevel == resLevel))
235  {
236  theUsedQueue.erase(anIterator);
237  return;
238  }
239  else
240  {
241  ++anIterator;
242  }
243  }
244 }
list< ossimAppCacheTileInfo > theUsedQueue

Member Data Documentation

◆ DEFAULT_BUCKET_SIZE

const ossim_uint32 ossimAppTileCache::DEFAULT_BUCKET_SIZE = 293
static

Definition at line 32 of file ossimAppTileCache.h.

◆ DEFAULT_SIZE

const ossim_uint32 ossimAppTileCache::DEFAULT_SIZE = 80*1024*1024
static

Definition at line 30 of file ossimAppTileCache.h.

Referenced by instance().

◆ theAppCache

map<ossimAppCacheId, ossimTileCache*> ossimAppTileCache::theAppCache
protected

Will hold the list of application caches

Definition at line 148 of file ossimAppTileCache.h.

Referenced by deleteAll(), deleteCache(), get(), and newTileCache().

◆ theCurrentCacheSize

ossim_uint32 ossimAppTileCache::theCurrentCacheSize
protected

This holds the current cache size.

Definition at line 160 of file ossimAppTileCache.h.

Referenced by deleteCache(), insert(), and removeTile().

◆ theInstance

ossimAppTileCache * ossimAppTileCache::theInstance = 0
staticprotected

Definition at line 140 of file ossimAppTileCache.h.

Referenced by instance().

◆ theMaxCacheSize

ossim_uint32 ossimAppTileCache::theMaxCacheSize
protected

Definition at line 154 of file ossimAppTileCache.h.

Referenced by insert().

◆ theMaxGlobalCacheSize

ossim_uint32 ossimAppTileCache::theMaxGlobalCacheSize
protected

Is the maximum size of the cache.

Definition at line 153 of file ossimAppTileCache.h.

◆ theUniqueAppIdCounter

ossimAppTileCache::ossimAppCacheId ossimAppTileCache::theUniqueAppIdCounter = 1
staticprotected

Will hold the current unique Application id.

Definition at line 144 of file ossimAppTileCache.h.

Referenced by newTileCache().

◆ theUsedQueue

list<ossimAppCacheTileInfo> ossimAppTileCache::theUsedQueue
protected

Is used in an Least recently used algorithm

Definition at line 166 of file ossimAppTileCache.h.

Referenced by adjustQueue(), deleteAppCacheFromQueue(), insert(), removeTile(), and removeTileFromQueue().


The documentation for this class was generated from the following files: