EntityBase.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
5// BaseClass
9
10#include "EntitySnapshotBase.h"
11#include "MemoryItem.h"
12
14{
15 /// @brief Interface functions for the longterm memory classes
16 template <class _EntitySnapshotT>
17 class EntityBase : public MemoryItem
18 {
19 public:
21 {
23 };
24
25 public:
26 using EntitySnapshotT = _EntitySnapshotT;
27
29
30 /// return the full sub-ltm as a wm::Entity with only references
31 /// the ltm may be huge, use with caution
32 void
37
38 void
43
44 /// convert the references of the input into a wm::Memory
45 void
47 {
48 _resolve(e);
49 }
50
51 /// encode the content of a wm::Memory and store
52 void
53 store(const armem::wm::Entity& e, bool simulatedVersion)
54 {
55 _store(e, simulatedVersion);
56 }
57
58 /// statistics
59 void
61 {
62 statistics.recordedSnapshots = 0;
63 }
64
65 Statistics
67 {
68 return statistics;
69 }
70
71 /// iterate over all entity snapshots of this ltm
72 bool
73 forEachSnapshot(std::function<void(EntitySnapshotT&)> func) const
74 {
75 return _implForEachSnapshot(func);
76 }
77
78 bool
80 long last,
81 std::function<void(EntitySnapshotT&)> func) const
82 {
83 return _implForEachSnapshotInIndexRange(first, last, func);
84 }
85
86 bool
88 const Time& max,
89 std::function<void(EntitySnapshotT&)> func) const
90 {
92 }
93
94 bool
96 std::function<void(EntitySnapshotT&)> func) const
97 {
98 return _implForEachSnapshotBeforeOrAt(time, func);
99 }
100
101 bool
103 std::function<void(EntitySnapshotT&)> func) const
104 {
105 return _implForEachSnapshotBefore(time, func);
106 }
107
108 bool
110 std::function<bool(EntitySnapshotT&)> func) const
111 {
112 return _implForEachSnapshotBeforeReverse(time, func);
113 }
114
115 /// check if snapshot segment exists
116 bool
117 hasSnapshot(const Time& time) const
118 {
119 return _implHasSnapshot(time);
120 }
121
122 /// find entity snapshot segment
123 std::shared_ptr<EntitySnapshotT>
124 findSnapshot(const Time& time) const
125 {
126 return _implFindSnapshot(time);
127 }
128
129 std::shared_ptr<EntitySnapshotT>
131 {
133 }
134
135 std::shared_ptr<EntitySnapshotT>
137 {
139 }
140
141 std::shared_ptr<EntitySnapshotT>
143 {
145 }
146
147 std::shared_ptr<EntitySnapshotT>
148 findFirstSnapshotAfter(const Time& time) const
149 {
150 return _implFindFirstSnapshotAfter(time);
151 }
152
153 std::shared_ptr<EntitySnapshotT>
155 {
157 }
158
159 static std::string
161 {
162 return "LT-Entity";
163 }
164
165 protected:
167 virtual void _loadLatestNReferences(int n, armem::wm::Entity& e) = 0;
168 virtual void _resolve(armem::wm::Entity&) = 0;
169 virtual void _store(const armem::wm::Entity& e, bool simulatedVersion = false) = 0;
170
171 // Implementation methods - subclasses override these
172 // Thread safety is handled by DiskPersistence's per-directory mutexes
173 virtual bool _implForEachSnapshot(std::function<void(EntitySnapshotT&)> func) const = 0;
174 virtual bool
176 long last,
177 std::function<void(EntitySnapshotT&)> func) const = 0;
178 virtual bool
180 const Time& max,
181 std::function<void(EntitySnapshotT&)> func) const = 0;
182 virtual bool
184 std::function<void(EntitySnapshotT&)> func) const = 0;
185 virtual bool
187 std::function<void(EntitySnapshotT&)> func) const = 0;
188 virtual bool
190 std::function<bool(EntitySnapshotT&)> func) const = 0;
191
192 virtual bool _implHasSnapshot(const Time&) const = 0;
193
194 virtual std::shared_ptr<EntitySnapshotT> _implFindSnapshot(const Time&) const = 0;
195 virtual std::shared_ptr<EntitySnapshotT> _implFindLatestSnapshot() const = 0;
196 virtual std::shared_ptr<EntitySnapshotT>
197 _implFindLatestSnapshotBefore(const Time& time) const = 0;
198 virtual std::shared_ptr<EntitySnapshotT>
200 virtual std::shared_ptr<EntitySnapshotT>
201 _implFindFirstSnapshotAfter(const Time& time) const = 0;
202 virtual std::shared_ptr<EntitySnapshotT>
203 _implFindFirstSnapshotAfterOrAt(const Time& time) const = 0;
204
205 protected:
207 };
208} // namespace armarx::armem::server::ltm::detail
Interface functions for the longterm memory classes.
Definition EntityBase.h:18
std::shared_ptr< EntitySnapshotT > findSnapshot(const Time &time) const
find entity snapshot segment
Definition EntityBase.h:124
std::shared_ptr< EntitySnapshotT > findFirstSnapshotAfterOrAt(const Time &time) const
Definition EntityBase.h:154
std::shared_ptr< EntitySnapshotT > findFirstSnapshotAfter(const Time &time) const
Definition EntityBase.h:148
void resolve(armem::wm::Entity &e)
convert the references of the input into a wm::Memory
Definition EntityBase.h:46
virtual bool _implHasSnapshot(const Time &) const =0
bool forEachSnapshotBeforeReverse(const Time &time, std::function< bool(EntitySnapshotT &)> func) const
Definition EntityBase.h:109
std::shared_ptr< EntitySnapshotT > findLatestSnapshot() const
Definition EntityBase.h:130
virtual bool _implForEachSnapshotBeforeReverse(const Time &time, std::function< bool(EntitySnapshotT &)> func) const =0
virtual void _loadAllReferences(armem::wm::Entity &)=0
std::shared_ptr< EntitySnapshotT > findLatestSnapshotBefore(const Time &time) const
Definition EntityBase.h:136
bool forEachSnapshotBefore(const Time &time, std::function< void(EntitySnapshotT &)> func) const
Definition EntityBase.h:102
virtual bool _implForEachSnapshotInIndexRange(long first, long last, std::function< void(EntitySnapshotT &)> func) const =0
bool forEachSnapshotBeforeOrAt(const Time &time, std::function< void(EntitySnapshotT &)> func) const
Definition EntityBase.h:95
void store(const armem::wm::Entity &e, bool simulatedVersion)
encode the content of a wm::Memory and store
Definition EntityBase.h:53
std::shared_ptr< EntitySnapshotT > findLatestSnapshotBeforeOrAt(const Time &time) const
Definition EntityBase.h:142
bool forEachSnapshotInIndexRange(long first, long last, std::function< void(EntitySnapshotT &)> func) const
Definition EntityBase.h:79
void loadAllReferences(armem::wm::Entity &e)
return the full sub-ltm as a wm::Entity with only references the ltm may be huge, use with caution
Definition EntityBase.h:33
virtual std::shared_ptr< EntitySnapshotT > _implFindFirstSnapshotAfterOrAt(const Time &time) const =0
virtual std::shared_ptr< EntitySnapshotT > _implFindFirstSnapshotAfter(const Time &time) const =0
virtual bool _implForEachSnapshotBefore(const Time &time, std::function< void(EntitySnapshotT &)> func) const =0
virtual std::shared_ptr< EntitySnapshotT > _implFindLatestSnapshot() const =0
bool hasSnapshot(const Time &time) const
check if snapshot segment exists
Definition EntityBase.h:117
virtual std::shared_ptr< EntitySnapshotT > _implFindSnapshot(const Time &) const =0
virtual bool _implForEachSnapshotBeforeOrAt(const Time &time, std::function< void(EntitySnapshotT &)> func) const =0
virtual bool _implForEachSnapshot(std::function< void(EntitySnapshotT &)> func) const =0
bool forEachSnapshotInTimeRange(const Time &min, const Time &max, std::function< void(EntitySnapshotT &)> func) const
Definition EntityBase.h:87
virtual std::shared_ptr< EntitySnapshotT > _implFindLatestSnapshotBefore(const Time &time) const =0
virtual bool _implForEachSnapshotInTimeRange(const Time &min, const Time &max, std::function< void(EntitySnapshotT &)> func) const =0
virtual void _store(const armem::wm::Entity &e, bool simulatedVersion=false)=0
bool forEachSnapshot(std::function< void(EntitySnapshotT &)> func) const
iterate over all entity snapshots of this ltm
Definition EntityBase.h:73
void loadLatestNReferences(int n, armem::wm::Entity &e)
Definition EntityBase.h:39
virtual void _loadLatestNReferences(int n, armem::wm::Entity &e)=0
virtual void _resolve(armem::wm::Entity &)=0
MemoryItem(const std::string &exportName, const MemoryID &)
virtual std::shared_ptr< EntitySnapshotT > _implFindLatestSnapshotBeforeOrAt(const Time &time) const =0
MemoryItem(const std::string &exportName, const MemoryID &)
Client-side working memory entity.
armarx::core::time::DateTime Time
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)