Cortex  10.0.0-a4
Public Types | Public Member Functions | List of all members
IECore::ComputationCache< T > Class Template Reference

#include <ComputationCache.h>

+ Inheritance diagram for IECore::ComputationCache< T >:

Public Types

enum  MissingBehaviour { ThrowIfMissing = 0, NullIfMissing, ComputeIfMissing }
 Enum used to specify behavior when retrieving computation results from the cache.
 
typedef ObjectPool::StoreMode StoreMode
 
typedef boost::function< IECore::ConstObjectPtr(const T &)> ComputeFn
 
typedef boost::function< IECore::MurmurHash(const T &)> HashFn
 
- Public Types inherited from IECore::RefCounted
typedef size_t RefCount
 

Public Member Functions

 ComputationCache (ComputeFn computeFn, HashFn hashFn, size_t maxResults=10000, ObjectPoolPtr objectPool=ObjectPool::defaultObjectPool())
 
void clear ()
 Removes all the stored computation information from the cache.
 
void erase (const T &args)
 Removes stored information about a specific computation result.
 
size_t getMaxComputations () const
 Returns the maximum number of stored computations in the cache.
 
void setMaxComputations (size_t maxComputations)
 Defines the maximum number of stored computations allowed in the cache. May trigger deallocation.
 
size_t cachedComputations () const
 Returns the number of stored computations.
 
ConstObjectPtr get (const T &args, MissingBehaviour missingBehaviour=ComputeIfMissing)
 
void set (const T &args, const Object *obj, StoreMode storeMode)
 Registers the result of a computation explicitly.
 
ObjectPoolobjectPool () const
 Returns the ObjectPool object used by this computation cache.
 
- 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.
 

Detailed Description

template<typename T>
class IECore::ComputationCache< T >

LRUCache for generic computation that results on Object derived classes. It uses ObjectPool for the storage and retrieval of the computation results, and internally it only holds a map of computationHash to objectHash. The get functions will return the resulting Object, which should be copied prior to modification. The retrieve function will only query the cache and not force computation.

Constructor & Destructor Documentation

template<typename T >
IECore::ComputationCache< T >::ComputationCache ( ComputeFn  computeFn,
HashFn  hashFn,
size_t  maxResults = 10000,
ObjectPoolPtr  objectPool = ObjectPool::defaultObjectPool() 
)

Constructs a cache for the given computation function and hash functions.

Parameters
computeFnFunctor that should know return the computation result from the templated parameters.
hashFnFunctor that should compute a unique hash from the templated parameters identifying the computation result.
maxResultsLimits the number of computation results this cache will hold.
objectPoolAllows overriding the ObjectPool instance to be used for holding the resulting computed objects.

Member Function Documentation

template<typename T >
ConstObjectPtr IECore::ComputationCache< T >::get ( const T &  args,
MissingBehaviour  missingBehaviour = ComputeIfMissing 
)

Returns the computation results if available on the cache, otherwise behaves according to the missingBehavior parameter explained below: ThrowIfMissing: Throws an Exception. NullIfMissing: Returns NULL pointer. ComputeIfMissing: Uses the compute function to generate the result and store it in the cache before returning it.


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