|
Katana Plug-in APIs 0.1
|
The AttributeKeyedCache is a templated class which takes an Attribute as a key and maps it to an instance of the templated type. More...
#include <AttributeKeyedCache.h>
Public Member Functions | |
| AttributeKeyedCache (const std::size_t maxNumEntries=0xffffffff, const std::size_t maxNumInvalidKeys=0xffffffff) | |
| IMPLPtr | getValue (const FnAttribute::Attribute &iAttr) |
| void | clear () |
Protected Member Functions | |
| virtual IMPLPtr | createValue (const FnAttribute::Attribute &iAttr)=0 |
The AttributeKeyedCache is a templated class which takes an Attribute as a key and maps it to an instance of the templated type.
The cache accepts any Attribute to be used as the key, internally the cache relies upon the attribute's hash. The use of the hash as a key allows for efficient storage even with very large keys such as large CEL statements.
In order to make use of the cache the pure virtual function createValue() must be implemented. This function will be called by the cache in response to client requests for a particular value via getValue(attr). createValue() must return a valid object instance or a null pointer.
The cache is actually composed of two internal caches. The main cache contains mappings for all valid key-value mappings. The 'invalid' cache contains mappings of all invalid hash values. That is, all attribute hash values that return NULL when passed to your createValue() implementation. In the following example, all Attributes whose hash is even will be placed in the main cache, all odd hash values will be stored in the invalid cache.
class EvenIntegerCache: public FnGeolibUtil::AttributeKeyedCache<int64_t> { public: EvenIntegerCache(std::size_t maxNumEntries, std::size_t maxNumInvalidKeys) : FnGeolibUtil::AttributeKeyedCache<int64_t>(maxNumEntries, maxNumInvalidKeys) {} private: EvenIntegerCache::IMPLPtr createValue(const FnAttribute::Attribute &attr) { // Only return valid value if the attribute's hash is even. int64_t hash = attr.getHash().uint64(); if( hash & 0x1 ) return EvenIntegerCache::IMPLPtr(); else return EvenIntegerCache::IMPLPtr(new int64_t(hash)); } };
| Foundry::Katana::Util::AttributeKeyedCache< T, PointerT, Base >::AttributeKeyedCache | ( | const std::size_t | maxNumEntries = 0xffffffff, |
| const std::size_t | maxNumInvalidKeys = 0xffffffff |
||
| ) | [inline] |
Construct new instance of the AttributeKeyedCache with specified cache size and invalid cache item size.
| maxNumEntries | maximum size of the main cache, once the number of entries in the cache grows above this value existing entries will be removed. |
| maxNumInvalidKeys | maximum size of the invalid key set, once the number of entries in the cache grows above this value existing entries will be removed. |
| void Foundry::Katana::Util::AttributeKeyedCache< T, PointerT, Base >::clear | ( | ) | [inline] |
Clears all entries from the cache.
| virtual IMPLPtr Foundry::Katana::Util::AttributeKeyedCache< T, PointerT, Base >::createValue | ( | const FnAttribute::Attribute & | iAttr | ) | [protected, pure virtual] |
Called by getValue() to obtain an instance of the templated type which corresponds to the specified attribute.
Subclasses of AttributeKeyedCache should implement whatever logic necessary to determine the appropriate value to be returned given the supplied attribute. If no value is appropriate NULL should be returned.
Note: The implementation of createValue() WILL be called from multiple threads and therefore, must be thread safe.
| iAttr | the attribute which should be used |
| IMPLPtr Foundry::Katana::Util::AttributeKeyedCache< T, PointerT, Base >::getValue | ( | const FnAttribute::Attribute & | iAttr | ) | [inline] |
Returns a pointer to the value that corresponds to the specified attribute. Returns NULL if the there is no corresponding value for the specified attribute.
| iAttr | the attribute key |
1.7.3