Cortex  10.0.0-a4
Public Member Functions | Static Public Member Functions | List of all members
IECore::CachedReader Class Reference

#include <CachedReader.h>

+ Inheritance diagram for IECore::CachedReader:

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 SearchPathgetSearchPath () const
 Returns the SearchPath in use.
 
void setSearchPath (const SearchPath &paths)
 
ObjectPoolobjectPool () const
 Returns the ObjectPool object used by this CachedReader.
 
- Public Member Functions inherited from IECore::RefCounted
 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 CachedReaderdefaultCachedReader ()
 

Additional Inherited Members

- Public Types inherited from IECore::RefCounted
typedef size_t RefCount
 

Detailed Description

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.

Todo:

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?

Constructor & Destructor Documentation

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.

Member Function Documentation

static CachedReader* IECore::CachedReader::defaultCachedReader ( )
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.

Threading:
It is safe to call this method from multiple concurrent threads.
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.


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