EntityInstanceBase.h
Go to the documentation of this file.
1#pragma once
2
5
6#include "detail/MemoryItem.h"
7
9{
10
11 /**
12 * @brief Default data of an entity instance (empty).
13 */
14 struct NoData
15 {
16 virtual ~NoData() = default;
17
18 bool
19 operator==(const NoData& other)
20 {
21 return true;
22 }
23
24 bool
25 operator!=(const NoData& other)
26 {
27 return false;
28 }
29 };
30
31 /**
32 * @brief Metadata of an entity instance.
33 */
35 {
36
37 virtual ~EntityInstanceMetadata() = default;
38
39 /**
40 * @brief Time this instance refers to.
41 *
42 * For example, the physical time point when an image was captured.
43 * If the image is processed, the result should have the same
44 * referencedTime as the image.
45 */
47
48 /// Time when this value was sent to the memory.
50 /// Time when this value has arrived at the memory.
52
53 /// An optional confidence, may be used for things like decay.
54 float confidence = 1.0;
55
56 /// An optional value indicating the time of last access.
58
59 /// A counter how often the instance has been accessed.
60 mutable unsigned long numAccessed = 0;
61
62 /// Indicates the source of the instance e.g. from a specific LTM
63 std::string origin = "undefinied";
64
65 /// Called whenever the entity instance this metadata belongs to is accessed (e.g. queried).
66 void access() const;
67
68 bool operator==(const EntityInstanceMetadata& other) const;
69
70 inline bool
72 {
73 return !(*this == other);
74 }
75 };
76
77 std::ostream& operator<<(std::ostream& os, const EntityInstanceMetadata& rhs);
78
79 /**
80 * @brief Data of a single entity instance.
81 */
82 template <class _DataT = NoData, class _MetadataT = EntityInstanceMetadata>
84 {
85 using Base = detail::MemoryItem;
86
87 public:
88 using MetadataT = _MetadataT;
89 using DataT = _DataT;
90
92 {
93 }
94
95 explicit EntityInstanceBase(int index, const MemoryID& parentID = {}) :
96 EntityInstanceBase(parentID.withInstanceIndex(index))
97 {
98 }
99
100 explicit EntityInstanceBase(const MemoryID& id) : Base(id)
101 {
102 }
103
104 // Key
105 inline int&
107 {
108 return id().instanceIndex;
109 }
110
111 inline int
112 index() const
113 {
114 return id().instanceIndex;
115 }
116
117 // Data
118
119 MetadataT&
121 {
122 return _metadata;
123 }
124
125 const MetadataT&
126 metadata() const
127 {
128 return _metadata;
129 }
130
131 const DataT&
132 data() const
133 {
134 return _data;
135 }
136
137 DataT&
139 {
140 return _data;
141 }
142
143 void
145 {
146 _data = data;
147 }
148
149 void
151 {
153 }
154
155 /**
156 * @brief Get the data converted to a generated Aron DTO class.
157 */
158 template <class AronDtoT>
159 AronDtoT
160 dataAs() const
161 {
162 return AronDtoT::FromAron(_data);
163 }
164
165 template <class AronDtoT>
168 {
170 instance.data() = dataAs<AronDtoT>();
171 instance.metadata() = _metadata;
172 return instance;
173 }
174
175 // Misc
176
177 static std::string
179 {
180 return "entity instance";
181 }
182
183 std::string
185 {
186 return std::to_string(index());
187 }
188
189
190 protected:
191 /// The metadata.
193
194 /// The data. May be nullptr.
196 };
197
198} // namespace armarx::armem::base
Data of a single entity instance.
void setMetadata(const MetadataT &metadata)
AronDtoT dataAs() const
Get the data converted to a generated Aron DTO class.
EntityInstanceBase(int index, const MemoryID &parentID={})
EntityInstanceBase< AronDtoT, MetadataT > withDataAs() const
Base class of memory classes on different levels.
Definition MemoryItem.h:14
static DateTime Invalid()
Definition DateTime.cpp:57
std::ostream & operator<<(std::ostream &os, const EntityInstanceMetadata &rhs)
armarx::core::time::DateTime Time
float confidence
An optional confidence, may be used for things like decay.
Time lastAccessedTime
An optional value indicating the time of last access.
unsigned long numAccessed
A counter how often the instance has been accessed.
bool operator!=(const EntityInstanceMetadata &other) const
Time arrivedTime
Time when this value has arrived at the memory.
Time referencedTime
Time this instance refers to.
void access() const
Called whenever the entity instance this metadata belongs to is accessed (e.g. queried).
std::string origin
Indicates the source of the instance e.g. from a specific LTM.
bool operator==(const EntityInstanceMetadata &other) const
Time sentTime
Time when this value was sent to the memory.
Default data of an entity instance (empty).
bool operator!=(const NoData &other)
virtual ~NoData()=default
bool operator==(const NoData &other)