Drake
Cache Class Reference

Stores all the CacheEntryValue objects owned by a particular Context, organized to allow fast access using a CacheIndex as an index. More...

#include <drake/systems/framework/cache.h>

Public Member Functions

 Cache (const internal::ContextMessageInterface *owning_subcontext)
 Constructor creates an empty cache referencing the system pathname service of its owning subcontext. More...
 
 ~Cache ()=default
 Destruction deletes all cache entries and their contained values; no dependency notifications are issued. More...
 
CacheEntryValueCreateNewCacheEntryValue (CacheIndex index, DependencyTicket ticket, const std::string &description, const std::set< DependencyTicket > &prerequisites, DependencyGraph *graph)
 Allocates a new CacheEntryValue and provides it a DependencyTracker using the given CacheIndex and DependencyTicket number. More...
 
bool has_cache_entry_value (CacheIndex index) const
 Returns true if there is a CacheEntryValue in this cache that has the given index. More...
 
int cache_size () const
 Returns the current size of the Cache container, providing for CacheIndex values from 0..cache_size()-1. More...
 
const CacheEntryValueget_cache_entry_value (CacheIndex index) const
 Returns a const CacheEntryValue given an index. More...
 
CacheEntryValueget_mutable_cache_entry_value (CacheIndex index)
 Returns a mutable CacheEntryValue given an index. More...
 
void DisableCaching ()
 (Advanced) Disables caching for all the entries in this Cache. More...
 
void EnableCaching ()
 (Advanced) Re-enables caching for all entries in this Cache if any were previously disabled. More...
 
void SetAllEntriesOutOfDate ()
 (Advanced) Mark every entry in this cache as "out of date". More...
 
Does not allow move or assignment; copy constructor is private.
 Cache (Cache &&)=delete
 
void operator= (const Cache &)=delete
 
void operator= (Cache &&)=delete
 

Friends

class ContextBase
 

Detailed Description

Stores all the CacheEntryValue objects owned by a particular Context, organized to allow fast access using a CacheIndex as an index.

Memory addresses of CacheEntryValue objects are stable once allocated, but CacheIndex numbers are stable even after a Context has been copied so should be preferred as a means for identifying particular cache entries.

Constructor & Destructor Documentation

Cache ( Cache &&  )
delete
Cache ( const internal::ContextMessageInterface *  owning_subcontext)
inlineexplicit

Constructor creates an empty cache referencing the system pathname service of its owning subcontext.

The supplied pointer must not be null.

~Cache ( )
default

Destruction deletes all cache entries and their contained values; no dependency notifications are issued.

Member Function Documentation

int cache_size ( ) const
inline

Returns the current size of the Cache container, providing for CacheIndex values from 0..cache_size()-1.

Note that it is possible to have empty slots in the cache. Use has_cache_entry_value() to determine if there is a cache entry associated with a particular index.

CacheEntryValue & CreateNewCacheEntryValue ( CacheIndex  index,
DependencyTicket  ticket,
const std::string &  description,
const std::set< DependencyTicket > &  prerequisites,
DependencyGraph graph 
)

Allocates a new CacheEntryValue and provides it a DependencyTracker using the given CacheIndex and DependencyTicket number.

The CacheEntryValue object is owned by this Cache and the returned reference remains valid if other cache entry values are created. If there is a pre-existing tracker with the given ticket number (allowed only for well-known cached computations, such as time derivatives), it is assigned the new cache entry value to manage. Otherwise a new DependencyTracker is created. The created tracker object is owned by the given DependencyGraph, which must be owned by the same Context that owns this Cache. The graph must already contain trackers for the indicated prerequisites. The tracker will retain a pointer to the created CacheEntryValue for invalidation purposes.

void DisableCaching ( )

(Advanced) Disables caching for all the entries in this Cache.

Note that this is done by setting individual is_disabled flags in the entries, so it can be changed on a per-entry basis later. This has no effect on the out_of_date flags.

void EnableCaching ( )

(Advanced) Re-enables caching for all entries in this Cache if any were previously disabled.

Note that this is done by clearing individual is_disabled flags in the entries, so it overrides any disabling that may have been done to individual entries. This has no effect on the out_of_date flags so subsequent Eval() calls might not initiate recomputation. Use SetAllEntriesOutOfDate() if you want to force recomputation.

const CacheEntryValue& get_cache_entry_value ( CacheIndex  index) const
inline

Returns a const CacheEntryValue given an index.

This is very fast. Behavior is undefined if the index is out of range [0..cache_size()-1] or if there is no CacheEntryValue with that index. Use has_cache_entry_value() first if you aren't sure.

CacheEntryValue& get_mutable_cache_entry_value ( CacheIndex  index)
inline

Returns a mutable CacheEntryValue given an index.

This is very fast. Behavior is undefined if the index is out of range [0..cache_size()-1] or if there is no CacheEntryValue with that index. Use has_cache_entry_value() first if you aren't sure.

bool has_cache_entry_value ( CacheIndex  index) const
inline

Returns true if there is a CacheEntryValue in this cache that has the given index.

void operator= ( const Cache )
delete
void operator= ( Cache &&  )
delete
void SetAllEntriesOutOfDate ( )

(Advanced) Mark every entry in this cache as "out of date".

This forces the next Eval() request for an entry to perform a recalculation. After that normal caching behavior resumes.

Friends And Related Function Documentation

friend class ContextBase
friend

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