EntitySnapshotBase.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
5// BaseClass
9
10#include "EntityBase.h"
11#include "MemoryItem.h"
12
14{
15 /// @brief Interface functions for the longterm memory classes
16 template <class InstanceT>
18 {
19 public:
21 {
23 };
24
25 public:
27
28 /// return the full sub-ltm as a wm::EntitySnapshot with only references
29 /// the ltm may be huge, use with caution
30 void
35
36 /// convert the references of the input into a wm::Memory
37 void
39 {
40 _resolve(e);
41 }
42
43 /// encode the content of a wm::Memory and store
44 void
46 {
47 _store(e);
48 }
49
50 /// statistics
51 void
53 {
54 statistics.recordedInstances = 0;
55 }
56
57 Statistics
59 {
60 return statistics;
61 }
62
63 static std::string
65 {
66 return "LT-EntitySnapshot";
67 }
68
69 /// iterate over all Instance segments of this ltm
70 bool
71 forEachInstance(std::function<void(InstanceT&)> func) const
72 {
73 return _implForEachInstance(func);
74 }
75
76 /// check if Instance segment exists
77 bool
78 hasInstance(const int instanceId) const
79 {
80 return _implHasInstance(instanceId);
81 }
82
83 /// find Instance segment
84 std::shared_ptr<InstanceT>
85 findInstance(const int instanceId) const
86 {
87 return _implFindInstance(instanceId);
88 }
89
90 protected:
92 virtual void _resolve(armem::wm::EntitySnapshot&) const = 0;
93 virtual void _store(const armem::wm::EntitySnapshot& s) = 0;
94
95 // Implementation methods - subclasses override these
96 // Thread safety is handled by DiskPersistence's per-directory mutexes
97 virtual bool _implForEachInstance(std::function<void(InstanceT&)> func) const = 0;
98 virtual bool _implHasInstance(const int instanceId) const = 0;
99 virtual std::shared_ptr<InstanceT> _implFindInstance(const int instanceId) const = 0;
100
101 protected:
103 };
104} // namespace armarx::armem::server::ltm::detail
Interface functions for the longterm memory classes.
bool hasInstance(const int instanceId) const
check if Instance segment exists
virtual bool _implHasInstance(const int instanceId) const =0
void resolve(armem::wm::EntitySnapshot &e) const
convert the references of the input into a wm::Memory
void loadAllReferences(armem::wm::EntitySnapshot &e) const
return the full sub-ltm as a wm::EntitySnapshot with only references the ltm may be huge,...
std::shared_ptr< InstanceT > findInstance(const int instanceId) const
find Instance segment
bool forEachInstance(std::function< void(InstanceT &)> func) const
iterate over all Instance segments of this ltm
void store(const armem::wm::EntitySnapshot &e)
encode the content of a wm::Memory and store
virtual void _resolve(armem::wm::EntitySnapshot &) const =0
virtual bool _implForEachInstance(std::function< void(InstanceT &)> func) const =0
virtual std::shared_ptr< InstanceT > _implFindInstance(const int instanceId) const =0
virtual void _store(const armem::wm::EntitySnapshot &s)=0
virtual void _loadAllReferences(armem::wm::EntitySnapshot &) const =0
MemoryItem(const std::string &exportName, const MemoryID &)
MemoryItem(const std::string &exportName, const MemoryID &)
Client-side working memory entity snapshot.