|
osgEarth 2.1.1
|
Inheritance diagram for osgEarth::MemCache:
Collaboration diagram for osgEarth::MemCache:Classes | |
| struct | CachedObject |
Public Member Functions | |
| MemCache (int maxTilesInCache=16) | |
| MemCache (const MemCache &rhs, const osg::CopyOp &op=osg::CopyOp::DEEP_COPY_ALL) | |
| META_Object (osgEarth, MemCache) | |
| unsigned int | getMaxNumTilesInCache () const |
| void | setMaxNumTilesInCache (unsigned int max) |
| virtual bool | isCached (const TileKey &key, const CacheSpec &spec) const |
| virtual bool | getImage (const TileKey &key, const CacheSpec &spec, osg::ref_ptr< const osg::Image > &out_image) |
| virtual void | setImage (const TileKey &key, const CacheSpec &spec, const osg::Image *image) |
| virtual bool | getHeightField (const TileKey &key, const CacheSpec &spec, osg::ref_ptr< const osg::HeightField > &out_hf) |
| virtual void | setHeightField (const TileKey &key, const CacheSpec &spec, const osg::HeightField *hf) |
| virtual bool | purge (const std::string &cacheId, int olderThan, bool async) |
Protected Types | |
| typedef std::list< CachedObject > | ObjectList |
| typedef std::map< std::string, ObjectList::iterator > | KeyToIteratorMap |
Protected Member Functions | |
| bool | getObject (const TileKey &key, const CacheSpec &spec, osg::ref_ptr< const osg::Object > &out_result) |
| void | setObject (const TileKey &key, const CacheSpec &spec, const osg::Object *image) |
Protected Attributes | |
| ObjectList | _objects |
| KeyToIteratorMap | _keyToIterMap |
| unsigned int | _maxNumTilesInCache |
| OpenThreads::Mutex | _mutex |
typedef std::map<std::string,ObjectList::iterator> osgEarth::MemCache::KeyToIteratorMap [protected] |
typedef std::list<CachedObject> osgEarth::MemCache::ObjectList [protected] |
| MemCache::MemCache | ( | int | maxTilesInCache = 16 | ) |
Definition at line 339 of file Caching.cpp.
: _maxNumTilesInCache( maxSize ) { setName( "mem" ); }
| MemCache::MemCache | ( | const MemCache & | rhs, |
| const osg::CopyOp & | op = osg::CopyOp::DEEP_COPY_ALL |
||
| ) |
Definition at line 345 of file Caching.cpp.
: _maxNumTilesInCache( rhs._maxNumTilesInCache ) { }
| bool MemCache::getHeightField | ( | const TileKey & | key, |
| const CacheSpec & | spec, | ||
| osg::ref_ptr< const osg::HeightField > & | out_hf | ||
| ) | [virtual] |
Gets the cached heightfield for the given TileKey
Reimplemented from osgEarth::Cache.
Definition at line 381 of file Caching.cpp.
{
osg::ref_ptr<const osg::Object> result;
if ( getObject(key, spec, result) )
{
out_hf = dynamic_cast<const osg::HeightField*>(result.get());
return out_hf.valid();
}
else return false;
}
Here is the call graph for this function:| bool MemCache::getImage | ( | const TileKey & | key, |
| const CacheSpec & | spec, | ||
| osg::ref_ptr< const osg::Image > & | out_image | ||
| ) | [virtual] |
Gets the cached image for the given TileKey
Implements osgEarth::Cache.
Definition at line 363 of file Caching.cpp.
{
osg::ref_ptr<const osg::Object> result;
if ( getObject(key, spec, result) )
{
out_image = dynamic_cast<const osg::Image*>( result.get() );
return out_image.valid();
}
else return false;
}
Here is the call graph for this function:| unsigned int MemCache::getMaxNumTilesInCache | ( | ) | const |
Gets the maximum number of tiles to keep in the cache
Definition at line 351 of file Caching.cpp.
{
return _maxNumTilesInCache;
}
| bool MemCache::getObject | ( | const TileKey & | key, |
| const CacheSpec & | spec, | ||
| osg::ref_ptr< const osg::Object > & | out_result | ||
| ) | [protected] |
Gets the cached object for the given TileKey
Definition at line 414 of file Caching.cpp.
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
std::string id = key.str() + spec.cacheId();
KeyToIteratorMap::iterator itr = _keyToIterMap.find(id);
if (itr != _keyToIterMap.end())
{
CachedObject entry = *itr->second;
_objects.erase(itr->second);
_objects.push_front(entry);
itr->second = _objects.begin();
output = itr->second->_object.get();
return output.valid();
}
return false;
}
Here is the call graph for this function:
Here is the caller graph for this function:Gets whether the given TileKey is cached or not
Reimplemented from osgEarth::Cache.
Definition at line 460 of file Caching.cpp.
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock( const_cast<MemCache*>(this)->_mutex);
std::string id = key.str() + spec.cacheId();
return _keyToIterMap.find(id) != _keyToIterMap.end();
//osg::ref_ptr<osg::Image> image = getImage(key,spec);
//return image.valid();
}
Here is the call graph for this function:| osgEarth::MemCache::META_Object | ( | osgEarth | , |
| MemCache | |||
| ) |
| bool MemCache::purge | ( | const std::string & | cacheId, |
| int | olderThan, | ||
| bool | async | ||
| ) | [virtual] |
Delete entries from the cache.
Reimplemented from osgEarth::Cache.
Definition at line 399 of file Caching.cpp.
{
//TODO: can this be a ReadWriteLock instead?
// MemCache does not support timestamps or async, so just clear it out altogether.
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
// MemCache does not support cacheId...
_keyToIterMap.clear();
_objects.clear();
return true;
}
| void MemCache::setHeightField | ( | const TileKey & | key, |
| const CacheSpec & | spec, | ||
| const osg::HeightField * | hf | ||
| ) | [virtual] |
Sets the cached heightfield for the given TileKey
Reimplemented from osgEarth::Cache.
Definition at line 393 of file Caching.cpp.
{
setObject( key, spec, new osg::HeightField(*hf) );
}
Here is the call graph for this function:| void MemCache::setImage | ( | const TileKey & | key, |
| const CacheSpec & | spec, | ||
| const osg::Image * | image | ||
| ) | [virtual] |
Sets the cached image for the given TileKey
Implements osgEarth::Cache.
Definition at line 375 of file Caching.cpp.
{
setObject( key, spec, ImageUtils::cloneImage(image) );
}
Here is the call graph for this function:| void MemCache::setMaxNumTilesInCache | ( | unsigned int | max | ) |
Sets the maximum number of tiles to keep in the cache
Definition at line 357 of file Caching.cpp.
{
_maxNumTilesInCache = max;
}
| void MemCache::setObject | ( | const TileKey & | key, |
| const CacheSpec & | spec, | ||
| const osg::Object * | image | ||
| ) | [protected] |
Sets the cached object for the given TileKey
Definition at line 433 of file Caching.cpp.
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
std::string id = key.str() + spec.cacheId();
_objects.push_front(CachedObject());
CachedObject& entry = _objects.front();
//CachedObject entry;
entry._object = referenced;
entry._key = id;
//_objects.push_front(entry);
_keyToIterMap[id] = _objects.begin();
if (_objects.size() > _maxNumTilesInCache)
{
_keyToIterMap.erase( _objects.back()._key );
_objects.pop_back();
//CachedObject toRemove = _objects.back();
//_objects.pop_back();
//_keyToIterMap.erase(toRemove._key);
}
}
Here is the call graph for this function:
Here is the caller graph for this function:KeyToIteratorMap osgEarth::MemCache::_keyToIterMap [protected] |
unsigned int osgEarth::MemCache::_maxNumTilesInCache [protected] |
OpenThreads::Mutex osgEarth::MemCache::_mutex [protected] |
ObjectList osgEarth::MemCache::_objects [protected] |
1.7.3