27 #ifndef TESSERACT_COMMON_OBJECT_CACHE_H
28 #define TESSERACT_COMMON_OBJECT_CACHE_H
36 #include <console_bridge/console.h>
50 template <
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()
86 std::shared_ptr<CacheType> cache =
getClone();
98 std::shared_ptr<CacheType> t;
99 if constexpr (has_member_func_signature_update<CacheType>::value)
105 std::shared_ptr<CacheType> cache =
getClone();
106 if (cache ==
nullptr)
116 std::shared_ptr<CacheType> t;
148 return static_cast<long>(
cache_.size());
158 std::shared_ptr<CacheType> t;
161 for (
auto& cache :
cache_)
163 if (cache->getRevision() !=
original_->getRevision())
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_;