CachedMemoryMixin.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <SimoxUtility/json.h>
4 
6 
8 
10 {
11  template <class _CoreSegmentT>
13  {
14  public:
15  CachedMemoryMixin(const MemoryID& id) : cache(std::make_unique<armem::wm::Memory>(id))
16  {
17  }
18 
19  protected:
21  getCache() const
22  {
23  std::lock_guard l(this->cache_mutex);
24  return *cache;
25  }
26 
27  /// configuration
28  void
29  configureMixin(const nlohmann::json& json)
30  {
31  // TODO: Max cache size
32  }
33 
34  void
36  {
37  ARMARX_CHECK_NOT_EMPTY(id.memoryName) << " The full id was: " << id.str();
38 
39  cache->id() = id.getMemoryID();
40  }
41 
42  void
44  {
45  std::lock_guard l(cache_mutex);
46  cache->append(memory);
47  }
48 
49  bool
50  cacheHasCoreSegment(const std::string& n) const
51  {
52  std::lock_guard l(cache_mutex);
53  return cache->hasCoreSegment(n);
54  }
55 
56  bool
57  cacheHasCoreSegment(const MemoryID& n) const
58  {
59  std::lock_guard l(cache_mutex);
60  return cache->hasCoreSegment(n);
61  }
62 
63  bool
65  {
66  std::lock_guard l(cache_mutex);
67  return cache->hasProviderSegment(n);
68  }
69 
70  bool
71  cacheHasEntity(const MemoryID& n) const
72  {
73  std::lock_guard l(cache_mutex);
74  return cache->hasEntity(n);
75  }
76 
77  bool
79  {
80  std::lock_guard l(cache_mutex);
81  return cache->hasSnapshot(n);
82  }
83 
84  bool
86  {
87  std::lock_guard l(cache_mutex);
88  return cache->hasInstance(n);
89  }
90 
91 
92  protected:
93  std::unique_ptr<armem::wm::Memory> cache;
94 
95  private:
96  mutable std::recursive_mutex cache_mutex;
97  };
98 } // namespace armarx::armem::server::ltm::detail::mixin
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::setMixinMemoryID
void setMixinMemoryID(const MemoryID &id)
Definition: CachedMemoryMixin.h:35
armarx::armem
Definition: LegacyRobotStateMemoryAdapter.cpp:31
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::cacheHasProviderSegment
bool cacheHasProviderSegment(const MemoryID &n) const
Definition: CachedMemoryMixin.h:64
PeriodicTask.h
ARMARX_CHECK_NOT_EMPTY
#define ARMARX_CHECK_NOT_EMPTY(c)
Definition: ExpressionException.h:224
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::armem::server::ltm::Memory
A memory storing data on the hard drive and in mongodb (needs 'armarx memory start' to start the mong...
Definition: Memory.h:19
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::addToCache
void addToCache(const armem::wm::Memory &memory)
Definition: CachedMemoryMixin.h:43
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::configureMixin
void configureMixin(const nlohmann::json &json)
configuration
Definition: CachedMemoryMixin.h:29
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::cacheHasCoreSegment
bool cacheHasCoreSegment(const MemoryID &n) const
Definition: CachedMemoryMixin.h:57
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::cacheHasEntity
bool cacheHasEntity(const MemoryID &n) const
Definition: CachedMemoryMixin.h:71
memory_definitions.h
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::cache
std::unique_ptr< armem::wm::Memory > cache
Definition: CachedMemoryMixin.h:93
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin
Definition: CachedMemoryMixin.h:12
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::CachedMemoryMixin
CachedMemoryMixin(const MemoryID &id)
Definition: CachedMemoryMixin.h:15
armarx::armem::server::ltm::detail::mixin
Definition: BufferedMemoryMixin.cpp:3
std
Definition: Application.h:66
armarx::armem::laser_scans::constants::memoryName
const std::string memoryName
Definition: constants.h:28
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::cacheHasCoreSegment
bool cacheHasCoreSegment(const std::string &n) const
Definition: CachedMemoryMixin.h:50
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::cacheHasEntityInstance
bool cacheHasEntityInstance(const MemoryID &n) const
Definition: CachedMemoryMixin.h:85
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::getCache
armem::wm::Memory getCache() const
Definition: CachedMemoryMixin.h:21
armarx::armem::server::ltm::detail::mixin::CachedMemoryMixin::cacheHasEntitySnapshot
bool cacheHasEntitySnapshot(const MemoryID &n) const
Definition: CachedMemoryMixin.h:78