EntityInstanceBase.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include "detail/MemoryItem.h"
7 
8 namespace armarx::armem::base
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  /// Called whenever the entity instance this metadata belongs to is accessed (e.g. queried).
63  void access() const;
64 
65  bool operator==(const EntityInstanceMetadata& other) const;
66 
67  inline bool
68  operator!=(const EntityInstanceMetadata& other) const
69  {
70  return !(*this == other);
71  }
72  };
73 
74  std::ostream& operator<<(std::ostream& os, const EntityInstanceMetadata& rhs);
75 
76  /**
77  * @brief Data of a single entity instance.
78  */
79  template <class _DataT = NoData, class _MetadataT = EntityInstanceMetadata>
81  {
82  using Base = detail::MemoryItem;
83 
84  public:
85  using MetadataT = _MetadataT;
86  using DataT = _DataT;
87 
89  {
90  }
91 
92  explicit EntityInstanceBase(int index, const MemoryID& parentID = {}) :
93  EntityInstanceBase(parentID.withInstanceIndex(index))
94  {
95  }
96 
97  explicit EntityInstanceBase(const MemoryID& id) : Base(id)
98  {
99  }
100 
101  // Key
102  inline int&
104  {
105  return id().instanceIndex;
106  }
107 
108  inline int
109  index() const
110  {
111  return id().instanceIndex;
112  }
113 
114  // Data
115 
116  MetadataT&
118  {
119  return _metadata;
120  }
121 
122  const MetadataT&
123  metadata() const
124  {
125  return _metadata;
126  }
127 
128  const DataT&
129  data() const
130  {
131  return _data;
132  }
133 
134  DataT&
136  {
137  return _data;
138  }
139 
140  void
142  {
143  _data = data;
144  }
145 
146  void
148  {
150  }
151 
152  /**
153  * @brief Get the data converted to a generated Aron DTO class.
154  */
155  template <class AronDtoT>
156  AronDtoT
157  dataAs() const
158  {
159  return AronDtoT::FromAron(_data);
160  }
161 
162  template <class AronDtoT>
164  withDataAs() const
165  {
167  instance.data() = dataAs<AronDtoT>();
168  instance.metadata() = _metadata;
169  return instance;
170  }
171 
172  // Misc
173 
174  static std::string
176  {
177  return "entity instance";
178  }
179 
180  std::string
181  getKeyString() const
182  {
183  return std::to_string(index());
184  }
185 
186 
187  protected:
188  /// The metadata.
190 
191  /// The data. May be nullptr.
193  };
194 
195 } // namespace armarx::armem::base
armarx::armem::base
Definition: CoreSegmentBase.h:15
armarx::armem::base::EntityInstanceMetadata::numAccessed
unsigned long numAccessed
A counter how often the instance has been accessed.
Definition: EntityInstanceBase.h:60
armarx::armem::base::NoData::~NoData
virtual ~NoData()=default
armarx::armem::base::EntityInstanceMetadata::~EntityInstanceMetadata
virtual ~EntityInstanceMetadata()=default
armarx::armem::base::EntityInstanceBase< EntityInstanceDataPtr, EntityInstanceMetadata >::DataT
EntityInstanceDataPtr DataT
Definition: EntityInstanceBase.h:86
armarx::armem::base::detail::MemoryItem
Base class of memory classes on different levels.
Definition: MemoryItem.h:14
armarx::armem::base::EntityInstanceBase::_data
DataT _data
The data. May be nullptr.
Definition: EntityInstanceBase.h:192
armarx::armem::base::EntityInstanceBase::index
int & index()
Definition: EntityInstanceBase.h:103
armarx::armem::base::EntityInstanceBase::withDataAs
EntityInstanceBase< AronDtoT, MetadataT > withDataAs() const
Definition: EntityInstanceBase.h:164
armarx::armem::wm::EntityInstanceMetadata
base::EntityInstanceMetadata EntityInstanceMetadata
Client-side working memory entity instance metadata.
Definition: memory_definitions.h:18
armarx::armem::base::EntityInstanceBase::data
DataT & data()
Definition: EntityInstanceBase.h:135
armarx::armem::base::EntityInstanceBase::EntityInstanceBase
EntityInstanceBase(const MemoryID &id)
Definition: EntityInstanceBase.h:97
armarx::armem::MemoryID::instanceIndex
int instanceIndex
Definition: MemoryID.h:55
armarx::armem::base::EntityInstanceBase::getLevelName
static std::string getLevelName()
Definition: EntityInstanceBase.h:175
armarx::armem::base::EntityInstanceBase::_metadata
MetadataT _metadata
The metadata.
Definition: EntityInstanceBase.h:189
armarx::armem::base::EntityInstanceBase::dataAs
AronDtoT dataAs() const
Get the data converted to a generated Aron DTO class.
Definition: EntityInstanceBase.h:157
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::base::EntityInstanceMetadata::sentTime
Time sentTime
Time when this value was sent to the memory.
Definition: EntityInstanceBase.h:49
armarx::armem::base::EntityInstanceMetadata::access
void access() const
Called whenever the entity instance this metadata belongs to is accessed (e.g. queried).
Definition: EntityInstanceBase.cpp:6
armarx::armem::base::NoData::operator==
bool operator==(const NoData &other)
Definition: EntityInstanceBase.h:19
armarx::armem::base::EntityInstanceBase::metadata
const MetadataT & metadata() const
Definition: EntityInstanceBase.h:123
armarx::armem::base::EntityInstanceMetadata::operator==
bool operator==(const EntityInstanceMetadata &other) const
Definition: EntityInstanceBase.cpp:12
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
armarx::armem::base::EntityInstanceMetadata::arrivedTime
Time arrivedTime
Time when this value has arrived at the memory.
Definition: EntityInstanceBase.h:51
armarx::armem::base::EntityInstanceBase::setMetadata
void setMetadata(const MetadataT &metadata)
Definition: EntityInstanceBase.h:147
armarx::armem::base::EntityInstanceBase::EntityInstanceBase
EntityInstanceBase()
Definition: EntityInstanceBase.h:88
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::armem::base::EntityInstanceBase
Data of a single entity instance.
Definition: EntityInstanceBase.h:80
armarx::armem::base::EntityInstanceBase::MetadataT
_MetadataT MetadataT
Definition: EntityInstanceBase.h:85
armarx::armem::base::EntityInstanceBase::EntityInstanceBase
EntityInstanceBase(int index, const MemoryID &parentID={})
Definition: EntityInstanceBase.h:92
Commit.h
armarx::armem::base::EntityInstanceMetadata::referencedTime
Time referencedTime
Time this instance refers to.
Definition: EntityInstanceBase.h:46
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::base::EntityInstanceBase::setData
void setData(const DataT &data)
Definition: EntityInstanceBase.h:141
armarx::armem::base::detail::MemoryItem::_id
MemoryID _id
Definition: MemoryItem.h:46
armarx::armem::base::EntityInstanceBase::getKeyString
std::string getKeyString() const
Definition: EntityInstanceBase.h:181
armarx::armem::base::EntityInstanceBase::index
int index() const
Definition: EntityInstanceBase.h:109
Time.h
armarx::armem::base::EntityInstanceMetadata
Metadata of an entity instance.
Definition: EntityInstanceBase.h:34
armarx::armem::base::EntityInstanceMetadata::lastAccessedTime
Time lastAccessedTime
An optional value indicating the time of last access.
Definition: EntityInstanceBase.h:57
armarx::armem::base::EntityInstanceMetadata::confidence
float confidence
An optional confidence, may be used for things like decay.
Definition: EntityInstanceBase.h:54
armarx::armem::base::EntityInstanceBase::metadata
MetadataT & metadata()
Definition: EntityInstanceBase.h:117
armarx::armem::base::operator<<
std::ostream & operator<<(std::ostream &os, const EntityInstanceMetadata &rhs)
Definition: EntityInstanceBase.cpp:22
armarx::armem::base::EntityInstanceBase::data
const DataT & data() const
Definition: EntityInstanceBase.h:129
armarx::armem::base::EntityInstanceMetadata::operator!=
bool operator!=(const EntityInstanceMetadata &other) const
Definition: EntityInstanceBase.h:68
armarx::armem::base::NoData::operator!=
bool operator!=(const NoData &other)
Definition: EntityInstanceBase.h:25
armarx::core::time::DateTime::Invalid
static DateTime Invalid()
Definition: DateTime.cpp:60
armarx::armem::base::NoData
Default data of an entity instance (empty).
Definition: EntityInstanceBase.h:14