Cortex
10.0.0-a4
|
#include <CachedReader.h>
Public Member Functions | |
IE_CORE_DECLAREMEMBERPTR (CachedReader) | |
CachedReader (const SearchPath &paths, ObjectPoolPtr objectPool=ObjectPool::defaultObjectPool()) | |
CachedReader (const SearchPath &paths, ConstModifyOpPtr postProcessor, ObjectPoolPtr objectPool=ObjectPool::defaultObjectPool()) | |
ConstObjectPtr | read (const std::string &file) |
void | clear () |
Frees all memory used by the cache. | |
void | clear (const std::string &file) |
Clears the cache for the given file. | |
void | insert (const std::string &file, ConstObjectPtr obj) |
Forces insertion on the cache for a file that is already loaded on memory. | |
bool | cached (const std::string &file) const |
Returns true if the object is cached on memory. | |
const SearchPath & | getSearchPath () const |
Returns the SearchPath in use. | |
void | setSearchPath (const SearchPath &paths) |
ObjectPool * | objectPool () const |
Returns the ObjectPool object used by this CachedReader. | |
![]() | |
IE_CORE_DECLAREMEMBERPTR (RefCounted) | |
void | addRef () const |
Add a reference to the current object. | |
void | removeRef () const |
Remove a reference from the current object. | |
RefCount | refCount () const |
Returns the current reference count. | |
Static Public Member Functions | |
static CachedReader * | defaultCachedReader () |
Additional Inherited Members | |
![]() | |
typedef size_t | RefCount |
The CachedReader class provides a means of loading files using the Reader subclasses, but caching them in memory to allow fast repeated loads. It uses a ObjectPool to store the images. It's recomended using the defaultObjectPool for sharing objects, which limits the memory used by the IECORE_OBJECTPOOL_MEMORY environment variable.
We probably need a way of setting parameters for the Readers, and treating reads with different parameters as different entities in the cache.
Stats on cache misses etc.
Can we do something to make sure that two paths to the same file (symlinks) result in only a single cache entry?
IECore::CachedReader::CachedReader | ( | const SearchPath & | paths, |
ObjectPoolPtr | objectPool = ObjectPool::defaultObjectPool() |
||
) |
Creates a reader that will search for files on the given paths and load them. Will use the given ObjectPool to store the loaded objects.
IECore::CachedReader::CachedReader | ( | const SearchPath & | paths, |
ConstModifyOpPtr | postProcessor, | ||
ObjectPoolPtr | objectPool = ObjectPool::defaultObjectPool() |
||
) |
As above, but also takes an Op which will be applied to objects following loading. Will use the given ObjectPool to store the loaded objects.
|
static |
Returns a static CachedReader instance to be used by anything wishing to share it's cache with others. It makes sense to use this wherever possible to conserve memory. This initially has searchPaths set from the IECORE_CACHEDREADER_PATHS environment variable. If it needs changing it's recommended to do that from a config file loaded by the ConfigLoader, to avoid multiple clients fighting over the same set of settings.
ConstObjectPtr IECore::CachedReader::read | ( | const std::string & | file | ) |
Searches for the given file and loads it if found. Throws an exception in case it cannot be found or no suitable Reader exists. The Object is returned with only const access as it actually refers to an object within the cache - you must call the copy() function on it if you wish to have something you are free to modify.
void IECore::CachedReader::setSearchPath | ( | const SearchPath & | paths | ) |
Changes the SearchPath used to find files. Note that this calls clear(), as changing the paths potentially invalidates the contents of the cache.