27#ifndef TESSERACT_COMMON_OBJECT_CACHE_H
28#define TESSERACT_COMMON_OBJECT_CACHE_H
36#include <console_bridge/console.h>
50template <
typename CacheType>
58 CloneCache(std::shared_ptr<CacheType> original, const
long& cache_size = 5)
65 static_assert(has_member_func_signature_getRevision<CacheType>::value,
66 "Class 'getRevision' function has incorrect signature");
67 static_assert(has_member_func_signature_clone<CacheType>::value,
"Class 'clone' function has incorrect signature");
69 for (
long i = 0; i < cache_size; i++)
79 std::shared_ptr<CacheType>
clone()
98 std::shared_ptr<CacheType> t;
99 if constexpr (has_member_func_signature_update<CacheType>::value)
106 if (
cache ==
nullptr)
116 std::shared_ptr<CacheType> t;
148 return static_cast<long>(
cache_.size());
158 std::shared_ptr<CacheType> t;
166 if constexpr (has_member_func_signature_update<CacheType>::value)
180 [](
const std::shared_ptr<CacheType>&
cache) { return (cache == nullptr); }),
185 CONSOLE_BRIDGE_logDebug(
"Adding clone to the cache. Current cache size: %i",
cache_.size());
187 if (
clone !=
nullptr)
201 if (
clone ==
nullptr)
211 std::shared_ptr<CacheType>
clone;
216 catch (std::exception& e)
218 CONSOLE_BRIDGE_logError(
"Clone Cache failed to update cache with the following exception: %s", e.what());
230 std::deque<std::shared_ptr<CacheType>>
cache_;
Used to create a cache of objects.
Definition: clone_cache.h:52
std::shared_ptr< CacheType > clone()
Gets a clone of original_.
Definition: clone_cache.h:79
std::deque< std::shared_ptr< CacheType > > cache_
A vector of cached objects.
Definition: clone_cache.h:230
const std::shared_ptr< CacheType > & operator->()
Definition: clone_cache.h:73
long getCacheSize() const
Get the set cache size.
Definition: clone_cache.h:139
void updateCache()
If original_ has changed it will update or rebuild the cache of objects.
Definition: clone_cache.h:152
std::shared_ptr< CacheType > original_
Definition: clone_cache.h:224
const bool supports_update
Definition: clone_cache.h:192
long getCurrentCacheSize() const
Get the current size of the cache.
Definition: clone_cache.h:145
std::shared_ptr< CacheType > getClone() const
Definition: clone_cache.h:209
void setCacheSize(long size)
Set the cache size.
Definition: clone_cache.h:126
std::size_t cache_size_
The assigned cache size.
Definition: clone_cache.h:227
std::mutex cache_mutex_
The mutex used when reading and writing to cache_.
Definition: clone_cache.h:233
void createClone()
Definition: clone_cache.h:195
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: allowed_collision_matrix.h:16
#define CREATE_MEMBER_FUNC_SIGNATURE_NOARGS_CHECK(func_name, return_type)
Check if a member function has a given return type that takes no arguments.
Definition: sfinae_utils.h:193
#define CREATE_MEMBER_FUNC_SIGNATURE_CHECK(func_name, return_type,...)
Check if a member function has a given return type.
Definition: sfinae_utils.h:168
object value
Definition: tesseract_common_serialization_unit.cpp:495
DefaultEnvironmentCache cache(env, 10)